aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableDocument.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-04-18 22:46:02 +0000
committerrowanbeentje <rowan@beent.je>2010-04-18 22:46:02 +0000
commitd432919237a6ed22798851a112e8c49e5086b9ed (patch)
treeda254dda343dad711c6d1056cf4ea2a62734c4b5 /Source/TableDocument.m
parent932fdc78e4c6739371edf3629a11a0659beb5c1e (diff)
downloadsequelpro-d432919237a6ed22798851a112e8c49e5086b9ed.tar.gz
sequelpro-d432919237a6ed22798851a112e8c49e5086b9ed.tar.bz2
sequelpro-d432919237a6ed22798851a112e8c49e5086b9ed.zip
- 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
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r--Source/TableDocument.m101
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];