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
Loading
@@ -14,8 +14,9 @@
NSScrubberDelegate,
NSScrubberDataSource>
 
- (void)updateTouchBarIfNeeded;
- (void)updateTouchBarIfNeeded:(BOOL)force;
- (void)updateTouchBarFunctionKeyLabels;
- (void)updateTouchBarWithWordAtCursor:(NSString *)word;
- (void)updateColorPresets;
 
@end
Loading
Loading
@@ -56,6 +56,11 @@ ITERM_IGNORE_PARTIAL_BEGIN
[self updateStatus];
}
 
- (void)updateColorPresets {
if (IsTouchBarAvailable() && [self respondsToSelector:@selector(touchBar)]) {
[self updateTouchBarIfNeeded:YES];
}
}
- (void)updateTouchBarWithWordAtCursor:(NSString *)word {
if (IsTouchBarAvailable() && [self respondsToSelector:@selector(touchBar)]) {
NSTouchBarItem *item = [self.touchBar itemForIdentifier:iTermTouchBarIdentifierManPage];
Loading
Loading
@@ -117,14 +122,14 @@ ITERM_IGNORE_PARTIAL_BEGIN
return touchBar;
}
 
- (void)updateTouchBarIfNeeded {
- (void)updateTouchBarIfNeeded:(BOOL)force {
if (!self.wellFormed) {
DLog(@"Not updating touch bar in %@ because not well formed", self);
return;
}
if (IsTouchBarAvailable()) {
NSTouchBar *replacement = [self amendTouchBar:[self makeGenericTouchBar]];
if (![replacement.customizationIdentifier isEqualToString:self.touchBar.customizationIdentifier]) {
if (force || ![replacement.customizationIdentifier isEqualToString:self.touchBar.customizationIdentifier]) {
self.touchBar = replacement;
} else {
NSScrubber *scrubber = (NSScrubber *)self.tabsTouchBarItem.view;
Loading
Loading
@@ -262,16 +267,7 @@ ITERM_IGNORE_PARTIAL_BEGIN
constant:0]];
}
 
- (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;
- (void)addButtonsToColorPresetsDocumentView:(NSView *)documentView {
NSButton *previous = nil;
for (NSDictionary *dict in @[ [iTermColorPresets builtInColorPresets] ?: @{},
[iTermColorPresets customColorPresets] ?: @{} ]) {
Loading
Loading
@@ -289,7 +285,7 @@ ITERM_IGNORE_PARTIAL_BEGIN
attributes:attributes] autorelease];
button = [iTermTouchBarButton buttonWithTitle:@""
target:self
action:@selector(colorPresetTouchBarItemSelected:)];
action:@selector(colorPresetTouchBarItemSelected:)];
[button sizeToFit];
button.attributedTitle = title;
button.bezelColor = backgroundColor;
Loading
Loading
@@ -303,6 +299,19 @@ ITERM_IGNORE_PARTIAL_BEGIN
if (previous) {
[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;
}
 
Loading
Loading
Loading
Loading
@@ -1176,7 +1176,7 @@ ITERM_WEAKLY_REFERENCEABLE
}
 
- (void)tabTitleDidChange:(PTYTab *)tab {
[self updateTouchBarIfNeeded];
[self updateTouchBarIfNeeded:NO];
}
 
// Allow frame to go off-screen while hotkey window is sliding in or out.
Loading
Loading
@@ -1506,11 +1506,11 @@ ITERM_WEAKLY_REFERENCEABLE
}
 
- (void)keyBindingsDidChange:(NSNotification *)notification {
[self updateTouchBarIfNeeded];
[self updateTouchBarIfNeeded:NO];
}
 
- (void)colorPresetsDidChange:(NSNotification *)notification {
[self updateTouchBarIfNeeded];
[self updateColorPresets];
}
 
- (IBAction)closeCurrentTab:(id)sender {
Loading
Loading
@@ -3659,7 +3659,7 @@ ITERM_WEAKLY_REFERENCEABLE
[self updateTabColors];
[self saveTmuxWindowOrigins];
 
[self updateTouchBarIfNeeded];
[self updateTouchBarIfNeeded:NO];
}
 
- (BOOL)fullScreen
Loading
Loading
@@ -3796,7 +3796,7 @@ ITERM_WEAKLY_REFERENCEABLE
[_didEnterLionFullscreen release];
_didEnterLionFullscreen = nil;
}
[self updateTouchBarIfNeeded];
[self updateTouchBarIfNeeded:NO];
}
 
- (void)windowWillExitFullScreen:(NSNotification *)notification
Loading
Loading
@@ -3832,7 +3832,7 @@ ITERM_WEAKLY_REFERENCEABLE
[self notifyTmuxOfWindowResize];
[self saveTmuxWindowOrigins];
[self.window makeFirstResponder:self.currentSession.textview];
[self updateTouchBarIfNeeded];
[self updateTouchBarIfNeeded:NO];
}
 
- (NSRect)windowWillUseStandardFrame:(NSWindow *)sender defaultFrame:(NSRect)defaultFrame {
Loading
Loading
@@ -4128,7 +4128,7 @@ ITERM_WEAKLY_REFERENCEABLE
if ([[PreferencePanel sessionsInstance] isWindowLoaded]) {
[self editSession:self.currentSession makeKey:NO];
}
[self updateTouchBarIfNeeded];
[self updateTouchBarIfNeeded:NO];
 
NSInteger darkCount = 0;
NSInteger lightCount = 0;
Loading
Loading
@@ -4465,7 +4465,7 @@ ITERM_WEAKLY_REFERENCEABLE
 
[self updateTabColors];
[self _updateTabObjectCounts];
[self updateTouchBarIfNeeded];
[self updateTouchBarIfNeeded:NO];
 
if (_contentView.tabView.numberOfTabViewItems == 1 &&
_previousNumberOfTabs == 0 &&
Loading
Loading
@@ -5717,7 +5717,7 @@ ITERM_WEAKLY_REFERENCEABLE
if ([[PreferencePanel sessionsInstance] isWindowLoaded]) {
[self editSession:self.currentSession makeKey:NO];
}
[self updateTouchBarIfNeeded];
[self updateTouchBarIfNeeded:NO];
[self updateCurrentLocation];
}
 
Loading
Loading
@@ -7439,7 +7439,7 @@ ITERM_WEAKLY_REFERENCEABLE
@(_anchoredScreenNumber), @(_isAnchoredToScreen), self);
}
}
[self updateTouchBarIfNeeded];
[self updateTouchBarIfNeeded:NO];
}
 
// 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