From a23e7b66395357ada37a1e6a8c386ce49b58a611 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 15 Nov 2015 18:08:40 +0100 Subject: Store the last export settings using the new "export settings" format --- Interfaces/English.lproj/ExportDialog.xib | 32 ------------ Resources/Plists/PreferenceDefaults.plist | 4 -- Source/SPConstants.h | 9 ++-- Source/SPConstants.m | 6 +-- Source/SPExportController.m | 83 +++++++++++-------------------- Source/SPExportSettingsPersistence.m | 3 +- 6 files changed, 33 insertions(+), 104 deletions(-) diff --git a/Interfaces/English.lproj/ExportDialog.xib b/Interfaces/English.lproj/ExportDialog.xib index 5275ec30..25d5b075 100644 --- a/Interfaces/English.lproj/ExportDialog.xib +++ b/Interfaces/English.lproj/ExportDialog.xib @@ -3808,38 +3808,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 1238 - - - value: values.SPExportMemoryModeLastValue - - - - - - value: values.SPExportMemoryModeLastValue - value - values.SPExportMemoryModeLastValue - 2 - - - 1389 - - - - selectedIndex: values.SPExportCompressionLastValue - - - - - - selectedIndex: values.SPExportCompressionLastValue - selectedIndex - values.SPExportCompressionLastValue - 2 - - - 1387 - diff --git a/Resources/Plists/PreferenceDefaults.plist b/Resources/Plists/PreferenceDefaults.plist index 687b4b09..1d55e65a 100644 --- a/Resources/Plists/PreferenceDefaults.plist +++ b/Resources/Plists/PreferenceDefaults.plist @@ -149,8 +149,6 @@ 3 NewFieldsAllowNulls - NoBOMforSQLdumpFile - NullValue NULL PrintBackground @@ -189,8 +187,6 @@ SPFirstRun - SQLExportUseCompression - SSHMultiplexingEnabled TableInformationPanelCollapsed diff --git a/Source/SPConstants.h b/Source/SPConstants.h index ec190ba4..db51b462 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -67,7 +67,8 @@ typedef NS_ENUM(NSUInteger, SPExportType) { SPDotExport = 3, SPPDFExport = 4, SPHTMLExport = 5, - SPExcelExport = 6 + SPExcelExport = 6, + SPAnyExportType = NSUIntegerMax, // this is a transient type to indicate "no specific choice" }; // Export source constants @@ -402,11 +403,7 @@ extern NSString *SPCSVImportFieldEscapeCharacter; extern NSString *SPCSVImportFirstLineIsHeader; extern NSString *SPCSVFieldImportMappingAlignment; extern NSString *SPImportClipboardTempFileNamePrefix; -extern NSString *SPSQLExportUseCompression; -extern NSString *SPNoBOMforSQLdumpFile; -extern NSString *SPExportLastDirectory; -extern NSString *SPExportFilenameFormat; // legacy -extern NSString *SPExportFilenameFormatIntl; // new, user language independent version +extern NSString *SPLastExportSettings; // Export filename tokens extern NSString *SPFileNameDatabaseTokenName; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index 1c62d37e..16f59f7a 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -202,11 +202,7 @@ NSString *SPCSVImportFirstLineIsHeader = @"CSVImportFirstLineIsHeader" NSString *SPCSVImportLineTerminator = @"CSVImportLineTerminator"; NSString *SPCSVFieldImportMappingAlignment = @"CSVFieldImportMappingAlignment"; NSString *SPImportClipboardTempFileNamePrefix = @"/tmp/_SP_ClipBoard_Import_File_"; -NSString *SPSQLExportUseCompression = @"SQLExportUseCompression"; -NSString *SPNoBOMforSQLdumpFile = @"NoBOMforSQLdumpFile"; -NSString *SPExportLastDirectory = @"SPExportLastDirectory"; -NSString *SPExportFilenameFormat = @"SPExportFilenameFormat"; -NSString *SPExportFilenameFormatIntl = @"CustomExportFilenameFormat"; +NSString *SPLastExportSettings = @"LastExportSettings"; // Export filename tokens NSString *SPFileNameDatabaseTokenName = @"database"; diff --git a/Source/SPExportController.m b/Source/SPExportController.m index 9113decc..2439dd86 100644 --- a/Source/SPExportController.m +++ b/Source/SPExportController.m @@ -42,6 +42,7 @@ #import "SPThreadAdditions.h" #import "SPCustomQuery.h" #import "SPExportController+SharedPrivateAPI.h" +#import "SPExportSettingsPersistence.h" #import @@ -63,7 +64,6 @@ static const NSString *SPSQLExportDropEnabled = @"SQLExportDropEnabled"; - (void)_displayExportTypeOptions:(BOOL)display; - (void)_updateExportFormatInformation; - (void)_updateExportAdvancedOptionsLabel; -- (void)_setPreviousExportFilenameAndPath; - (void)_toggleExportButton:(id)uiStateDict; - (void)_toggleExportButtonOnBackgroundThread; @@ -120,8 +120,6 @@ static const NSString *SPSQLExportDropEnabled = @"SQLExportDropEnabled"; heightOffset1 = 0; heightOffset2 = 0; - windowMinWidth = [[self window] minSize].width; - windowMinHeigth = [[self window] minSize].height; prefs = [NSUserDefaults standardUserDefaults]; @@ -150,13 +148,17 @@ static const NSString *SPSQLExportDropEnabled = @"SQLExportDropEnabled"; if (mainNibLoaded) return; mainNibLoaded = YES; + + windowMinWidth = [[self window] minSize].width; + windowMinHeigth = [[self window] minSize].height; // Select the 'selected tables' option [exportInputPopUpButton selectItemAtIndex:SPTableExport]; // Select the SQL tab [[exportTypeTabBar tabViewItemAtIndex:0] setView:exporterView]; - + [exportTypeTabBar selectTabViewItemAtIndex:0]; + // By default a new SQL INSERT statement should be created every 250KiB of data [exportSQLInsertNValueTextField setIntegerValue:250]; @@ -186,14 +188,28 @@ static const NSString *SPSQLExportDropEnabled = @"SQLExportDropEnabled"; * @param source The source of the export. See SPExportSource constants. */ - (void)exportTables:(NSArray *)exportTables asFormat:(SPExportType)format usingSource:(SPExportSource)source -{ - // Select the correct tab - [exportTypeTabBar selectTabViewItemAtIndex:format]; +{ + // set some defaults + [exportCSVNULLValuesAsTextField setStringValue:[prefs stringForKey:SPNullValue]]; + [exportXMLNULLValuesAsTextField setStringValue:[prefs stringForKey:SPNullValue]]; + if(![[exportPathField stringValue] length]) { + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSAllDomainsMask, YES); + // If found the set the default path to the user's desktop, otherwise use their home directory + [exportPathField setStringValue:([paths count] > 0) ? [paths objectAtIndex:0] : NSHomeDirectory()]; + } - [self _setPreviousExportFilenameAndPath]; + // initially popuplate the tables list + [self refreshTableList:nil]; + + // overwrite defaults with user settings from last export + [self applySettingsFromDictionary:[prefs objectForKey:SPLastExportSettings] error:NULL]; + + // overwrite those with settings for the current export + + // Select the correct tab + if(format != SPAnyExportType) [exportTypeTabBar selectTabViewItemAtIndex:format]; [self updateDisplayedExportFilename]; - [self refreshTableList:nil]; [exporters removeAllObjects]; [exportFiles removeAllObjects]; @@ -281,7 +297,7 @@ static const NSString *SPSQLExportDropEnabled = @"SQLExportDropEnabled"; */ - (IBAction)export:(id)sender { - SPExportType selectedExportType = SPSQLExport; + SPExportType selectedExportType = SPAnyExportType; SPExportSource selectedExportSource = SPTableExport; NSArray *selectedTables = [tablesListInstance selectedTableItems]; @@ -454,7 +470,6 @@ set_input: userInfo:nil]; } [exportPathField setStringValue:path]; - [prefs setObject:path forKey:SPExportLastDirectory]; } }]; } @@ -703,24 +718,8 @@ set_input: { // Perform the export if (returnCode == NSOKButton) { - - // Check whether to save the export filename. Save it if it's not blank and contains at least one - // token - this suggests it's not a one-off filename - if ([[exportCustomFilenameTokenField stringValue] length] < 1) { - [prefs removeObjectForKey:SPExportFilenameFormatIntl]; - } - else { - BOOL saveFilename = NO; - - NSArray *representedObjects = [exportCustomFilenameTokenField objectValue]; - - for (id aToken in representedObjects) - { - if ([aToken isKindOfClass:[SPExportFileNameTokenObject class]]) saveFilename = YES; - } - - if (saveFilename) [prefs setObject:[NSKeyedArchiver archivedDataWithRootObject:representedObjects] forKey:SPExportFilenameFormatIntl]; - } + + [prefs setObject:[self currentSettingsAsDictionary] forKey:SPLastExportSettings]; // 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 @@ -843,9 +842,6 @@ set_input: [exportDotForceLowerTableNamesCheck setState:(serverLowerCaseTableNameValue == 0)?NSOffState:NSOnState]; } - - [exportCSVNULLValuesAsTextField setStringValue:[prefs stringForKey:SPNullValue]]; - [exportXMLNULLValuesAsTextField setStringValue:[prefs stringForKey:SPNullValue]]; [self _displayExportTypeOptions:(isSQL || isCSV || isXML || isDot)]; [self updateAvailableExportFilenameTokens]; @@ -972,29 +968,6 @@ set_input: [exportAdvancedOptionsViewLabelButton setTitle:[NSString stringWithFormat:@"%@ (%@)", NSLocalizedString(@"Advanced", @"Advanced options short title"), [optionsSummary componentsJoinedByString:@", "]]]; } -/** - * Sets the previous export filename and path if available. - */ -- (void)_setPreviousExportFilenameAndPath -{ - id o; - // Restore the export filename if it exists, and update the display - if ((o = [prefs objectForKey:SPExportFilenameFormatIntl])) { - [exportCustomFilenameTokenField setObjectValue:[NSKeyedUnarchiver unarchiveObjectWithData:o]]; - } - - // If a directory has previously been selected, reselect it - if ((o = [prefs objectForKey:SPExportLastDirectory])) { - [exportPathField setStringValue:o]; - } - else { - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSAllDomainsMask, YES); - - // If found the set the default path to the user's desktop, otherwise use their home directory - [exportPathField setStringValue:([paths count] > 0) ? [paths objectAtIndex:0] : NSHomeDirectory()]; - } -} - /** * Enables or disables the export button based on the state of various interface controls. * diff --git a/Source/SPExportSettingsPersistence.m b/Source/SPExportSettingsPersistence.m index 38a4ed84..29a981af 100644 --- a/Source/SPExportSettingsPersistence.m +++ b/Source/SPExportSettingsPersistence.m @@ -46,7 +46,6 @@ static inline void SetOnOff(NSNumber *ref,id obj); @interface SPExportController (Private) - (void)_updateExportAdvancedOptionsLabel; -- (void)_switchTab; @end @@ -463,7 +462,7 @@ static inline void SetOnOff(NSNumber *ref,id obj); // token pool is only valid once the schema object selection is done [self updateAvailableExportFilenameTokens]; - if((o = [dict objectForKey:@"customFilename"])) [self setCustomFilenameFromArray:o]; + if((o = [dict objectForKey:@"customFilename"]) && [o isKindOfClass:[NSArray class]]) [self setCustomFilenameFromArray:o]; return YES; } -- cgit v1.2.3