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

Fix bug where window arrangements were incompatible with custom prefs dir....

Fix bug where window arrangements were incompatible with custom prefs dir. Improve wording of initial alert w/ custom prefs. Add alert when quitting when there are custom prefs and you've changed something
parent 8bbb57fd
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -213,6 +213,7 @@ typedef enum { CURSOR_UNDERLINE, CURSOR_VERTICAL, CURSOR_BOX } ITermCursorType;
IBOutlet NSButton *browseCustomFolder;
IBOutlet NSButton *pushToCustomFolder;
IBOutlet NSImageView *prefsDirWarning;
BOOL customFolderChanged_;
 
// hide scrollbar and resize
IBOutlet NSButton *hideScrollbar;
Loading
Loading
@@ -584,7 +585,10 @@ typedef enum { BulkCopyColors, BulkCopyDisplay, BulkCopyWindow, BulkCopyTerminal
- (void)changeFont:(id)fontManager;
- (NSString*)_chooseBackgroundImage;
- (IBAction)browseCustomFolder:(id)sender;
- (BOOL)prefsDifferFromRemote;
- (NSString *)remotePrefsLocation;
- (IBAction)pushToCustomFolder:(id)sender;
- (BOOL)customFolderChanged;
- (IBAction)bookmarkSettingChanged:(id)sender;
- (IBAction)copyToProfile:(id)sender;
- (IBAction)bookmarkUrlSchemeHandlerChanged:(id)sender;
Loading
Loading
Loading
Loading
@@ -184,7 +184,6 @@ static const int MIN_SESSION_COLUMNS = 2;
- (NSDictionary*)arrangement;
 
- (BOOL)hasMaximizedPane;
- (void)maximizeWithoutMakingKey;
- (void)maximize;
- (void)unmaximize;
 
Loading
Loading
Loading
Loading
@@ -1374,7 +1374,7 @@ static float versionNumber;
// The directory is valid and it's probably the user's first time downt this path.
if ([[NSAlert alertWithMessageText:@"Copy local preferences to custom folder now?"
defaultButton:@"Copy"
alternateButton:@"Cancel"
alternateButton:@"Don't Copy"
otherButton:nil
informativeTextWithFormat:@""] runModal] == NSOKButton) {
[self pushToCustomFolder:nil];
Loading
Loading
@@ -1390,7 +1390,7 @@ static float versionNumber;
[prefs setObject:[prefsCustomFolder stringValue]
forKey:@"PrefsCustomFolder"];
defaultPrefsCustomFolder = [prefs objectForKey:@"PrefsCustomFolder"];
customFolderChanged_ = YES;
[self _updatePrefsDirWarning];
} else if (sender == windowStyle ||
sender == tabPosition ||
Loading
Loading
@@ -1892,26 +1892,28 @@ static float versionNumber;
return [NSString stringWithFormat:@"%@/%@.plist", base, [[NSBundle mainBundle] bundleIdentifier]];
}
 
- (BOOL)loadPrefs
- (NSString *)remotePrefsLocation
{
static BOOL done;
if (done) {
return YES;
}
done = YES;
BOOL doLoad = [prefs objectForKey:@"LoadPrefsFromCustomFolder"] ? [[prefs objectForKey:@"LoadPrefsFromCustomFolder"] boolValue] : NO;
if (!doLoad) {
return YES;
}
NSString *folder = [prefs objectForKey:@"PrefsCustomFolder"] ? [prefs objectForKey:@"PrefsCustomFolder"] : @"";
NSString *filename = [self _prefsFilenameWithBaseDir:folder];
NSDictionary *remotePrefs;
if ([folder hasPrefix:@"http://"] ||
[folder hasPrefix:@"https://"]) {
 
filename = folder;
}
return filename;
}
 
- (NSDictionary *)_remotePrefs
{
BOOL doLoad = [prefs objectForKey:@"LoadPrefsFromCustomFolder"] ? [[prefs objectForKey:@"LoadPrefsFromCustomFolder"] boolValue] : NO;
if (!doLoad) {
return nil;
}
NSString *filename = [self remotePrefsLocation];
NSDictionary *remotePrefs;
if ([filename hasPrefix:@"http://"] ||
[filename hasPrefix:@"https://"]) {
// Download the URL's contents.
NSURL *url = [NSURL URLWithString:filename];
const NSTimeInterval kFetchTimeout = 5.0;
Loading
Loading
@@ -1955,20 +1957,44 @@ static float versionNumber;
} else {
remotePrefs = [NSDictionary dictionaryWithContentsOfFile:filename];
}
return remotePrefs;
}
- (BOOL)loadPrefs
{
static BOOL done;
if (done) {
return YES;
}
done = YES;
BOOL doLoad = [prefs objectForKey:@"LoadPrefsFromCustomFolder"] ? [[prefs objectForKey:@"LoadPrefsFromCustomFolder"] boolValue] : NO;
if (!doLoad) {
return YES;
}
NSDictionary *remotePrefs = [self _remotePrefs];
 
if (remotePrefs && [remotePrefs count]) {
NSDictionary *localPrefs = [NSDictionary dictionaryWithContentsOfFile:[self _prefsFilename]];
// Empty out the current prefs
NSArray *exemptKeys = [NSArray arrayWithObjects:@"LoadPrefsFromCustomFolder",
@"PrefsCustomFolder", nil];
@"PrefsCustomFolder", @"iTerm Version", nil];
for (NSString *key in localPrefs) {
if (![exemptKeys containsObject:key]) {
if (![exemptKeys containsObject:key] &&
![key hasPrefix:@"NS"] &&
![key hasPrefix:@"SU"] &&
![key hasPrefix:@"UK"]) {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
}
}
 
for (NSString *key in remotePrefs) {
if (![exemptKeys containsObject:key]) {
if (![exemptKeys containsObject:key] &&
![key hasPrefix:@"NS"] &&
![key hasPrefix:@"SU"] &&
![key hasPrefix:@"UK"]) {
[[NSUserDefaults standardUserDefaults] setObject:[remotePrefs objectForKey:key]
forKey:key];
}
Loading
Loading
@@ -1979,11 +2005,51 @@ static float versionNumber;
defaultButton:@"OK"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@"Missing or malformed file at \"%@\"", filename] runModal];
informativeTextWithFormat:@"Missing or malformed file at \"%@\"", [self remotePrefsLocation]] runModal];
}
return NO;
}
 
