aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPExportInitializer.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2011-05-07 15:31:54 +0000
committerrowanbeentje <rowan@beent.je>2011-05-07 15:31:54 +0000
commit0c2a225a68ef1512e51ff3a48fef1fa13eacce60 (patch)
tree624b65144aac2f2a5d57172f8dd7625a5a8e236a /Source/SPExportInitializer.m
parent47a1c49e95403e6da6c9e0ae979144fd5c1dff08 (diff)
downloadsequelpro-0c2a225a68ef1512e51ff3a48fef1fa13eacce60.tar.gz
sequelpro-0c2a225a68ef1512e51ff3a48fef1fa13eacce60.tar.bz2
sequelpro-0c2a225a68ef1512e51ff3a48fef1fa13eacce60.zip
Implement a large number of minor fixes and improvements to export functionality, including an overhaul of filename NSTokenField functionality:
- Improve the NSTokenField used for export filenames: only tokenise reserved tokens, don't tokenise reserved words which are parts of other words, allow the comma to be used, update tokenisation during typing, and prevent whitespace triming. - Save the last selected export path, and make the path selection button open a dialog to the selected directory - Save the export filename and restore on future uses of the export dialog (only if the name contains placeholder tokens, so one-off export names aren't saved) - If the advanced options are collapsed, display a summary of the selected options next to the disclosure triangle - Display a small warning in the corner of the window if the export file cannot be imported into Sequel Pro, to warn those people attempting to back up their databases in XML - Clarify and improve the export warning dialog if files already exist or could not be created; make the simpler file-exists cases reflect OS-style dialogs, alter wording based on the number of files that failed and how they failed, and only show the "replace" or "skip" type buttons if it makes sense to do so. - Fix a mutation-during-enumeration error when skipping files - If "Cancel" is chosen in the export file creation replace/error dialog, redisplay the export sheet with the previous selection still active - Add support for year, month and day tokens in the filename token list - Don't allow blank custom filenames, before or after tokenisation, as this can cause problems - instead fall back to default filenames in those cases - Only append the extension if one hasn't been set - on all export formats, extending r3284 - If exporting to multiple files option is enabled but only one table is selected, supply that table name for filename table tokens - Update the progress bar to reflect update progress when exporting CSV data - Fix a bug causing exports to hang if the low-memory advanced option was set and content was selected to export and any empty tables were encountered - Save memory use and compression advanced export settings across sessions - Update localisable strings
Diffstat (limited to 'Source/SPExportInitializer.m')
-rw-r--r--Source/SPExportInitializer.m58
1 files changed, 46 insertions, 12 deletions
diff --git a/Source/SPExportInitializer.m b/Source/SPExportInitializer.m
index 32ce7ff5..f9d23b63 100644
--- a/Source/SPExportInitializer.m
+++ b/Source/SPExportInitializer.m
@@ -42,6 +42,7 @@
#import "SPExportFile.h"
#import "SPExportFileUtilities.h"
#import "SPExportFilenameUtilities.h"
+#import "SPExportFileNameTokenObject.h"
@implementation SPExportController (SPExportInitializer)
@@ -209,9 +210,16 @@
// If the user has selected to only export to a single file or this is a filtered or custom query
// export, create the single file now and assign it to all subsequently created exporters.
if ((![self exportToMultipleFiles]) || (exportSource == SPFilteredExport) || (exportSource == SPQueryExport)) {
+ NSString *selectedTableName = nil;
+ if (exportSource == SPTableExport && [exportTables count] == 1) selectedTableName = [exportTables objectAtIndex:0];
+
+ [exportFilename setString:(createCustomFilename) ? [self expandCustomFilenameFormatUsingTableName:selectedTableName] : [self generateDefaultExportFilename]];
+
+ // Only append the extension if necessary
+ if (![[exportFilename pathExtension] length]) {
+ [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]];
+ }
- [exportFilename setString:(createCustomFilename) ? [self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:nil] : [self generateDefaultExportFilename]];
-
singleExportFile = [SPExportFile exportFileAtPath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]];
}
@@ -280,7 +288,7 @@
[sqlExporter setSqlExportTables:exportTables];
// Create custom filename if required
- [exportFilename setString:(createCustomFilename) ? [self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:nil] : [self generateDefaultExportFilename]];
+ [exportFilename setString:(createCustomFilename) ? [self expandCustomFilenameFormatUsingTableName:nil] : [self generateDefaultExportFilename]];
// Only append the extension if necessary
if (![[exportFilename pathExtension] length]) {
@@ -305,9 +313,16 @@
// If the user has selected to only export to a single file or this is a filtered or custom query
// export, create the single file now and assign it to all subsequently created exporters.
if ((![self exportToMultipleFiles]) || (exportSource == SPFilteredExport) || (exportSource == SPQueryExport)) {
+ NSString *selectedTableName = nil;
+ if (exportSource == SPTableExport && [exportTables count] == 1) selectedTableName = [exportTables objectAtIndex:0];
- [exportFilename setString:(createCustomFilename) ? [self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:nil] : [self generateDefaultExportFilename]];
+ [exportFilename setString:(createCustomFilename) ? [self expandCustomFilenameFormatUsingTableName:selectedTableName] : [self generateDefaultExportFilename]];
+ // Only append the extension if necessary
+ if (![[exportFilename pathExtension] length]) {
+ [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]];
+ }
+
singleExportFile = [SPExportFile exportFileAtPath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]];
}
@@ -374,13 +389,16 @@
// Create custom filename if required
if (createCustomFilename) {
- [exportFilename setString:[self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:nil]];
+ [exportFilename setString:[self expandCustomFilenameFormatUsingTableName:nil]];
}
else {
[exportFilename setString:[tableDocumentInstance database]];
}
- [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]];
+ // Only append the extension if necessary
+ if (![[exportFilename pathExtension] length]) {
+ [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]];
+ }
file = [SPExportFile exportFileAtPath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]];
@@ -468,19 +486,27 @@
if (createCustomFilename) {
// Create custom filename based on the selected format
- [exportFilename setString:[self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:table]];
+ [exportFilename setString:[self expandCustomFilenameFormatUsingTableName:table]];
// If the user chose to use a custom filename format and we exporting to multiple files, make
// sure the table name is included to ensure the output files are unique.
if (exportTableCount > 1) {
- [exportFilename setString:([[exportCustomFilenameTokenField stringValue] rangeOfString:@"table" options:NSLiteralSearch].location == NSNotFound) ? [exportFilename stringByAppendingFormat:@"_%@", table] : exportFilename];
+ BOOL tableNameInTokens = NO;
+ NSArray *representedObjects = [exportCustomFilenameTokenField objectValue];
+ for (id representedObject in representedObjects) {
+ if ([representedObject isKindOfClass:[SPExportFileNameTokenObject class]] && [[representedObject tokenContent] isEqualToString:NSLocalizedString(@"table", @"table")]) tableNameInTokens = YES;
+ }
+ [exportFilename setString:(tableNameInTokens ? exportFilename : [exportFilename stringByAppendingFormat:@"_%@", table])];
}
}
else {
[exportFilename setString:(dataArray) ? [tableDocumentInstance database] : table];
}
- [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]];
+ // Only append the extension if necessary
+ if (![[exportFilename pathExtension] length]) {
+ [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]];
+ }
SPExportFile *file = [SPExportFile exportFileAtPath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]];
@@ -522,19 +548,27 @@
if (createCustomFilename) {
// Create custom filename based on the selected format
- [exportFilename setString:[self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:table]];
+ [exportFilename setString:[self expandCustomFilenameFormatUsingTableName:table]];
// If the user chose to use a custom filename format and we exporting to multiple files, make
// sure the table name is included to ensure the output files are unique.
if (exportTableCount > 1) {
- [exportFilename setString:([[exportCustomFilenameTokenField stringValue] rangeOfString:@"table" options:NSLiteralSearch].location == NSNotFound) ? [exportFilename stringByAppendingFormat:@"_%@", table] : exportFilename];
+ BOOL tableNameInTokens = NO;
+ NSArray *representedObjects = [exportCustomFilenameTokenField objectValue];
+ for (id representedObject in representedObjects) {
+ if ([representedObject isKindOfClass:[SPExportFileNameTokenObject class]] && [[representedObject tokenContent] isEqualToString:NSLocalizedString(@"table", @"table")]) tableNameInTokens = YES;
+ }
+ [exportFilename setString:(tableNameInTokens ? exportFilename : [exportFilename stringByAppendingFormat:@"_%@", table])];
}
}
else {
[exportFilename setString:(dataArray) ? [tableDocumentInstance database] : table];
}
- [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]];
+ // Only append the extension if necessary
+ if (![[exportFilename pathExtension] length]) {
+ [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]];
+ }
SPExportFile *file = [SPExportFile exportFileAtPath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]];