From d432919237a6ed22798851a112e8c49e5086b9ed Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 18 Apr 2010 22:46:02 +0000 Subject: - Add a new couldCommitCurrentViewActions method to TableDocument, and standardise current view-commit-checks to use that - Add checking of that status to history navigation (fixing http://spbug.com/l/127 ) and window closing (fixing http://spbug.com/lr/263 ) - Improve thread safety/deferred actions in TableContent --- Source/TableDocument.m | 101 ++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 51 deletions(-) (limited to 'Source/TableDocument.m') 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]; -- cgit v1.2.3