aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/CustomQuery.m14
-rw-r--r--Source/TableContent.m14
-rw-r--r--Source/TableDocument.h1
-rw-r--r--Source/TableDocument.m12
-rw-r--r--Source/TableSource.h7
-rw-r--r--Source/TableSource.m78
-rw-r--r--Source/TablesList.m6
7 files changed, 119 insertions, 13 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 108d360e..2df3227e 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -2548,8 +2548,11 @@
- (void) startDocumentTaskForTab:(NSNotification *)aNotification
{
- // Only disable elements if the current tab is the content view
- if (![[aNotification object] isEqualToString:@"SwitchToRunQueryToolbarItemIdentifier"]) return;
+ // Only proceed if the current document is the notifying document, and only if
+ // this view is selected.
+ if ([aNotification object] != tableDocumentInstance
+ || ![[[aNotification object] selectedToolbarItemIdentifier] isEqualToString:@"SwitchToRunQueryToolbarItemIdentifier"])
+ return;
[customQueryView setEnabled:NO];
[runSelectionButton setEnabled:NO];
@@ -2564,8 +2567,11 @@
- (void) endDocumentTaskForTab:(NSNotification *)aNotification
{
- // Only enable elements if the current tab is the content view
- if (![[aNotification object] isEqualToString:@"SwitchToRunQueryToolbarItemIdentifier"]) return;
+ // Only proceed if the current document is the notifying document, and only if
+ // this view is selected.
+ if ([aNotification object] != tableDocumentInstance
+ || ![[[aNotification object] selectedToolbarItemIdentifier] isEqualToString:@"SwitchToRunQueryToolbarItemIdentifier"])
+ return;
if (selectionButtonCanBeEnabled) {
[runSelectionButton setEnabled:YES];
diff --git a/Source/TableContent.m b/Source/TableContent.m
index 4286723a..156b46ab 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -2657,8 +2657,11 @@
- (void) startDocumentTaskForTab:(NSNotification *)aNotification
{
- // Only disable elements if the current tab is the content view
- if (![[aNotification object] isEqualToString:@"SwitchToTableContentToolbarItemIdentifier"]) return;
+ // Only proceed if the current document is the notifying document, and only if
+ // this view is selected.
+ if ([aNotification object] != tableDocumentInstance
+ || ![[[aNotification object] selectedToolbarItemIdentifier] isEqualToString:@"SwitchToTableContentToolbarItemIdentifier"])
+ return;
[tableContentView setEnabled:NO];
[addButton setEnabled:NO];
@@ -2674,8 +2677,11 @@
- (void) endDocumentTaskForTab:(NSNotification *)aNotification
{
- // Only enable elements if the current tab is the content view
- if (![[aNotification object] isEqualToString:@"SwitchToTableContentToolbarItemIdentifier"]) return;
+ // Only proceed if the current document is the notifying document, and only if
+ // this view is selected.
+ if ([aNotification object] != tableDocumentInstance
+ || ![[[aNotification object] selectedToolbarItemIdentifier] isEqualToString:@"SwitchToTableContentToolbarItemIdentifier"])
+ return;
if ( ![[[tableDataInstance statusValues] objectForKey:@"Rows"] isNSNull] && selectedTable && [selectedTable length] && [tableDataInstance tableEncoding]) [addButton setEnabled:YES];
if ([tableContentView numberOfSelectedRows] > 0) {
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index ef941f60..30d44084 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -273,6 +273,7 @@ enum sp_current_query_mode
// Toolbar methods
- (void)setupToolbar;
+- (NSString *)selectedToolbarItemIdentifier;
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag;
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 2515dde2..40428e53 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -1132,7 +1132,7 @@
_isWorking = YES;
[dbTablesTableView setEnabled:NO];
[historyControl setEnabled:NO];
- [[NSNotificationCenter defaultCenter] postNotificationName:SPDocumentTaskStartNotification object:[mainToolbar selectedItemIdentifier]];
+ [[NSNotificationCenter defaultCenter] postNotificationName:SPDocumentTaskStartNotification object:self];
// Reset the progress indicator
taskDisplayIsIndeterminate = YES;
@@ -1209,7 +1209,7 @@
_isWorking = NO;
[dbTablesTableView setEnabled:YES];
[historyControl setEnabled:YES];
- [[NSNotificationCenter defaultCenter] postNotificationName:SPDocumentTaskEndNotification object:[mainToolbar selectedItemIdentifier]];
+ [[NSNotificationCenter defaultCenter] postNotificationName:SPDocumentTaskEndNotification object:self];
}
/**
@@ -3002,6 +3002,14 @@
}
/**
+ * Return the identifier for the currently selected toolbar item, or nil if none is selected.
+ */
+- (NSString *)selectedToolbarItemIdentifier;
+{
+ return [mainToolbar selectedItemIdentifier];
+}
+
+/**
* toolbar delegate method
*/
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)willBeInsertedIntoToolbar
diff --git a/Source/TableSource.h b/Source/TableSource.h
index 4d10a5c9..c30a70bd 100644
--- a/Source/TableSource.h
+++ b/Source/TableSource.h
@@ -30,6 +30,7 @@
{
IBOutlet id tablesListInstance;
IBOutlet id tableDataInstance;
+ IBOutlet id tableDocumentInstance;
IBOutlet id tableWindow;
IBOutlet id indexSheet;
@@ -39,8 +40,10 @@
IBOutlet id addFieldButton;
IBOutlet id copyFieldButton;
IBOutlet id removeFieldButton;
+ IBOutlet id reloadFieldsButton;
IBOutlet id addIndexButton;
IBOutlet id removeIndexButton;
+ IBOutlet id reloadIndexesButton;
IBOutlet id indexTypeField;
IBOutlet id indexNameField;
IBOutlet id indexedColumnsField;
@@ -93,4 +96,8 @@
- (NSDictionary *)enumFields;
- (NSArray *)tableStructureForPrint;
+// Task interaction
+- (void) startDocumentTaskForTab:(NSNotification *)aNotification;
+- (void) endDocumentTaskForTab:(NSNotification *)aNotification;
+
@end
diff --git a/Source/TableSource.m b/Source/TableSource.m
index 48ae859f..77e05efb 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -24,6 +24,7 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import "TableSource.h"
+#import "TableDocument.h"
#import "TablesList.h"
#import "SPTableData.h"
#import "SPSQLParser.h"
@@ -46,6 +47,7 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab
id extra;
int i;
SPSQLParser *fieldParser;
+ BOOL enableInteraction = ![tableDocumentInstance isWorking];
// Check whether a save of the current row is required.
if ( ![self saveRowOnDeselect] ) return;
@@ -81,7 +83,7 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab
}
// Enable edit table button
- [editTableButton setEnabled:YES];
+ [editTableButton setEnabled:enableInteraction];
//query started
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self];
@@ -185,7 +187,7 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab
}
// If a view is selected, disable the buttons; otherwise enable.
- BOOL editingEnabled = ([tablesListInstance tableType] == SP_TABLETYPE_TABLE);
+ BOOL editingEnabled = ([tablesListInstance tableType] == SP_TABLETYPE_TABLE) && enableInteraction;
[addFieldButton setEnabled:editingEnabled];
[addIndexButton setEnabled:editingEnabled];
@@ -238,7 +240,7 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab
// if no field is selected 'Duplicate field' will copy the last field
// Enable 'Duplicate field' only for tables!
if([tablesListInstance tableType] == SP_TABLETYPE_TABLE)
- [copyFieldButton setEnabled:([tableSourceView numberOfRows] > 0)];
+ [copyFieldButton setEnabled:enableInteraction && ([tableSourceView numberOfRows] > 0)];
else
[copyFieldButton setEnabled:NO];
@@ -1046,6 +1048,64 @@ returns a dictionary containing enum/set field names as key and possible values
}
#pragma mark -
+#pragma mark Task interaction
+
+/**
+ * Disable all content interactive elements during an ongoing task.
+ */
+- (void) startDocumentTaskForTab:(NSNotification *)aNotification
+{
+
+ // Only proceed if the current document is the notifying document, and only if
+ // this view is selected.
+ if ([aNotification object] != tableDocumentInstance
+ || ![[[aNotification object] selectedToolbarItemIdentifier] isEqualToString:@"SwitchToTableStructureToolbarItemIdentifier"])
+ return;
+
+ [tableSourceView setEnabled:NO];
+ [addFieldButton setEnabled:NO];
+ [removeFieldButton setEnabled:NO];
+ [copyFieldButton setEnabled:NO];
+ [reloadFieldsButton setEnabled:NO];
+ [editTableButton setEnabled:NO];
+
+ [indexView setEnabled:NO];
+ [addIndexButton setEnabled:NO];
+ [removeIndexButton setEnabled:NO];
+ [reloadIndexesButton setEnabled:NO];
+}
+
+/**
+ * Enable all content interactive elements after an ongoing task.
+ */
+- (void) endDocumentTaskForTab:(NSNotification *)aNotification
+{
+
+ // Only re-enable elements if the current tab is the structure view
+ if ([aNotification object] != tableDocumentInstance
+ || ![[[aNotification object] selectedToolbarItemIdentifier] isEqualToString:@"SwitchToTableStructureToolbarItemIdentifier"])
+ return;
+
+ BOOL editingEnabled = ([tablesListInstance tableType] == SP_TABLETYPE_TABLE);
+ [tableSourceView setEnabled:YES];
+ [tableSourceView displayIfNeeded];
+ [addFieldButton setEnabled:editingEnabled];
+ if (editingEnabled && [tableSourceView numberOfSelectedRows] > 0) {
+ [removeFieldButton setEnabled:YES];
+ [copyFieldButton setEnabled:YES];
+ }
+ [reloadFieldsButton setEnabled:YES];
+ [editTableButton setEnabled:YES];
+
+ [indexView setEnabled:YES];
+ [indexView displayIfNeeded];
+ [addIndexButton setEnabled:editingEnabled];
+ if (editingEnabled && [indexView numberOfSelectedRows] > 0)
+ [removeIndexButton setEnabled:YES];
+ [reloadIndexesButton setEnabled:YES];
+}
+
+#pragma mark -
#pragma mark TableView datasource methods
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
@@ -1405,10 +1465,22 @@ would result in a position change.
// Set the structure and index view's vertical gridlines if required
[tableSourceView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
[indexView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
+
+ // Add observers for document task activity
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(startDocumentTaskForTab:)
+ name:SPDocumentTaskStartNotification
+ object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(endDocumentTaskForTab:)
+ name:SPDocumentTaskEndNotification
+ object:nil];
}
- (void)dealloc
{
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+
[tableFields release];
[indexes release];
[oldRow release];
diff --git a/Source/TablesList.m b/Source/TablesList.m
index 2d56938d..5be863fd 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -1541,6 +1541,10 @@
*/
- (void) startDocumentTaskForTab:(NSNotification *)aNotification
{
+
+ // Only proceed if the notification was received from the current document.
+ if ([aNotification object] != tableDocumentInstance) return;
+
[tablesListView setEnabled:NO];
[toolbarAddButton setEnabled:NO];
[toolbarActionsButton setEnabled:NO];
@@ -1552,6 +1556,8 @@
*/
- (void) endDocumentTaskForTab:(NSNotification *)aNotification
{
+ if ([aNotification object] != tableDocumentInstance) return;
+
[tablesListView setEnabled:YES];
[toolbarAddButton setEnabled:YES];
[toolbarActionsButton setEnabled:YES];