From 8c1128f6710c6738cc969a11f05bef89c8722c63 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 18 Aug 2010 13:55:36 +0000 Subject: =?UTF-8?q?=E2=80=A2=C2=A0added=20Query=20Editor=20color=20theme?= =?UTF-8?q?=20manager=20to=20the=20Editor=20Pref=20-=20themes=20can=20be?= =?UTF-8?q?=20saved/loaded=20in/from=20~/Library/Application=20Support/Seq?= =?UTF-8?q?uel=20Pro/Themes=20by=20using=20the=20gear=20menu=20items=20in?= =?UTF-8?q?=20the=20Editor=20Pref=20-=20rearrange=20the=20GUI=20-=20Edit?= =?UTF-8?q?=20Theme=20List=20follows=20soon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/Preferences.xib | 690 ++++++++++++++++++++++++++++--- Source/SPConstants.h | 1 + Source/SPConstants.m | 1 + Source/SPPreferenceController.h | 19 + Source/SPPreferenceController.m | 596 +++++++++++++++++--------- 5 files changed, 1046 insertions(+), 261 deletions(-) diff --git a/Interfaces/English.lproj/Preferences.xib b/Interfaces/English.lproj/Preferences.xib index f44b75b9..46df42c1 100644 --- a/Interfaces/English.lproj/Preferences.xib +++ b/Interfaces/English.lproj/Preferences.xib @@ -21,7 +21,8 @@ YES - + + YES @@ -604,7 +605,7 @@ 12 {{202.5, 176}, {360, 5}} - {{4, 0}, {352, 5}} + {{5.5, 0}, {349, 5}} {0, 0} @@ -3279,6 +3280,38 @@ AQAAAAA 268 YES + + + 268 + {{124, 28}, {121, 14}} + + YES + + 68288064 + 272761856 + theme name + + + + + + + + + 268 + {{49, 28}, {83, 14}} + + YES + + 68288064 + 272761856 + Color Theme: + + + + + + 268 @@ -3401,7 +3434,7 @@ AQAAAAA 0.57142859697341919 - {{20, 20}, {222, 244}} + {{20, 55}, {222, 244}} 2 @@ -3413,7 +3446,7 @@ AQAAAAA 268 - {{204, 275}, {24, 24}} + {{20, 23}, {24, 24}} YES @@ -3450,9 +3483,47 @@ AQAAAAA YES + + + Save current Theme… + + 2147483647 + + + _popUpItemAction: + + + + + Load saved Theme + + 2147483647 + + + submenuAction: + + Load saved Theme + + YES + + YES + + + + + YES + YES + + + 2147483647 + + + _popUpItemAction: + + - Export Color Scheme… + Export current Color Theme… 1048576 2147483647 @@ -3464,7 +3535,7 @@ AQAAAAA - Import Color Scheme… + Import Color Theme… 1048576 2147483647 @@ -3477,6 +3548,7 @@ AQAAAAA + 4 YES 1 YES @@ -3605,26 +3677,6 @@ AQAAAAA - - - 268 - {{26, 269}, {176, 32}} - - YES - - -2080244224 - 134217728 - Default Colors - - - -2038284033 - 129 - - - 200 - 25 - - 268 @@ -4185,6 +4237,112 @@ AQAAAAA + + 1 + 2 + {{343, 491}, {216, 104}} + 1886912512 + + NSWindow + + View + + {216, 104} + {216, 104} + + + 256 + + YES + + + 256 + {{17, 76}, {182, 14}} + + YES + + 68288064 + 4195328 + Name: + + + + + + + + + 258 + {{20, 50}, {176, 18}} + + YES + + -1804468671 + 4326400 + + + + YES + + + + + + + 259 + {{113, 13}, {88, 28}} + + 1 + YES + + 604110336 + 138018816 + Save + + + 1 + -2038284033 + 1 + + Helvetica + 11 + 16 + + + DQ + 200 + 25 + + + + + 259 + {{15, 13}, {88, 28}} + + YES + + 67239424 + 138018816 + Cancel + + + -2038284033 + 1 + + + Gw + 200 + 25 + + + + {216, 104} + + + {{0, 0}, {1280, 778}} + {216, 126} + {216, 126} + @@ -4786,14 +4944,6 @@ AQAAAAA 961 - - - setDefaultColors: - - - - 1086 - showCustomQueryFontPanel: @@ -6354,6 +6504,143 @@ AQAAAAA 1693 + + + saveColorScheme: + + + + 1713 + + + + themeSelectionMenu + + + + 1715 + + + + nextKeyView + + + + 1733 + + + + nextKeyView + + + + 1734 + + + + enterNameWindow + + + + 1735 + + + + enterNameLabel + + + + 1736 + + + + enterNameInputField + + + + 1737 + + + + colorThemeName + + + + 1742 + + + + colorThemeNameLabel + + + + 1743 + + + + value: values.CustomQueryEditorThemeName + + + + + + value: values.CustomQueryEditorThemeName + value + values.CustomQueryEditorThemeName + + YES + + YES + NSMultipleValuesPlaceholder + NSNoSelectionPlaceholder + NSNotApplicablePlaceholder + NSNullPlaceholder + + + YES + User-defined + User-defined + User-defined + User-defined + + + 2 + + + 1751 + + + + closePanelSheet: + + + + 1752 + + + + closePanelSheet: + + + + 1753 + + + + themeNameSaveButton + + + + 1754 + + + + delegate + + + + 1755 + @@ -7296,9 +7583,10 @@ AQAAAAA - - + + + Editor @@ -7340,15 +7628,6 @@ AQAAAAA - - 1035 - - - YES - - - - 1036 @@ -7447,11 +7726,6 @@ AQAAAAA - - 1059 - - - 1060 @@ -8947,6 +9221,9 @@ AQAAAAA + + + @@ -9024,6 +9301,139 @@ AQAAAAA + + 1708 + + + + + 1709 + + + YES + + + + + + 1710 + + + YES + + + + + 1712 + + + + + 1716 + + + YES + + + + Enter Name Sheet + + + 1717 + + + YES + + + + + + + + + 1718 + + + YES + + + + + + 1721 + + + YES + + + + + + 1722 + + + YES + + + + + + 1723 + + + YES + + + + + + 1724 + + + + + 1725 + + + + + 1726 + + + + + 1730 + + + + + 1738 + + + YES + + + + + + 1739 + + + + + 1740 + + + YES + + + + + + 1741 + + + @@ -9045,7 +9455,6 @@ AQAAAAA 102.IBPluginDependency 102.ImportedFromIB2 1034.IBPluginDependency - 1035.IBPluginDependency 1036.IBPluginDependency 1037.IBPluginDependency 1039.IBPluginDependency @@ -9068,7 +9477,6 @@ AQAAAAA 1055.IBPluginDependency 1057.IBPluginDependency 1058.IBPluginDependency - 1059.IBPluginDependency 1060.IBPluginDependency 1083.IBPluginDependency 1084.IBPluginDependency @@ -9276,6 +9684,7 @@ AQAAAAA 1672.IBPluginDependency 1673.IBAttributePlaceholdersKey 1673.IBPluginDependency + 1674.IBAttributePlaceholdersKey 1674.IBPluginDependency 1682.IBPluginDependency 1683.IBPluginDependency @@ -9288,6 +9697,39 @@ AQAAAAA 17.IBEditorWindowLastContentRect 17.IBPluginDependency 17.IBUserGuides + 1708.IBAttributePlaceholdersKey + 1708.IBPluginDependency + 1709.IBPluginDependency + 1710.IBEditorWindowLastContentRect + 1710.IBPluginDependency + 1712.IBPluginDependency + 1716.IBEditorWindowLastContentRect + 1716.IBPluginDependency + 1716.IBWindowTemplateEditedContentRect + 1716.ImportedFromIB2 + 1716.windowTemplate.hasMaxSize + 1716.windowTemplate.hasMinSize + 1716.windowTemplate.maxSize + 1716.windowTemplate.minSize + 1717.IBPluginDependency + 1717.ImportedFromIB2 + 1718.IBPluginDependency + 1718.ImportedFromIB2 + 1721.IBPluginDependency + 1721.ImportedFromIB2 + 1722.IBPluginDependency + 1722.ImportedFromIB2 + 1723.IBPluginDependency + 1723.ImportedFromIB2 + 1724.IBPluginDependency + 1725.IBPluginDependency + 1726.IBPluginDependency + 1730.IBPluginDependency + 1738.IBPluginDependency + 1739.IBPluginDependency + 1740.IBAttributePlaceholdersKey + 1740.IBPluginDependency + 1741.IBPluginDependency 2.IBPluginDependency 24.IBPluginDependency 24.ImportedFromIB2 @@ -9555,7 +9997,6 @@ AQAAAAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -9585,7 +10026,6 @@ AQAAAAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin InitialTabViewItem @@ -9791,22 +10231,31 @@ AQAAAAA ToolTip - Export/Import Color Scheme + Manage Color Theme com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{214, 248}, {184, 71}} + {{127, 100}, {220, 115}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - YES - - - YES + ToolTip + + ToolTip + + Export the current set color theme as 'spTheme' to disk com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Import a theme saved as 'spTheme' or 'tmTheme' (TextMate™) file + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -9826,6 +10275,53 @@ AQAAAAA 0 + + ToolTip + + ToolTip + + Save the current set color theme by providing an unique name into Sequel Pro's Application Support folder + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{352, 158}, {64, 6}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{202, 175}, {216, 104}} + com.apple.InterfaceBuilder.CocoaPlugin + {{202, 175}, {216, 104}} + + + + {216, 104} + {216, 104} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + The name of the current set color theme + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -10106,7 +10602,7 @@ AQAAAAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{286, 395}, {580, 361}} + {{118, 168}, {580, 361}} com.apple.InterfaceBuilder.CocoaPlugin YES @@ -10159,7 +10655,7 @@ AQAAAAA - 1707 + 1755 @@ -10667,6 +11163,7 @@ AQAAAAA YES addFavorite: changeFont: + closePanelSheet: displayAutoUpdatePreferences: displayEditorPreferences: displayFavoritePreferences: @@ -10678,9 +11175,11 @@ AQAAAAA exportColorScheme: favoriteTypeDidChange: importColorScheme: + loadColorScheme: makeSelectedFavoriteDefault: removeFavorite: reverseFavoritesSortOrder: + saveColorScheme: setDefaultColors: showCustomQueryFontPanel: showGlobalResultTableFontPanel: @@ -10710,6 +11209,9 @@ AQAAAAA id id id + id + id + id @@ -10718,6 +11220,7 @@ AQAAAAA YES addFavorite: changeFont: + closePanelSheet: displayAutoUpdatePreferences: displayEditorPreferences: displayFavoritePreferences: @@ -10729,9 +11232,11 @@ AQAAAAA exportColorScheme: favoriteTypeDidChange: importColorScheme: + loadColorScheme: makeSelectedFavoriteDefault: removeFavorite: reverseFavoritesSortOrder: + saveColorScheme: setDefaultColors: showCustomQueryFontPanel: showGlobalResultTableFontPanel: @@ -10748,6 +11253,10 @@ AQAAAAA changeFont: id + + closePanelSheet: + id + displayAutoUpdatePreferences: id @@ -10792,6 +11301,10 @@ AQAAAAA importColorScheme: id + + loadColorScheme: + id + makeSelectedFavoriteDefault: id @@ -10804,6 +11317,10 @@ AQAAAAA reverseFavoritesSortOrder: id + + saveColorScheme: + id + setDefaultColors: id @@ -10832,9 +11349,14 @@ AQAAAAA YES autoUpdateView colorSettingTableView + colorThemeName + colorThemeNameLabel defaultFavoritePopup editorFontName editorView + enterNameInputField + enterNameLabel + enterNameWindow favoriteHostTextField favoriteHostTextFieldSSH favoriteNameTextField @@ -10858,16 +11380,23 @@ AQAAAAA standardPasswordField tableCell tablesView + themeNameSaveButton + themeSelectionMenu YES NSView NSTableView + NSTextField + NSTextField NSPopUpButton NSTextField NSView NSTextField NSTextField + NSWindow + NSTextField + NSTextField NSTextField NSTextField NSTextField @@ -10889,6 +11418,8 @@ AQAAAAA NSSecureTextField id NSView + id + NSMenu @@ -10897,9 +11428,14 @@ AQAAAAA YES autoUpdateView colorSettingTableView + colorThemeName + colorThemeNameLabel defaultFavoritePopup editorFontName editorView + enterNameInputField + enterNameLabel + enterNameWindow favoriteHostTextField favoriteHostTextFieldSSH favoriteNameTextField @@ -10923,6 +11459,8 @@ AQAAAAA standardPasswordField tableCell tablesView + themeNameSaveButton + themeSelectionMenu YES @@ -10934,6 +11472,14 @@ AQAAAAA colorSettingTableView NSTableView + + colorThemeName + NSTextField + + + colorThemeNameLabel + NSTextField + defaultFavoritePopup NSPopUpButton @@ -10946,6 +11492,18 @@ AQAAAAA editorView NSView + + enterNameInputField + NSTextField + + + enterNameLabel + NSTextField + + + enterNameWindow + NSWindow + favoriteHostTextField NSTextField @@ -11038,6 +11596,14 @@ AQAAAAA tablesView NSView + + themeNameSaveButton + id + + + themeSelectionMenu + NSMenu + diff --git a/Source/SPConstants.h b/Source/SPConstants.h index 58630aa6..9086128a 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -296,6 +296,7 @@ extern NSString *SPCustomQueryEditorTabStopWidth; extern NSString *SPCustomQueryAutoComplete; extern NSString *SPCustomQueryAutoCompleteDelay; extern NSString *SPCustomQueryFunctionCompletionInsertsArguments; +extern NSString *SPCustomQueryEditorThemeName; // AutoUpdate Prefpane extern NSString *SPLastUsedVersion; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index f9865eb6..8fa5aadd 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -119,6 +119,7 @@ NSString *SPCustomQueryEditorTabStopWidth = @"CustomQueryEditorTabStopWid NSString *SPCustomQueryAutoComplete = @"CustomQueryAutoComplete"; NSString *SPCustomQueryAutoCompleteDelay = @"CustomQueryAutoCompleteDelay"; NSString *SPCustomQueryFunctionCompletionInsertsArguments = @"CustomQueryFunctionCompletionInsertsArguments"; +NSString *SPCustomQueryEditorThemeName = @"CustomQueryEditorThemeName"; // AutoUpdate Prefpane NSString *SPLastUsedVersion = @"LastUsedVersion"; diff --git a/Source/SPPreferenceController.h b/Source/SPPreferenceController.h index 428bfd6d..8dae6077 100644 --- a/Source/SPPreferenceController.h +++ b/Source/SPPreferenceController.h @@ -59,9 +59,17 @@ IBOutlet NSTextField *favoriteHostTextFieldSSH; IBOutlet NSMenuItem *favoritesSortByMenuItem; + IBOutlet NSWindow *enterNameWindow; + IBOutlet NSTextField *enterNameLabel; + IBOutlet NSTextField *enterNameInputField; + IBOutlet NSTextField *colorThemeName; + IBOutlet NSTextField *colorThemeNameLabel; + IBOutlet id themeNameSaveButton; + IBOutlet id tableCell; IBOutlet NSTableView *colorSettingTableView; + IBOutlet NSMenu *themeSelectionMenu; NSArray *editorColors; NSArray *editorNameForColors; NSUInteger colorRow; @@ -92,6 +100,8 @@ BOOL reverseFavoritesSort; SPFavoritesSortItem previousSortItem, currentSortItem; + + NSString *themePath; } - (void)applyRevisionChanges; @@ -109,6 +119,9 @@ - (IBAction)makeSelectedFavoriteDefault:(id)sender; - (IBAction)exportColorScheme:(id)sender; - (IBAction)importColorScheme:(id)sender; +- (IBAction)saveColorScheme:(id)sender; +- (IBAction)loadColorScheme:(id)sender; +- (IBAction)closePanelSheet:(id)sender; // Toolbar item IBAction methods @@ -126,5 +139,11 @@ - (void)changeFont:(id)sender; - (IBAction)favoriteTypeDidChange:(id)sender; - (void)updateFavoritePasswordsFromField:(NSControl *)passwordControl; +- (void)updateColorSchemeSelectionMenu; +- (void)saveColorThemeAtPath:(NSString*)path; +- (BOOL)loadColorSchemeFromFile:(NSString*)filename; +- (BOOL)checkForUnsavedTheme; +- (void)updateDisplayColorThemeName; +- (NSArray *)getAvailableThemes; @end diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index ad8d6bb8..19cfbfd0 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -60,9 +60,13 @@ favoriteType = 0; fontChangeTarget = 0; reverseFavoritesSort = NO; - + previousSortItem = SPFavoritesSortNameItem; + [NSColor setIgnoresAlpha:NO]; + + themePath = [[[NSString stringWithString:@"~/Library/Application Support/Sequel Pro/Themes"] stringByExpandingTildeInPath] retain]; + } return self; @@ -568,6 +572,10 @@ - (IBAction)importColorScheme:(id)sender { + + if(![self checkForUnsavedTheme]) return; + + NSOpenPanel *panel = [NSOpenPanel openPanel]; [panel setCanSelectHiddenExtension:YES]; [panel setDelegate:self]; @@ -584,6 +592,39 @@ } +- (IBAction)loadColorScheme:(id)sender +{ + + if(![self checkForUnsavedTheme]) return; + + if([self loadColorSchemeFromFile:[NSString stringWithFormat:@"%@/%@.%@", themePath, [sender title], SPColorThemeFileExtension]]) { + [prefs setObject:[sender title] forKey:SPCustomQueryEditorThemeName]; + [self updateDisplayColorThemeName]; + } + +} + +- (IBAction)saveColorScheme:(id)sender +{ + + [[NSColorPanel sharedColorPanel] close]; + + [enterNameLabel setStringValue:NSLocalizedString(@"Theme Name:", @"theme name label")]; + + [NSApp beginSheet:enterNameWindow + modalForWindow:[self window] + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:@"saveTheme"]; + +} + +- (IBAction)closePanelSheet:(id)sender +{ + [NSApp endSheet:[sender window] returnCode:[sender tag]]; + [[sender window] orderOut:self]; +} + #pragma mark - #pragma mark Toolbar item IBAction methods @@ -618,6 +659,10 @@ // ------------------------------------------------------------------------------- - (IBAction)displayEditorPreferences:(id)sender { + + [self updateColorSchemeSelectionMenu]; + [self updateDisplayColorThemeName]; + [[self window] setMinSize:NSMakeSize(0, 0)]; [[self window] setShowsResizeIndicator:NO]; @@ -1041,6 +1086,27 @@ - (void)controlTextDidChange:(NSNotification *)aNotification { id field = [aNotification object]; + + // Validate 'Save' button for entering a valid theme name + if(field == enterNameInputField) { + NSString *name = [[enterNameInputField stringValue] lowercaseString]; + + if(![name length] || [name isEqualToString:@"default"] || [name isEqualToString:@"user-defined"]) { + [themeNameSaveButton setEnabled:NO]; + } else { + BOOL enable = YES; + for(NSString* item in [self getAvailableThemes]) { + if([[item lowercaseString] isEqualToString:name]) { + enable = NO; + break; + } + } + [themeNameSaveButton setEnabled:enable]; + } + + return; + + } BOOL nameFieldIsEmpty = ( [[favoritesController valueForKeyPath:@"selection.name"] isEqualToString:@""] @@ -1279,7 +1345,22 @@ [self updateDefaultFavoritePopup]; } + } else if([contextInfo isEqualToString:@"saveTheme"]) { + if (returnCode == NSOKButton) { + NSFileManager *fm = [NSFileManager defaultManager]; + if(![fm fileExistsAtPath:themePath isDirectory:nil]) { + if(![fm createDirectoryAtPath:themePath withIntermediateDirectories:YES attributes:nil error:nil]) { + NSBeep(); + return; + } + } + [self saveColorThemeAtPath:[NSString stringWithFormat:@"%@/%@.%@", themePath, [enterNameInputField stringValue], SPColorThemeFileExtension]]; + [self updateColorSchemeSelectionMenu]; + [prefs setObject:[enterNameInputField stringValue] forKey:SPCustomQueryEditorThemeName]; + [self updateDisplayColorThemeName]; + } } + } - (void)setGrowlEnabled:(BOOL)value @@ -1300,7 +1381,82 @@ return [prefs boolForKey:SPGrowlEnabled]; } +- (void)editThemeList +{ + NSAlert *alert = [NSAlert alertWithMessageText:@"Not yet implemented. Please be patient." + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:@""]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; +} + +- (NSArray *)getAvailableThemes +{ + // Read ~/Library/Application Support/Sequel Pro/Themes + NSFileManager *fm = [NSFileManager defaultManager]; + if([fm fileExistsAtPath:themePath isDirectory:nil]) { + NSArray *allItemsRaw = [fm contentsOfDirectoryAtPath:themePath error:NULL]; + if(!allItemsRaw) return [NSArray array]; + + // Filter out all themes + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH %@", [NSString stringWithFormat:@".%@", SPColorThemeFileExtension]]; + NSMutableArray *allItems = [NSMutableArray arrayWithArray:allItemsRaw]; + [allItems filterUsingPredicate:predicate]; + + allItemsRaw = [NSArray arrayWithArray:allItems]; + [allItems removeAllObjects]; + + // Remove file extension + for(NSString* item in allItemsRaw) + [allItems addObject:[item substringToIndex:[item length]-[SPColorThemeFileExtension length]-1]]; + + return (NSArray *)allItems; + } + return [NSArray array]; +} + +- (void)updateColorSchemeSelectionMenu +{ + + // Build theme selection submenu + [themeSelectionMenu removeAllItems]; + [themeSelectionMenu setAutoenablesItems:YES]; + [themeSelectionMenu setShowsStateColumn:YES]; + [themeSelectionMenu addItemWithTitle:NSLocalizedString(@"Default", @"default color scheme label") action:@selector(setDefaultColors:) keyEquivalent:@""]; + [themeSelectionMenu addItem:[NSMenuItem separatorItem]]; + + NSArray *foundThemes = [self getAvailableThemes]; + if([foundThemes count]) { + for(NSString* item in foundThemes) + [themeSelectionMenu addItemWithTitle:item action:@selector(loadColorScheme:) keyEquivalent:@""]; + [themeSelectionMenu addItem:[NSMenuItem separatorItem]]; + } + [themeSelectionMenu addItemWithTitle:NSLocalizedString(@"Edit Theme List…", @"edit theme list label") action:@selector(editThemeList) keyEquivalent:@""]; + +} +- (void)updateDisplayColorThemeName +{ + + if(![prefs objectForKey:SPCustomQueryEditorThemeName]) { + [colorThemeName setHidden:YES]; + [colorThemeNameLabel setHidden:YES]; + return; + } + + if([[[prefs objectForKey:SPCustomQueryEditorThemeName] lowercaseString] isEqualToString:@"user-defined"]) { + [colorThemeName setHidden:YES]; + [colorThemeNameLabel setHidden:YES]; + return; + } + + [colorThemeName setHidden:NO]; + [colorThemeNameLabel setHidden:NO]; + +} // ------------------------------------------------------------------------------- // updateDefaultFavoritePopup: // @@ -1375,7 +1531,11 @@ // reset syntax highlighting colors - (IBAction)setDefaultColors:(id)sender { + + if(![self checkForUnsavedTheme]) return; + [[NSColorPanel sharedColorPanel] close]; + [prefs setObject:@"Default" forKey:SPCustomQueryEditorThemeName]; [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.000 green:0.455 blue:0.000 alpha:1.000]] forKey:SPCustomQueryEditorCommentColor]; [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.769 green:0.102 blue:0.086 alpha:1.000]] forKey:SPCustomQueryEditorQuoteColor]; [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.200 green:0.250 blue:1.000 alpha:1.000]] forKey:SPCustomQueryEditorSQLKeywordColor]; @@ -1388,6 +1548,7 @@ [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:SPCustomQueryEditorCaretColor]; [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor whiteColor]] forKey:SPCustomQueryEditorBackgroundColor]; [colorSettingTableView reloadData]; + [self updateDisplayColorThemeName]; } - (void)colorClick:(id)sender @@ -1409,6 +1570,8 @@ if(![[NSColorPanel sharedColorPanel] isVisible]) return; [prefs setObject:[NSArchiver archivedDataWithRootObject:[sender color]] forKey:[editorColors objectAtIndex:colorRow]]; [colorSettingTableView reloadData]; + [prefs setObject:@"User-defined" forKey:SPCustomQueryEditorThemeName]; + [self updateDisplayColorThemeName]; } @@ -1473,226 +1636,260 @@ return YES; } -/** - * Save panel did end method. - */ -- (void)panelDidEnd:(NSSavePanel *)panel returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo +- (void)saveColorThemeAtPath:(NSString*)path { + // Build plist dictionary + NSMutableDictionary *scheme = [NSMutableDictionary dictionary]; + NSMutableDictionary *mainsettings = [NSMutableDictionary dictionary]; + NSMutableArray *settings = [NSMutableArray array]; - if([contextInfo isEqualToString:@"exportColorScheme"]) { - if (returnCode == NSOKButton) { + CGFloat red, green, blue, alpha; + NSInteger redInt, greenInt, blueInt, alphaInt; + NSString *redHexValue, *greenHexValue, *blueHexValue, *alphaHexValue; + + [prefs synchronize]; - // Build plist dictionary - NSMutableDictionary *scheme = [NSMutableDictionary dictionary]; - NSMutableDictionary *mainsettings = [NSMutableDictionary dictionary]; - NSMutableArray *settings = [NSMutableArray array]; + NSColor *aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]]; + [mainsettings setObject:[aColor rgbHexString] forKey:@"background"]; - CGFloat red, green, blue, alpha; - NSInteger redInt, greenInt, blueInt, alphaInt; - NSString *redHexValue, *greenHexValue, *blueHexValue, *alphaHexValue; + aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCaretColor]]; + [mainsettings setObject:[aColor rgbHexString] forKey:@"caret"]; - [prefs synchronize]; + aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorTextColor]]; + [mainsettings setObject:[aColor rgbHexString] forKey:@"foreground"]; - NSColor *aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]]; - [mainsettings setObject:[aColor rgbHexString] forKey:@"background"]; - - aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCaretColor]]; - [mainsettings setObject:[aColor rgbHexString] forKey:@"caret"]; - - aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorTextColor]]; - [mainsettings setObject:[aColor rgbHexString] forKey:@"foreground"]; - - aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorHighlightQueryColor]]; - [mainsettings setObject:[aColor rgbHexString] forKey:@"lineHighlight"]; - - aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSelectionColor]]; - [mainsettings setObject:[aColor rgbHexString] forKey:@"selection"]; - - [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys:mainsettings, @"settings", nil]]; - - aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCommentColor]]; - [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: - @"Comment", @"name", - [NSDictionary dictionaryWithObjectsAndKeys: - [aColor rgbHexString], @"foreground", - nil - ], @"settings", - nil - ]]; - - aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorQuoteColor]]; - [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: - @"String", @"name", - [NSDictionary dictionaryWithObjectsAndKeys: - [aColor rgbHexString], @"foreground", - nil - ], @"settings", - nil - ]]; - - aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSQLKeywordColor]]; - [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: - @"Keyword", @"name", - [NSDictionary dictionaryWithObjectsAndKeys: - [aColor rgbHexString], @"foreground", - nil - ], @"settings", - nil - ]]; - - aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBacktickColor]]; - [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: - @"User-defined constant", @"name", - [NSDictionary dictionaryWithObjectsAndKeys: - [aColor rgbHexString], @"foreground", - nil - ], @"settings", - nil - ]]; - - aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorNumericColor]]; - [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: - @"Number", @"name", - [NSDictionary dictionaryWithObjectsAndKeys: - [aColor rgbHexString], @"foreground", - nil - ], @"settings", - nil - ]]; - - aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorVariableColor]]; - [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: - @"Variable", @"name", - [NSDictionary dictionaryWithObjectsAndKeys: - [aColor rgbHexString], @"foreground", - nil - ], @"settings", - nil - ]]; - - [scheme setObject:settings forKey:@"settings"]; - - NSString *err = nil; - NSData *plist = [NSPropertyListSerialization dataFromPropertyList:scheme - format:NSPropertyListXMLFormat_v1_0 - errorDescription:&err]; - - if(err != nil) { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting color scheme data", @"error while converting color scheme data")] - defaultButton:NSLocalizedString(@"OK", @"OK button") - alternateButton:nil - otherButton:nil - informativeTextWithFormat:err]; - - [alert setAlertStyle:NSCriticalAlertStyle]; - [alert runModal]; - return; - } + aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorHighlightQueryColor]]; + [mainsettings setObject:[aColor rgbHexString] forKey:@"lineHighlight"]; + + aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSelectionColor]]; + [mainsettings setObject:[aColor rgbHexString] forKey:@"selection"]; + + [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys:mainsettings, @"settings", nil]]; + + aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCommentColor]]; + [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: + @"Comment", @"name", + [NSDictionary dictionaryWithObjectsAndKeys: + [aColor rgbHexString], @"foreground", + nil + ], @"settings", + nil + ]]; + + aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorQuoteColor]]; + [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: + @"String", @"name", + [NSDictionary dictionaryWithObjectsAndKeys: + [aColor rgbHexString], @"foreground", + nil + ], @"settings", + nil + ]]; + + aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSQLKeywordColor]]; + [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: + @"Keyword", @"name", + [NSDictionary dictionaryWithObjectsAndKeys: + [aColor rgbHexString], @"foreground", + nil + ], @"settings", + nil + ]]; - NSError *error = nil; - [plist writeToFile:[panel filename] options:NSAtomicWrite error:&error]; - if (error) [[NSAlert alertWithError:error] runModal]; + aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBacktickColor]]; + [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: + @"User-defined constant", @"name", + [NSDictionary dictionaryWithObjectsAndKeys: + [aColor rgbHexString], @"foreground", + nil + ], @"settings", + nil + ]]; + + aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorNumericColor]]; + [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: + @"Number", @"name", + [NSDictionary dictionaryWithObjectsAndKeys: + [aColor rgbHexString], @"foreground", + nil + ], @"settings", + nil + ]]; + + aColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorVariableColor]]; + [settings addObject:[NSDictionary dictionaryWithObjectsAndKeys: + @"Variable", @"name", + [NSDictionary dictionaryWithObjectsAndKeys: + [aColor rgbHexString], @"foreground", + nil + ], @"settings", + nil + ]]; + + [scheme setObject:settings forKey:@"settings"]; + + NSString *err = nil; + NSData *plist = [NSPropertyListSerialization dataFromPropertyList:scheme + format:NSPropertyListXMLFormat_v1_0 + errorDescription:&err]; + + if(err != nil) { + NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting color scheme data", @"error while converting color scheme data")] + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:err]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + return; + } + + NSError *error = nil; + [plist writeToFile:path options:NSAtomicWrite error:&error]; + if (error) [[NSAlert alertWithError:error] runModal]; +} + +- (BOOL)checkForUnsavedTheme +{ + if(![prefs objectForKey:SPCustomQueryEditorThemeName] || [[[prefs objectForKey:SPCustomQueryEditorThemeName] lowercaseString] isEqualToString:@"user-defined"]) { + + NSAlert *alert = [[[NSAlert alloc] init] autorelease]; + [alert addButtonWithTitle:NSLocalizedString(@"Proceed", @"proceed button")]; + [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"cancel button")]; + [alert setMessageText:NSLocalizedString(@"Current color theme is unsaved. Do you want to proceed without saving it?", @"Current color theme is unsaved. Do you want to proceed without saving it message")]; + [alert setInformativeText:@""]; + [alert setAlertStyle:NSWarningAlertStyle]; + NSInteger choice = [[alert onMainThread] runModal]; + if(choice == NSAlertFirstButtonReturn) { + [[NSColorPanel sharedColorPanel] close]; + return YES; } + + return NO; } - else if([contextInfo isEqualToString:@"importColorScheme"]) { - if (returnCode == NSOKButton) { - NSString *filename = [[panel filenames] objectAtIndex:0]; - NSError *readError = nil; - NSString *convError = nil; - NSPropertyListFormat format; + [[NSColorPanel sharedColorPanel] close]; + return YES; +} - NSDictionary *theme = nil; +- (BOOL)loadColorSchemeFromFile:(NSString*)filename +{ + NSError *readError = nil; + NSString *convError = nil; + NSPropertyListFormat format; - NSData *pData = [NSData dataWithContentsOfFile:filename options:NSUncachedRead error:&readError]; + NSDictionary *theme = nil; - theme = [[NSPropertyListSerialization propertyListFromData:pData - mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain]; + NSData *pData = [NSData dataWithContentsOfFile:filename options:NSUncachedRead error:&readError]; - if(!theme || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading data file", @"error while reading data file")] - defaultButton:NSLocalizedString(@"OK", @"OK button") - alternateButton:nil - otherButton:nil - informativeTextWithFormat:NSLocalizedString(@"File couldn't be read.", @"error while reading data file")]; + theme = [[NSPropertyListSerialization propertyListFromData:pData + mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain]; - [alert setAlertStyle:NSCriticalAlertStyle]; - [alert runModal]; - if (theme) [theme release]; - return; - } + if(!theme || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { + NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading data file", @"error while reading data file")] + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:NSLocalizedString(@"File couldn't be read.", @"error while reading data file")]; - if([theme objectForKey:@"settings"] - && [[theme objectForKey:@"settings"] isKindOfClass:[NSArray class]] - && [[theme objectForKey:@"settings"] count] - && [[[theme objectForKey:@"settings"] objectAtIndex:0] isKindOfClass:[NSDictionary class]] - && [[[theme objectForKey:@"settings"] objectAtIndex:0] objectForKey:@"settings"]) { - - NSInteger counter = 0; - for(NSDictionary *dict in [theme objectForKey:@"settings"]) { - if(counter == 0) { - if([dict objectForKey:@"settings"]) { - NSDictionary *dic = [dict objectForKey:@"settings"]; - if([dic objectForKey:@"background"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"background"]]] forKey:SPCustomQueryEditorBackgroundColor]; - if([dic objectForKey:@"caret"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"caret"]]] forKey:SPCustomQueryEditorCaretColor]; - if([dic objectForKey:@"foreground"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"foreground"]]] forKey:SPCustomQueryEditorTextColor]; - if([dic objectForKey:@"lineHighlight"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"lineHighlight"]]] forKey:SPCustomQueryEditorHighlightQueryColor]; - if([dic objectForKey:@"selection"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"selection"]]] forKey:SPCustomQueryEditorSelectionColor]; - } else { - continue; - } - } else { - if([dict objectForKey:@"name"] && [dict objectForKey:@"settings"] && [[dict objectForKey:@"settings"] isKindOfClass:[NSDictionary class]] && [[dict objectForKey:@"settings"] objectForKey:@"foreground"]) { - if([[dict objectForKey:@"name"] isEqualToString:@"Comment"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject: - [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] - forKey:SPCustomQueryEditorCommentColor]; - else if([[dict objectForKey:@"name"] isEqualToString:@"String"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject: - [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] - forKey:SPCustomQueryEditorQuoteColor]; - else if([[dict objectForKey:@"name"] isEqualToString:@"Keyword"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject: - [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] - forKey:SPCustomQueryEditorSQLKeywordColor]; - else if([[dict objectForKey:@"name"] isEqualToString:@"User-defined constant"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject: - [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] - forKey:SPCustomQueryEditorBacktickColor]; - else if([[dict objectForKey:@"name"] isEqualToString:@"Number"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject: - [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] - forKey:SPCustomQueryEditorNumericColor]; - else if([[dict objectForKey:@"name"] isEqualToString:@"Variable"]) - [prefs setObject:[NSArchiver archivedDataWithRootObject: - [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] - forKey:SPCustomQueryEditorVariableColor]; - } - } - counter++; + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + if (theme) [theme release]; + return NO; + } + + if([theme objectForKey:@"settings"] + && [[theme objectForKey:@"settings"] isKindOfClass:[NSArray class]] + && [[theme objectForKey:@"settings"] count] + && [[[theme objectForKey:@"settings"] objectAtIndex:0] isKindOfClass:[NSDictionary class]] + && [[[theme objectForKey:@"settings"] objectAtIndex:0] objectForKey:@"settings"]) { + + NSInteger counter = 0; + for(NSDictionary *dict in [theme objectForKey:@"settings"]) { + if(counter == 0) { + if([dict objectForKey:@"settings"]) { + NSDictionary *dic = [dict objectForKey:@"settings"]; + if([dic objectForKey:@"background"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"background"]]] forKey:SPCustomQueryEditorBackgroundColor]; + if([dic objectForKey:@"caret"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"caret"]]] forKey:SPCustomQueryEditorCaretColor]; + if([dic objectForKey:@"foreground"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"foreground"]]] forKey:SPCustomQueryEditorTextColor]; + if([dic objectForKey:@"lineHighlight"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"lineHighlight"]]] forKey:SPCustomQueryEditorHighlightQueryColor]; + if([dic objectForKey:@"selection"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithRGBHexString:[dic objectForKey:@"selection"]]] forKey:SPCustomQueryEditorSelectionColor]; + } else { + continue; } + } else { + if([dict objectForKey:@"name"] && [dict objectForKey:@"settings"] && [[dict objectForKey:@"settings"] isKindOfClass:[NSDictionary class]] && [[dict objectForKey:@"settings"] objectForKey:@"foreground"]) { + if([[dict objectForKey:@"name"] isEqualToString:@"Comment"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject: + [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] + forKey:SPCustomQueryEditorCommentColor]; + else if([[dict objectForKey:@"name"] isEqualToString:@"String"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject: + [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] + forKey:SPCustomQueryEditorQuoteColor]; + else if([[dict objectForKey:@"name"] isEqualToString:@"Keyword"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject: + [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] + forKey:SPCustomQueryEditorSQLKeywordColor]; + else if([[dict objectForKey:@"name"] isEqualToString:@"User-defined constant"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject: + [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] + forKey:SPCustomQueryEditorBacktickColor]; + else if([[dict objectForKey:@"name"] isEqualToString:@"Number"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject: + [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] + forKey:SPCustomQueryEditorNumericColor]; + else if([[dict objectForKey:@"name"] isEqualToString:@"Variable"]) + [prefs setObject:[NSArchiver archivedDataWithRootObject: + [NSColor colorWithRGBHexString:[[dict objectForKey:@"settings"] objectForKey:@"foreground"]]] + forKey:SPCustomQueryEditorVariableColor]; + } + } + counter++; + } - [theme release]; - [colorSettingTableView reloadData]; + [theme release]; + [colorSettingTableView reloadData]; - } else { + } else { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading data file", @"error while reading data file")] - defaultButton:NSLocalizedString(@"OK", @"OK button") - alternateButton:nil - otherButton:nil - informativeTextWithFormat:NSLocalizedString(@"No color theme data found.", @"error that no color theme found")]; + NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading data file", @"error while reading data file")] + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:NSLocalizedString(@"No color theme data found.", @"error that no color theme found")]; - [alert setAlertStyle:NSInformationalAlertStyle]; - [alert runModal]; - [theme release]; - return; + [alert setAlertStyle:NSInformationalAlertStyle]; + [alert runModal]; + [theme release]; + return NO; + + } + return YES; +} +/** + * Save panel did end method. + */ +- (void)panelDidEnd:(NSSavePanel *)panel returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo +{ + + if([contextInfo isEqualToString:@"exportColorScheme"]) { + if (returnCode == NSOKButton) { + [self saveColorThemeAtPath:[panel filename]]; + } + } + else if([contextInfo isEqualToString:@"importColorScheme"]) { + if (returnCode == NSOKButton) { + if([self loadColorSchemeFromFile:[[panel filenames] objectAtIndex:0]]) { + [prefs setObject:@"User-defined" forKey:SPCustomQueryEditorThemeName]; + [self updateDisplayColorThemeName]; } } } @@ -1704,6 +1901,7 @@ */ - (void)dealloc { + if(themePath) [themePath release], themePath = nil; if(editorColors) [editorColors release], editorColors = nil; if(editorNameForColors) [editorNameForColors release], editorNameForColors = nil; if (keychain) [keychain release], keychain = nil; -- cgit v1.2.3