diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-05-07 08:29:42 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-05-07 08:29:42 +0000 |
commit | 166b844e7a4e84b79d2cfad5cac1d5d8333988f5 (patch) | |
tree | 21b9eb5bd92f22e4114688c0aaaf11d231a1efb4 /Source/SPPreferenceController.m | |
parent | 2a4bbd2e425fbbf0ffd20a9c36921778b92963ae (diff) | |
download | sequelpro-166b844e7a4e84b79d2cfad5cac1d5d8333988f5.tar.gz sequelpro-166b844e7a4e84b79d2cfad5cac1d5d8333988f5.tar.bz2 sequelpro-166b844e7a4e84b79d2cfad5cac1d5d8333988f5.zip |
• added "Query Editor" preference pane for setting colors, font, and modes (from the CQ's action gear which are still customizable there)
- in addition to the syntax colors it's now possible to change the fore/background color as well
• added "Update Help while typing" feature in the Custom Query editor
• first trial to improve syntax highlighting for large text in the Custom Query editor
- if the text is larger than 10k the highlighting is performed only for the visible text area ±bias (3.5k)
- if the user changes the visible area the highlighting follows time-delayed 500ms) to assure user interaction
- a test with a 45MB SQL dump worked (of course a tick slowier)
-- todo: improve prev/current query detection (mainly the SQLParser)
- if the text size is > 6MB the completion list won't show words from the text due to parsing time
- if the text size is > 6MB the line numbering will be disabled due to performance issue (improvements should follow)
• some tiny clarification changes in the syntax highlighting code
• some minor code cosmetics
Diffstat (limited to 'Source/SPPreferenceController.m')
-rw-r--r-- | Source/SPPreferenceController.m | 130 |
1 files changed, 98 insertions, 32 deletions
diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index 0d44a373..de17860c 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -25,6 +25,7 @@ #import "SPWindowAdditions.h" #import "SPFavoriteTextFieldCell.h" #import "KeyChain.h" +#import "TableDocument.h" #define FAVORITES_PB_DRAG_TYPE @"SequelProPreferencesPasteboard" @@ -34,6 +35,7 @@ #define PREFERENCE_TOOLBAR_NOTIFICATIONS @"Preference Toolbar Notifications" #define PREFERENCE_TOOLBAR_AUTOUPDATE @"Preference Toolbar Auto Update" #define PREFERENCE_TOOLBAR_NETWORK @"Preference Toolbar Network" +#define PREFERENCE_TOOLBAR_EDITOR @"Preference Toolbar Editor" #pragma mark - @@ -57,6 +59,7 @@ prefs = [NSUserDefaults standardUserDefaults]; [self applyRevisionChanges]; } + return self; } @@ -82,6 +85,8 @@ [favoritesTableView reloadData]; [self updateDefaultFavoritePopup]; + + [prefs synchronize]; } #pragma mark - @@ -355,6 +360,17 @@ } // ------------------------------------------------------------------------------- +// displayEditorPreferences: +// ------------------------------------------------------------------------------- +- (IBAction)displayEditorPreferences:(id)sender +{ + [toolbar setSelectedItemIdentifier:PREFERENCE_TOOLBAR_EDITOR]; + NSFont *nf = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorFont"]]; + [editorFontName setStringValue:[NSString stringWithFormat:@"%@, %.1f pt", [nf displayName], [nf pointSize]]]; + [self _resizeWindowForContentView:editorView]; +} + +// ------------------------------------------------------------------------------- // displayFavoritePreferences: // ------------------------------------------------------------------------------- - (IBAction)displayFavoritePreferences:(id)sender @@ -567,6 +583,9 @@ else if ([itemIdentifier isEqualToString:PREFERENCE_TOOLBAR_NETWORK]) { return networkItem; } + else if ([itemIdentifier isEqualToString:PREFERENCE_TOOLBAR_EDITOR]) { + return editorItem; + } return [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier] autorelease]; } @@ -576,7 +595,7 @@ // ------------------------------------------------------------------------------- - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar { - return [NSArray arrayWithObjects:PREFERENCE_TOOLBAR_GENERAL, PREFERENCE_TOOLBAR_TABLES, PREFERENCE_TOOLBAR_FAVORITES, PREFERENCE_TOOLBAR_NOTIFICATIONS, PREFERENCE_TOOLBAR_AUTOUPDATE, PREFERENCE_TOOLBAR_NETWORK, nil]; + return [NSArray arrayWithObjects:PREFERENCE_TOOLBAR_GENERAL, PREFERENCE_TOOLBAR_TABLES, PREFERENCE_TOOLBAR_FAVORITES, PREFERENCE_TOOLBAR_NOTIFICATIONS, PREFERENCE_TOOLBAR_AUTOUPDATE, PREFERENCE_TOOLBAR_NETWORK, PREFERENCE_TOOLBAR_EDITOR, nil]; } // ------------------------------------------------------------------------------- @@ -584,7 +603,7 @@ // ------------------------------------------------------------------------------- - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar { - return [NSArray arrayWithObjects:PREFERENCE_TOOLBAR_GENERAL, PREFERENCE_TOOLBAR_TABLES, PREFERENCE_TOOLBAR_FAVORITES, PREFERENCE_TOOLBAR_NOTIFICATIONS, PREFERENCE_TOOLBAR_AUTOUPDATE, PREFERENCE_TOOLBAR_NETWORK, nil]; + return [NSArray arrayWithObjects:PREFERENCE_TOOLBAR_GENERAL, PREFERENCE_TOOLBAR_TABLES, PREFERENCE_TOOLBAR_FAVORITES, PREFERENCE_TOOLBAR_NOTIFICATIONS, PREFERENCE_TOOLBAR_AUTOUPDATE, PREFERENCE_TOOLBAR_NETWORK, PREFERENCE_TOOLBAR_EDITOR, nil]; } // ------------------------------------------------------------------------------- @@ -592,7 +611,7 @@ // ------------------------------------------------------------------------------- - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar { - return [NSArray arrayWithObjects:PREFERENCE_TOOLBAR_GENERAL, PREFERENCE_TOOLBAR_TABLES, PREFERENCE_TOOLBAR_FAVORITES, PREFERENCE_TOOLBAR_NOTIFICATIONS, PREFERENCE_TOOLBAR_AUTOUPDATE, PREFERENCE_TOOLBAR_NETWORK, nil]; + return [NSArray arrayWithObjects:PREFERENCE_TOOLBAR_GENERAL, PREFERENCE_TOOLBAR_TABLES, PREFERENCE_TOOLBAR_FAVORITES, PREFERENCE_TOOLBAR_NOTIFICATIONS, PREFERENCE_TOOLBAR_AUTOUPDATE, PREFERENCE_TOOLBAR_NETWORK, PREFERENCE_TOOLBAR_EDITOR, nil]; } #pragma mark - @@ -683,6 +702,7 @@ // Mark the currently selected field in the window as having finished editing, to trigger saves. if ([preferencesWindow firstResponder]) [preferencesWindow endEditingFor:[preferencesWindow firstResponder]]; + } #pragma mark - @@ -729,6 +749,43 @@ } // ------------------------------------------------------------------------------- +// query editor font selection +// +// ------------------------------------------------------------------------------- +// show the font panel +- (IBAction)showCustomQueryFontPanel:(id)sender +{ + [[NSFontPanel sharedFontPanel] setPanelFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorFont"]] isMultiple:NO]; + [[NSFontPanel sharedFontPanel] makeKeyAndOrderFront:self]; +} +// reset syntax highlighting colors +- (IBAction)setDefaultColors:(id)sender +{ + + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.000 green:0.455 blue:0.000 alpha:1.000]] forKey:@"CustomQueryEditorCommentColor"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.769 green:0.102 blue:0.086 alpha:1.000]] forKey:@"CustomQueryEditorQuoteColor"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.200 green:0.250 blue:1.000 alpha:1.000]] forKey:@"CustomQueryEditorSQLKeywordColor"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.000 green:0.000 blue:0.658 alpha:1.000]] forKey:@"CustomQueryEditorBacktickColor"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.506 green:0.263 blue:0.000 alpha:1.000]] forKey:@"CustomQueryEditorNumericColor"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.500 green:0.500 blue:0.500 alpha:1.000]] forKey:@"CustomQueryEditorVariableColor"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:@"CustomQueryEditorTextColor"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor whiteColor]] forKey:@"CustomQueryEditorBackgroundColor"]; + +} +// set font panel's valid modes +- (unsigned int)validModesForFontPanel:(NSFontPanel *)fontPanel +{ + return (NSFontPanelFaceModeMask | NSFontPanelSizeModeMask); +} +// Action receiver for a font change in the font panel +- (void)changeFont:(id)sender +{ + NSFont *nf = [[NSFontPanel sharedFontPanel] panelConvertFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorFont"]]]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:nf] forKey:@"CustomQueryEditorFont"]; + [editorFontName setStringValue:[NSString stringWithFormat:@"%@, %.1f pt", [nf displayName], [nf pointSize]]]; +} + +// ------------------------------------------------------------------------------- // dealloc // ------------------------------------------------------------------------------- - (void)dealloc @@ -752,62 +809,71 @@ - (void)_setupToolbar { toolbar = [[[NSToolbar alloc] initWithIdentifier:@"Preference Toolbar"] autorelease]; - + // General preferences generalItem = [[NSToolbarItem alloc] initWithItemIdentifier:PREFERENCE_TOOLBAR_GENERAL]; - + [generalItem setLabel:NSLocalizedString(@"General", @"")]; - [generalItem setImage:[NSImage imageNamed:@"toolbar-preferences-general"]]; - [generalItem setTarget:self]; - [generalItem setAction:@selector(displayGeneralPreferences:)]; - + [generalItem setImage:[NSImage imageNamed:@"toolbar-preferences-general"]]; + [generalItem setTarget:self]; + [generalItem setAction:@selector(displayGeneralPreferences:)]; + // Table preferences tablesItem = [[NSToolbarItem alloc] initWithItemIdentifier:PREFERENCE_TOOLBAR_TABLES]; - + [tablesItem setLabel:NSLocalizedString(@"Tables", @"")]; [tablesItem setImage:[NSImage imageNamed:@"toolbar-preferences-tables"]]; [tablesItem setTarget:self]; [tablesItem setAction:@selector(displayTablePreferences:)]; - + // Favorite preferences favoritesItem = [[NSToolbarItem alloc] initWithItemIdentifier:PREFERENCE_TOOLBAR_FAVORITES]; - + [favoritesItem setLabel:NSLocalizedString(@"Favorites", @"")]; - [favoritesItem setImage:[NSImage imageNamed:@"toolbar-preferences-favorites"]]; - [favoritesItem setTarget:self]; - [favoritesItem setAction:@selector(displayFavoritePreferences:)]; - + [favoritesItem setImage:[NSImage imageNamed:@"toolbar-preferences-favorites"]]; + [favoritesItem setTarget:self]; + [favoritesItem setAction:@selector(displayFavoritePreferences:)]; + // Notification preferences notificationsItem = [[NSToolbarItem alloc] initWithItemIdentifier:PREFERENCE_TOOLBAR_NOTIFICATIONS]; - + [notificationsItem setLabel:NSLocalizedString(@"Notifications", @"")]; - [notificationsItem setImage:[NSImage imageNamed:@"toolbar-preferences-notifications"]]; - [notificationsItem setTarget:self]; - [notificationsItem setAction:@selector(displayNotificationPreferences:)]; + [notificationsItem setImage:[NSImage imageNamed:@"toolbar-preferences-notifications"]]; + [notificationsItem setTarget:self]; + [notificationsItem setAction:@selector(displayNotificationPreferences:)]; // AutoUpdate preferences autoUpdateItem = [[NSToolbarItem alloc] initWithItemIdentifier:PREFERENCE_TOOLBAR_AUTOUPDATE]; - + [autoUpdateItem setLabel:NSLocalizedString(@"Auto Update", @"")]; - [autoUpdateItem setImage:[NSImage imageNamed:@"toolbar-preferences-autoupdate"]]; - [autoUpdateItem setTarget:self]; - [autoUpdateItem setAction:@selector(displayAutoUpdatePreferences:)]; - + [autoUpdateItem setImage:[NSImage imageNamed:@"toolbar-preferences-autoupdate"]]; + [autoUpdateItem setTarget:self]; + [autoUpdateItem setAction:@selector(displayAutoUpdatePreferences:)]; + // Network preferences networkItem = [[NSToolbarItem alloc] initWithItemIdentifier:PREFERENCE_TOOLBAR_NETWORK]; - + [networkItem setLabel:NSLocalizedString(@"Network", @"")]; - [networkItem setImage:[NSImage imageNamed:@"toolbar-preferences-network"]]; - [networkItem setTarget:self]; - [networkItem setAction:@selector(displayNetworkPreferences:)]; - + [networkItem setImage:[NSImage imageNamed:@"toolbar-preferences-network"]]; + [networkItem setTarget:self]; + [networkItem setAction:@selector(displayNetworkPreferences:)]; + + // Editor preferences + editorItem = [[NSToolbarItem alloc] initWithItemIdentifier:PREFERENCE_TOOLBAR_EDITOR]; + + [editorItem setLabel:NSLocalizedString(@"Query Editor", @"")]; + [editorItem setImage:[NSImage imageNamed:@"toolbar-switch-to-sql"]]; + [editorItem setTarget:self]; + [editorItem setAction:@selector(displayEditorPreferences:)]; + + [toolbar setDelegate:self]; [toolbar setSelectedItemIdentifier:PREFERENCE_TOOLBAR_GENERAL]; [toolbar setAllowsUserCustomization:NO]; - + [preferencesWindow setToolbar:toolbar]; [preferencesWindow setShowsToolbarButton:NO]; - + [self displayGeneralPreferences:nil]; } |