Skip to content

Commit fdef91b

Browse files
committed
Allow import of saved export settings (in export dialog)
1 parent 72951bf commit fdef91b

11 files changed

Lines changed: 746 additions & 93 deletions

Interfaces/English.lproj/ExportDialog.xib

Lines changed: 209 additions & 58 deletions
Large diffs are not rendered by default.

Source/SPBundleEditorController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ - (IBAction)saveBundle:(id)sender
721721
[panel setNameFieldStringValue:[[self _currentSelectedObject] objectForKey:kBundleNameKey]];
722722

723723
[panel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger returnCode) {
724-
if (returnCode != NSOKButton) return;
724+
if (returnCode != NSFileHandlingPanelOKButton) return;
725725

726726
// Panel is still on screen. Hide it first. (This is Apple's recommended way)
727727
[panel orderOut:nil];

Source/SPConstants.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,16 @@ extern NSString *SPURLSchemeQueryResultStatusPathHeader;
641641
extern NSString *SPURLSchemeQueryResultMetaPathHeader;
642642

643643
extern NSString *SPCommonCryptoExceptionName;
644+
extern NSString *SPErrorDomain; // generic SP error domain for NSError
645+
646+
typedef NS_ENUM(NSInteger,SPErrorCode) { // error codes in SPErrorDomain
647+
/** When plist deserialization fails with nil return and no NSError or the returned object has the wrong type */
648+
SPErrorWrongTypeOrNil = 110001,
649+
/** Parsed data is syntactically correct, but semantically wrong (e.g. a SPF file with the wrong content format */
650+
SPErrorWrongContentType = 110002,
651+
/** Some data has a version that we don't know how to handle (can be used with e.g. SPF files, which have explicit version numbers) */
652+
SPErrorWrongContentVersion = 110003,
653+
};
644654

645655
#define SPAppDelegate ((SPAppController *)[NSApp delegate])
646656

Source/SPConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@
443443
NSString *SPURLSchemeQueryResultMetaPathHeader = @"/tmp/SP_QUERY_META_";
444444

445445
NSString *SPCommonCryptoExceptionName = @"SPCommonCryptoException";
446+
NSString *SPErrorDomain = @"SPErrorDomain";
446447

447448
void inline _SPClear(id *addr) {
448449
[*addr release], *addr = nil;

Source/SPExportController.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@
254254
- (void)openExportErrorsSheetWithString:(NSString *)errors;
255255
- (void)displayExportFinishedGrowlNotification;
256256

257+
/**
258+
* Tries to set the export input to a given value or falls back to a default if not valid
259+
* @param input The source to use
260+
* @return YES if the source was accepted, NO otherwise
261+
* @pre _switchTab needs to have been run before this method to decide valid inputs
262+
*/
263+
- (BOOL)setExportInput:(SPExportSource)input;
264+
257265
// IB action methods
258266
- (IBAction)export:(id)sender;
259267
- (IBAction)closeSheet:(id)sender;

Source/SPExportController.m

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,6 @@ - (void)exportTables:(NSArray *)exportTables asFormat:(SPExportType)format using
198198
[exporters removeAllObjects];
199199
[exportFiles removeAllObjects];
200200

201-
// Select the 'selected tables' source option
202-
[exportInputPopUpButton selectItemAtIndex:source];
203-
204201
// If tables were supplied, select them
205202
if (exportTables) {
206203

@@ -231,6 +228,7 @@ - (void)exportTables:(NSArray *)exportTables asFormat:(SPExportType)format using
231228
// Ensure interface validation
232229
[self _switchTab];
233230
[self _updateExportAdvancedOptionsLabel];
231+
[self setExportInput:source];
234232

235233
[NSApp beginSheet:[self window]
236234
modalForWindow:[tableDocumentInstance parentWindow]
@@ -306,9 +304,6 @@ - (IBAction)export:(id)sender
306304
}
307305

308306
[self exportTables:selectedTables asFormat:selectedExportType usingSource:selectedExportSource];
309-
310-
// Ensure UI validation
311-
[self switchInput:exportInputPopUpButton];
312307
}
313308

314309
/**
@@ -337,27 +332,50 @@ - (IBAction)closeSheet:(id)sender
337332
[[sender window] orderOut:self];
338333
}
339334

335+
- (BOOL)setExportInput:(SPExportSource)input
336+
{
337+
SPExportSource actualInput = input;
338+
// Dot will always be a TableExport
339+
if(exportType == SPDotExport) {
340+
actualInput = SPTableExport;
341+
}
342+
//check if the type actually is valid
343+
else if(![[exportInputPopUpButton itemAtIndex:input] isEnabled]) {
344+
//...no, pick a valid one instead
345+
for (NSMenuItem *item in [exportInputPopUpButton itemArray]) {
346+
if([item isEnabled]) {
347+
actualInput = [exportInputPopUpButton indexOfItem:item];
348+
goto set_input;
349+
}
350+
}
351+
// nothing found (should not happen)
352+
SPLog(@"did not find any valid export input!?");
353+
return NO;
354+
}
355+
set_input:
356+
exportSource = actualInput;
357+
358+
[exportInputPopUpButton selectItemAtIndex:exportSource];
359+
360+
BOOL isSelectedTables = (exportSource == SPTableExport);
361+
362+
[exportFilePerTableCheck setHidden:(!isSelectedTables) || (exportType == SPSQLExport)];
363+
[exportTableList setEnabled:isSelectedTables];
364+
[exportSelectAllTablesButton setEnabled:isSelectedTables];
365+
[exportDeselectAllTablesButton setEnabled:isSelectedTables];
366+
[exportRefreshTablesButton setEnabled:isSelectedTables];
367+
368+
[self updateAvailableExportFilenameTokens]; // will also update the filename itself
369+
370+
return (actualInput == input);
371+
}
372+
340373
/**
341374
* Enables/disables and shows/hides various interface controls depending on the selected item.
342375
*/
343376
- (IBAction)switchInput:(id)sender
344377
{
345-
if ([sender isKindOfClass:[NSPopUpButton class]]) {
346-
347-
// Determine what data to use (filtered result, custom query result or selected table(s)) for the export operation
348-
exportSource = (exportType == SPDotExport) ? SPTableExport : [exportInputPopUpButton indexOfSelectedItem];
349-
350-
BOOL isSelectedTables = ([sender indexOfSelectedItem] == SPTableExport);
351-
352-
[exportFilePerTableCheck setHidden:(!isSelectedTables) || (exportType == SPSQLExport)];
353-
[exportTableList setEnabled:isSelectedTables];
354-
[exportSelectAllTablesButton setEnabled:isSelectedTables];
355-
[exportDeselectAllTablesButton setEnabled:isSelectedTables];
356-
[exportRefreshTablesButton setEnabled:isSelectedTables];
357-
358-
[self updateAvailableExportFilenameTokens];
359-
[self updateDisplayedExportFilename];
360-
}
378+
[self setExportInput:(SPExportSource)[exportInputPopUpButton indexOfSelectedItem]];
361379
}
362380

363381
/**
@@ -428,7 +446,7 @@ - (IBAction)changeExportOutputPath:(id)sender
428446

429447
[panel setDirectoryURL:[NSURL URLWithString:[exportPathField stringValue]]];
430448
[panel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger returnCode) {
431-
if (returnCode == NSOKButton) {
449+
if (returnCode == NSFileHandlingPanelOKButton) {
432450
NSString *path = [[panel directoryURL] path];
433451
if(!path) {
434452
@throw [NSException exceptionWithName:NSInternalInconsistencyException
@@ -673,9 +691,6 @@ - (IBAction)toggleNewFilePerTable:(NSButton *)sender
673691
- (IBAction)exportCustomQueryResultAsFormat:(id)sender
674692
{
675693
[self exportTables:nil asFormat:[sender tag] usingSource:SPQueryExport];
676-
677-
// Ensure UI validation
678-
[self switchInput:exportInputPopUpButton];
679694
}
680695

681696
#pragma mark -
@@ -770,11 +785,11 @@ - (void)_switchTab
770785
BOOL isSQL = (exportType == SPSQLExport);
771786
BOOL isCSV = (exportType == SPCSVExport);
772787
BOOL isXML = (exportType == SPXMLExport);
773-
BOOL isHTML = (exportType == SPHTMLExport);
774-
BOOL isPDF = (exportType == SPPDFExport);
788+
//BOOL isHTML = (exportType == SPHTMLExport);
789+
//BOOL isPDF = (exportType == SPPDFExport);
775790
BOOL isDot = (exportType == SPDotExport);
776791

777-
BOOL enable = (isCSV || isXML || isHTML || isPDF || isDot);
792+
BOOL enable = (isCSV || isXML /* || isHTML || isPDF */ || isDot);
778793

779794
[exportFilePerTableCheck setHidden:(isSQL || isDot)];
780795
[exportTableList setEnabled:(!isDot)];

Source/SPExportControllerDelegate.m

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
#import "SPExportFilenameUtilities.h"
3333
#import "SPExportFileNameTokenObject.h"
3434

35-
#define IS_TOKEN(x) [x isKindOfClass:[SPExportFileNameTokenObject class]]
36-
#define IS_STRING(x) [x isKindOfClass:[NSString class]]
35+
static inline BOOL IS_TOKEN(id x);
36+
static inline BOOL IS_STRING(id x);
3737

3838
// Defined to suppress warnings
3939
@interface SPExportController (SPExportControllerPrivateAPI)
@@ -345,5 +345,15 @@ - (void)_tokenizeCustomFilenameTokenField
345345

346346
@end
347347

348-
#undef IS_TOKEN
349-
#undef IS_STRING
348+
#pragma mark -
349+
350+
BOOL IS_TOKEN(id x)
351+
{
352+
return [x isKindOfClass:[SPExportFileNameTokenObject class]];
353+
}
354+
355+
BOOL IS_STRING(id x)
356+
{
357+
return [x isKindOfClass:[NSString class]];
358+
}
359+

Source/SPExportFilenameUtilities.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
- (void)updateDisplayedExportFilename;
4343
- (void)updateAvailableExportFilenameTokens;
44+
- (NSArray *)currentAllowedExportFilenameTokens;
4445
- (NSString *)generateDefaultExportFilename;
4546
- (NSString *)currentDefaultExportFileExtension;
4647
- (NSString *)expandCustomFilenameFormatUsingTableName:(NSString *)table;

Source/SPExportFilenameUtilities.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ - (void)updateAvailableExportFilenameTokens
153153
[self updateDisplayedExportFilename];
154154
}
155155

