Skip to content

Commit

Permalink
Fix bug where we showed bogus "this profile doesn't exist" messages w…
Browse files Browse the repository at this point in the history
…hen the profile was divorced. Look up the original guid and preserve the original guid when divorcing on restore.
  • Loading branch information
gnachman committed Jan 20, 2017
1 parent d603da9 commit eba22cd
Showing 1 changed file with 58 additions and 36 deletions.
94 changes: 58 additions & 36 deletions sources/PTYSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,48 @@ + (NSDictionary *)repairedArrangement:(NSDictionary *)arrangement
}
}

- (iTermAnnouncementViewController *)announcementForMissingProfileInArrangement:(NSDictionary *)arrangement {
iTermAnnouncementViewController *announcement = nil;
NSString *missingProfileName = [[arrangement[SESSION_ARRANGEMENT_BOOKMARK][KEY_NAME] copy] autorelease];
DLog(@"Can't find profile %@ guid %@", missingProfileName, arrangement[SESSION_ARRANGEMENT_BOOKMARK][KEY_GUID]);
if (![iTermAdvancedSettingsModel noSyncSuppressMissingProfileInArrangementWarning]) {
NSString *notice;
NSArray<NSString *> *actions = @[ @"Don't Warn Again" ];
NSString *savedArranagementName = [[iTermController sharedInstance] savedArrangementNameBeingRestored];
if ([[ProfileModel sharedInstance] bookmarkWithName:missingProfileName]) {
notice = [NSString stringWithFormat:@"This session's profile, “%@”, no longer exists. A profile with that name happens to exist.", missingProfileName];
if (savedArranagementName) {
actions = [actions arrayByAddingObject:@"Repair Saved Arrangement"];
}
} else {
notice = [NSString stringWithFormat:@"This session's profile, “%@”, no longer exists.", missingProfileName];
}
Profile *thisProfile = arrangement[SESSION_ARRANGEMENT_BOOKMARK];
[_missingSavedArrangementProfileGUID autorelease];
_missingSavedArrangementProfileGUID = [thisProfile[KEY_GUID] copy];
announcement =
[iTermAnnouncementViewController announcementWithTitle:notice
style:kiTermAnnouncementViewStyleWarning
withActions:actions
completion:^(int selection) {
if (selection == 0) {
[iTermAdvancedSettingsModel setNoSyncSuppressMissingProfileInArrangementWarning:YES];
} else if (selection == 1) {
// Repair
Profile *similarlyNamedProfile = [[ProfileModel sharedInstance] bookmarkWithName:missingProfileName];
[[iTermController sharedInstance] repairSavedArrangementNamed:savedArranagementName
replacingMissingGUID:thisProfile[KEY_GUID]
withGUID:similarlyNamedProfile[KEY_GUID]];
[[NSNotificationCenter defaultCenter] postNotificationName:PTYSessionDidRepairSavedArrangement
object:thisProfile[KEY_GUID]
userInfo:@{ @"new profile": similarlyNamedProfile }];
}
}];
announcement.dismissOnKeyDown = YES;
}
return announcement;
}

+ (PTYSession *)sessionFromArrangement:(NSDictionary *)arrangement
inView:(SessionView *)sessionView
withDelegate:(id<PTYSessionDelegate>)delegate
Expand All @@ -791,41 +833,9 @@ + (PTYSession *)sessionFromArrangement:(NSDictionary *)arrangement
BOOL needDivorce = NO;
iTermAnnouncementViewController *announcement = nil;
if (!theBookmark) {
NSString *missingProfileName = [[arrangement[SESSION_ARRANGEMENT_BOOKMARK][KEY_NAME] copy] autorelease];
DLog(@"Can't find profile %@ guid %@", missingProfileName, arrangement[SESSION_ARRANGEMENT_BOOKMARK][KEY_GUID]);
if (![iTermAdvancedSettingsModel noSyncSuppressMissingProfileInArrangementWarning]) {
NSString *notice;
NSArray<NSString *> *actions = @[ @"Don't Warn Again" ];
NSString *savedArranagementName = [[iTermController sharedInstance] savedArrangementNameBeingRestored];
if ([[ProfileModel sharedInstance] bookmarkWithName:missingProfileName]) {
notice = [NSString stringWithFormat:@"This session's profile, “%@”, no longer exists, although a profile with that name happens to exist.", missingProfileName];
if (savedArranagementName) {
actions = [actions arrayByAddingObject:@"Repair Saved Arrangement"];
}
} else {
notice = [NSString stringWithFormat:@"This session's profile, “%@”, no longer exists.", missingProfileName];
}
Profile *thisProfile = arrangement[SESSION_ARRANGEMENT_BOOKMARK];
aSession->_missingSavedArrangementProfileGUID = [thisProfile[KEY_GUID] copy];
announcement =
[iTermAnnouncementViewController announcementWithTitle:notice
style:kiTermAnnouncementViewStyleWarning
withActions:actions
completion:^(int selection) {
if (selection == 0) {
[iTermAdvancedSettingsModel setNoSyncSuppressMissingProfileInArrangementWarning:YES];
} else if (selection == 1) {
// Repair
Profile *similarlyNamedProfile = [[ProfileModel sharedInstance] bookmarkWithName:missingProfileName];
[[iTermController sharedInstance] repairSavedArrangementNamed:savedArranagementName
replacingMissingGUID:thisProfile[KEY_GUID]
withGUID:similarlyNamedProfile[KEY_GUID]];
[[NSNotificationCenter defaultCenter] postNotificationName:PTYSessionDidRepairSavedArrangement
object:thisProfile[KEY_GUID]
userInfo:@{ @"new profile": similarlyNamedProfile }];
}
}];
announcement.dismissOnKeyDown = YES;
NSString *originalGuid = arrangement[SESSION_ARRANGEMENT_BOOKMARK][KEY_ORIGINAL_GUID];
if (![[ProfileModel sharedInstance] bookmarkWithGuid:originalGuid]) {
announcement = [aSession announcementForMissingProfileInArrangement:arrangement];
}

theBookmark = [arrangement objectForKey:SESSION_ARRANGEMENT_BOOKMARK];
Expand All @@ -844,7 +854,19 @@ + (PTYSession *)sessionFromArrangement:(NSDictionary *)arrangement
needDivorce = YES;
}
if (needDivorce) {
// Keep it from stepping on an existing sesion with the same guid.
// Keep it from stepping on an existing sesion with the same guid. Assign a fresh GUID.
// Set the ORIGINAL_GUID to an existing guid from which this profile originated if possible.
NSString *originalGuid = nil;
NSString *recordedGuid = arrangement[SESSION_ARRANGEMENT_BOOKMARK][KEY_GUID];
NSString *recordedOriginalGuid = arrangement[SESSION_ARRANGEMENT_BOOKMARK][KEY_ORIGINAL_GUID];
if ([[ProfileModel sharedInstance] bookmarkWithGuid:recordedGuid]) {
originalGuid = recordedGuid;
} else if ([[ProfileModel sharedInstance] bookmarkWithGuid:recordedOriginalGuid]) {
originalGuid = recordedOriginalGuid;
}
if (originalGuid) {
theBookmark = [theBookmark dictionaryBySettingObject:originalGuid forKey:KEY_ORIGINAL_GUID];
}
theBookmark = [theBookmark dictionaryBySettingObject:[ProfileModel freshGuid] forKey:KEY_GUID];
}

Expand Down

0 comments on commit eba22cd

Please sign in to comment.