aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-09-19 19:24:42 +0000
committerstuconnolly <stuart02@gmail.com>2010-09-19 19:24:42 +0000
commit4c1ea21e96c0b1bf21f483e7d4de9264b04bb1e2 (patch)
treecba9d3334e317bdd7800e4f6c024c34960a0c648 /Source
parentec5eab3636bf33422c6e540eefd38cc56685da99 (diff)
downloadsequelpro-4c1ea21e96c0b1bf21f483e7d4de9264b04bb1e2.tar.gz
sequelpro-4c1ea21e96c0b1bf21f483e7d4de9264b04bb1e2.tar.bz2
sequelpro-4c1ea21e96c0b1bf21f483e7d4de9264b04bb1e2.zip
- Before performing an export (except from a dot export), refresh the table list to accommodate cases where additional tables have been added to the database by external applications. If so inform the user of this, giving them the choice of whether or not to continue with the export.
- Update Localizable.strings
Diffstat (limited to 'Source')
-rw-r--r--Source/SPExportController.m152
1 files changed, 106 insertions, 46 deletions
diff --git a/Source/SPExportController.m b/Source/SPExportController.m
index ff7a9143..78f187d9 100644
--- a/Source/SPExportController.m
+++ b/Source/SPExportController.m
@@ -35,10 +35,13 @@
#import "SPConstants.h"
#import "SPGrowlController.h"
#import "SPExportFile.h"
+#import "SPAlertSheets.h"
@interface SPExportController (PrivateAPI)
- (void)_switchTab;
+- (void)_checkForDatabaseChanges;
+- (NSUInteger)_refreshDatabaseTableList;
- (void)_toggleExportButton:(id)uiStateDict;
- (void)_toggleExportButtonOnBackgroundThread;
@@ -373,51 +376,7 @@
*/
- (IBAction)refreshTableList:(id)sender
{
- [tables removeAllObjects];
-
- // For all modes, retrieve table and view names
- NSArray *tablesAndViews = [tablesListInstance allTableAndViewNames];
-
- for (id itemName in tablesAndViews) {
- [tables addObject:[NSMutableArray arrayWithObjects:
- itemName,
- [NSNumber numberWithBool:YES],
- [NSNumber numberWithBool:YES],
- [NSNumber numberWithBool:YES],
- [NSNumber numberWithInt:SPTableTypeTable],
- nil]];
- }
-
- // For SQL only, add procedures and functions
- if (exportType == SPSQLExport) {
- NSArray *procedures = [tablesListInstance allProcedureNames];
-
- for (id procName in procedures)
- {
- [tables addObject:[NSMutableArray arrayWithObjects:
- procName,
- [NSNumber numberWithBool:YES],
- [NSNumber numberWithBool:YES],
- [NSNumber numberWithBool:YES],
- [NSNumber numberWithInt:SPTableTypeProc],
- nil]];
- }
-
- NSArray *functions = [tablesListInstance allFunctionNames];
-
- for (id funcName in functions)
- {
- [tables addObject:[NSMutableArray arrayWithObjects:
- funcName,
- [NSNumber numberWithBool:YES],
- [NSNumber numberWithBool:YES],
- [NSNumber numberWithBool:YES],
- [NSNumber numberWithInt:SPTableTypeFunc],
- nil]];
- }
- }
-
- [exportTableList reloadData];
+ [self _refreshDatabaseTableList];
}
/**
@@ -603,9 +562,29 @@
// Perform the export
if (returnCode == NSOKButton) {
- // Initialize the export after half a second to give the export sheet a chance to close
+ // If we are about to perform a table export, cache the current number of tables within the list,
+ // refresh the list and then compare the numbers to accommodate situations where new tables are
+ // added by external applications.
+ if ((exportSource == SPTableExport) && (exportType != SPDotExport)) {
+
+ // Give the export sheet a chance to close
+ [self performSelector:@selector(_checkForDatabaseChanges) withObject:nil afterDelay:0.5];
+ }
+ }
+}
+
+- (void)tableListChangedAlertDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
+{
+ // Perform the export ignoring the new tables
+ if (returnCode == NSOKButton) {
+
+ // Initialize the export after a slight delay to give the alert a chance to close
[self performSelector:@selector(initializeExportUsingSelectedOptions) withObject:nil afterDelay:0.5];
}
+ else {
+ // Cancel the export and redisplay the export dialog after a short delay
+ [self performSelector:@selector(export:) withObject:self afterDelay:0.5];
+ }
}
/**
@@ -720,6 +699,87 @@
}
/**
+ * Checks for changes in the current database, by refreshing the table list and warning the user if required.
+ */
+- (void)_checkForDatabaseChanges
+{
+ NSUInteger i = [tables count];
+
+ [tablesListInstance updateTables:self];
+
+ NSUInteger j = [self _refreshDatabaseTableList];
+
+ if (j > i) {
+ NSUInteger diff = (j - i);
+
+ SPBeginAlertSheet(NSLocalizedString(@"The list of tables has changed", @"table list change alert message"),
+ NSLocalizedString(@"Continue", @"continue button"),
+ NSLocalizedString(@"Cancel", @"cancel button"), nil, [tableDocumentInstance parentWindow], self,
+ @selector(tableListChangedAlertDidEnd:returnCode:contextInfo:), nil,
+ [NSString stringWithFormat:NSLocalizedString(@"The number of tables in this database has changed since the export dialog was opened. There are now %d additional table(s), most likely added by an external application.\n\nHow would you like to proceed?", @"table list change alert informative message"), diff]);
+ }
+ else {
+ [self initializeExportUsingSelectedOptions];
+ }
+}
+
+/**
+ * Refreshes the database table list.
+ *
+ * @return An unsigned integer indicating the number of items within the list.
+ */
+- (NSUInteger)_refreshDatabaseTableList
+{
+ [tables removeAllObjects];
+
+ // For all modes, retrieve table and view names
+ NSArray *tablesAndViews = [tablesListInstance allTableAndViewNames];
+
+ for (id itemName in tablesAndViews) {
+ [tables addObject:[NSMutableArray arrayWithObjects:
+ itemName,
+ [NSNumber numberWithBool:YES],
+ [NSNumber numberWithBool:YES],
+ [NSNumber numberWithBool:YES],
+ [NSNumber numberWithInt:SPTableTypeTable],
+ nil]];
+ }
+
+ // For SQL only, add procedures and functions
+ if (exportType == SPSQLExport) {
+ NSArray *procedures = [tablesListInstance allProcedureNames];
+
+ for (id procName in procedures)
+ {
+ [tables addObject:[NSMutableArray arrayWithObjects:
+ procName,
+ [NSNumber numberWithBool:YES],
+ [NSNumber numberWithBool:YES],
+ [NSNumber numberWithBool:YES],
+ [NSNumber numberWithInt:SPTableTypeProc],
+ nil]];
+ }
+
+ NSArray *functions = [tablesListInstance allFunctionNames];
+
+ for (id funcName in functions)
+ {
+ [tables addObject:[NSMutableArray arrayWithObjects:
+ funcName,
+ [NSNumber numberWithBool:YES],
+ [NSNumber numberWithBool:YES],
+ [NSNumber numberWithBool:YES],
+ [NSNumber numberWithInt:SPTableTypeFunc],
+ nil]];
+ }
+ }
+
+ [exportTableList reloadData];
+
+ return [tables count];
+}
+
+/**
* Enables or disables the export button based on the state of various interface controls.
*
* @param uiStateDict A dictionary containing the state of various UI controls.