From 166b844e7a4e84b79d2cfad5cac1d5d8333988f5 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 7 May 2009 08:29:42 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20"Query=20Editor"=20preference=20pan?= =?UTF-8?q?e=20for=20setting=20colors,=20font,=20and=20modes=20(from=20the?= =?UTF-8?q?=20CQ's=20action=20gear=20which=20are=20still=20customizable=20?= =?UTF-8?q?there)=20-=20in=20addition=20to=20the=20syntax=20colors=20it's?= =?UTF-8?q?=20now=20possible=20to=20change=20the=20fore/background=20color?= =?UTF-8?q?=20as=20well=20=E2=80=A2=20added=20"Update=20Help=20while=20typ?= =?UTF-8?q?ing"=20feature=20in=20the=20Custom=20Query=20editor=20=E2=80=A2?= =?UTF-8?q?=20first=20trial=20to=20improve=20syntax=20highlighting=20for?= =?UTF-8?q?=20large=20text=20in=20the=20Custom=20Query=20editor=20-=20if?= =?UTF-8?q?=20the=20text=20is=20larger=20than=2010k=20the=20highlighting?= =?UTF-8?q?=20is=20performed=20only=20for=20the=20visible=20text=20area=20?= =?UTF-8?q?=C2=B1bias=20(3.5k)=20-=20if=20the=20user=20changes=20the=20vis?= =?UTF-8?q?ible=20area=20the=20highlighting=20follows=20time-delayed=20500?= =?UTF-8?q?ms)=20to=20assure=20user=20interaction=20-=20a=20test=20with=20?= =?UTF-8?q?a=2045MB=20SQL=20dump=20worked=20(of=20course=20a=20tick=20slow?= =?UTF-8?q?ier)=20--=20todo:=20improve=20prev/current=20query=20detection?= =?UTF-8?q?=20(mainly=20the=20SQLParser)=20-=20if=20the=20text=20size=20is?= =?UTF-8?q?=20>=206MB=20the=20completion=20list=20won't=20show=20words=20f?= =?UTF-8?q?rom=20the=20text=20due=20to=20parsing=20time=20-=20if=20the=20t?= =?UTF-8?q?ext=20size=20is=20>=206MB=20the=20line=20numbering=20will=20be?= =?UTF-8?q?=20disabled=20due=20to=20performance=20issue=20(improvements=20?= =?UTF-8?q?should=20follow)=20=E2=80=A2=20some=20tiny=20clarification=20ch?= =?UTF-8?q?anges=20in=20the=20syntax=20highlighting=20code=20=E2=80=A2=20s?= =?UTF-8?q?ome=20minor=20code=20cosmetics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPPreferenceController.m | 130 ++++++++++++++++++++++++++++++---------- 1 file changed, 98 insertions(+), 32 deletions(-) (limited to 'Source/SPPreferenceController.m') 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 - @@ -354,6 +359,17 @@ [self _resizeWindowForContentView:tablesView]; } +// ------------------------------------------------------------------------------- +// 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: // ------------------------------------------------------------------------------- @@ -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 - @@ -728,6 +748,43 @@ [favoritesController setSelectedObjects:favorites]; } +// ------------------------------------------------------------------------------- +// 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 // ------------------------------------------------------------------------------- @@ -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]; } -- cgit v1.2.3