Remove existance check before removing user style

This commit is contained in:
1024jp 2016-05-17 15:14:45 +09:00
parent 2af95be7a9
commit cd714d5908
4 changed files with 42 additions and 37 deletions

View File

@ -20,6 +20,7 @@ develop
- Fix an issue where hanging indent was applied when document style is changed even it is turned off.
- Fix an issue where the current line highlight didn't update under the specific condition.
- Fix an issue where editor area was not focused when document opens.
- Fix an issue where custom syntax style/theme couldn't be removed from the style list if the definition file is already deleted.
- Fix an issue where URL links were removed when editor is split.

View File

@ -577,8 +577,6 @@ NSString *_Nonnull const IsUTF8WithBOM = @"UTF-8 with BOM";
- (void)deleteSyntaxStyleWithName:(nonnull NSString *)styleName
// ------------------------------------------------------
{
if (![[CESyntaxManager sharedManager] URLForUserStyle:styleName]) { return; }
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:[NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to delete “%@” syntax style?", nil), styleName]];
[alert setInformativeText:NSLocalizedString(@"This action cannot be undone.", nil)];

View File

@ -328,25 +328,28 @@ NSString *_Nonnull const CESyntaxValidationMessageKey = @"MessageKey";
if ([URL checkResourceIsReachableAndReturnError:nil]) {
success = [[NSFileManager defaultManager] trashItemAtURL:URL resultingItemURL:nil error:nil];
if (success) {
//
[[self styleCaches] removeObjectForKey:styleName];
__weak typeof(self) weakSelf = self;
[self updateCacheWithCompletionHandler:^{
typeof(self) self = weakSelf; // strong self
[[NSNotificationCenter defaultCenter] postNotificationName:CESyntaxDidUpdateNotification
object:self
userInfo:@{CEOldNameKey: styleName,
CENewNameKey: NSLocalizedString(@"None", nil)}];
}];
} else {
NSLog(@"Error. Could not remove \"%@\".", URL);
}
} else {
NSLog(@"Error. Could not be found \"%@\" for remove.", URL);
// already removed.
success = YES;
}
if (!success) {
NSLog(@"Error. Could not remove \"%@\".", URL);
return NO;
}
//
[[self styleCaches] removeObjectForKey:styleName];
__weak typeof(self) weakSelf = self;
[self updateCacheWithCompletionHandler:^{
typeof(self) self = weakSelf; // strong self
[[NSNotificationCenter defaultCenter] postNotificationName:CESyntaxDidUpdateNotification
object:self
userInfo:@{CEOldNameKey: styleName,
CENewNameKey: NSLocalizedString(@"None", nil)}];
}];
return success;
}
@ -361,25 +364,28 @@ NSString *_Nonnull const CESyntaxValidationMessageKey = @"MessageKey";
if ([URL checkResourceIsReachableAndReturnError:nil]) {
success = [[NSFileManager defaultManager] trashItemAtURL:URL resultingItemURL:nil error:nil];
if (success) {
//
[self styleCaches][styleName] = [[self bundledStyleDictionaryWithStyleName:styleName] mutableCopy];
__weak typeof(self) weakSelf = self;
[self updateCacheWithCompletionHandler:^{
typeof(self) self = weakSelf; // strong self
[[NSNotificationCenter defaultCenter] postNotificationName:CESyntaxDidUpdateNotification
object:self
userInfo:@{CEOldNameKey: styleName,
CENewNameKey: styleName}];
}];
} else {
NSLog(@"Error. Could not restore \"%@\".", URL);
}
} else {
NSLog(@"Error. Could not be restore \"%@\" for restore.", URL);
// already removed.
success = YES;
}
if (!success) {
NSLog(@"Error. Could not restore \"%@\".", URL);
return NO;
}
//
[self styleCaches][styleName] = [[self bundledStyleDictionaryWithStyleName:styleName] mutableCopy];
__weak typeof(self) weakSelf = self;
[self updateCacheWithCompletionHandler:^{
typeof(self) self = weakSelf; // strong self
[[NSNotificationCenter defaultCenter] postNotificationName:CESyntaxDidUpdateNotification
object:self
userInfo:@{CEOldNameKey: styleName,
CENewNameKey: styleName}];
}];
return success;
}

View File

@ -245,7 +245,7 @@ NSString *_Nonnull const CEThemeDidUpdateNotification = @"CEThemeDidUpdateNotifi
{
NSURL *URL = [self URLForUserTheme:themeName available:YES];
if (!URL) { return NO; }
if (!URL) { return YES; } // already removed
BOOL success = [[NSFileManager defaultManager] trashItemAtURL:URL resultingItemURL:nil error:nil];