Skip to content

Commit

Permalink
Update sessions profile prefs window when a session-specific profile …
Browse files Browse the repository at this point in the history
…setting is changed (such as background image via escape code). Ignore set-background-image escape code when the file doesn’t exist. Fix allow/deny lists.
  • Loading branch information
gnachman committed Jun 18, 2014
1 parent 0e32346 commit c4d2f82
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 16 deletions.
37 changes: 25 additions & 12 deletions PTYSession.m
Expand Up @@ -1950,6 +1950,8 @@ - (void)sessionProfileDidChange
DLog(@"After session profile change overridden keys are: %@", _overriddenFields);
[self setPreferencesFromAddressBookEntry:updatedProfile];
[self setProfile:updatedProfile];
[[NSNotificationCenter defaultCenter] postNotificationName:kSessionProfileDidChange
object:_profile[KEY_GUID]];
}

- (BOOL)reloadProfile
Expand Down Expand Up @@ -5491,17 +5493,20 @@ - (void)screenRequestAttention:(BOOL)request isCritical:(BOOL)isCritical {
}

- (void)screenSetBackgroundImageFile:(NSString *)filename {
if (![[NSFileManager defaultManager] fileExistsAtPath:filename]) {
return;
}
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
static NSString *kIdentifier = @"SetBackgroundImageFile";
static NSString *kAllowedFilesKey = @"AlwaysAllowBackgroundImage";
static NSString *kDeniedFilesKey = @"AlwaysDenyBackgroundImage";
NSArray *allowedFiles = [userDefaults objectForKey:kAllowedFilesKey];
NSArray *deniedFiles = [userDefaults objectForKey:kAllowedFilesKey];
NSArray *deniedFiles = [userDefaults objectForKey:kDeniedFilesKey];
if ([deniedFiles containsObject:filename]) {
return;
}
if ([allowedFiles containsObject:filename]) {
[self setBackgroundImagePath:filename];
[self setSessionSpecificProfileValues:@{ KEY_BACKGROUND_IMAGE_LOCATION: filename }];
return;
}

Expand All @@ -5520,20 +5525,28 @@ - (void)screenSetBackgroundImageFile:(NSString *)filename {
break;

case 0: // Yes
[self setBackgroundImagePath:filename];
[self setSessionSpecificProfileValues:@{ KEY_BACKGROUND_IMAGE_LOCATION: filename }];
break;

case 1: // Always
[userDefaults setObject:[[userDefaults objectForKey:kAllowedFilesKey] arrayByAddingObject:filename]
forKey:kAllowedFilesKey];
[self setBackgroundImagePath:filename];
case 1: { // Always
NSArray *allowed = [userDefaults objectForKey:kAllowedFilesKey];
if (!allowed) {
allowed = @[];
}
allowed = [allowed arrayByAddingObject:filename];
[userDefaults setObject:allowed forKey:kAllowedFilesKey];
[self setSessionSpecificProfileValues:@{ KEY_BACKGROUND_IMAGE_LOCATION: filename }];
break;

case 2: // Never
[userDefaults setObject:[[userDefaults objectForKey:kDeniedFilesKey] arrayByAddingObject:filename]
forKey:kDeniedFilesKey];
}
case 2: { // Never
NSArray *denied = [userDefaults objectForKey:kDeniedFilesKey];
if (!denied) {
denied = @[];
}
denied = [denied arrayByAddingObject:filename];
[userDefaults setObject:denied forKey:kDeniedFilesKey];
break;
}
}
}];
[self queueAnnouncement:announcement identifier:kIdentifier];
Expand Down
1 change: 1 addition & 0 deletions PreferencePanel.h
Expand Up @@ -37,6 +37,7 @@ extern NSString *const kRefreshTerminalNotification;
extern NSString *const kUpdateLabelsNotification;
extern NSString *const kKeyBindingsChangedNotification;
extern NSString *const kPreferencePanelDidUpdateProfileFields;
extern NSString *const kSessionProfileDidChange; // Posted by a session when it changes to update the Get Info window.

// All profiles should be reloaded.
extern NSString *const kReloadAllProfiles;
Expand Down
1 change: 1 addition & 0 deletions PreferencePanel.m
Expand Up @@ -99,6 +99,7 @@
NSString *const kKeyBindingsChangedNotification = @"kKeyBindingsChangedNotification";
NSString *const kReloadAllProfiles = @"kReloadAllProfiles";
NSString *const kPreferencePanelDidUpdateProfileFields = @"kPreferencePanelDidUpdateProfileFields";
NSString *const kSessionProfileDidChange = @"kSessionProfileDidChange";

