From b267968964adb3402b38df683debee16c6c310d1 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 4 Mar 2009 21:57:35 +0000 Subject: Alter the open panel to recognise .csv and .sql extensions on selected files and automatically change the format dropdown to match --- Source/TableDump.h | 3 +++ Source/TableDump.m | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'Source') diff --git a/Source/TableDump.h b/Source/TableDump.h index c5f83cd0..3f89ab68 100644 --- a/Source/TableDump.h +++ b/Source/TableDump.h @@ -138,6 +138,9 @@ //additional methods - (void)setConnection:(CMMCPConnection *)theConnection; +// Import/export delegate notifications +- (void)panelSelectionDidChange:(id)sender; + //last but not least - (id)init; - (void)dealloc; diff --git a/Source/TableDump.m b/Source/TableDump.m index 5c813407..f7fd3a80 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -330,6 +330,7 @@ // prepare open panel and accessory view NSOpenPanel *openPanel = [NSOpenPanel openPanel]; [openPanel setAccessoryView:importCSVView]; + [openPanel setDelegate:self]; if ([prefs valueForKey:@"importFormatPopupValue"]) { [importFormatPopup selectItemWithTitle:[prefs valueForKey:@"importFormatPopupValue"]]; [self changeFormat:self]; @@ -1874,6 +1875,29 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn } } + +#pragma mark - +#pragma mark Import/export delegate notifications + +// Called when the selection within an open/save panel changes +- (void)panelSelectionDidChange:(id)sender +{ + NSArray *selectedFilenames = [sender filenames]; + NSString *pathExtension; + + // If a single file is selected and the extension is recognised, change the format dropdown automatically + if ( [selectedFilenames count] != 1 ) return; + pathExtension = [[[selectedFilenames objectAtIndex:0] pathExtension] uppercaseString]; + if ([pathExtension isEqualToString:@"SQL"]) { + [importFormatPopup selectItemWithTitle:@"SQL"]; + [self changeFormat:self]; + } else if ([pathExtension isEqualToString:@"CSV"]) { + [importFormatPopup selectItemWithTitle:@"CSV"]; + [self changeFormat:self]; + } +} + + #pragma mark - #pragma mark other //last but not least -- cgit v1.2.3