Skip to content

Commit

Permalink
Add menu item to pin a hotkey window
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Oct 23, 2016
1 parent 833353d commit 865bd84
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
15 changes: 12 additions & 3 deletions Interfaces/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16A320" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand Down Expand Up @@ -1039,6 +1039,15 @@ DQ
<menuItem isSeparatorItem="YES" id="zl8-Q7-4RO">
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</menuItem>
<menuItem title="Pin Hotkey Window" keyEquivalent="-" id="Kd2-6A-mAn">
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
<connections>
<action selector="togglePinHotkeyWindow:" target="201" id="lqK-e4-zQn"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="tbC-nC-pds">
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</menuItem>
<menuItem title="Bring All To Front" id="f7R-Y0-F8w">
<connections>
<action selector="arrangeInFront:" target="-1" id="DIN-7V-f31"/>
Expand Down
14 changes: 14 additions & 0 deletions sources/iTermApplicationDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,16 @@ - (void)awakeFromNib {
}
}

- (iTermProfileHotKey *)currentProfileHotkey {
PseudoTerminal *term = [[iTermController sharedInstance] currentTerminal];
return [[iTermHotKeyController sharedInstance] profileHotKeyForWindowController:term];
}

- (IBAction)togglePinHotkeyWindow:(id)sender {
iTermProfileHotKey *profileHotkey = self.currentProfileHotkey;
profileHotkey.pinned = !profileHotkey.pinned;
}

- (IBAction)openPasswordManager:(id)sender {
DLog(@"Menu item selected");
[self openPasswordManagerToAccountName:nil inSession:nil];
Expand Down Expand Up @@ -1796,6 +1806,10 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
} else if ([menuItem action] == @selector(toggleSecureInput:)) {
menuItem.state = IsSecureEventInputEnabled() ? NSOnState : NSOffState;
return YES;
} else if ([menuItem action] == @selector(togglePinHotkeyWindow:)) {
iTermProfileHotKey *profileHotkey = self.currentProfileHotkey;
menuItem.state = profileHotkey.pinned ? NSOnState : NSOffState;
return profileHotkey != nil;
} else {
return YES;
}
Expand Down
3 changes: 3 additions & 0 deletions sources/iTermProfileHotKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
// This is computed based on the current settings of the profile we were created with.
@property(nonatomic, readonly) iTermHotkeyWindowType hotkeyWindowType;

// If YES, then -autoHides will return NO.
@property(nonatomic) BOOL pinned;

- (instancetype)initWithShortcuts:(NSArray<iTermShortcut *> *)shortcuts
hasModifierActivation:(BOOL)hasModifierActivation
modifierActivation:(iTermHotKeyModifierActivation)modifierActivation
Expand Down
22 changes: 21 additions & 1 deletion sources/iTermProfileHotKey.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ @interface iTermProfileHotKey()
@property(nonatomic, retain) NSWindowController *windowControllerBeingBorn;
@end

static NSString *const kPinnedGUIDsUserDefaultKey = @"NoSyncPinnedHotkeyWindowGUIDs";

@implementation iTermProfileHotKey

- (instancetype)initWithShortcuts:(NSArray<iTermShortcut *> *)shortcuts
Expand All @@ -58,6 +60,7 @@ - (instancetype)initWithShortcuts:(NSArray<iTermShortcut *> *)shortcuts
if (self) {
_allowsStateRestoration = YES;
_profileGuid = [profile[KEY_GUID] copy];
_pinned = [[[NSUserDefaults standardUserDefaults] objectForKey:kPinnedGUIDsUserDefaultKey] containsObject:_profileGuid];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(terminalWindowControllerCreated:)
name:kTerminalWindowControllerWasCreatedNotification
Expand Down Expand Up @@ -587,7 +590,24 @@ - (void)didFinishRollingOut {
}

- (BOOL)autoHides {
return [iTermProfilePreferences boolForKey:KEY_HOTKEY_AUTOHIDE inProfile:self.profile];
return !self.pinned && [iTermProfilePreferences boolForKey:KEY_HOTKEY_AUTOHIDE inProfile:self.profile];
}

- (void)setPinned:(BOOL)pinned {
_pinned = pinned;

if (_profileGuid) {
NSMutableArray<NSString *> *pinnedProfiles = [[[[NSUserDefaults standardUserDefaults] objectForKey:kPinnedGUIDsUserDefaultKey] mutableCopy] autorelease];
if (!pinnedProfiles) {
pinnedProfiles = [NSMutableArray array];
}
if (self.pinned) {
[pinnedProfiles addObject:_profileGuid];
} else {
[pinnedProfiles removeObject:_profileGuid];
}
[[NSUserDefaults standardUserDefaults] setObject:pinnedProfiles forKey:kPinnedGUIDsUserDefaultKey];
}
}

// If there's a visible hotkey window that is either not key or is on another space, switch to it.
Expand Down

0 comments on commit 865bd84

Please sign in to comment.