@implementation PreferencePanel {
ProfileModel *_profileModel;
Expand Down
19 changes: 16 additions & 3 deletions ProfilePreferencesViewController.m
Expand Up @@ -90,6 +90,10 @@ - (id)init {
selector:@selector(reloadProfiles)
name:kReloadAllProfiles
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sessionProfileDidChange:)
name:kSessionProfileDidChange
object:nil];
}
return self;
}
Expand Down Expand Up @@ -175,10 +179,14 @@ - (void)selectGeneralTab {
[_tabView selectTabViewItem:_generalTab];
}

- (void)reloadProfileInProfileViewControllers {
[[self tabViewControllers] makeObjectsPerformSelector:@selector(reloadProfile)];
}

- (void)openToProfileWithGuid:(NSString *)guid {
[_profilesListView reloadData];
if ([[self selectedProfile][KEY_GUID] isEqualToString:guid]) {
[[self tabViewControllers] makeObjectsPerformSelector:@selector(reloadProfile)];
[self reloadProfileInProfileViewControllers];
} else {
[self selectGuid:guid];
}
Expand Down Expand Up @@ -211,13 +219,13 @@ - (void)profileTableSelectionDidChange:(id)profileTable {
if (!_tabView.isHidden) {
// Epilogue
[self reloadData];

[[NSNotificationCenter defaultCenter] postNotificationName:kPreferencePanelDidUpdateProfileFields
object:nil
userInfo:nil];
}

[[self tabViewControllers] makeObjectsPerformSelector:@selector(reloadProfile)];
[self reloadProfileInProfileViewControllers];
}

- (void)profileTableRowSelected:(id)profileTable {
Expand Down Expand Up @@ -448,7 +456,12 @@ - (void)refreshProfileTable {

- (void)reloadProfiles {
[self refresh];
}

- (void)sessionProfileDidChange:(NSNotification *)notification {
if ([[notification object] isEqual:[self selectedProfile][KEY_GUID]]) {
[self reloadProfileInProfileViewControllers];
}
}

#pragma mark - Sheet
Expand Down
12 changes: 12 additions & 0 deletions iTerm.xcodeproj/project.pbxproj
Expand Up @@ -518,6 +518,10 @@
1DC2A1CD1949165D005769D5 /* Maximized.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DC2A1CA1949165D005769D5 /* Maximized.png */; };
1DC2A1CE1949165D005769D5 /* Maximized@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DC2A1CB1949165D005769D5 /* Maximized@2x.png */; };
1DC2A1CF1949165D005769D5 /* Maximized@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DC2A1CB1949165D005769D5 /* Maximized@2x.png */; };
1DC2AF5119521CFF005769D5 /* QuestionMarkSign.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DC2AF4F19521CFF005769D5 /* QuestionMarkSign.png */; };
1DC2AF5219521CFF005769D5 /* QuestionMarkSign.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DC2AF4F19521CFF005769D5 /* QuestionMarkSign.png */; };
1DC2AF5319521CFF005769D5 /* QuestionMarkSign@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DC2AF5019521CFF005769D5 /* QuestionMarkSign@2x.png */; };
1DC2AF5419521CFF005769D5 /* QuestionMarkSign@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DC2AF5019521CFF005769D5 /* QuestionMarkSign@2x.png */; };
1DC38818148E840700B89F7C /* SolidColorView.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DC38816148E840600B89F7C /* SolidColorView.h */; };
1DC38819148E840700B89F7C /* SolidColorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1DC38817148E840700B89F7C /* SolidColorView.m */; };
1DC742A0127C96F90069594C /* IBarCursor.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DC7429F127C96F90069594C /* IBarCursor.png */; };
Expand Down Expand Up @@ -1264,6 +1268,8 @@
1DC13AC61886507D00034DAE /* CommandHistoryPopup.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CommandHistoryPopup.xib; sourceTree = "<group>"; };
1DC2A1CA1949165D005769D5 /* Maximized.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Maximized.png; path = images/Maximized.png; sourceTree = "<group>"; };
1DC2A1CB1949165D005769D5 /* Maximized@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Maximized@2x.png"; path = "images/Maximized@2x.png"; sourceTree = "<group>"; };
1DC2AF4F19521CFF005769D5 /* QuestionMarkSign.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = QuestionMarkSign.png; path = images/QuestionMarkSign.png; sourceTree = "<group>"; };
1DC2AF5019521CFF005769D5 /* QuestionMarkSign@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "QuestionMarkSign@2x.png"; path = "images/QuestionMarkSign@2x.png"; sourceTree = "<group>"; };
1DC38816148E840600B89F7C /* SolidColorView.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = SolidColorView.h; sourceTree = "<group>"; tabWidth = 4; };
1DC38817148E840700B89F7C /* SolidColorView.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = SolidColorView.m; sourceTree = "<group>"; tabWidth = 4; };
1DC393C317B59B08000EE0F2 /* SearchResult.h */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = SearchResult.h; sourceTree = "<group>"; tabWidth = 4; };
Expand Down Expand Up @@ -2127,6 +2133,8 @@
1D093C131217412B0029F9AD /* Images */ = {
isa = PBXGroup;
children = (
1DC2AF4F19521CFF005769D5 /* QuestionMarkSign.png */,
1DC2AF5019521CFF005769D5 /* QuestionMarkSign@2x.png */,
1DC2A1CA1949165D005769D5 /* Maximized.png */,
1DC2A1CB1949165D005769D5 /* Maximized@2x.png */,
1DEF5E6B185F889600300319 /* Alert.png */,
Expand Down Expand Up @@ -3167,12 +3175,14 @@
1DB8FBCF19468A40006BAF5C /* AquaTabsSeparatorDown_vertical.png in Resources */,
1DB8FBCB19468A40006BAF5C /* AquaTabsDownNonKey_vertical.png in Resources */,
1DFA9D6818F37160008ADC98 /* iTermEditKeyActionWindowController.xib in Resources */,
1DC2AF5419521CFF005769D5 /* QuestionMarkSign@2x.png in Resources */,
1DB8FBC719468A40006BAF5C /* AquaTabsBackground_vertical.png in Resources */,
1D03D424191419080049EB8F /* DirectoriesPopup.xib in Resources */,
1DD39AE1180B8118004E56D5 /* InfoPlist.strings in Resources */,
1DD39AEF180B8118004E56D5 /* Images.xcassets in Resources */,
1DEF5E6E185F889600300319 /* Alert.png in Resources */,
1D01609C1852AA6F0014D26A /* mark@2x.png in Resources */,
1DC2AF5219521CFF005769D5 /* QuestionMarkSign.png in Resources */,
1DB8FBD119468A40006BAF5C /* TabClose_Front_Rollover.png in Resources */,
A697101518DFA7FC007E901D /* closebutton.png in Resources */,
A6E713B718FCB559008D94DD /* AdvancedWorkingDirectoryWindow.xib in Resources */,
Expand Down Expand Up @@ -3200,7 +3210,9 @@
1D5FDD831208E91100C46BA3 /* iTerm.scriptTerminology in Resources */,
F638C2620AD483BF00BEE23D /* iTerm.strings in Resources */,
1D5FDD891208E91100C46BA3 /* AquaTabNew.png in Resources */,
1DC2AF5119521CFF005769D5 /* QuestionMarkSign.png in Resources */,
1D5FDD8A1208E91100C46BA3 /* AquaTabNewPressed.png in Resources */,
1DC2AF5319521CFF005769D5 /* QuestionMarkSign@2x.png in Resources */,
1D5FDD8B1208E91100C46BA3 /* AquaTabNewRollover.png in Resources */,
1D5FDD8C1208E91100C46BA3 /* AquaTabsBackground.png in Resources */,
1D5FDD8D1208E91100C46BA3 /* AquaTabsDown.png in Resources */,
Expand Down
2 changes: 1 addition & 1 deletion iTermAnnouncementView.m
Expand Up @@ -165,7 +165,7 @@ - (NSImage *)iconImage {
iconString = @""; // Warning sign
break;
case kiTermAnnouncementViewStyleQuestion:
iconString = @"?\u20e4";
return [NSImage imageNamed:@"QuestionMarkSign"];
break;
}

Expand Down
Binary file added images/QuestionMarkSign.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/QuestionMarkSign@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/question mark sign.psd
Binary file not shown.

0 comments on commit c4d2f82

Please sign in to comment.