aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPExportFilenameUtilities.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-04-01 13:56:59 +0000
committerstuconnolly <stuart02@gmail.com>2012-04-01 13:56:59 +0000
commitd951d5bcd6a86736c09863af98bef18cbb41eef5 (patch)
tree7563cc520b5c4570df7f4b818dc0378abbe6a06f /Source/SPExportFilenameUtilities.m
parente0c3c7e6d7eb9748245d2e75759fdc6141890929 (diff)
downloadsequelpro-d951d5bcd6a86736c09863af98bef18cbb41eef5.tar.gz
sequelpro-d951d5bcd6a86736c09863af98bef18cbb41eef5.tar.bz2
sequelpro-d951d5bcd6a86736c09863af98bef18cbb41eef5.zip
Improve the availability of the table name token on the custom export filename selection.
It's now no longer available during the following situations: - Exporting more than one table during an SQL export - Exporting more than one table during a CSV or XML, but only if the export to multiple files is not checked
Diffstat (limited to 'Source/SPExportFilenameUtilities.m')
-rw-r--r--Source/SPExportFilenameUtilities.m89
1 files changed, 80 insertions, 9 deletions
diff --git a/Source/SPExportFilenameUtilities.m b/Source/SPExportFilenameUtilities.m
index 31625a4c..ad5ab36b 100644
--- a/Source/SPExportFilenameUtilities.m
+++ b/Source/SPExportFilenameUtilities.m
@@ -54,11 +54,61 @@
}
/**
- * Updates the available export filename tokens.
+ * Updates the available export filename tokens based on the currently selected options.
*/
- (void)updateAvailableExportFilenameTokens
{
- [exportCustomFilenameTokensField setStringValue:((exportSource == SPQueryExport) || (exportType == SPDotExport)) ? NSLocalizedString(@"host,database,date,year,month,day,time", @"custom export filename tokens without table") : NSLocalizedString(@"host,database,table,date,year,month,day,time", @"default custom export filename tokens")];
+ NSUInteger i = 0;
+ BOOL removeTable = NO;
+
+ BOOL isSQL = exportType == SPSQLExport;
+ BOOL isCSV = exportType == SPCSVExport;
+ BOOL isDot = exportType == SPDotExport;
+ BOOL isXML = exportType == SPXMLExport;
+
+ NSString *tokens = NSLocalizedString(@"host,database,table,date,year,month,day,time", @"default custom export filename tokens");;
+ NSString *tokensWithoutTable = NSLocalizedString(@"host,database,date,year,month,day,time", @"custom export filename tokens without table");
+
+ if (exportSource == SPQueryExport || isDot) {
+ tokens = tokensWithoutTable;
+ }
+ else if (isSQL || isCSV || isXML) {
+ for (NSArray *table in tables)
+ {
+ if ([NSArrayObjectAtIndex(table, 2) boolValue]) {
+ i++;
+ removeTable = YES;
+
+ if (i == 2) break;
+ }
+ }
+
+ if (i > 1) {
+ removeTable = isSQL ? YES : ![exportFilePerTableCheck state];
+
+ tokens = isSQL ? tokensWithoutTable : ([exportFilePerTableCheck state] ? tokens : tokensWithoutTable);
+ }
+ }
+
+ if (removeTable) {
+ NSArray *tokenParts = [exportCustomFilenameTokenField objectValue];
+
+ for (id token in [exportCustomFilenameTokenField objectValue])
+ {
+ if ([token isKindOfClass:[SPExportFileNameTokenObject class]]) {
+ if ([[token tokenContent] isEqualToString:NSLocalizedString(@"table", @"table")]) {
+ NSMutableArray *newTokens = [NSMutableArray arrayWithArray:tokenParts];
+
+ [newTokens removeObjectAtIndex:[tokenParts indexOfObject:token]];
+
+ [exportCustomFilenameTokenField setObjectValue:newTokens];
+ break;
+ }
+ }
+ }
+ }
+
+ [exportCustomFilenameTokensField setStringValue:tokens];
}
/**
@@ -69,7 +119,9 @@
{
if ([[exportCustomFilenameTokensField objectValue] containsObject:stringToTokenize]) {
SPExportFileNameTokenObject *newToken = [[SPExportFileNameTokenObject alloc] init];
+
[newToken setTokenContent:stringToTokenize];
+
return [newToken autorelease];
}
@@ -78,6 +130,7 @@
/**
* Tokenize the filename field.
+ *
* This is called on a delay after text entry to update the tokens during text entry.
* There's no API to perform tokenizing, but the same result can be achieved by using the return key;
* however, this only works if the cursor is after text, not after a token.
@@ -90,6 +143,7 @@
if ([exportCustomFilenameTokenField currentEditor] == nil) return;
NSRange selectedRange = [[exportCustomFilenameTokenField currentEditor] selectedRange];
+
if (selectedRange.location == NSNotFound) return;
if (selectedRange.length > 0) return;
@@ -98,10 +152,15 @@
// Walk through the strings - not the tokens - and determine whether any need tokenizing
BOOL tokenizingRequired = NO;
- for (id representedObject in representedObjects) {
+
+ for (id representedObject in representedObjects)
+ {
if ([representedObject isKindOfClass:[SPExportFileNameTokenObject class]]) continue;
+
NSArray *tokenParts = [representedObject componentsSeparatedByCharactersInSet:nonAlphanumericSet];
- for (NSString *tokenPart in tokenParts) {
+
+ for (NSString *tokenPart in tokenParts)
+ {
if ([validTokens containsObject:tokenPart]) {
tokenizingRequired = YES;
break;
@@ -115,12 +174,16 @@
// Detect where the cursor is currently located. If it's at the end of a token, also return -
// or the enter key would result in closing the sheet.
NSUInteger stringPosition = 0;
- for (id representedObject in representedObjects) {
+
+ for (id representedObject in representedObjects)
+ {
if ([representedObject isKindOfClass:[SPExportFileNameTokenObject class]]) {
stringPosition++;
- } else {
+ }
+ else {
stringPosition += [(NSString *)representedObject length];
}
+
if (selectedRange.location <= stringPosition) {
if ([representedObject isKindOfClass:[SPExportFileNameTokenObject class]]) return;
break;
@@ -128,7 +191,17 @@
}
// All conditions met - synthesize the return key to trigger tokenization.
- NSEvent *tokenizingEvent = [NSEvent keyEventWithType:NSKeyDown location:NSMakePoint(0,0) modifierFlags:0 timestamp:0 windowNumber:[[exportCustomFilenameTokenField window] windowNumber] context:[NSGraphicsContext currentContext] characters:nil charactersIgnoringModifiers:nil isARepeat:NO keyCode:0x24];
+ NSEvent *tokenizingEvent = [NSEvent keyEventWithType:NSKeyDown
+ location:NSMakePoint(0,0)
+ modifierFlags:0
+ timestamp:0
+ windowNumber:[[exportCustomFilenameTokenField window] windowNumber]
+ context:[NSGraphicsContext currentContext]
+ characters:nil
+ charactersIgnoringModifiers:nil
+ isARepeat:NO
+ keyCode:0x24];
+
[[NSApplication sharedApplication] postEvent:tokenizingEvent atStart:NO];
// Update the filename preview
@@ -235,7 +308,6 @@
}
else if ([tokenContent isEqualToString:NSLocalizedString(@"table", @"table")]) {
[string appendString:(table) ? table : @""];
-
}
else if ([tokenContent isEqualToString:NSLocalizedString(@"date", @"export filename date token")]) {
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
@@ -259,7 +331,6 @@
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[string appendString:[dateFormatter stringFromDate:[NSDate date]]];
-
}
}
else {