Skip to content
Snippets Groups Projects
Commit 223717bc authored by George Nachman's avatar George Nachman
Browse files

Rebuild touch bar when color presets change. It was not picking up changes on...

Rebuild touch bar when color presets change. It was not picking up changes on macOS 10.13. Mentioned in a comment in issue 5281
parent 2b4e2f59
No related branches found
No related tags found
No related merge requests found
Loading
@@ -14,8 +14,9 @@
Loading
@@ -14,8 +14,9 @@
NSScrubberDelegate, NSScrubberDelegate,
NSScrubberDataSource> NSScrubberDataSource>
   
- (void)updateTouchBarIfNeeded; - (void)updateTouchBarIfNeeded:(BOOL)force;
- (void)updateTouchBarFunctionKeyLabels; - (void)updateTouchBarFunctionKeyLabels;
- (void)updateTouchBarWithWordAtCursor:(NSString *)word; - (void)updateTouchBarWithWordAtCursor:(NSString *)word;
- (void)updateColorPresets;
   
@end @end
Loading
@@ -56,6 +56,11 @@ ITERM_IGNORE_PARTIAL_BEGIN
Loading
@@ -56,6 +56,11 @@ ITERM_IGNORE_PARTIAL_BEGIN
[self updateStatus]; [self updateStatus];
} }
   
- (void)updateColorPresets {
if (IsTouchBarAvailable() && [self respondsToSelector:@selector(touchBar)]) {
[self updateTouchBarIfNeeded:YES];
}
}
- (void)updateTouchBarWithWordAtCursor:(NSString *)word { - (void)updateTouchBarWithWordAtCursor:(NSString *)word {
if (IsTouchBarAvailable() && [self respondsToSelector:@selector(touchBar)]) { if (IsTouchBarAvailable() && [self respondsToSelector:@selector(touchBar)]) {
NSTouchBarItem *item = [self.touchBar itemForIdentifier:iTermTouchBarIdentifierManPage]; NSTouchBarItem *item = [self.touchBar itemForIdentifier:iTermTouchBarIdentifierManPage];
Loading
@@ -117,14 +122,14 @@ ITERM_IGNORE_PARTIAL_BEGIN
Loading
@@ -117,14 +122,14 @@ ITERM_IGNORE_PARTIAL_BEGIN
return touchBar; return touchBar;
} }
   
- (void)updateTouchBarIfNeeded { - (void)updateTouchBarIfNeeded:(BOOL)force {
if (!self.wellFormed) { if (!self.wellFormed) {
DLog(@"Not updating touch bar in %@ because not well formed", self); DLog(@"Not updating touch bar in %@ because not well formed", self);
return; return;
} }
if (IsTouchBarAvailable()) { if (IsTouchBarAvailable()) {
NSTouchBar *replacement = [self amendTouchBar:[self makeGenericTouchBar]]; NSTouchBar *replacement = [self amendTouchBar:[self makeGenericTouchBar]];
if (![replacement.customizationIdentifier isEqualToString:self.touchBar.customizationIdentifier]) { if (force || ![replacement.customizationIdentifier isEqualToString:self.touchBar.customizationIdentifier]) {
self.touchBar = replacement; self.touchBar = replacement;
} else { } else {
NSScrubber *scrubber = (NSScrubber *)self.tabsTouchBarItem.view; NSScrubber *scrubber = (NSScrubber *)self.tabsTouchBarItem.view;
Loading
@@ -262,16 +267,7 @@ ITERM_IGNORE_PARTIAL_BEGIN
Loading
@@ -262,16 +267,7 @@ ITERM_IGNORE_PARTIAL_BEGIN
constant:0]]; constant:0]];
} }
   
- (NSTouchBarItem *)colorPresetsScrollViewTouchBarItem { - (void)addButtonsToColorPresetsDocumentView:(NSView *)documentView {
if (!IsTouchBarAvailable()) {
return nil;
}
NSScrollView *scrollView = [[[NSScrollView alloc] init] autorelease];
NSCustomTouchBarItem *item = [[[NSCustomTouchBarItem alloc] initWithIdentifier:iTermTouchBarIdentifierColorPresetScrollview] autorelease];
item.view = scrollView;
NSView *documentView = [[NSView alloc] init];
documentView.translatesAutoresizingMaskIntoConstraints = NO;
scrollView.documentView = documentView;
NSButton *previous = nil; NSButton *previous = nil;
for (NSDictionary *dict in @[ [iTermColorPresets builtInColorPresets] ?: @{}, for (NSDictionary *dict in @[ [iTermColorPresets builtInColorPresets] ?: @{},
[iTermColorPresets customColorPresets] ?: @{} ]) { [iTermColorPresets customColorPresets] ?: @{} ]) {
Loading
@@ -289,7 +285,7 @@ ITERM_IGNORE_PARTIAL_BEGIN
Loading
@@ -289,7 +285,7 @@ ITERM_IGNORE_PARTIAL_BEGIN
attributes:attributes] autorelease]; attributes:attributes] autorelease];
button = [iTermTouchBarButton buttonWithTitle:@"" button = [iTermTouchBarButton buttonWithTitle:@""
target:self target:self
action:@selector(colorPresetTouchBarItemSelected:)]; action:@selector(colorPresetTouchBarItemSelected:)];
[button sizeToFit]; [button sizeToFit];
button.attributedTitle = title; button.attributedTitle = title;
button.bezelColor = backgroundColor; button.bezelColor = backgroundColor;
Loading
@@ -303,6 +299,19 @@ ITERM_IGNORE_PARTIAL_BEGIN
Loading
@@ -303,6 +299,19 @@ ITERM_IGNORE_PARTIAL_BEGIN
if (previous) { if (previous) {
[self constrainButton:previous toRightOfSuperview:documentView]; [self constrainButton:previous toRightOfSuperview:documentView];
} }
}
- (NSTouchBarItem *)colorPresetsScrollViewTouchBarItem {
if (!IsTouchBarAvailable()) {
return nil;
}
NSScrollView *scrollView = [[[NSScrollView alloc] init] autorelease];
NSCustomTouchBarItem *item = [[[NSCustomTouchBarItem alloc] initWithIdentifier:iTermTouchBarIdentifierColorPresetScrollview] autorelease];
item.view = scrollView;
NSView *documentView = [[NSView alloc] init];
documentView.translatesAutoresizingMaskIntoConstraints = NO;
scrollView.documentView = documentView;
[self addButtonsToColorPresetsDocumentView:documentView];
return item; return item;
} }
   
