From f4bede9def108d8fd25334871ca00971687c4e51 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 12 Sep 2009 16:19:51 +0000 Subject: Add back/forward history menu items to the view menu with the assigned shortcuts of cmd+[ and cmd+]. --- Source/SPHistoryController.h | 9 +++++++-- Source/SPHistoryController.m | 32 ++++++++++++++++++++++++++------ Source/TableContent.m | 2 +- Source/TableDocument.h | 2 +- Source/TableDocument.m | 36 ++++++++++++++++++++++++++++++++---- 5 files changed, 67 insertions(+), 14 deletions(-) (limited to 'Source') diff --git a/Source/SPHistoryController.h b/Source/SPHistoryController.h index 5829dce7..58f66352 100644 --- a/Source/SPHistoryController.h +++ b/Source/SPHistoryController.h @@ -35,20 +35,25 @@ enum sphistory_view_types SP_VIEW_RELATIONS = 4 }; -@interface SPHistoryController : NSObject { +@interface SPHistoryController : NSObject +{ IBOutlet TableDocument *theDocument; IBOutlet NSSegmentedControl *historyControl; TableContent *tableContentInstance; NSMutableArray *history; - unsigned int historyPosition; + NSUInteger historyPosition; BOOL modifyingHistoryState; } +@property (readonly) NSUInteger historyPosition; +@property (readonly) NSMutableArray *history; @property (readwrite, assign) BOOL modifyingHistoryState; // Interface interaction - (void) updateToolbarItem; +- (void)goBackwardInHistory; +- (void)goForwardInHistory; - (IBAction) historyControlClicked:(NSSegmentedControl *)theControl; - (unsigned int) currentlySelectedView; diff --git a/Source/SPHistoryController.m b/Source/SPHistoryController.m index d602d8d4..e3fbb9cf 100644 --- a/Source/SPHistoryController.m +++ b/Source/SPHistoryController.m @@ -30,6 +30,8 @@ @implementation SPHistoryController +@synthesize history; +@synthesize historyPosition; @synthesize modifyingHistoryState; #pragma mark Setup and teardown @@ -101,24 +103,42 @@ } } +/** + * Go backward in the history. + */ +- (void)goBackwardInHistory +{ + if (historyPosition == NSNotFound || !historyPosition) return; + + [self loadEntryAtPosition:historyPosition - 1]; +} + +/** + * Go forward in the history. + */ +- (void)goForwardInHistory +{ + if (historyPosition == NSNotFound || historyPosition + 1 >= [history count]) return; + + [self loadEntryAtPosition:historyPosition + 1]; +} + /** * Trigger a navigation action in response to a click */ - (IBAction) historyControlClicked:(NSSegmentedControl *)theControl { - switch ([theControl selectedSegment]) { - + switch ([theControl selectedSegment]) + { // Back button clicked: case 0: - if (historyPosition == NSNotFound || !historyPosition) return; - [self loadEntryAtPosition:historyPosition - 1]; + [self goBackwardInHistory]; break; // Forward button clicked: case 1: - if (historyPosition == NSNotFound || historyPosition + 1 >= [history count]) return; - [self loadEntryAtPosition:historyPosition + 1]; + [self goForwardInHistory]; break; } } diff --git a/Source/TableContent.m b/Source/TableContent.m index 2efd6d75..806e1f47 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -2164,7 +2164,7 @@ * Confirm whether to allow editing of a row. Returns YES by default, unless the multipleLineEditingButton is in * the ON state, or for blob or text fields - in those cases opens a sheet for editing instead and returns NO. */ -- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSUInteger)rowIndex +- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { NSUInteger i; diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 868b5dcd..57cbeb4f 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -29,7 +29,6 @@ #import #import - @class SPConnectionController, SPUserManager; enum sp_current_query_mode @@ -206,6 +205,7 @@ enum sp_current_query_mode - (IBAction)validateSaveConnectionAccessory:(id)sender; - (BOOL)saveDocumentWithFilePath:(NSString *)fileName inBackground:(BOOL)saveInBackground onlyPreferences:(BOOL)saveOnlyPreferences; - (IBAction)closePasswordSheet:(id)sender; +- (IBAction)backForwardInHistory:(id)sender; // Getter methods - (NSString *)name; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index a546333a..dbb4e2f7 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -496,6 +496,24 @@ [NSApp abortModal]; } +/** + * Go backward or forward in the history depending on the menu item selected. + */ +- (IBAction)backForwardInHistory:(id)sender +{ + switch ([sender tag]) + { + // Go backward + case 0: + [spHistoryControllerInstance goBackwardInHistory]; + break; + // Go forward + case 1: + [spHistoryControllerInstance goForwardInHistory]; + break; + } +} + #pragma mark - #pragma mark Connection callback and methods @@ -2467,13 +2485,13 @@ // and disable it if no query in the editor if ([menuItem action] == @selector(saveConnectionSheet:) && [menuItem tag] == 0) { if([customQueryInstance numberOfQueries] < 1) { - [menuItem setTitle:NSLocalizedString(@"Save Query…",@"Save Query…")]; + [menuItem setTitle:NSLocalizedString(@"Save Query…", @"Save Query…")]; return NO; } else if([customQueryInstance numberOfQueries] == 1) - [menuItem setTitle:NSLocalizedString(@"Save Query…",@"Save Query…")]; + [menuItem setTitle:NSLocalizedString(@"Save Query…", @"Save Query…")]; else - [menuItem setTitle:NSLocalizedString(@"Save Queries…",@"Save Queries…")]; + [menuItem setTitle:NSLocalizedString(@"Save Queries…", @"Save Queries…")]; return YES; } @@ -2502,7 +2520,17 @@ } if ([menuItem action] == @selector(addConnectionToFavorites:)) { - return ([connectionController selectedFavorite]?NO:YES); + return ([connectionController selectedFavorite] ? NO : YES); + } + + // Backward in history menu item + if (([menuItem action] == @selector(backForwardInHistory:)) && ([menuItem tag] == 0)) { + return (([[spHistoryControllerInstance history] count]) && ([spHistoryControllerInstance historyPosition] > 0)); + } + + // Forward in history menu item + if (([menuItem action] == @selector(backForwardInHistory:)) && ([menuItem tag] == 1)) { + return (([[spHistoryControllerInstance history] count]) && (([spHistoryControllerInstance historyPosition] + 1) < [[spHistoryControllerInstance history] count])); } return [super validateMenuItem:menuItem]; -- cgit v1.2.3