- (BOOL)prefsDifferFromRemote
{
BOOL doLoad = [prefs objectForKey:@"LoadPrefsFromCustomFolder"] ? [[prefs objectForKey:@"LoadPrefsFromCustomFolder"] boolValue] : NO;
if (!doLoad) {
return NO;
}
NSDictionary *remotePrefs = [self _remotePrefs];
if (remotePrefs && [remotePrefs count]) {
NSDictionary *localPrefs = [NSDictionary dictionaryWithContentsOfFile:[self _prefsFilename]];
// Iterate over each set of prefs and validate that the other has the same value for each key.
NSArray *exemptKeys = [NSArray arrayWithObjects:@"LoadPrefsFromCustomFolder",
@"PrefsCustomFolder", @"iTerm Version", nil];
for (NSString *key in localPrefs) {
if (![exemptKeys containsObject:key]) {
if (![key hasPrefix:@"NS"] &&
![key hasPrefix:@"SU"] &&
![key hasPrefix:@"UK"] &&
![[remotePrefs objectForKey:key] isEqual:[localPrefs objectForKey:key]]) {
return YES;
}
}
}
for (NSString *key in remotePrefs) {
if (![exemptKeys containsObject:key]) {
if (![key hasPrefix:@"NS"] &&
![key hasPrefix:@"SU"] &&
![key hasPrefix:@"UK"] &&
![[remotePrefs objectForKey:key] isEqual:[localPrefs objectForKey:key]]) {
return YES;
}
}
}
return NO;
} else {
// Can't load remote prefs, so no problem.
return NO;
}
}
- (NSString *)loadPrefsFromCustomFolder
{
if (defaultLoadPrefsFromCustomFolder) {
Loading
Loading
@@ -2662,6 +2728,11 @@ static float versionNumber;
}
}
 