Loading
Loading
Loading
@@ -1176,7 +1176,7 @@ ITERM_WEAKLY_REFERENCEABLE
Loading
@@ -1176,7 +1176,7 @@ ITERM_WEAKLY_REFERENCEABLE
} }
   
- (void)tabTitleDidChange:(PTYTab *)tab { - (void)tabTitleDidChange:(PTYTab *)tab {
[self updateTouchBarIfNeeded]; [self updateTouchBarIfNeeded:NO];
} }
   
// Allow frame to go off-screen while hotkey window is sliding in or out. // Allow frame to go off-screen while hotkey window is sliding in or out.
Loading
@@ -1506,11 +1506,11 @@ ITERM_WEAKLY_REFERENCEABLE
Loading
@@ -1506,11 +1506,11 @@ ITERM_WEAKLY_REFERENCEABLE
} }
   
- (void)keyBindingsDidChange:(NSNotification *)notification { - (void)keyBindingsDidChange:(NSNotification *)notification {
[self updateTouchBarIfNeeded]; [self updateTouchBarIfNeeded:NO];
} }
   
- (void)colorPresetsDidChange:(NSNotification *)notification { - (void)colorPresetsDidChange:(NSNotification *)notification {
[self updateTouchBarIfNeeded]; [self updateColorPresets];
} }
   
- (IBAction)closeCurrentTab:(id)sender { - (IBAction)closeCurrentTab:(id)sender {
Loading
@@ -3659,7 +3659,7 @@ ITERM_WEAKLY_REFERENCEABLE
Loading
@@ -3659,7 +3659,7 @@ ITERM_WEAKLY_REFERENCEABLE
[self updateTabColors]; [self updateTabColors];
[self saveTmuxWindowOrigins]; [self saveTmuxWindowOrigins];
   
[self updateTouchBarIfNeeded]; [self updateTouchBarIfNeeded:NO];
} }
   
