Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions GitUp/Application/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ @interface AppDelegate () <UNUserNotificationCenterDelegate, SPUUpdaterDelegate,
@property(nonatomic, strong) CloneWindowController* cloneWindowController;
@property(nonatomic, strong) PreferencesWindowController* preferencesWindowController;
@property(nonatomic, strong) WelcomeWindowController* welcomeWindowController;
@property(nonatomic, weak) IBOutlet NSMenuItem* openInNewTabMenuItem;
@end

@implementation AppDelegate {
Expand Down Expand Up @@ -175,6 +176,12 @@ - (void)_openDocumentAtURL:(NSURL*)url {

- (void)handleDocumentCountChanged {
[self.welcomeWindowController handleDocumentCountChanged];

// Only offer "Open in New Tab…" as the Option alternate of "Open…" when there is a repository window to add a tab to
// (AppKit still swaps in hidden alternates, so the item must also stop being one)
BOOL hasDocuments = ([[NSDocumentController sharedDocumentController] documents].count > 0);
_openInNewTabMenuItem.hidden = !hasDocuments;
_openInNewTabMenuItem.alternate = hasDocuments;
}

- (void)_showNotificationWithTitle:(NSString*)title action:(SEL)action message:(NSString*)format, ... NS_FORMAT_FUNCTION(3, 4) {
Expand Down Expand Up @@ -381,6 +388,16 @@ - (IBAction)openDocument:(id)sender {
[[NSDocumentController sharedDocumentController] openDocument:sender];
}

- (IBAction)openDocumentInNewTab:(id)sender {
NSDocumentController* controller = [NSDocumentController sharedDocumentController];
[controller beginOpenPanelWithCompletionHandler:^(NSArray<NSURL*>* urls) {
BOOL inTab = (controller.documents.count > 0); // Fall back to a new window if the last repository window was closed in the meantime
for (NSURL* url in urls) {
[self _openRepositoryWithURL:url inTab:inTab withCloneMode:kCloneMode_None windowModeID:NSNotFound];
}
}];
}

- (IBAction)viewWiki:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:kURL_Wiki]];
}
Expand Down
12 changes: 11 additions & 1 deletion GitUp/Application/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="openInNewTabMenuItem" destination="T4b-oP-nNw" id="T4b-oP-oLt"/>
</connections>
</customObject>
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
<items>
<menuItem title="GitUp" id="1Xt-HY-uBw">
Expand Down Expand Up @@ -102,6 +106,12 @@
<action selector="openDocument:" target="-1" id="FlH-np-HFe"/>
</connections>
</menuItem>
<menuItem title="Open in New Tab…" alternate="YES" keyEquivalent="o" id="T4b-oP-nNw">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="openDocumentInNewTab:" target="-1" id="T4b-oP-aCt"/>
</connections>
</menuItem>
<menuItem title="Open Recent" id="H69-uH-spF">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="YgH-RV-NQr">
Expand Down
14 changes: 10 additions & 4 deletions GitUpKit/Utilities/GIWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ - (instancetype)initWithWindow:(NSWindow*)window {
if ((self = [super initWithWindow:window])) {
[[NSBundle bundleForClass:[GIWindowController class]] loadNibNamed:@"GIWindowController" owner:self topLevelObjects:NULL];
XLOG_DEBUG_CHECK(_overlayView);
_overlayView.translatesAutoresizingMaskIntoConstraints = NO;
[_overlayView.heightAnchor constraintEqualToConstant:_overlayView.frame.size.height].active = YES;

_area = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:(NSTrackingInVisibleRect | NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited) owner:self userInfo:nil];
[_overlayView addTrackingArea:_area];
Expand Down Expand Up @@ -230,11 +232,15 @@ - (void)showOverlayWithStyle:(GIOverlayStyle)style message:(NSString*)message {
}

if (_overlayView.superview == nil) {
NSRect bounds = self.window.contentLayoutRect;
NSRect frame = _overlayView.frame;
_overlayView.frame = NSMakeRect(0, bounds.size.height - frame.size.height, bounds.size.width, frame.size.height);
NSView* contentView = self.window.contentView;
_overlayView.alphaValue = 0;
[self.window.contentView addSubview:_overlayView]; // Must be above everything else
[contentView addSubview:_overlayView]; // Must be above everything else
[NSLayoutConstraint activateConstraints:@[
[_overlayView.topAnchor constraintEqualToAnchor:contentView.safeAreaLayoutGuide.topAnchor], // Follows the titlebar as the tab bar appears or disappears
[_overlayView.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor],
[_overlayView.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor]
]];
[contentView layoutSubtreeIfNeeded];
[CATransaction flush];

_overlayTextField.stringValue = message;
Expand Down
Loading