Skip to content
Permalink
Browse files

Allow import of saved export settings (in export dialog)

  • Loading branch information...
dmoagx committed Nov 7, 2015
1 parent 72951bf commit fdef91b45a56b2f94aa477041b8f4185a2e7e7e2

Large diffs are not rendered by default.

@@ -721,7 +721,7 @@ - (IBAction)saveBundle:(id)sender
[panel setNameFieldStringValue:[[self _currentSelectedObject] objectForKey:kBundleNameKey]];

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

// Panel is still on screen. Hide it first. (This is Apple's recommended way)
[panel orderOut:nil];
@@ -641,6 +641,16 @@ extern NSString *SPURLSchemeQueryResultStatusPathHeader;
extern NSString *SPURLSchemeQueryResultMetaPathHeader;

extern NSString *SPCommonCryptoExceptionName;
extern NSString *SPErrorDomain; // generic SP error domain for NSError

typedef NS_ENUM(NSInteger,SPErrorCode) { // error codes in SPErrorDomain
/** When plist deserialization fails with nil return and no NSError or the returned object has the wrong type */
SPErrorWrongTypeOrNil = 110001,
/** Parsed data is syntactically correct, but semantically wrong (e.g. a SPF file with the wrong content format */
SPErrorWrongContentType = 110002,
/** 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) */
SPErrorWrongContentVersion = 110003,
};

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

@@ -443,6 +443,7 @@
NSString *SPURLSchemeQueryResultMetaPathHeader = @"/tmp/SP_QUERY_META_";

NSString *SPCommonCryptoExceptionName = @"SPCommonCryptoException";
NSString *SPErrorDomain = @"SPErrorDomain";

