diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPCSVExporter.h | 10 | ||||
-rw-r--r-- | Source/SPCSVExporter.m | 10 | ||||
-rw-r--r-- | Source/SPExportController.h | 4 | ||||
-rw-r--r-- | Source/SPExportController.m | 42 | ||||
-rw-r--r-- | Source/SPExporter.h | 13 | ||||
-rw-r--r-- | Source/SPExporter.m | 10 | ||||
-rw-r--r-- | Source/SPExporterDataAccess.h | 45 |
7 files changed, 99 insertions, 35 deletions
diff --git a/Source/SPCSVExporter.h b/Source/SPCSVExporter.h index 95f30b46..c0cc75c4 100644 --- a/Source/SPCSVExporter.h +++ b/Source/SPCSVExporter.h @@ -28,6 +28,16 @@ #import "MCPKit.h" #import "SPExporter.h" +/** + * + */ +@interface SPCSVExporterDelegate + +- (void)csvDataAvailable:(NSString *)data; + +@end + + @interface SPCSVExporter : SPExporter { // CSV data diff --git a/Source/SPCSVExporter.m b/Source/SPCSVExporter.m index 82f43a79..3464b72d 100644 --- a/Source/SPCSVExporter.m +++ b/Source/SPCSVExporter.m @@ -83,11 +83,6 @@ // Check that we have at least some data to export if ((![self csvDataArray]) && (![self csvDataResult])) return; - // Tell the delegate that we are starting the export process - if (delegate && [delegate respondsToSelector:@selector(exportProcessDidStart:)]) { - [delegate exportProcessDidStart:self]; - } - // Mark the process as running [self setExportProcessIsRunning:YES]; @@ -277,11 +272,6 @@ // Mark the process as not running [self setExportProcessIsRunning:NO]; - // Tell the delegate that the export process has ended - if (delegate && [delegate respondsToSelector:@selector(exportProcessDidEnd:)]) { - [delegate exportProcessDidEnd:self]; - } - // Pass the resulting CSV data back to the delegate by calling the specified didEndSelector [[self delegate] performSelectorOnMainThread:[self didEndSelector] withObject:csvData waitUntilDone:YES]; diff --git a/Source/SPExportController.h b/Source/SPExportController.h index ec396db5..645ade0a 100644 --- a/Source/SPExportController.h +++ b/Source/SPExportController.h @@ -25,6 +25,8 @@ #import <Cocoa/Cocoa.h> #import <MCPKit/MCPKit.h> +#import "SPExporterDataAccess.h" + // Export type constants enum { SP_SQL_EXPORT = 1, @@ -44,7 +46,7 @@ enum { }; typedef NSUInteger SPExportSource; -@interface SPExportController : NSObject +@interface SPExportController : NSObject <SPExporterDataAccess> { // Table document IBOutlet id tableDocumentInstance; diff --git a/Source/SPExportController.m b/Source/SPExportController.m index 91a3a0b7..f365de75 100644 --- a/Source/SPExportController.m +++ b/Source/SPExportController.m @@ -195,6 +195,34 @@ } #pragma mark - +#pragma mark Exporter delegate methods + +/** + * Called when CSV data conversion process is complete and the data is available. + */ +- (void)csvDataAvailable:(NSString *)data +{ + +} + +/** + * Called when SQL data conversion process is complete and the data is available. + */ +- (void)sqlDataAvailable:(NSString *)data +{ + +} + +/** + * Called when XML data conversion process is complete and the data is available. + */ +- (void)xmlDataAvailable:(NSString *)data +{ + +} + + +#pragma mark - #pragma mark Other /** @@ -236,14 +264,6 @@ @implementation SPExportController (PrivateAPI) /** - * This method is called by SPCSVExporter objects once they have completed converting their data to CSV data. - */ -- (void)_csvDataAvialble:(NSString *)data -{ - -} - -/** * Loads all the available database tables in table view. */ - (void)_loadTables @@ -345,7 +365,7 @@ break; case SP_CSV_EXPORT: - csvExporter = [[SPCSVExporter alloc] init]; + csvExporter = [[SPCSVExporter alloc] initWithDelegate:self]; [csvExporter setCsvOutputFieldNames:[exportCSVIncludeFieldNamesCheck state]]; [csvExporter setCsvFieldSeparatorString:[exportCSVFieldsTerminatedField stringValue]]; @@ -372,10 +392,6 @@ break; } - // Set the exporter's delegate and didEndSelector - [exporter setDelegate:self]; - [exporter setDidEndSelector:@selector(_csvDataAvialble:)]; - switch (exportSource) { case SP_FILTERED_EXPORT: diff --git a/Source/SPExporter.h b/Source/SPExporter.h index 9bc2e592..685fc597 100644 --- a/Source/SPExporter.h +++ b/Source/SPExporter.h @@ -25,6 +25,8 @@ #import <Cocoa/Cocoa.h> +#import "SPExporterDataAccess.h" + /** * This class is designed to be the base class of all data exporters and provide basic functionality * common to each of them. Each data exporter (i.e. CSV, SQL, XML, etc.) should be implemented as a subclass @@ -45,16 +47,9 @@ * once the exporter instance is placed on the operation queue once its ready to be run. */ -@interface NSObject (SPExporterDelegate) - -- (void)exportProcessDidStart:(id)exporter; -- (void)exportProcessDidEnd:(id)exporter; - -@end - @interface SPExporter : NSOperation { - id delegate; + id <SPExporterDataAccess> delegate; SEL didEndSelector; double exportProgressValue; @@ -72,4 +67,6 @@ @property (readwrite, assign) NSStringEncoding exportOutputEncoding; +- (id)initWithDelegate:(id)exportDelegate; + @end diff --git a/Source/SPExporter.m b/Source/SPExporter.m index a5a1f834..f99b35c3 100644 --- a/Source/SPExporter.m +++ b/Source/SPExporter.m @@ -34,16 +34,20 @@ @synthesize exportOutputEncoding; /** - * Initialize an instance of the exporter setting some default values + * Initialise an instance of SPCSVExporter using the supplied delegate and set some default values. */ -- (id)init +- (id)initWithDelegate:(id)exportDelegate { - if ((self == [super init])) { + if ((self = [super init])) { + [self setDelegate:exportDelegate]; + [self setExportProgressValue:0]; [self setExportProcessIsRunning:NO]; // Default the output encoding to UTF-8 [self setExportOutputEncoding:NSUTF8StringEncoding]; + + [self setDidEndSelector:@selector(csvDataAvailable:)]; } return self; diff --git a/Source/SPExporterDataAccess.h b/Source/SPExporterDataAccess.h new file mode 100644 index 00000000..1444313d --- /dev/null +++ b/Source/SPExporterDataAccess.h @@ -0,0 +1,45 @@ +// +// $Id$ +// +// SPExporterDataAccess.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on October 6, 2009 +// Copyright (c) 2009 Stuart Connolly. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import <Cocoa/Cocoa.h> + +@protocol SPExporterDataAccess + +/** + * Called when CSV data conversion process is complete and the data is available. + */ +- (void)csvDataAvailable:(NSString *)data; + +/** + * Called when SQL data conversion process is complete and the data is available. + */ +- (void)sqlDataAvailable:(NSString *)data; + +/** + * Called when XML data conversion process is complete and the data is available. + */ +- (void)xmlDataAvailable:(NSString *)data; + +@end |