- (BOOL)fullScreen - (BOOL)fullScreen
Loading
@@ -3796,7 +3796,7 @@ ITERM_WEAKLY_REFERENCEABLE
Loading
@@ -3796,7 +3796,7 @@ ITERM_WEAKLY_REFERENCEABLE
[_didEnterLionFullscreen release]; [_didEnterLionFullscreen release];
_didEnterLionFullscreen = nil; _didEnterLionFullscreen = nil;
} }
[self updateTouchBarIfNeeded]; [self updateTouchBarIfNeeded:NO];
} }
   
- (void)windowWillExitFullScreen:(NSNotification *)notification - (void)windowWillExitFullScreen:(NSNotification *)notification
Loading
@@ -3832,7 +3832,7 @@ ITERM_WEAKLY_REFERENCEABLE
Loading
@@ -3832,7 +3832,7 @@ ITERM_WEAKLY_REFERENCEABLE
[self notifyTmuxOfWindowResize]; [self notifyTmuxOfWindowResize];
[self saveTmuxWindowOrigins]; [self saveTmuxWindowOrigins];
[self.window makeFirstResponder:self.currentSession.textview]; [self.window makeFirstResponder:self.currentSession.textview];
[self updateTouchBarIfNeeded]; [self updateTouchBarIfNeeded:NO];
} }
   
- (NSRect)windowWillUseStandardFrame:(NSWindow *)sender defaultFrame:(NSRect)defaultFrame { - (NSRect)windowWillUseStandardFrame:(NSWindow *)sender defaultFrame:(NSRect)defaultFrame {
Loading
@@ -4128,7 +4128,7 @@ ITERM_WEAKLY_REFERENCEABLE
Loading
@@ -4128,7 +4128,7 @@ ITERM_WEAKLY_REFERENCEABLE
if ([[PreferencePanel sessionsInstance] isWindowLoaded]) { if ([[PreferencePanel sessionsInstance] isWindowLoaded]) {
[self editSession:self.currentSession makeKey:NO]; [self editSession:self.currentSession makeKey:NO];
} }
[self updateTouchBarIfNeeded]; [self updateTouchBarIfNeeded:NO];
   
NSInteger darkCount = 0; NSInteger darkCount = 0;
NSInteger lightCount = 0; NSInteger lightCount = 0;
Loading
@@ -4465,7 +4465,7 @@ ITERM_WEAKLY_REFERENCEABLE
Loading
@@ -4465,7 +4465,7 @@ ITERM_WEAKLY_REFERENCEABLE
   
[self updateTabColors]; [self updateTabColors];
[self _updateTabObjectCounts]; [self _updateTabObjectCounts];
[self updateTouchBarIfNeeded]; [self updateTouchBarIfNeeded:NO];
   
if (_contentView.tabView.numberOfTabViewItems == 1 && if (_contentView.tabView.numberOfTabViewItems == 1 &&
_previousNumberOfTabs == 0 && _previousNumberOfTabs == 0 &&
Loading
@@ -5717,7 +5717,7 @@ ITERM_WEAKLY_REFERENCEABLE
Loading
@@ -5717,7 +5717,7 @@ ITERM_WEAKLY_REFERENCEABLE
if ([[PreferencePanel sessionsInstance] isWindowLoaded]) { if ([[PreferencePanel sessionsInstance] isWindowLoaded]) {
[self editSession:self.currentSession makeKey:NO]; [self editSession:self.currentSession makeKey:NO];
} }
[self updateTouchBarIfNeeded]; [self updateTouchBarIfNeeded:NO];
[self updateCurrentLocation]; [self updateCurrentLocation];
} }
   
Loading
@@ -7439,7 +7439,7 @@ ITERM_WEAKLY_REFERENCEABLE
Loading
@@ -7439,7 +7439,7 @@ ITERM_WEAKLY_REFERENCEABLE
@(_anchoredScreenNumber), @(_isAnchoredToScreen), self); @(_anchoredScreenNumber), @(_isAnchoredToScreen), self);
} }
} }
[self updateTouchBarIfNeeded]; [self updateTouchBarIfNeeded:NO];
} }
   
// Called when the parameter panel should close. // Called when the parameter panel should close.
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment