Skip to content

Commit

Permalink
Fix a retain cycle in the keys prefs view controller that caused a cr…
Browse files Browse the repository at this point in the history
…ash when toggling the hotkey pinned button because a vc belonging to a now-dead window got a notification that something changed and asserted trying to get the info for the control.
  • Loading branch information
gnachman committed Aug 5, 2016
1 parent 0877eef commit 6dd0325
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions sources/KeysPreferencesViewController.m
Expand Up @@ -18,7 +18,8 @@
#import "PreferencePanel.h"
#import "PSMTabBarControl.h"

static NSString * const kHotkeyWindowGeneratedProfileNameKey = @"Hotkey Window";
static NSString *const kHotkeyWindowGeneratedProfileNameKey = @"Hotkey Window";
static NSString *const kHotkeyAutoHidesPreferenceDidChange = @"kHotkeyAutoHidesPreferenceDidChange";

@interface KeysPreferencesViewController () <iTermKeyMappingViewControllerDelegate>
@end
Expand All @@ -45,11 +46,20 @@ @implementation KeysPreferencesViewController {
IBOutlet NSPopUpButton *_hotkeyBookmark;
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}

- (void)awakeFromNib {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadAddressBookNotification:)
name:kReloadAddressBookNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hotkeyAutoHidesPreferenceDidChange:)
name:kHotkeyAutoHidesPreferenceDidChange
object:nil];

PreferenceInfo *info;

Expand Down Expand Up @@ -122,17 +132,19 @@ - (void)awakeFromNib {
key:kPreferenceKeyHotKeyTogglesWindow
type:kPreferenceInfoTypeCheckbox];
info.onChange = ^() { [self hotkeyTogglesWindowDidChange]; };

info = [self defineControl:_hotkeyAutoHides
key:kPreferenceKeyHotkeyAutoHides
type:kPreferenceInfoTypeCheckbox];
info.onChange = ^() { [self postRefreshNotification]; };
// You can change this setting with a key binding action, so we observer it to update the
// You can change this setting with a key binding action, so we observe it to update the
// control when the user default changes.
[iTermPreferences addObserverForKey:kPreferenceKeyHotkeyAutoHides
block:^(id before, id after) {
[self updateValueForInfo:info];
}];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[iTermPreferences addObserverForKey:kPreferenceKeyHotkeyAutoHides block:^(id before, id after) {
[[NSNotificationCenter defaultCenter] postNotificationName:kHotkeyAutoHidesPreferenceDidChange
object:nil];
}];
});

[self defineControl:_hotkeyBookmark
key:kPreferenceKeyHotkeyProfileGuid
Expand Down Expand Up @@ -383,6 +395,10 @@ - (void)keyMapping:(iTermKeyMappingViewController *)viewController

#pragma mark - Notification handlers

- (void)hotkeyAutoHidesPreferenceDidChange:(NSNotification *)notification {
[self updateValueForInfo:[self infoForControl:_hotkeyAutoHides]];
}

- (void)reloadAddressBookNotification:(NSNotification *)aNotification {
[self populateHotKeyProfilesMenu];
}
Expand Down

0 comments on commit 6dd0325

Please sign in to comment.