From 876dde21d97897ad4ee98aa0d6b11898282982ce Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 13 Dec 2014 18:02:01 +0100 Subject: Change [NSArray arrayWithObject:] to @[] literal Note: [NSArray arrayWithObjects:...,nil] is left unchanged as that could possibly cause a NPE if converted to @[] --- Source/SPEditorPreferencePane.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/SPEditorPreferencePane.m') diff --git a/Source/SPEditorPreferencePane.m b/Source/SPEditorPreferencePane.m index 93e5c42b..e5250e1d 100644 --- a/Source/SPEditorPreferencePane.m +++ b/Source/SPEditorPreferencePane.m @@ -131,7 +131,7 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; { NSSavePanel *panel = [NSSavePanel savePanel]; - [panel setAllowedFileTypes:[NSArray arrayWithObject:SPColorThemeFileExtension]]; + [panel setAllowedFileTypes:@[SPColorThemeFileExtension]]; [panel setExtensionHidden:NO]; [panel setAllowsOtherFileTypes:NO]; @@ -770,7 +770,7 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; if ([fm fileExistsAtPath:themePath isDirectory:nil]) { NSArray *allItemsRaw = [fm contentsOfDirectoryAtPath:themePath error:NULL]; - if(!allItemsRaw) return [NSArray array]; + if(!allItemsRaw) return @[]; // Filter out all themes NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH %@", [NSString stringWithFormat:@".%@", SPColorThemeFileExtension]]; @@ -791,7 +791,7 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; return (NSArray *)allItems; } - return [NSArray array]; + return @[]; } - (void)_saveColorThemeAtPath:(NSString *)path -- cgit v1.2.3 From 3b251b8e3d4dc9a694ef76562b388ab07da54785 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 13 Dec 2014 19:48:41 +0100 Subject: Replace some NSDictionaries with literals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [NSDictionary dictionary] → @{} * [NSDictionary dictionaryWithObject:forKey:] can safely be replaced. object==nil would have already thrown a NPE in the past. * Also replaced some (hopefully safe) NSArray initializers (ie. their objects should always exist). --- Source/SPEditorPreferencePane.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/SPEditorPreferencePane.m') diff --git a/Source/SPEditorPreferencePane.m b/Source/SPEditorPreferencePane.m index e5250e1d..d5127e65 100644 --- a/Source/SPEditorPreferencePane.m +++ b/Source/SPEditorPreferencePane.m @@ -66,7 +66,7 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; editThemeListItems = [[NSArray arrayWithArray:[self _getAvailableThemes]] retain]; editorColors = - [[NSArray arrayWithObjects: + [@[ SPCustomQueryEditorTextColor, SPCustomQueryEditorBackgroundColor, SPCustomQueryEditorCaretColor, @@ -77,11 +77,11 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; SPCustomQueryEditorBacktickColor, SPCustomQueryEditorVariableColor, SPCustomQueryEditorHighlightQueryColor, - SPCustomQueryEditorSelectionColor, - nil] retain]; + SPCustomQueryEditorSelectionColor + ] retain]; editorNameForColors = - [[NSArray arrayWithObjects: + [@[ NSLocalizedString(@"Text", @"text label for color table (Prefs > Editor)"), NSLocalizedString(@"Background", @"background label for color table (Prefs > Editor)"), NSLocalizedString(@"Caret", @"caret label for color table (Prefs > Editor)"), @@ -92,8 +92,8 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; NSLocalizedString(@"Backtick Quote", @"backtick quote label for color table (Prefs > Editor)"), NSLocalizedString(@"Variable", @"variable label for color table (Prefs > Editor)"), NSLocalizedString(@"Query Background", @"query background label for color table (Prefs > Editor)"), - NSLocalizedString(@"Selection", @"selection label for color table (Prefs > Editor)"), - nil] retain]; + NSLocalizedString(@"Selection", @"selection label for color table (Prefs > Editor)") + ] retain]; } return self; -- cgit v1.2.3 From f12b95bb7b3dda011dea4bb3e0edff1428a38209 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 31 Dec 2014 03:00:10 +0100 Subject: Remove some duplicate code by adding abstraction --- Source/SPEditorPreferencePane.m | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Source/SPEditorPreferencePane.m') diff --git a/Source/SPEditorPreferencePane.m b/Source/SPEditorPreferencePane.m index d5127e65..08a833c2 100644 --- a/Source/SPEditorPreferencePane.m +++ b/Source/SPEditorPreferencePane.m @@ -732,6 +732,14 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; return NO; } +- (void)preferencePaneWillBeShown +{ + [self updateColorSchemeSelectionMenu]; + [self updateDisplayColorThemeName]; + + [self updateDisplayedEditorFontName]; +} + #pragma mark - #pragma mark Private API -- cgit v1.2.3 From 2735e15bf5d4b3a976435ebb29ca9073de0e5071 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 4 Jan 2015 03:57:26 +0100 Subject: Formalize [x release], x = nil; convention Take this commit as a proposal to formalize our existing "[x release], x = nil;" convention by introducing a macro for it. Feel free to revert this commit if you see issues with the approch or implementation. --- Source/SPEditorPreferencePane.m | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Source/SPEditorPreferencePane.m') diff --git a/Source/SPEditorPreferencePane.m b/Source/SPEditorPreferencePane.m index 08a833c2..7eaecf47 100644 --- a/Source/SPEditorPreferencePane.m +++ b/Source/SPEditorPreferencePane.m @@ -209,7 +209,7 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; if (![fm fileExistsAtPath:selectedPath isDirectory:nil]) { if ([fm copyItemAtPath:[NSString stringWithFormat:@"%@/%@.%@", themePath, [editThemeListItems objectAtIndex:[editThemeListTable selectedRow]], SPColorThemeFileExtension] toPath:selectedPath error:nil]) { - if (editThemeListItems) [editThemeListItems release], editThemeListItems = nil; + if (editThemeListItems) SPClear(editThemeListItems); editThemeListItems = [[NSArray arrayWithArray:[self _getAvailableThemes]] retain]; @@ -243,7 +243,7 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; [prefs setObject:SPCustomColorSchemeName forKey:SPCustomQueryEditorThemeName]; } - if (editThemeListItems) [editThemeListItems release], editThemeListItems = nil; + if (editThemeListItems) SPClear(editThemeListItems); editThemeListItems = [[NSArray arrayWithArray:[self _getAvailableThemes]] retain]; @@ -313,7 +313,7 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; { [[NSColorPanel sharedColorPanel] close]; - if (editThemeListItems) [editThemeListItems release], editThemeListItems = nil; + if (editThemeListItems) SPClear(editThemeListItems); editThemeListItems = [[NSArray arrayWithArray:[self _getAvailableThemes]] retain]; @@ -595,7 +595,7 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; } // Reload everything needed - if (editThemeListItems) [editThemeListItems release], editThemeListItems = nil; + if (editThemeListItems) SPClear(editThemeListItems); editThemeListItems = [[NSArray arrayWithArray:[self _getAvailableThemes]] retain]; [editThemeListTable reloadData]; @@ -1029,10 +1029,10 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; */ - (void)dealloc { - if (themePath) [themePath release], themePath = nil; - if (editThemeListItems) [editThemeListItems release], editThemeListItems = nil; - if (editorColors) [editorColors release], editorColors = nil; - if (editorNameForColors) [editorNameForColors release], editorNameForColors = nil; + if (themePath) SPClear(themePath); + if (editThemeListItems) SPClear(editThemeListItems); + if (editorColors) SPClear(editorColors); + if (editorNameForColors) SPClear(editorNameForColors); [super dealloc]; } -- cgit v1.2.3