diff options
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r-- | Source/TableDocument.m | 101 |
1 files changed, 50 insertions, 51 deletions
diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 16b0a6f0..d97a146e 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -615,6 +615,10 @@ */ - (IBAction)backForwardInHistory:(id)sender { + + // Ensure history navigation is permitted - trigger end editing and any required saves + if (![self couldCommitCurrentViewActions]) return; + switch ([sender tag]) { // Go backward @@ -2395,6 +2399,31 @@ return ([[self fileURL] isFileURL]) ? NO : YES; } +/** + * Asks any currently editing views to commit their changes; + * returns YES if changes were successfully committed, and NO + * if an error occurred or user interaction is required. + */ +- (BOOL)couldCommitCurrentViewActions +{ + [tableWindow endEditingFor:nil]; + switch ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]]) { + + // Table structure view + case 0: + return [tableSourceInstance saveRowOnDeselect]; + + // Table content view + case 1: + return [tableContentInstance saveRowOnDeselect]; + + default: + break; + } + + return YES; +} + #pragma mark - #pragma mark Accessor methods @@ -3204,10 +3233,9 @@ - (IBAction)viewStructure:(id)sender { - // Cancel the selection if currently editing a content row and unable to save - if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1 - && ![tableContentInstance saveRowOnDeselect]) { - [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableContent]; + // Cancel the selection if currently editing a view and unable to save + if (![self couldCommitCurrentViewActions]) { + [mainToolbar setSelectedItemIdentifier:*SPViewModeToMainToolbarMap[[prefs integerForKey:SPLastViewMode]]]; return; } @@ -3220,10 +3248,10 @@ - (IBAction)viewContent:(id)sender { - // Cancel the selection if currently editing structure/a field and unable to save - if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 0 - && ![tableSourceInstance saveRowOnDeselect]) { - [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableStructure]; + + // Cancel the selection if currently editing a view and unable to save + if (![self couldCommitCurrentViewActions]) { + [mainToolbar setSelectedItemIdentifier:*SPViewModeToMainToolbarMap[[prefs integerForKey:SPLastViewMode]]]; return; } @@ -3236,17 +3264,10 @@ - (IBAction)viewQuery:(id)sender { - // Cancel the selection if currently editing structure/a field and unable to save - if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 0 - && ![tableSourceInstance saveRowOnDeselect]) { - [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableStructure]; - return; - } - // Cancel the selection if currently editing a content row and unable to save - if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1 - && ![tableContentInstance saveRowOnDeselect]) { - [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableContent]; + // Cancel the selection if currently editing a view and unable to save + if (![self couldCommitCurrentViewActions]) { + [mainToolbar setSelectedItemIdentifier:*SPViewModeToMainToolbarMap[[prefs integerForKey:SPLastViewMode]]]; return; } @@ -3262,17 +3283,10 @@ - (IBAction)viewStatus:(id)sender { - // Cancel the selection if currently editing structure/a field and unable to save - if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 0 - && ![tableSourceInstance saveRowOnDeselect]) { - [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableStructure]; - return; - } - // Cancel the selection if currently editing a content row and unable to save - if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1 - && ![tableContentInstance saveRowOnDeselect]) { - [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableContent]; + // Cancel the selection if currently editing a view and unable to save + if (![self couldCommitCurrentViewActions]) { + [mainToolbar setSelectedItemIdentifier:*SPViewModeToMainToolbarMap[[prefs integerForKey:SPLastViewMode]]]; return; } @@ -3293,17 +3307,10 @@ - (IBAction)viewRelations:(id)sender { - // Cancel the selection if currently editing structure/a field and unable to save - if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 0 - && ![tableSourceInstance saveRowOnDeselect]) { - [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableStructure]; - return; - } - // Cancel the selection if currently editing a content row and unable to save - if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1 - && ![tableContentInstance saveRowOnDeselect]) { - [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableContent]; + // Cancel the selection if currently editing a view and unable to save + if (![self couldCommitCurrentViewActions]) { + [mainToolbar setSelectedItemIdentifier:*SPViewModeToMainToolbarMap[[prefs integerForKey:SPLastViewMode]]]; return; } @@ -3316,20 +3323,12 @@ - (IBAction)viewTriggers:(id)sender { - // Cancel the selection if currently editing structure/a field and unable to save - if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 0 - && ![tableSourceInstance saveRowOnDeselect]) { - [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableStructure]; - return; - } - - // Cancel the selection if currently editing a content row and unable to save - if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1 - && ![tableContentInstance saveRowOnDeselect]) { - [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableContent]; + + // Cancel the selection if currently editing a view and unable to save + if (![self couldCommitCurrentViewActions]) { + [mainToolbar setSelectedItemIdentifier:*SPViewModeToMainToolbarMap[[prefs integerForKey:SPLastViewMode]]]; return; - } - + } [tableTabView selectTabViewItemAtIndex:5]; [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableTriggers]; |