- (BOOL)customFolderChanged
{
return customFolderChanged_;
}
- (IBAction)pushToCustomFolder:(id)sender
{
[[NSUserDefaults standardUserDefaults] synchronize];
Loading
Loading
Loading
Loading
@@ -201,6 +201,26 @@ static BOOL hasBecomeActive = NO;
encoding:NSUTF8StringEncoding
error:nil];
}
- (void)_updateArrangementsMenu
{
while ([[windowArrangements_ submenu] numberOfItems]) {
[[windowArrangements_ submenu] removeItemAtIndex:0];
}
NSString *defaultName = [WindowArrangements defaultArrangementName];
for (NSString *theName in [WindowArrangements allNames]) {
NSString *theShortcut;
if ([theName isEqualToString:defaultName]) {
theShortcut = @"R";
} else {
theShortcut = @"";
}
[[windowArrangements_ submenu] addItemWithTitle:theName
action:@selector(restoreWindowArrangement:)
keyEquivalent:theShortcut];
}
}
 
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
Loading
Loading
@@ -224,6 +244,8 @@ static BOOL hasBecomeActive = NO;
if ([ppanel isAnyModifierRemapped]) {
[[iTermController sharedInstance] beginRemappingModifiers];
}
[self _updateArrangementsMenu];
// register for services
[NSApp registerServicesMenuSendTypes:[NSArray arrayWithObjects:NSStringPboardType, nil]
returnTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, NSStringPboardType, nil]];
Loading
Loading
@@ -274,6 +296,32 @@ static BOOL hasBecomeActive = NO;
 
// save preferences
[[PreferencePanel sharedInstance] savePreferences];
if (![[PreferencePanel sharedInstance] customFolderChanged]) {
if ([[PreferencePanel sharedInstance] prefsDifferFromRemote]) {
NSString *remote = [[PreferencePanel sharedInstance] remotePrefsLocation];
if ([remote hasPrefix:@"http://"] ||
[remote hasPrefix:@"https://"]) {
NSRunAlertPanel(@"Preference Changes Will be Lost!",
[NSString stringWithFormat:@"Your preferences are loaded from a URL and differ from your local preferences. To save your local preferences, copy ~/Library/Preferences/com.googlecode.iterm2.plist to %@ after quitting iTerm2.", remote],
@"OK",
nil,
nil);
} else {
switch (NSRunAlertPanel(@"Preference Changes Will be Lost!",
[NSString stringWithFormat:@"Your preferences are loaded from a custom location and differ from your local preferences. Your local preferences will be lost if not copied to %@.", remote],
@"Copy",
@"Lose Changes",
nil)) {
case NSAlertDefaultReturn:
[[PreferencePanel sharedInstance] pushToCustomFolder:nil];
break;
case NSAlertAlternateReturn:
break;
}
}
}
}
 
return YES;
}
Loading
Loading
@@ -429,27 +477,6 @@ static BOOL hasBecomeActive = NO;
return self;
}
 
- (void)_updateArrangementsMenu
{
while ([[windowArrangements_ submenu] numberOfItems]) {
[[windowArrangements_ submenu] removeItemAtIndex:0];
}
NSString *defaultName = [WindowArrangements defaultArrangementName];
for (NSString *theName in [WindowArrangements allNames]) {
NSString *theShortcut;
if ([theName isEqualToString:defaultName]) {
theShortcut = @"R";
} else {
theShortcut = @"";
}
[[windowArrangements_ submenu] addItemWithTitle:theName
action:@selector(restoreWindowArrangement:)
keyEquivalent:theShortcut];
}
}
- (void)windowArrangementsDidChange:(id)sender
{
[self _updateArrangementsMenu];
Loading
Loading
@@ -463,7 +490,6 @@ static BOOL hasBecomeActive = NO;
- (void)awakeFromNib
{
secureInputDesired_ = [[[NSUserDefaults standardUserDefaults] objectForKey:@"Secure Input"] boolValue];
[self _updateArrangementsMenu];
}
 
- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
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