From cb406e22d30aaf6dc62ea0917943adb555a8b3e6 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 5 Apr 2009 20:22:04 +0000 Subject: Fix an issue where by the show/hide console menu item was not being updated when the toolbar item was used. Also add more interface validation by only enabling the 'Clear Console' menu and toolbar items when there is at least one message in the console. --- Source/SPQueryConsole.h | 8 +++++--- Source/SPQueryConsole.m | 12 ++++++++++++ Source/TableDocument.m | 33 ++++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 12 deletions(-) (limited to 'Source') diff --git a/Source/SPQueryConsole.h b/Source/SPQueryConsole.h index 65d716d4..155517f7 100644 --- a/Source/SPQueryConsole.h +++ b/Source/SPQueryConsole.h @@ -24,14 +24,14 @@ @interface SPQueryConsole : NSWindowController { - NSFont *consoleFont; - NSMutableArray *messages, *messagesActiveSet, *messagesFilterSet, *messagesSubset; - IBOutlet NSView *saveLogView; IBOutlet NSTableView *consoleTableView; IBOutlet NSSearchField *consoleSearchField; IBOutlet NSProgressIndicator *progressIndicator; IBOutlet NSButton *includeTimeStampsButton, *saveConsoleButton, *clearConsoleButton; + + NSFont *consoleFont; + NSMutableArray *messages, *messagesActiveSet, *messagesFilterSet, *messagesSubset; } @property (readwrite, retain) NSFont *consoleFont; @@ -47,4 +47,6 @@ - (void)showMessageInConsole:(NSString *)message; - (void)showErrorInConsole:(NSString *)error; +- (NSUInteger)consoleMessageCount; + @end diff --git a/Source/SPQueryConsole.m b/Source/SPQueryConsole.m index 7b7edccb..0ba6c982 100644 --- a/Source/SPQueryConsole.m +++ b/Source/SPQueryConsole.m @@ -224,6 +224,14 @@ static SPQueryConsole *sharedQueryConsole = nil; [self _addMessageToConsole:error isError:YES]; } +/** + * Returns the number of messages currently in the console. + */ +- (NSUInteger)consoleMessageCount +{ + return [messages count]; +} + /** * Called when the NSSavePanel sheet ends. Writes the console's current content to the selected file if required. */ @@ -310,6 +318,10 @@ static SPQueryConsole *sharedQueryConsole = nil; if ([menuItem action] == @selector(copy:)) { return ([consoleTableView numberOfSelectedRows] > 0); } + + if ([menuItem action] == @selector(clearConsole:)) { + return ([self consoleMessageCount] > 0); + } return [[self window] validateMenuItem:menuItem]; } diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 9e0853e0..72742cf6 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -609,12 +609,15 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa { BOOL isConsoleVisible = [[[SPQueryConsole sharedQueryConsole] window] isVisible]; + // Show or hide the console [[[SPQueryConsole sharedQueryConsole] window] setIsVisible:(!isConsoleVisible)]; + // Get the menu item for showing and hiding the console. This is isn't the best way to get it as any + // changes to the menu structure will result in the wrong item being selected. + NSMenuItem *menuItem = [[[[NSApp mainMenu] itemAtIndex:3] submenu] itemAtIndex:5]; + // Only update the menu item title if its the menu item and not the toolbar - if ([sender isKindOfClass:[NSMenuItem class]]) { - [(NSMenuItem *)sender setTitle:(!isConsoleVisible) ? NSLocalizedString(@"Hide Console", @"Hide Console") : NSLocalizedString(@"Show Console", @"Show Console")]; - } + [menuItem setTitle:(!isConsoleVisible) ? NSLocalizedString(@"Hide Console", @"Hide Console") : NSLocalizedString(@"Show Console", @"Show Console")]; } /** @@ -1301,8 +1304,8 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa mainToolbar = [[[NSToolbar alloc] initWithIdentifier:@"TableWindowToolbar"] autorelease]; // set up toolbar properties - [mainToolbar setAllowsUserCustomization: YES]; - [mainToolbar setAutosavesConfiguration: YES]; + [mainToolbar setAllowsUserCustomization:YES]; + [mainToolbar setAutosavesConfiguration:YES]; [mainToolbar setDisplayMode:NSToolbarDisplayModeIconAndLabel]; // set ourself as the delegate @@ -1365,7 +1368,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa [toolbarItem setToolTip:NSLocalizedString(@"Clear the console which shows all MySQL commands performed by Sequel Pro", @"tooltip for toolbar item for clear console")]; [toolbarItem setImage:[NSImage imageNamed:@"clearconsole"]]; //set up the target action - [toolbarItem setTarget:[SPQueryConsole sharedQueryConsole]]; + [toolbarItem setTarget:self]; [toolbarItem setAction:@selector(clearConsole:)]; } else if ([itemIdentifier isEqualToString:@"SwitchToTableStructureToolbarItemIdentifier"]) { @@ -1452,6 +1455,9 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa nil]; } +/** + * toolbar delegate method + */ - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar { return [NSArray arrayWithObjects: @@ -1464,20 +1470,29 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa } /** - * validates the toolbar items + * Validates the toolbar items */ - (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem; { - if ([[toolbarItem itemIdentifier] isEqualToString:@"ToggleConsoleIdentifier"]) { + NSString *identifier = [toolbarItem itemIdentifier]; + + // Toggle console item + if ([identifier isEqualToString:@"ToggleConsoleIdentifier"]) { if ([[[SPQueryConsole sharedQueryConsole] window] isVisible]) { [toolbarItem setLabel:@"Hide Console"]; [toolbarItem setImage:[NSImage imageNamed:@"hideconsole"]]; - } else { + } + else { [toolbarItem setLabel:@"Show Console"]; [toolbarItem setImage:[NSImage imageNamed:@"showconsole"]]; } } + // Clear console item + if ([identifier isEqualToString:@"ClearConsoleIdentifier"]) { + return ([[SPQueryConsole sharedQueryConsole] consoleMessageCount] > 0); + } + return YES; } -- cgit v1.2.3