aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--Source/SPConstants.h1
-rw-r--r--Source/SPConstants.m1
-rw-r--r--Source/SPHistoryController.m3
-rw-r--r--Source/TableContent.m6
-rw-r--r--Source/TableDocument.h3
-rw-r--r--Source/TableDocument.m101
-rw-r--r--Source/TablesList.m8
7 files changed, 62 insertions, 61 deletions
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index 4bda5116..193fc27c 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -275,6 +275,7 @@ extern NSString *SPMainToolbarTableInfo;
extern NSString *SPMainToolbarTableRelations;
extern NSString *SPMainToolbarTableTriggers;
extern NSString *SPMainToolbarUserManager;
+extern NSString **SPViewModeToMainToolbarMap[];
// Preferences toolbar
extern NSString *SPPreferenceToolbarGeneral;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index da9e6b10..11d3a5fe 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -189,6 +189,7 @@ NSString *SPMainToolbarTableInfo = @"SwitchToTableInfoToolbarIte
NSString *SPMainToolbarTableRelations = @"SwitchToTableRelationsToolbarItemIdentifier";
NSString *SPMainToolbarTableTriggers = @"SwitchToTableTriggersToolbarItemIdentifier";
NSString *SPMainToolbarUserManager = @"SwitchToUserManagerToolbarItemIdentifier";
+NSString **SPViewModeToMainToolbarMap[] = {nil, &SPMainToolbarTableStructure, &SPMainToolbarTableContent, &SPMainToolbarCustomQuery, &SPMainToolbarTableInfo, &SPMainToolbarTableRelations, &SPMainToolbarTableTriggers};
// Preferences toolbar
NSString *SPPreferenceToolbarGeneral = @"SPPreferenceToolbarGeneral";
diff --git a/Source/SPHistoryController.m b/Source/SPHistoryController.m
index dcef796c..567ebd7a 100644
--- a/Source/SPHistoryController.m
+++ b/Source/SPHistoryController.m
@@ -145,6 +145,9 @@
- (IBAction) historyControlClicked:(NSSegmentedControl *)theControl
{
+ // Ensure history navigation is permitted - trigger end editing and any required saves
+ if (![theDocument couldCommitCurrentViewActions]) return;
+
switch ([theControl selectedSegment])
{
// Back button clicked:
diff --git a/Source/TableContent.m b/Source/TableContent.m
index cfad7136..b20b48d4 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -221,7 +221,7 @@
}
// Update display if necessary
- [tableContentView performSelectorOnMainThread:@selector(displayIfNeeded) withObject:nil waitUntilDone:NO];
+ [[tableContentView onMainThread] setNeedsDisplay:YES];
// Init copyTable with necessary information for copying selected rows as SQL INSERT
[tableContentView setTableInstance:self withTableData:tableValues withColumns:dataColumns withTableName:selectedTable withConnection:mySQLConnection];
@@ -737,9 +737,9 @@
// Update the table view with new results every now and then
if (rowsProcessed > nextTableDisplayBoundary) {
if (rowsProcessed > tableRowsCount) tableRowsCount = rowsProcessed;
- [tableContentView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:NO];
+ [[tableContentView onMainThread] noteNumberOfRowsChanged];
if (!tableViewRedrawn) {
- [tableContentView performSelectorOnMainThread:@selector(displayIfNeeded) withObject:nil waitUntilDone:NO];
+ [[tableContentView onMainThread] setNeedsDisplay:YES];
tableViewRedrawn = YES;
}
nextTableDisplayBoundary *= 2;
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index e3598c18..530fa1b4 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -58,7 +58,7 @@
IBOutlet NSSearchField *listFilterField;
- IBOutlet id tableWindow;
+ IBOutlet NSWindow *tableWindow;
IBOutlet id titleAccessoryView;
IBOutlet id titleImageView;
@@ -168,6 +168,7 @@
}
- (BOOL)isUntitled;
+- (BOOL)couldCommitCurrentViewActions;
- (void)initQueryEditorWithString:(NSString *)query;
- (void)initWithConnectionFile:(NSString *)path;
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];
diff --git a/Source/TablesList.m b/Source/TablesList.m
index 7d7eb586..78ec12f8 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -1429,12 +1429,8 @@
return NO;
}
- // We have to be sure that TableSource and TableContent have finished editing
- if ( ![tableSourceInstance saveRowOnDeselect] || ![tableContentInstance saveRowOnDeselect] ) {
- return NO;
- } else {
- return YES;
- }
+ // We have to be sure that document views have finished editing
+ return [tableDocumentInstance couldCommitCurrentViewActions];
}
/**