Skip to content

Commit

Permalink
Make pseudoterminal pull the tab color from the current session inste…
Browse files Browse the repository at this point in the history
…ad of considering the tab's current color the canonical value. Also fix a bug for when the underlying profile of a divorced session has a nil value for a key and is an overridden field.
  • Loading branch information
gnachman committed Jan 25, 2014
1 parent 403d5c0 commit 5e95c42
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 153 deletions.
29 changes: 0 additions & 29 deletions FakeWindow.h
Expand Up @@ -37,7 +37,6 @@
BOOL hasPendingResetTempTitle;

NSColor* pendingLabelColor;
NSColor* pendingTabColor;
BOOL scrollbarShouldBeVisible;
}

Expand All @@ -48,32 +47,4 @@
// PseudoTerminal should call this after adding the session to its tab view.
- (void)rejoin:(NSWindowController<iTermWindowController> *)aTerm;

- (void)sessionInitiatedResize:(PTYSession*)session width:(int)width height:(int)height;
- (BOOL)fullScreen;
- (BOOL)anyFullScreen;
- (void)closeSession:(PTYSession*)aSession;
- (IBAction)nextTab:(id)sender;
- (IBAction)previousTab:(id)sender;
- (void)setLabelColor:(NSColor *)color forTabViewItem:tabViewItem;
- (void)setTabColor:(NSColor *)color forTabViewItem:tabViewItem;
- (NSColor*)tabColorForTabViewItem:(NSTabViewItem*)tabViewItem;
- (void)enableBlur:(double)radius;
- (void)disableBlur;
- (BOOL)tempTitle;
- (PTYTabView *)tabView;
- (PTYSession *)currentSession;
- (void)setWindowTitle;
- (void)resetTempTitle;
- (PTYTab*)currentTab;

- (void)windowSetFrameTopLeftPoint:(NSPoint)point;
- (void)windowPerformMiniaturize:(id)sender;
- (void)windowDeminiaturize:(id)sender;
- (void)windowOrderFront:(id)sender;
- (void)windowOrderBack:(id)sender;
- (BOOL)windowIsMiniaturized;
- (NSRect)windowFrame;
- (NSScreen*)windowScreen;
- (BOOL)scrollbarShouldBeVisible;

@end
31 changes: 7 additions & 24 deletions FakeWindow.m
Expand Up @@ -57,9 +57,6 @@ - (void)dealloc
if (pendingLabelColor) {
[pendingLabelColor release];
}
if (pendingTabColor) {
[pendingTabColor release];
}
[super dealloc];
}

Expand Down Expand Up @@ -91,15 +88,13 @@ - (void)rejoin:(NSWindowController<iTermWindowController> *)aTerm
if (pendingLabelColor) {
[aTerm setLabelColor:pendingLabelColor forTabViewItem:[[session tab] tabViewItem]];
}
if (pendingTabColor) {
[aTerm setTabColor:pendingTabColor forTabViewItem:[[session tab]tabViewItem]];
}
if (hasPendingSetWindowTitle) {
[aTerm setWindowTitle];
}
if (hasPendingResetTempTitle) {
[aTerm resetTempTitle];
}
[aTerm updateTabColors];
}

- (void)sessionInitiatedResize:(PTYSession*)session width:(int)width height:(int)height
Expand Down Expand Up @@ -134,11 +129,11 @@ - (void)closeTab:(PTYTab*)theTab
hasPendingClose = YES;
}

- (IBAction)nextTab:(id)sender
- (void)nextTab:(id)sender
{
}

- (IBAction)previousTab:(id)sender
- (void)previousTab:(id)sender
{
}

Expand All @@ -149,22 +144,6 @@ - (void)setLabelColor:(NSColor *)color forTabViewItem:tabViewItem
[pendingLabelColor retain];
}

- (void)setTabColor:(NSColor *)color forTabViewItem:tabViewItem
{
[pendingTabColor release];
pendingTabColor = color;
[pendingTabColor retain];
}

- (NSColor*)tabColorForTabViewItem:(NSTabViewItem*)tabViewItem
{
if (pendingTabColor) {
return pendingTabColor;
} else {
return [realWindow tabColorForTabViewItem:tabViewItem];
}
}