156+
- (NSArray *)currentAllowedExportFilenameTokens
157+
{
158+
NSArray *mixed = [exportCustomFilenameTokenPool objectValue];
159+
NSMutableArray *tokens = [NSMutableArray arrayWithCapacity:[mixed count]]; // ...or less
160+
161+
for (id obj in mixed) {
162+
if([obj isKindOfClass:[SPExportFileNameTokenObject class]]) [tokens addObject:obj];
163+
}
164+
165+
return tokens;
166+
}
167+
156168
/**
157169
* Generates the default export filename based on the selected export options.
158170
*

Source/SPExportSettingsPersistence.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,31 @@
3434
@interface SPExportController (SPExportSettingsPersistence)
3535

3636
- (IBAction)exportCurrentSettings:(id)sender;
37+
- (IBAction)importCurrentSettings:(id)sender;
38+
39+
/**
40+
* @return The current settings as a dictionary which can be serialized
41+
*/
3742
- (NSDictionary *)currentSettingsAsDictionary;
3843

44+
/** Overwrite current export settings with those defined in dict
45+
* @param dict The new settings to apply (passing nil is an error.)
46+
* @param err Errors while applying (will mostly be about invalid format, type)
47+
* Can pass NULL, if not interested in details.
48+
* Will NOT be changed unless the method also returns NO
49+
* @return success
50+
*/
51+
- (BOOL)applySettingsFromDictionary:(NSDictionary *)dict error:(NSError **)err;
52+
3953
/**
4054
* @return A serialized form of the "custom filename" field
4155
*/
4256
- (NSArray *)currentCustomFilenameAsArray;
4357

58+
/**
59+
* @param tokenList A serialized form of the "custom filename" field
60+
* @see currentCustomFilenameAsArray
61+
*/
62+
- (void)setCustomFilenameFromArray:(NSArray *)tokenList;
63+
4464
@end

0 commit comments

Comments
 (0)