@@ -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)];
0 commit comments