- (void)enableBlur:(double)radius
{
hasPendingBlurChange = YES;
Expand Down Expand Up @@ -254,4 +233,8 @@ - (NSScrollerStyle)scrollerStyle
return [self anyFullScreen] ? NSScrollerStyleOverlay : [NSScroller preferredScrollerStyle];
}

- (void)updateTabColors
{
}

@end
4 changes: 1 addition & 3 deletions PTYSession.h
Expand Up @@ -65,6 +65,7 @@ typedef enum {

@property(nonatomic, assign) BOOL alertOnNextMark;
@property(nonatomic, readonly) int sessionID;
@property(nonatomic, copy) NSColor *tabColor;

// Return the current pasteboard value as a string.
+ (NSString*)pasteboardString;
Expand Down Expand Up @@ -391,9 +392,6 @@ typedef enum {
// Select this session and tab and bring window to foreground.
- (void)reveal;

// Color for tab this session is in.
- (NSColor *)tabColor;

// FinalTerm
- (NSArray *)autocompleteSuggestionsForCurrentCommand;
- (NSString *)currentCommand;
Expand Down
79 changes: 51 additions & 28 deletions PTYSession.m
Expand Up @@ -1892,7 +1892,12 @@ - (NSDictionary *)dictionaryByMergingOriginalPreferencesWithDictionary:(NSDictio

NSMutableDictionary *combined = [NSMutableDictionary dictionaryWithDictionary:currentVersionOfOriginal];
for (NSString *key in overriddenFields_) {
combined[key] = overlay[key];
NSObject *overlayValue = overlay[key];
if (overlayValue) {
combined[key] = overlay[key];
} else {
[combined removeObjectForKey:key];
}
}

return combined;
Expand Down Expand Up @@ -1966,7 +1971,7 @@ - (void)setPreferencesFromAddressBookEntry:(NSDictionary *)aePrefs
[self setBoldColor:[ITAddressBookMgr decodeColor:[aDict objectForKey:KEY_BOLD_COLOR]]];
[self setCursorColor:[ITAddressBookMgr decodeColor:[aDict objectForKey:KEY_CURSOR_COLOR]]];
[self setCursorTextColor:[ITAddressBookMgr decodeColor:[aDict objectForKey:KEY_CURSOR_TEXT_COLOR]]];
[[[self tab] realParentWindow] setTabColor:[self tabColorInProfile:aDict] forTabViewItem:[[self tab] tabViewItem]];
[[[self tab] realParentWindow] updateTabColors];

BOOL scc;
if ([aDict objectForKey:KEY_SMART_CURSOR_COLOR]) {
Expand Down Expand Up @@ -3135,13 +3140,9 @@ - (void)changeFontSizeDirection:(int)dir
// Move this bookmark into the sessions model.
NSString* guid = [self divorceAddressBookEntryFromPreferences];

[self setSessionSpecificProfileValues:@{ KEY_NORMAL_FONT: [ITAddressBookMgr descFromFont:font],
KEY_NON_ASCII_FONT: [ITAddressBookMgr descFromFont:nafont] }];
// Set the font in the bookmark dictionary
NSMutableDictionary* temp = [NSMutableDictionary dictionaryWithDictionary:addressBookEntry];
[temp setObject:[ITAddressBookMgr descFromFont:font] forKey:KEY_NORMAL_FONT];
[temp setObject:[ITAddressBookMgr descFromFont:nafont] forKey:KEY_NON_ASCII_FONT];

// Update this session's copy of the bookmark
[self setAddressBookEntry:[NSDictionary dictionaryWithDictionary:temp]];

// Update the model's copy of the bookmark.
[[ProfileModel sessionsInstance] setBookmark:[self addressBookEntry] withGuid:guid];
Expand All @@ -3153,6 +3154,21 @@ - (void)changeFontSizeDirection:(int)dir
}
}

- (void)setSessionSpecificProfileValues:(NSDictionary *)newValues
{
if (!isDivorced) {
[self divorceAddressBookEntryFromPreferences];
}
NSMutableDictionary* temp = [NSMutableDictionary dictionaryWithDictionary:addressBookEntry];
for (NSString *key in newValues) {
NSObject *value = newValues[key];
temp[key] = value;
}
// Update this session's copy of the bookmark
[self updateOverriddenFieldsWithProfile:temp];
[self setAddressBookEntry:[self dictionaryByMergingOriginalPreferencesWithDictionary:temp]];
}

- (void)remarry
{
isDivorced = NO;
Expand Down Expand Up @@ -5432,42 +5448,49 @@ - (void)screenSetColorTableEntryAtIndex:(int)n color:(NSColor *)color {
}

- (void)screenSetCurrentTabColor:(NSColor *)color {
NSTabViewItem* tabViewItem = [[self ptytab] tabViewItem];
[self setTabColor:color];
id<WindowControllerInterface> term = [[self ptytab] parentWindow];
[term setTabColor:nil forTabViewItem:tabViewItem];
[term updateTabColors];
}

- (NSColor *)tabColor {
NSTabViewItem* tabViewItem = [[self ptytab] tabViewItem];
id<WindowControllerInterface> term = [[self ptytab] parentWindow];
return [term tabColorForTabViewItem:tabViewItem];
NSDictionary *colorDict = addressBookEntry[KEY_TAB_COLOR];
if (colorDict) {
return [ITAddressBookMgr decodeColor:colorDict];
} else {
return nil;
}
}

- (void)setTabColor:(NSColor *)color {
[self setSessionSpecificProfileValues:@{ KEY_TAB_COLOR: [ITAddressBookMgr encodeColor:color] }];
}

- (void)screenSetTabColorRedComponentTo:(CGFloat)color {
NSColor *curColor = [self tabColor];
[[[self ptytab] parentWindow] setTabColor:[NSColor colorWithCalibratedRed:color
green:[curColor greenComponent]
blue:[curColor blueComponent]
alpha:1]
forTabViewItem:[[self ptytab] tabViewItem]];
[self setTabColor:[NSColor colorWithCalibratedRed:color
green:[curColor greenComponent]
blue:[curColor blueComponent]
alpha:1]];
[[[self ptytab] parentWindow] updateTabColors];
}

- (void)screenSetTabColorGreenComponentTo:(CGFloat)color {
NSColor *curColor = [self tabColor];
[[[self ptytab] parentWindow] setTabColor:[NSColor colorWithCalibratedRed:[curColor redComponent]
green:color
blue:[curColor blueComponent]
alpha:1]
forTabViewItem:[[self ptytab] tabViewItem]];
[self setTabColor:[NSColor colorWithCalibratedRed:[curColor redComponent]
green:color
blue:[curColor blueComponent]
alpha:1]];
[[[self ptytab] parentWindow] updateTabColors];
}

- (void)screenSetTabColorBlueComponentTo:(CGFloat)color {
NSColor *curColor = [self tabColor];
[[[self ptytab] parentWindow] setTabColor:[NSColor colorWithCalibratedRed:[curColor redComponent]
green:[curColor greenComponent]
blue:color
alpha:1]
forTabViewItem:[[self ptytab] tabViewItem]];
[self setTabColor:[NSColor colorWithCalibratedRed:[curColor redComponent]
green:[curColor greenComponent]
blue:color
alpha:1]];
[[[self ptytab] parentWindow] updateTabColors];
}

- (void)screenCurrentHostDidChange:(VT100RemoteHost *)host {
Expand Down
10 changes: 2 additions & 8 deletions PTYTab.m
Expand Up @@ -335,7 +335,7 @@ - (void)setActiveSessionPreservingViewOrder:(PTYSession*)session
[[self realParentWindow] tabActiveSessionDidChange];
}

[[self realParentWindow] setTabColor:[activeSession_ tabColor] forTabViewItem:tabViewItem_];
[[self realParentWindow] updateTabColors];
}

- (void)setActiveSession:(PTYSession*)session
Expand Down Expand Up @@ -2179,13 +2179,7 @@ - (void)addToTerminal:(NSWindowController<iTermWindowController> *)term

[self numberOfSessionsDidChange];
[term setDimmingForSessions];

NSColor *tabColor;
NSString *colorName = [arrangement objectForKey:TAB_ARRANGEMENT_COLOR];
tabColor = [[self class] colorForHtmlName:colorName];
if (tabColor) {
[term setTabColor:tabColor forTabViewItem:tabViewItem_];
}
[term updateTabColors];
}

+ (PTYTab *)openTabWithArrangement:(NSDictionary*)arrangement
Expand Down

0 comments on commit 5e95c42

Please sign in to comment.