diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPCSVExporter.h | 2 | ||||
-rw-r--r-- | Source/SPDotExporter.h | 2 | ||||
-rw-r--r-- | Source/SPExportController.h | 3 | ||||
-rw-r--r-- | Source/SPExportController.m | 177 | ||||
-rw-r--r-- | Source/SPExportFilenameUtilities.h | 43 | ||||
-rw-r--r-- | Source/SPExportFilenameUtilities.m | 188 | ||||
-rw-r--r-- | Source/SPExportInitializer.h | 2 | ||||
-rw-r--r-- | Source/SPExportInitializer.m | 12 | ||||
-rw-r--r-- | Source/SPExporter.h | 2 | ||||
-rw-r--r-- | Source/SPHTMLExporter.h | 2 | ||||
-rw-r--r-- | Source/SPPDFExporter.h | 2 | ||||
-rw-r--r-- | Source/SPSQLExporter.h | 2 | ||||
-rw-r--r-- | Source/SPXMLExporter.h | 2 |
13 files changed, 244 insertions, 195 deletions
diff --git a/Source/SPCSVExporter.h b/Source/SPCSVExporter.h index b0c6c46b..f1148b7e 100644 --- a/Source/SPCSVExporter.h +++ b/Source/SPCSVExporter.h @@ -23,8 +23,6 @@ // // More info at <http://code.google.com/p/sequel-pro/> -#import <Cocoa/Cocoa.h> - #import "SPExporter.h" #import "SPCSVExporterProtocol.h" diff --git a/Source/SPDotExporter.h b/Source/SPDotExporter.h index 338acc37..40954782 100644 --- a/Source/SPDotExporter.h +++ b/Source/SPDotExporter.h @@ -23,8 +23,6 @@ // // More info at <http://code.google.com/p/sequel-pro/> -#import <Cocoa/Cocoa.h> - #import "SPExporter.h" #import "SPDotExporterProtocol.h" diff --git a/Source/SPExportController.h b/Source/SPExportController.h index 1868ec00..3e4d6aa7 100644 --- a/Source/SPExportController.h +++ b/Source/SPExportController.h @@ -23,8 +23,6 @@ // // More info at <http://code.google.com/p/sequel-pro/> -#import <Cocoa/Cocoa.h> - #import "SPConstants.h" @class MCPConnection, BWAnchoredButtonBar; @@ -242,7 +240,6 @@ - (void)exportTables:(NSArray *)table asFormat:(SPExportType)format usingSource:(SPExportSource)source; - (void)openExportErrorsSheetWithString:(NSString *)errors; - (void)displayExportFinishedGrowlNotification; -- (NSString *)expandCustomFilenameFormatFromString:(NSString *)format usingTableName:(NSString *)table; // IB action methods - (IBAction)closeSheet:(id)sender; diff --git a/Source/SPExportController.m b/Source/SPExportController.m index 0a36a32c..bb16d36f 100644 --- a/Source/SPExportController.m +++ b/Source/SPExportController.m @@ -37,11 +37,6 @@ @interface SPExportController (PrivateAPI) -- (void)_updateDisplayedExportFilename; -- (void)_updateAvailableExportFilenameTokens; -- (NSString *)_generateDefaultExportFilename; -- (NSString *)_currentDefaultExportFileExtension; - - (void)_toggleExportButton:(id)uiStateDict; - (void)_toggleExportButtonOnBackgroundThread; - (void)_toggleExportButtonWithBool:(NSNumber *)enable; @@ -179,7 +174,7 @@ [exportTypeTabBar selectTabViewItemAtIndex:format]; // Set the default export filename - [self _updateDisplayedExportFilename]; + [self updateDisplayedExportFilename]; [self refreshTableList:self]; @@ -253,71 +248,6 @@ } /** - * Expands the custom filename format based on the selected tokens. - */ -- (NSString *)expandCustomFilenameFormatFromString:(NSString *)format usingTableName:(NSString *)table -{ - NSMutableString *string = [NSMutableString stringWithString:format]; - - NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; - - [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; - - [dateFormatter setDateStyle:NSDateFormatterShortStyle]; - [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; - - [string replaceOccurrencesOfString:NSLocalizedString(@"host", @"export filename host token") - withString:[tableDocumentInstance host] - options:NSLiteralSearch - range:NSMakeRange(0, [string length])]; - - [string replaceOccurrencesOfString:NSLocalizedString(@"database", @"export filename database token") - withString:[tableDocumentInstance database] - options:NSLiteralSearch - range:NSMakeRange(0, [string length])]; - - [string replaceOccurrencesOfString:NSLocalizedString(@"table", @"table") - withString:(table) ? table : @"" - options:NSLiteralSearch - range:NSMakeRange(0, [string length])]; - - [string replaceOccurrencesOfString:NSLocalizedString(@"date", @"export filename date token") - withString:[dateFormatter stringFromDate:[NSDate date]] - options:NSLiteralSearch - range:NSMakeRange(0, [string length])]; - - [dateFormatter setDateStyle:NSDateFormatterNoStyle]; - [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; - - [string replaceOccurrencesOfString:NSLocalizedString(@"time", @"export filename time token") - withString:[dateFormatter stringFromDate:[NSDate date]] - options:NSLiteralSearch - range:NSMakeRange(0, [string length])]; - - // Strip comma separators - [string replaceOccurrencesOfString:@"," - withString:@"" - options:NSLiteralSearch - range:NSMakeRange(0, [string length])]; - - // Replace colons with hyphens - [string replaceOccurrencesOfString:@":" - withString:@"-" - options:NSLiteralSearch - range:NSMakeRange(0, [string length])]; - - // Replace forward slashes with hyphens - [string replaceOccurrencesOfString:@"/" - withString:@"-" - options:NSLiteralSearch - range:NSMakeRange(0, [string length])]; - - [dateFormatter release]; - - return string; -} - -/** * Closes the export dialog. */ - (IBAction)closeSheet:(id)sender @@ -392,9 +322,9 @@ [exportCSVNULLValuesAsTextField setStringValue:[prefs stringForKey:SPNullValue]]; [exportXMLNULLValuesAsTextField setStringValue:[prefs stringForKey:SPNullValue]]; - [self _updateAvailableExportFilenameTokens]; + [self updateAvailableExportFilenameTokens]; - if (!showCustomFilenameView) [self _updateDisplayedExportFilename]; + if (!showCustomFilenameView) [self updateDisplayedExportFilename]; } /** @@ -415,8 +345,8 @@ [exportDeselectAllTablesButton setEnabled:isSelectedTables]; [exportRefreshTablesButton setEnabled:isSelectedTables]; - [self _updateAvailableExportFilenameTokens]; - [self _updateDisplayedExportFilename]; + [self updateAvailableExportFilenameTokens]; + [self updateDisplayedExportFilename]; } } @@ -571,7 +501,7 @@ */ - (IBAction)changeExportCompressionFormat:(id)sender { - [self _updateDisplayedExportFilename]; + [self updateDisplayedExportFilename]; } /** @@ -589,7 +519,7 @@ // On close update the displayed filename if (!showCustomFilenameView) { - [self _updateDisplayedExportFilename]; + [self updateDisplayedExportFilename]; } else { [exportCustomFilenameViewLabelButton setTitle:NSLocalizedString(@"Customize Filename", @"default customize file name label")]; @@ -758,99 +688,6 @@ #pragma mark Private API /** - * Updates the displayed export filename, either custom or default. - */ -- (void)_updateDisplayedExportFilename -{ - NSString *filename = @""; - - if ([[exportCustomFilenameTokenField stringValue] length] > 0) { - - // Get the current export file extension - NSString *extension = [self _currentDefaultExportFileExtension]; - - filename = [self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:[[tablesListInstance tables] objectAtIndex:1]]; - - if ([extension length] > 0) filename = [filename stringByAppendingPathExtension:extension]; - } - else { - filename = [self _generateDefaultExportFilename]; - } - - [exportCustomFilenameViewLabelButton setTitle:[NSString stringWithFormat:NSLocalizedString(@"Customize Filename (%@)", @"customize file name label"), filename]]; -} - -/** - * Updates the available export filename tokens. - */ -- (void)_updateAvailableExportFilenameTokens -{ - [exportCustomFilenameTokensField setStringValue:((exportSource == SPQueryExport) || (exportType == SPDotExport)) ? NSLocalizedString(@"host,database,date,time", @"custom export filename tokens without table") : NSLocalizedString(@"host,database,table,date,time", @"default custom export filename tokens")]; -} - -/** - * Generates the default export filename based on the selected export options. - */ -- (NSString *)_generateDefaultExportFilename -{ - NSString *filename = @""; - NSString *extension = [self _currentDefaultExportFileExtension]; - - // Determine what the file name should be - switch (exportSource) - { - case SPFilteredExport: - filename = [NSString stringWithFormat:@"%@_view", [tableDocumentInstance table]]; - break; - case SPQueryExport: - filename = @"query_result"; - break; - case SPTableExport: - filename = [tableDocumentInstance database]; - break; - } - - return ([extension length] > 0) ? [filename stringByAppendingPathExtension:extension] : filename; -} - -/** - * Returns the current default export file extension based on the selected export type. - */ -- (NSString *)_currentDefaultExportFileExtension -{ - NSString *extension = @""; - - switch (exportType) { - case SPSQLExport: - extension = SPFileExtensionSQL; - break; - case SPCSVExport: - extension = @"csv"; - break; - case SPXMLExport: - extension = @"xml"; - break; - case SPDotExport: - extension = @"dot"; - break; - } - - if ([exportOutputCompressionFormatPopupButton indexOfSelectedItem] != SPNoCompression) { - - SPFileCompressionFormat compressionFormat = [exportOutputCompressionFormatPopupButton indexOfSelectedItem]; - - if ([extension length] > 0) { - extension = [extension stringByAppendingPathExtension:(compressionFormat == SPGzipCompression) ? @"gz" : @"bz2"]; - } - else { - extension = (compressionFormat == SPGzipCompression) ? @"gz" : @"bz2"; - } - } - - return extension; -} - -/** * Enables or disables the export button based on the state of various interface controls. */ - (void)_toggleExportButton:(id)uiStateDict diff --git a/Source/SPExportFilenameUtilities.h b/Source/SPExportFilenameUtilities.h new file mode 100644 index 00000000..7bbcea25 --- /dev/null +++ b/Source/SPExportFilenameUtilities.h @@ -0,0 +1,43 @@ +// +// $Id$ +// +// SPExportFilenameUtilities.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on July 25, 2010 +// Copyright (c) 2010 Stuart Connolly. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import "SPExportController.h" + +/** + * @category SPExportFilenameUtilities SPExportFilenameUtilities.h + * + * @author Stuart Connolly http://stuconnolly.com/ + * + * Export filename utilities category. + */ +@interface SPExportController (SPExportFilenameUtilities) + +- (void)updateDisplayedExportFilename; +- (void)updateAvailableExportFilenameTokens; +- (NSString *)generateDefaultExportFilename; +- (NSString *)currentDefaultExportFileExtension; +- (NSString *)expandCustomFilenameFormatFromString:(NSString *)format usingTableName:(NSString *)table; + +@end diff --git a/Source/SPExportFilenameUtilities.m b/Source/SPExportFilenameUtilities.m new file mode 100644 index 00000000..53786d51 --- /dev/null +++ b/Source/SPExportFilenameUtilities.m @@ -0,0 +1,188 @@ +// +// $Id$ +// +// SPExportFilenameUtilities.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on July 25, 2010 +// Copyright (c) 2010 Stuart Connolly. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import "SPExportFilenameUtilities.h" + +@implementation SPExportController (SPExportFilenameUtilities) + +/** + * Updates the displayed export filename, either custom or default. + */ +- (void)updateDisplayedExportFilename +{ + NSString *filename = @""; + + if ([[exportCustomFilenameTokenField stringValue] length] > 0) { + + // Get the current export file extension + NSString *extension = [self currentDefaultExportFileExtension]; + + filename = [self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:[[tablesListInstance tables] objectAtIndex:1]]; + + if ([extension length] > 0) filename = [filename stringByAppendingPathExtension:extension]; + } + else { + filename = [self generateDefaultExportFilename]; + } + + [exportCustomFilenameViewLabelButton setTitle:[NSString stringWithFormat:NSLocalizedString(@"Customize Filename (%@)", @"customize file name label"), filename]]; +} + +/** + * Updates the available export filename tokens. + */ +- (void)updateAvailableExportFilenameTokens +{ + [exportCustomFilenameTokensField setStringValue:((exportSource == SPQueryExport) || (exportType == SPDotExport)) ? NSLocalizedString(@"host,database,date,time", @"custom export filename tokens without table") : NSLocalizedString(@"host,database,table,date,time", @"default custom export filename tokens")]; +} + +/** + * Generates the default export filename based on the selected export options. + */ +- (NSString *)generateDefaultExportFilename +{ + NSString *filename = @""; + NSString *extension = [self currentDefaultExportFileExtension]; + + // Determine what the file name should be + switch (exportSource) + { + case SPFilteredExport: + filename = [NSString stringWithFormat:@"%@_view", [tableDocumentInstance table]]; + break; + case SPQueryExport: + filename = @"query_result"; + break; + case SPTableExport: + filename = [tableDocumentInstance database]; + break; + } + + return ([extension length] > 0) ? [filename stringByAppendingPathExtension:extension] : filename; +} + +/** + * Returns the current default export file extension based on the selected export type. + */ +- (NSString *)currentDefaultExportFileExtension +{ + NSString *extension = @""; + + switch (exportType) { + case SPSQLExport: + extension = SPFileExtensionSQL; + break; + case SPCSVExport: + extension = @"csv"; + break; + case SPXMLExport: + extension = @"xml"; + break; + case SPDotExport: + extension = @"dot"; + break; + } + + if ([exportOutputCompressionFormatPopupButton indexOfSelectedItem] != SPNoCompression) { + + SPFileCompressionFormat compressionFormat = [exportOutputCompressionFormatPopupButton indexOfSelectedItem]; + + if ([extension length] > 0) { + extension = [extension stringByAppendingPathExtension:(compressionFormat == SPGzipCompression) ? @"gz" : @"bz2"]; + } + else { + extension = (compressionFormat == SPGzipCompression) ? @"gz" : @"bz2"; + } + } + + return extension; +} + +/** + * Expands the custom filename format based on the selected tokens. + */ +- (NSString *)expandCustomFilenameFormatFromString:(NSString *)format usingTableName:(NSString *)table +{ + NSMutableString *string = [NSMutableString stringWithString:format]; + + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; + + [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; + + [dateFormatter setDateStyle:NSDateFormatterShortStyle]; + [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; + + [string replaceOccurrencesOfString:NSLocalizedString(@"host", @"export filename host token") + withString:[tableDocumentInstance host] + options:NSLiteralSearch + range:NSMakeRange(0, [string length])]; + + [string replaceOccurrencesOfString:NSLocalizedString(@"database", @"export filename database token") + withString:[tableDocumentInstance database] + options:NSLiteralSearch + range:NSMakeRange(0, [string length])]; + + [string replaceOccurrencesOfString:NSLocalizedString(@"table", @"table") + withString:(table) ? table : @"" + options:NSLiteralSearch + range:NSMakeRange(0, [string length])]; + + [string replaceOccurrencesOfString:NSLocalizedString(@"date", @"export filename date token") + withString:[dateFormatter stringFromDate:[NSDate date]] + options:NSLiteralSearch + range:NSMakeRange(0, [string length])]; + + [dateFormatter setDateStyle:NSDateFormatterNoStyle]; + [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; + + [string replaceOccurrencesOfString:NSLocalizedString(@"time", @"export filename time token") + withString:[dateFormatter stringFromDate:[NSDate date]] + options:NSLiteralSearch + range:NSMakeRange(0, [string length])]; + + // Strip comma separators + [string replaceOccurrencesOfString:@"," + withString:@"" + options:NSLiteralSearch + range:NSMakeRange(0, [string length])]; + + // Replace colons with hyphens + [string replaceOccurrencesOfString:@":" + withString:@"-" + options:NSLiteralSearch + range:NSMakeRange(0, [string length])]; + + // Replace forward slashes with hyphens + [string replaceOccurrencesOfString:@"/" + withString:@"-" + options:NSLiteralSearch + range:NSMakeRange(0, [string length])]; + + [dateFormatter release]; + + return string; +} + +@end diff --git a/Source/SPExportInitializer.h b/Source/SPExportInitializer.h index 189a46d2..d42429ee 100644 --- a/Source/SPExportInitializer.h +++ b/Source/SPExportInitializer.h @@ -23,8 +23,6 @@ // // More info at <http://code.google.com/p/sequel-pro/> -#import <Cocoa/Cocoa.h> - #import "SPExportController.h" @class SPCSVExporter, SPSQLExporter, SPXMLExporter, SPFileHandle; diff --git a/Source/SPExportInitializer.m b/Source/SPExportInitializer.m index fab11da9..0ba5037f 100644 --- a/Source/SPExportInitializer.m +++ b/Source/SPExportInitializer.m @@ -187,7 +187,7 @@ } } - [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self _currentDefaultExportFileExtension]]]; + [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; singleFileHandle = [self getFileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; } @@ -285,7 +285,7 @@ // Create custom filename if required [exportFilename setString:(createCustomFilename) ? [self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:nil] : [NSString stringWithFormat:@"%@_%@", [tableDocumentInstance database], [[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%d" timeZone:nil locale:nil]]]; - [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self _currentDefaultExportFileExtension]]]; + [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; SPFileHandle *fileHandle = [self getFileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; @@ -324,7 +324,7 @@ } } - [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self _currentDefaultExportFileExtension]]]; + [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; singleFileHandle = [self getFileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; } @@ -393,7 +393,7 @@ [exportFilename setString:[tableDocumentInstance database]]; } - [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self _currentDefaultExportFileExtension]]]; + [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; SPFileHandle *fileHandle = [self getFileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; @@ -466,7 +466,7 @@ [exportFilename setString:(dataArray) ? [tableDocumentInstance database] : table]; } - [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self _currentDefaultExportFileExtension]]]; + [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; fileHandle = [self getFileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; @@ -502,7 +502,7 @@ // If required create separate files if ((exportSource == SPTableExport) && exportToMultipleFiles && (exportTableCount > 0)) { [exportFilename setString:[[exportPathField stringValue] stringByAppendingPathComponent:table]]; - [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self _currentDefaultExportFileExtension]]]; + [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; fileHandle = [self getFileHandleForFilePath:exportFilename]; diff --git a/Source/SPExporter.h b/Source/SPExporter.h index d9dadb6c..22ca0cc3 100644 --- a/Source/SPExporter.h +++ b/Source/SPExporter.h @@ -23,8 +23,6 @@ // // More info at <http://code.google.com/p/sequel-pro/> -#import <Cocoa/Cocoa.h> - /** * @class SPExporter SPExporter.m * diff --git a/Source/SPHTMLExporter.h b/Source/SPHTMLExporter.h index e58f8c80..fb0ce7f1 100644 --- a/Source/SPHTMLExporter.h +++ b/Source/SPHTMLExporter.h @@ -23,8 +23,6 @@ // // More info at <http://code.google.com/p/sequel-pro/> -#import <Cocoa/Cocoa.h> - #import "SPExporter.h" #import "SPHTMLExporterProtocol.h" diff --git a/Source/SPPDFExporter.h b/Source/SPPDFExporter.h index 62283c43..9071084f 100644 --- a/Source/SPPDFExporter.h +++ b/Source/SPPDFExporter.h @@ -23,8 +23,6 @@ // // More info at <http://code.google.com/p/sequel-pro/> -#import <Cocoa/Cocoa.h> - #import "SPExporter.h" #import "SPPDFExporterProtocol.h" diff --git a/Source/SPSQLExporter.h b/Source/SPSQLExporter.h index 6f42dd4c..43ba0172 100644 --- a/Source/SPSQLExporter.h +++ b/Source/SPSQLExporter.h @@ -23,8 +23,6 @@ // // More info at <http://code.google.com/p/sequel-pro/> -#import <Cocoa/Cocoa.h> - #import "SPExporter.h" #import "SPConstants.h" #import "SPSQLExporterProtocol.h" diff --git a/Source/SPXMLExporter.h b/Source/SPXMLExporter.h index f80aacc6..b74c76bf 100644 --- a/Source/SPXMLExporter.h +++ b/Source/SPXMLExporter.h @@ -23,8 +23,6 @@ // // More info at <http://code.google.com/p/sequel-pro/> -#import <Cocoa/Cocoa.h> - #import "SPExporter.h" #import "SPXMLExporterProtocol.h" |