void inline _SPClear(id *addr) {
[*addr release], *addr = nil;
@@ -254,6 +254,14 @@
- (void)openExportErrorsSheetWithString:(NSString *)errors;
- (void)displayExportFinishedGrowlNotification;

/**
* Tries to set the export input to a given value or falls back to a default if not valid
* @param input The source to use
* @return YES if the source was accepted, NO otherwise
* @pre _switchTab needs to have been run before this method to decide valid inputs
*/
- (BOOL)setExportInput:(SPExportSource)input;

// IB action methods
- (IBAction)export:(id)sender;
- (IBAction)closeSheet:(id)sender;
@@ -198,9 +198,6 @@ - (void)exportTables:(NSArray *)exportTables asFormat:(SPExportType)format using
[exporters removeAllObjects];
[exportFiles removeAllObjects];

// Select the 'selected tables' source option
[exportInputPopUpButton selectItemAtIndex:source];

// If tables were supplied, select them
if (exportTables) {

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

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

[self exportTables:selectedTables asFormat:selectedExportType usingSource:selectedExportSource];

// Ensure UI validation
[self switchInput:exportInputPopUpButton];
}

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

- (BOOL)setExportInput:(SPExportSource)input
{
SPExportSource actualInput = input;
// Dot will always be a TableExport
if(exportType == SPDotExport) {
actualInput = SPTableExport;
}
//check if the type actually is valid
else if(![[exportInputPopUpButton itemAtIndex:input] isEnabled]) {
//...no, pick a valid one instead
for (NSMenuItem *item in [exportInputPopUpButton itemArray]) {
if([item isEnabled]) {
actualInput = [exportInputPopUpButton indexOfItem:item];
goto set_input;
}
}
// nothing found (should not happen)
SPLog(@"did not find any valid export input!?");
return NO;
}
set_input:
exportSource = actualInput;

[exportInputPopUpButton selectItemAtIndex:exportSource];

BOOL isSelectedTables = (exportSource == SPTableExport);

[exportFilePerTableCheck setHidden:(!isSelectedTables) || (exportType == SPSQLExport)];
[exportTableList setEnabled:isSelectedTables];
[exportSelectAllTablesButton setEnabled:isSelectedTables];
[exportDeselectAllTablesButton setEnabled:isSelectedTables];
[exportRefreshTablesButton setEnabled:isSelectedTables];

[self updateAvailableExportFilenameTokens]; // will also update the filename itself

return (actualInput == input);
}

/**
* Enables/disables and shows/hides various interface controls depending on the selected item.
*/
- (IBAction)switchInput:(id)sender
{
if ([sender isKindOfClass:[NSPopUpButton class]]) {

// Determine what data to use (filtered result, custom query result or selected table(s)) for the export operation
exportSource = (exportType == SPDotExport) ? SPTableExport : [exportInputPopUpButton indexOfSelectedItem];

BOOL isSelectedTables = ([sender indexOfSelectedItem] == SPTableExport);

[exportFilePerTableCheck setHidden:(!isSelectedTables) || (exportType == SPSQLExport)];
[exportTableList setEnabled:isSelectedTables];
[exportSelectAllTablesButton setEnabled:isSelectedTables];
[exportDeselectAllTablesButton setEnabled:isSelectedTables];
[exportRefreshTablesButton setEnabled:isSelectedTables];

[self updateAvailableExportFilenameTokens];
[self updateDisplayedExportFilename];
}
[self setExportInput:(SPExportSource)[exportInputPopUpButton indexOfSelectedItem]];
}

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

[panel setDirectoryURL:[NSURL URLWithString:[exportPathField stringValue]]];
[panel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger returnCode) {
if (returnCode == NSOKButton) {
if (returnCode == NSFileHandlingPanelOKButton) {
NSString *path = [[panel directoryURL] path];
if(!path) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
@@ -673,9 +691,6 @@ - (IBAction)toggleNewFilePerTable:(NSButton *)sender
- (IBAction)exportCustomQueryResultAsFormat:(id)sender
{
[self exportTables:nil asFormat:[sender tag] usingSource:SPQueryExport];

// Ensure UI validation
[self switchInput:exportInputPopUpButton];
}

#pragma mark -
@@ -770,11 +785,11 @@ - (void)_switchTab
BOOL isSQL = (exportType == SPSQLExport);
BOOL isCSV = (exportType == SPCSVExport);
BOOL isXML = (exportType == SPXMLExport);
BOOL isHTML = (exportType == SPHTMLExport);
BOOL isPDF = (exportType == SPPDFExport);
//BOOL isHTML = (exportType == SPHTMLExport);
//BOOL isPDF = (exportType == SPPDFExport);
BOOL isDot = (exportType == SPDotExport);

BOOL enable = (isCSV || isXML || isHTML || isPDF || isDot);
BOOL enable = (isCSV || isXML /* || isHTML || isPDF */ || isDot);

[exportFilePerTableCheck setHidden:(isSQL || isDot)];
[exportTableList setEnabled:(!isDot)];
@@ -32,8 +32,8 @@
#import "SPExportFilenameUtilities.h"
#import "SPExportFileNameTokenObject.h"

#define IS_TOKEN(x) [x isKindOfClass:[SPExportFileNameTokenObject class]]
#define IS_STRING(x) [x isKindOfClass:[NSString class]]
static inline BOOL IS_TOKEN(id x);
static inline BOOL IS_STRING(id x);

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

@end

#undef IS_TOKEN
#undef IS_STRING
#pragma mark -

BOOL IS_TOKEN(id x)
{
return [x isKindOfClass:[SPExportFileNameTokenObject class]];
}

BOOL IS_STRING(id x)
{
return [x isKindOfClass:[NSString class]];
}

@@ -41,6 +41,7 @@

- (void)updateDisplayedExportFilename;
- (void)updateAvailableExportFilenameTokens;
- (NSArray *)currentAllowedExportFilenameTokens;
- (NSString *)generateDefaultExportFilename;
- (NSString *)currentDefaultExportFileExtension;
- (NSString *)expandCustomFilenameFormatUsingTableName:(NSString *)table;
@@ -153,6 +153,18 @@ - (void)updateAvailableExportFilenameTokens
[self updateDisplayedExportFilename];
}

- (NSArray *)currentAllowedExportFilenameTokens
{
NSArray *mixed = [exportCustomFilenameTokenPool objectValue];
NSMutableArray *tokens = [NSMutableArray arrayWithCapacity:[mixed count]]; // ...or less

for (id obj in mixed) {
if([obj isKindOfClass:[SPExportFileNameTokenObject class]]) [tokens addObject:obj];
}

return tokens;
}

/**
* Generates the default export filename based on the selected export options.
*
@@ -34,11 +34,31 @@
@interface SPExportController (SPExportSettingsPersistence)

- (IBAction)exportCurrentSettings:(id)sender;
- (IBAction)importCurrentSettings:(id)sender;

/**
* @return The current settings as a dictionary which can be serialized
*/
- (NSDictionary *)currentSettingsAsDictionary;

/** Overwrite current export settings with those defined in dict
* @param dict The new settings to apply (passing nil is an error.)
* @param err Errors while applying (will mostly be about invalid format, type)
* Can pass NULL, if not interested in details.
* Will NOT be changed unless the method also returns NO
* @return success
*/
- (BOOL)applySettingsFromDictionary:(NSDictionary *)dict error:(NSError **)err;

/**
* @return A serialized form of the "custom filename" field
*/
- (NSArray *)currentCustomFilenameAsArray;

/**
* @param tokenList A serialized form of the "custom filename" field
* @see currentCustomFilenameAsArray
*/
- (void)setCustomFilenameFromArray:(NSArray *)tokenList;

@end

0 comments on commit fdef91b

Please sign in to comment.
You can’t perform that action at this time.