diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CustomQuery.m | 68 | ||||
-rw-r--r-- | Source/TableContent.m | 58 | ||||
-rw-r--r-- | Source/TableDocument.m | 25 | ||||
-rw-r--r-- | Source/TableSource.m | 40 |
4 files changed, 125 insertions, 66 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 27f72b04..9245d953 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -39,13 +39,10 @@ #define SP_HELP_GOFORWARD_BUTTON 2 #define SP_HELP_NOT_AVAILABLE @"__no_help_available" - @implementation CustomQuery - #pragma mark IBAction methods - /* * Split all the queries in the text view, split them into individual queries, * and run sequentially. @@ -912,7 +909,6 @@ sets the connection (received from TableDocument) and makes things that have to mySQLConnection = theConnection; - prefs = [[NSUserDefaults standardUserDefaults] retain]; if ( [prefs objectForKey:@"queryFavorites"] ) { queryFavorites = [[NSMutableArray alloc] initWithArray:[prefs objectForKey:@"queryFavorites"]]; } else { @@ -1802,7 +1798,6 @@ traps enter key and } } - /* * Manage contextual menu in helpWebView * Ignore "Reload", "Open Link", "Open Link in new Window", "Download link" etc. @@ -1872,44 +1867,65 @@ traps enter key and } +#pragma mark - +#pragma mark Other + +/** + * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface. + */ +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + if ([keyPath isEqualToString:@"DisplayTableViewVerticalGridlines"]) { + [customQueryView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + } +} #pragma mark - // Last but not least - (id)init; { - self = [super init]; - prefs = nil; - usedQuery = [[NSString stringWithString:@""] retain]; - - // init helpHTMLTemplate - NSError *error; - helpHTMLTemplate = [[NSString alloc] - initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sequel-pro-mysql-help-template" ofType:@"html"] - encoding:NSUTF8StringEncoding - error:&error]; - // an error occurred while reading - if (helpHTMLTemplate == nil) - { - NSLog(@"%@", [NSString stringWithFormat:@"Error reading “sequel-pro-mysql-help-template.html”!<br>%@", [error localizedFailureReason]]); - NSBeep(); + if ((self = [super init])) { + + usedQuery = [[NSString stringWithString:@""] retain]; + + // init helpHTMLTemplate + NSError *error; + + helpHTMLTemplate = [[NSString alloc] + initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sequel-pro-mysql-help-template" ofType:@"html"] + encoding:NSUTF8StringEncoding + error:&error]; + + // an error occurred while reading + if (helpHTMLTemplate == nil) { + NSLog(@"%@", [NSString stringWithFormat:@"Error reading “sequel-pro-mysql-help-template.html”!<br>%@", [error localizedFailureReason]]); + NSBeep(); + } + + // init search history + [helpWebView setMaintainsBackForwardList:YES]; + [[helpWebView backForwardList] setCapacity:20]; + + prefs = [NSUserDefaults standardUserDefaults]; } - // init search history - [helpWebView setMaintainsBackForwardList:YES]; - [[helpWebView backForwardList] setCapacity:20]; - return self; } +- (void)awakeFromNib +{ + // Set the structure and index view's vertical gridlines if required + [customQueryView setGridStyleMask:([prefs boolForKey:@"DisplayTableViewVerticalGridlines"]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; +} + - (void)dealloc { [queryResult release]; - [prefs release]; [queryFavorites release]; [usedQuery release]; + [super dealloc]; - } @end diff --git a/Source/TableContent.m b/Source/TableContent.m index ac5a4f45..cc06902d 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -40,23 +40,37 @@ @implementation TableContent +/** + * Standard init method. Initialize various ivars. + */ - (id)init { - if (![super init]) - return nil; - - fullResult = [[NSMutableArray alloc] init]; - filteredResult = [[NSMutableArray alloc] init]; - oldRow = [[NSMutableDictionary alloc] init]; - selectedTable = nil; - sortField = nil; - areShowingAllRows = false; - currentlyEditingRow = -1; - usedQuery = [[NSString stringWithString:@""] retain]; + if ((self == [super init])) { + + fullResult = [[NSMutableArray alloc] init]; + filteredResult = [[NSMutableArray alloc] init]; + oldRow = [[NSMutableDictionary alloc] init]; + + selectedTable = nil; + sortField = nil; + + areShowingAllRows = false; + currentlyEditingRow = -1; + prefs = [NSUserDefaults standardUserDefaults]; + + usedQuery = [[NSString stringWithString:@""] retain]; + } + return self; } +- (void)awakeFromNib +{ + // Set the table content view's vertical gridlines if required + [tableContentView setGridStyleMask:([prefs boolForKey:@"DisplayTableViewVerticalGridlines"]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; +} + /* * Loads aTable, retrieving column information and updating the tableViewColumns before * reloading table data into the fullResults array and redrawing the table. @@ -1084,7 +1098,6 @@ [tableContentView setVerticalMotionCanBeginDrag:NO]; - prefs = [[NSUserDefaults standardUserDefaults] retain]; if ( [prefs boolForKey:@"UseMonospacedFonts"] ) { [argumentField setFont:[NSFont fontWithName:@"Monaco" size:10]]; [limitRowsField setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; @@ -2191,12 +2204,12 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn } } +// TextView delegate methods -//textView delegate methods -- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector -/* - traps enter and return key and closes editSheet instead of inserting a linebreak when user hits return +/** + * Traps enter and return key and closes editSheet instead of inserting a linebreak when user hits return. */ +- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector { if ( aTextView == editTextView ) { if ( [aTextView methodForSelector:aSelector] == [aTextView methodForSelector:@selector(insertNewline:)] && @@ -2211,9 +2224,17 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn return NO; } +/** + * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface. + */ +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + if ([keyPath isEqualToString:@"DisplayTableViewVerticalGridlines"]) { + [tableContentView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + } +} -//last but not least - +// Last but not least - (void)dealloc { [editData release]; @@ -2223,7 +2244,6 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn [oldRow release]; [compareType release]; if (sortField) [sortField release]; - [prefs release]; [usedQuery release]; [super dealloc]; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 0169a86e..6cd9284a 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -63,28 +63,38 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum - (id)init { if ((self = [super init])) { + _encoding = [@"utf8" retain]; chooseDatabaseButton = nil; chooseDatabaseToolbarItem = nil; + + printWebView = [[WebView alloc] init]; + [printWebView setFrameLoadDelegate:self]; + + prefs = [NSUserDefaults standardUserDefaults]; } - printWebView = [[WebView alloc] init]; - [printWebView setFrameLoadDelegate:self]; + return self; } - (void)awakeFromNib { - // register selection did change handler for favorites controller (used in connect sheet) + // Register selection did change handler for favorites controller (used in connect sheet) [favoritesController addObserver:self forKeyPath:@"selectionIndex" options:NSKeyValueChangeInsertion context:TableDocumentFavoritesControllerSelectionIndexDidChange]; - // register double click for the favorites view (double click favorite to connect) + // Register observers for when the DisplayTableViewVerticalGridlines preference changes + [prefs addObserver:tableSourceInstance forKeyPath:@"DisplayTableViewVerticalGridlines" options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:tableContentInstance forKeyPath:@"DisplayTableViewVerticalGridlines" options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:customQueryInstance forKeyPath:@"DisplayTableViewVerticalGridlines" options:NSKeyValueObservingOptionNew context:NULL]; + + // Register double click for the favorites view (double click favorite to connect) [connectFavoritesTableView setTarget:self]; [connectFavoritesTableView setDoubleAction:@selector(connect:)]; - // find the Database -> Database Encoding menu (it's not in our nib, so we can't use interface builder) + // Find the Database -> Database Encoding menu (it's not in our nib, so we can't use interface builder) selectEncodingMenu = [[[[[NSApp mainMenu] itemWithTag:1] submenu] itemWithTag:1] submenu]; - // hide the tabs in the tab view (we only show them to allow switching tabs in interface builder) + // Hide the tabs in the tab view (we only show them to allow switching tabs in interface builder) [tableTabView setTabViewType:NSNoTabsNoBorder]; } @@ -1927,8 +1937,6 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum NSEnumerator *theCols = [[variablesTableView tableColumns] objectEnumerator]; NSTableColumn *theCol; - prefs = [[NSUserDefaults standardUserDefaults] retain]; - //register for notifications [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willPerformQuery:) name:@"SMySQLQueryWillBePerformed" object:nil]; @@ -2130,7 +2138,6 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum [variables release]; [selectedDatabase release]; [mySQLVersion release]; - [prefs release]; [super dealloc]; } diff --git a/Source/TableSource.m b/Source/TableSource.m index 8267afb5..7ac9212e 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -508,8 +508,6 @@ sets the connection (received from TableDocument) and makes things that have to mySQLConnection = theConnection; - prefs = [[NSUserDefaults standardUserDefaults] retain]; - //set up tableView [tableSourceView registerForDraggedTypes:[NSArray arrayWithObjects:@"SequelProPasteboard", nil]]; @@ -816,6 +814,16 @@ fetches the result as an array with a dictionary for each row in it } } +/** + * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface. + */ +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + if ([keyPath isEqualToString:@"DisplayTableViewVerticalGridlines"]) { + [tableSourceView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + [indexView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + } +} #pragma mark Getter methods @@ -1194,28 +1202,36 @@ traps enter and esc and make/cancel editing without entering next row return [structureGrabber convertRect:[structureGrabber bounds] toView:splitView]; } -//last but not least +// Last but not least - (id)init { - self = [super init]; - - tableFields = [[NSMutableArray alloc] init]; - indexes = [[NSMutableArray alloc] init]; - oldRow = [[NSMutableDictionary alloc] init]; - enumFields = [[NSMutableDictionary alloc] init]; - - currentlyEditingRow = -1; + if ((self = [super init])) { + tableFields = [[NSMutableArray alloc] init]; + indexes = [[NSMutableArray alloc] init]; + oldRow = [[NSMutableDictionary alloc] init]; + enumFields = [[NSMutableDictionary alloc] init]; + + currentlyEditingRow = -1; + + prefs = [NSUserDefaults standardUserDefaults]; + } return self; } +- (void)awakeFromNib +{ + // Set the structure and index view's vertical gridlines if required + [tableSourceView setGridStyleMask:([prefs boolForKey:@"DisplayTableViewVerticalGridlines"]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + [indexView setGridStyleMask:([prefs boolForKey:@"DisplayTableViewVerticalGridlines"]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; +} + - (void)dealloc { [tableFields release]; [indexes release]; [oldRow release]; [defaultValues release]; - [prefs release]; [enumFields release]; [super dealloc]; |