diff options
author | stuconnolly <stuart02@gmail.com> | 2009-10-17 00:35:09 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-10-17 00:35:09 +0000 |
commit | 6a4e2994d17220eb43015162522deec1efdd429b (patch) | |
tree | f1d2abc0691948bcbd901929c82347137ee0de85 /Source | |
parent | c3eb7de88f2baf7774749f4311a84b75ef833eb7 (diff) | |
download | sequelpro-6a4e2994d17220eb43015162522deec1efdd429b.tar.gz sequelpro-6a4e2994d17220eb43015162522deec1efdd429b.tar.bz2 sequelpro-6a4e2994d17220eb43015162522deec1efdd429b.zip |
Replace the use of hard coded preference keys with constants to prevent issues such as the one fixed in revision 1419. All future preference usage should be done so using these constants.
Diffstat (limited to 'Source')
32 files changed, 552 insertions, 352 deletions
diff --git a/Source/AMIndeterminateProgressIndicatorCell.h b/Source/AMIndeterminateProgressIndicatorCell.h index fc8b9311..04f7f13b 100644 --- a/Source/AMIndeterminateProgressIndicatorCell.h +++ b/Source/AMIndeterminateProgressIndicatorCell.h @@ -27,7 +27,6 @@ #import <Cocoa/Cocoa.h> - @interface AMIndeterminateProgressIndicatorCell : NSCell { double doubleValue; NSTimeInterval animationDelay; diff --git a/Source/CMCopyTable.m b/Source/CMCopyTable.m index c0197c0e..0c276b72 100644 --- a/Source/CMCopyTable.m +++ b/Source/CMCopyTable.m @@ -30,6 +30,7 @@ #import "TableContent.h" #import "CustomQuery.h" #import "SPNotLoaded.h" +#import "SPConstants.h" int MENU_EDIT_COPY_WITH_COLUMN = 2001; int MENU_EDIT_COPY_AS_SQL = 2002; @@ -133,7 +134,7 @@ int MENU_EDIT_COPY_AS_SQL = 2002; if ( nil != rowData ) { if ([rowData isNSNull]) - [result appendString:[NSString stringWithFormat:@"%@\t", [prefs objectForKey:@"NullValue"]]]; + [result appendString:[NSString stringWithFormat:@"%@\t", [prefs objectForKey:SPNullValue]]]; else if ([rowData isSPNotLoaded]) [result appendString:[NSString stringWithFormat:@"%@\t", NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")]]; else @@ -268,7 +269,7 @@ int MENU_EDIT_COPY_AS_SQL = 2002; } break; case 3: // long text data - if (![[self delegate] isKindOfClass:[CustomQuery class]] && [prefs boolForKey:@"LoadBlobsAsNeeded"]) { + if (![[self delegate] isKindOfClass:[CustomQuery class]] && [prefs boolForKey:SPLoadBlobsAsNeeded]) { // Abort if there are no indices on this table or if there's no table name given. if (![[tableInstance argumentForRow:rowIndex] length] || selectedTable == nil) @@ -371,7 +372,7 @@ int MENU_EDIT_COPY_AS_SQL = 2002; if ( nil != rowData ) { if ([rowData isNSNull]) - [result appendString:[NSString stringWithFormat:@"%@\t", [prefs objectForKey:@"NullValue"]]]; + [result appendString:[NSString stringWithFormat:@"%@\t", [prefs objectForKey:SPNullValue]]]; else if ([rowData isSPNotLoaded]) [result appendString:[NSString stringWithFormat:@"%@\t", NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")]]; else diff --git a/Source/CMTextView.h b/Source/CMTextView.h index a7766f39..ce064470 100644 --- a/Source/CMTextView.h +++ b/Source/CMTextView.h @@ -31,7 +31,6 @@ #define SP_TEXT_SIZE_TRIGGER_FOR_PARTLY_PARSING 10000 - static inline void NSMutableAttributedStringAddAttributeValueRange (NSMutableAttributedString* self, NSString* aStr, id aValue, NSRange aRange) { typedef void (*SPMutableAttributedStringAddAttributeValueRangeMethodPtr)(NSMutableAttributedString*, SEL, NSString*, id, NSRange); static SPMutableAttributedStringAddAttributeValueRangeMethodPtr SPMutableAttributedStringAddAttributeValueRange; diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 4cf7b155..ae526221 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -29,6 +29,7 @@ #import "SPArrayAdditions.h" #import "SPTextViewAdditions.h" #import "SPNarrowDownCompletion.h" +#import "SPConstants.h" #pragma mark - #pragma mark lex init @@ -436,7 +437,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) { // Cancel autoHelp timer - if([prefs boolForKey:@"CustomQueryUpdateAutoHelp"]) + if([prefs boolForKey:SPCustomQueryUpdateAutoHelp]) [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(autoHelp) object:nil]; @@ -444,8 +445,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [super mouseDown:theEvent]; // Start autoHelp timer - if([prefs boolForKey:@"CustomQueryUpdateAutoHelp"]) - [self performSelector:@selector(autoHelp) withObject:nil afterDelay:[[[prefs valueForKey:@"CustomQueryAutoHelpDelay"] retain] floatValue]]; + if([prefs boolForKey:SPCustomQueryUpdateAutoHelp]) + [self performSelector:@selector(autoHelp) withObject:nil afterDelay:[[[prefs valueForKey:SPCustomQueryAutoHelpDelay] retain] floatValue]]; } @@ -455,12 +456,12 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) - (void) keyDown:(NSEvent *)theEvent { - if([prefs boolForKey:@"CustomQueryUpdateAutoHelp"]) {// restart autoHelp timer + if([prefs boolForKey:SPCustomQueryUpdateAutoHelp]) {// restart autoHelp timer [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(autoHelp) object:nil]; [self performSelector:@selector(autoHelp) withObject:nil - afterDelay:[[[prefs valueForKey:@"CustomQueryAutoHelpDelay"] retain] floatValue]]; + afterDelay:[[[prefs valueForKey:SPCustomQueryAutoHelpDelay] retain] floatValue]]; } long allFlags = (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask); @@ -528,7 +529,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } // Only process for character autopairing if autopairing is enabled and a single character is being added. - if ([prefs boolForKey:@"CustomQueryAutoPairCharacters"] && characters && [characters length] == 1) { + if ([prefs boolForKey:SPCustomQueryAutoPairCharacters] && characters && [characters length] == 1) { delBackwardsWasPressed = NO; @@ -689,7 +690,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) // Handle newlines, adding any indentation found on the current line to the new line - ignoring the enter key if appropriate if (aSelector == @selector(insertNewline:) - && [prefs boolForKey:@"CustomQueryAutoIndent"] + && [prefs boolForKey:SPCustomQueryAutoIndent] && (!autoindentIgnoresEnter || [[NSApp currentEvent] keyCode] != 0x4C)) { NSString *textViewString = [[self textStorage] string]; @@ -1999,7 +2000,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) - (void)autoHelp { - if(![prefs boolForKey:@"CustomQueryUpdateAutoHelp"]) return; + if(![prefs boolForKey:SPCustomQueryUpdateAutoHelp]) return; // If selection show Help for it if([self selectedRange].length) @@ -2087,15 +2088,15 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSColor *tokenColor; - NSColor *commentColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorCommentColor"]] retain]; - NSColor *quoteColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorQuoteColor"]] retain]; - NSColor *keywordColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorSQLKeywordColor"]] retain]; - NSColor *backtickColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorBacktickColor"]] retain]; - NSColor *numericColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorNumericColor"]] retain]; - NSColor *variableColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorVariableColor"]] retain]; - NSColor *textColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorTextColor"]] retain]; + NSColor *commentColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCommentColor]] retain]; + NSColor *quoteColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorQuoteColor]] retain]; + NSColor *keywordColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSQLKeywordColor]] retain]; + NSColor *backtickColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBacktickColor]] retain]; + NSColor *numericColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorNumericColor]] retain]; + NSColor *variableColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorVariableColor]] retain]; + NSColor *textColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorTextColor]] retain]; - BOOL autouppercaseKeywords = [prefs boolForKey:@"CustomQueryAutoUppercaseKeywords"]; + BOOL autouppercaseKeywords = [prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]; unsigned long tokenEnd, token; NSRange tokenRange; @@ -2317,7 +2318,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) */ - (void)changeColor:(id)sender { - [self setInsertionPointColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorCaretColor"]]]; + [self setInsertionPointColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCaretColor]]]; // Remember the old selected range NSRange oldRange = [self selectedRange]; // Invoke syntax highlighting @@ -2358,8 +2359,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if (textStore!=[self textStorage]) return; // Start autohelp only if the user really changed the text (not e.g. for setting a background color) - if([prefs boolForKey:@"CustomQueryUpdateAutoHelp"] && [textStore editedMask] != 1) - [self performSelector:@selector(autoHelp) withObject:nil afterDelay:[[[prefs valueForKey:@"CustomQueryAutoHelpDelay"] retain] floatValue]]; + if([prefs boolForKey:SPCustomQueryUpdateAutoHelp] && [textStore editedMask] != 1) + [self performSelector:@selector(autoHelp) withObject:nil afterDelay:[[[prefs valueForKey:SPCustomQueryAutoHelpDelay] retain] floatValue]]; if([[self string] length] > SP_TEXT_SIZE_TRIGGER_FOR_PARTLY_PARSING) [NSObject cancelPreviousPerformRequestsWithTarget:self diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 323a9078..3fffaa7a 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -39,6 +39,7 @@ #import "SPTooltip.h" #import "SPQueryFavoriteManager.h" #import "SPQueryController.h" +#import "SPConstants.h" @implementation CustomQuery @@ -179,14 +180,14 @@ } else if ([queryFavoritesButton indexOfSelectedItem] > 5) { // Choose favorite - BOOL replaceContent = [prefs boolForKey:@"QueryFavoriteReplacesContent"]; + BOOL replaceContent = [prefs boolForKey:SPQueryFavoriteReplacesContent]; if([[NSApp currentEvent] modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask)) replaceContent = !replaceContent; if(replaceContent) [textView setSelectedRange:NSMakeRange(0,[[textView string] length])]; - // [textView insertText:[[[prefs objectForKey:@"queryFavorites"] objectAtIndex:([queryFavoritesButton indexOfSelectedItem] - 6)] objectForKey:@"query"]]; + // [textView insertText:[[[prefs objectForKey:SPQueryFavorites] objectAtIndex:([queryFavoritesButton indexOfSelectedItem] - 6)] objectForKey:@"query"]]; // The actual query strings have been already stored as tooltip [textView insertText:[[queryFavoritesButton selectedItem] toolTip]]; } @@ -203,7 +204,7 @@ // Choose history item if ([queryHistoryButton indexOfSelectedItem] > 1) { - BOOL replaceContent = [prefs boolForKey:@"QueryHistoryReplacesContent"]; + BOOL replaceContent = [prefs boolForKey:SPQueryHistoryReplacesContent]; if([[NSApp currentEvent] modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask)) replaceContent = !replaceContent; @@ -280,7 +281,7 @@ // "Indent new lines" toggle if (sender == autoindentMenuItem) { BOOL enableAutoindent = !([autoindentMenuItem state] == NSOffState); - [prefs setBool:enableAutoindent forKey:@"CustomQueryAutoIndent"]; + [prefs setBool:enableAutoindent forKey:SPCustomQueryAutoIndent]; [prefs synchronize]; [autoindentMenuItem setState:enableAutoindent?NSOnState:NSOffState]; [textView setAutoindent:enableAutoindent]; @@ -289,7 +290,7 @@ // "Auto-pair characters" toggle if (sender == autopairMenuItem) { BOOL enableAutopair = !([autopairMenuItem state] == NSOffState); - [prefs setBool:enableAutopair forKey:@"CustomQueryAutoPairCharacters"]; + [prefs setBool:enableAutopair forKey:SPCustomQueryAutoPairCharacters]; [prefs synchronize]; [autopairMenuItem setState:enableAutopair?NSOnState:NSOffState]; [textView setAutopair:enableAutopair]; @@ -298,7 +299,7 @@ // "Auto-help" toggle if (sender == autohelpMenuItem) { BOOL enableAutohelp = !([autohelpMenuItem state] == NSOffState); - [prefs setBool:enableAutohelp forKey:@"CustomQueryUpdateAutoHelp"]; + [prefs setBool:enableAutohelp forKey:SPCustomQueryUpdateAutoHelp]; [prefs synchronize]; [autohelpMenuItem setState:enableAutohelp?NSOnState:NSOffState]; [textView setAutohelp:enableAutohelp]; @@ -307,7 +308,7 @@ // "Auto-uppercase keywords" toggle if (sender == autouppercaseKeywordsMenuItem) { BOOL enableAutouppercaseKeywords = !([autouppercaseKeywordsMenuItem state] == NSOffState); - [prefs setBool:enableAutouppercaseKeywords forKey:@"CustomQueryAutoUppercaseKeywords"]; + [prefs setBool:enableAutouppercaseKeywords forKey:SPCustomQueryAutoUppercaseKeywords]; [prefs synchronize]; [autouppercaseKeywordsMenuItem setState:enableAutouppercaseKeywords?NSOnState:NSOffState]; [textView setAutouppercaseKeywords:enableAutouppercaseKeywords]; @@ -494,7 +495,7 @@ [queryHistoryButton insertItemWithTitle:usedQuery atIndex:2]; // Check for max history - NSUInteger maxHistoryItems = [[prefs objectForKey:@"CustomQueryMaxHistoryItems"] intValue]; + NSUInteger maxHistoryItems = [[prefs objectForKey:SPCustomQueryMaxHistoryItems] intValue]; while ( [queryHistoryButton numberOfItems] > maxHistoryItems + 2 ) [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1]; @@ -630,7 +631,7 @@ SPTextAndLinkCell *dataCell = [[[SPTextAndLinkCell alloc] initTextCell:@""] autorelease]; [dataCell setEditable:YES]; [dataCell setFormatter:[[SPDataCellFormatter new] autorelease]]; - if ( [prefs boolForKey:@"UseMonospacedFonts"] ) { + if ( [prefs boolForKey:SPUseMonospacedFonts] ) { [dataCell setFont:[NSFont fontWithName:@"Monaco" size:10]]; } else { [dataCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; @@ -641,7 +642,7 @@ // Set the width of this column to saved value if exists and maps to a real column if ([columnDefinition objectForKey:@"org_name"] && [[columnDefinition objectForKey:@"org_name"] length]) { - NSNumber *colWidth = [[[[prefs objectForKey:@"tableColumnWidths"] objectForKey:[NSString stringWithFormat:@"%@@%@", [columnDefinition objectForKey:@"db"], [tableDocumentInstance host]]] objectForKey:[columnDefinition objectForKey:@"org_table"]] objectForKey:[columnDefinition objectForKey:@"org_name"]]; + NSNumber *colWidth = [[[[prefs objectForKey:SPTableColumnWidths] objectForKey:[NSString stringWithFormat:@"%@@%@", [columnDefinition objectForKey:@"db"], [tableDocumentInstance host]]] objectForKey:[columnDefinition objectForKey:@"org_table"]] objectForKey:[columnDefinition objectForKey:@"org_name"]]; if ( colWidth ) { [theCol setWidth:[colWidth floatValue]]; } @@ -1063,21 +1064,21 @@ toObject: [NSUserDefaultsController sharedUserDefaultsController] withKeyPath:@"values.CustomQueryEditorBackgroundColor" options:bindingOptions]; - [textView setBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorBackgroundColor"]]]; - [textView setTextColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorTextColor"]]]; - [textView setInsertionPointColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorCaretColor"]]]; + [textView setBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]]]; + [textView setTextColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorTextColor]]]; + [textView setInsertionPointColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCaretColor]]]; [customQueryView setVerticalMotionCanBeginDrag:NO]; [textView setContinuousSpellCheckingEnabled:NO]; - [autoindentMenuItem setState:([prefs boolForKey:@"CustomQueryAutoIndent"]?NSOnState:NSOffState)]; - [textView setAutoindent:[prefs boolForKey:@"CustomQueryAutoIndent"]]; + [autoindentMenuItem setState:([prefs boolForKey:SPCustomQueryAutoIndent]?NSOnState:NSOffState)]; + [textView setAutoindent:[prefs boolForKey:SPCustomQueryAutoIndent]]; [textView setAutoindentIgnoresEnter:YES]; - [autopairMenuItem setState:([prefs boolForKey:@"CustomQueryAutoPairCharacters"]?NSOnState:NSOffState)]; - [textView setAutopair:[prefs boolForKey:@"CustomQueryAutoPairCharacters"]]; - [autohelpMenuItem setState:([prefs boolForKey:@"CustomQueryUpdateAutoHelp"]?NSOnState:NSOffState)]; - [textView setAutohelp:[prefs boolForKey:@"CustomQueryUpdateAutoHelp"]]; - [autouppercaseKeywordsMenuItem setState:([prefs boolForKey:@"CustomQueryAutoUppercaseKeywords"]?NSOnState:NSOffState)]; - [textView setAutouppercaseKeywords:[prefs boolForKey:@"CustomQueryAutoUppercaseKeywords"]]; + [autopairMenuItem setState:([prefs boolForKey:SPCustomQueryAutoPairCharacters]?NSOnState:NSOffState)]; + [textView setAutopair:[prefs boolForKey:SPCustomQueryAutoPairCharacters]]; + [autohelpMenuItem setState:([prefs boolForKey:SPCustomQueryUpdateAutoHelp]?NSOnState:NSOffState)]; + [textView setAutohelp:[prefs boolForKey:SPCustomQueryUpdateAutoHelp]]; + [autouppercaseKeywordsMenuItem setState:([prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]?NSOnState:NSOffState)]; + [textView setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]]; if ( [[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] ) { @@ -1239,7 +1240,7 @@ return [theValue shortStringRepresentationUsingEncoding:[mySQLConnection encoding]]; if ( [theValue isNSNull] ) - return [prefs objectForKey:@"NullValue"]; + return [prefs objectForKey:SPNullValue]; return theValue; @@ -1297,7 +1298,7 @@ } else { if ( [[anObject description] isEqualToString:@"CURRENT_TIMESTAMP"] ) { newObject = @"CURRENT_TIMESTAMP"; - } else if([anObject isEqualToString:[prefs stringForKey:@"NullValue"]]) { + } else if([anObject isEqualToString:[prefs stringForKey:SPNullValue]]) { newObject = @"NULL"; } else if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"bit"]) { newObject = ((![[anObject description] length] || [[anObject description] isEqualToString:@"0"])?@"0":@"1"); @@ -1327,7 +1328,7 @@ // This shouldn't happen – for safety reasons if ( ![mySQLConnection affectedRows] ) { - if ( [prefs boolForKey:@"ShowNoAffectedRowsError"] ) { + if ( [prefs boolForKey:SPShowNoAffectedRowsError] ) { NSBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, NSLocalizedString(@"The row was not written to the MySQL database. You probably haven't changed anything.\nReload the table to be sure that the row exists and use a primary key for your table.\n(This error can be turned off in the preferences.)", @"message of panel when no rows have been affected after writing to the db")); } else { @@ -1643,7 +1644,7 @@ [fieldEditor setTextMaxLength:[[columnDefinition valueForKey:@"char_length"] intValue]]; id originalData = [[fullResult objectAtIndex:rowIndex] objectAtIndex:[[aTableColumn identifier] intValue]]; - if ([originalData isNSNull]) originalData = [prefs objectForKey:@"NullValue"]; + if ([originalData isNSNull]) originalData = [prefs objectForKey:SPNullValue]; id editData = [[fieldEditor editWithObject:originalData fieldName:[columnDefinition objectForKey:@"name"] @@ -1691,8 +1692,8 @@ NSString *col = [columnDefinition objectForKey:@"org_name"]; // Retrieve or instantiate the tableColumnWidths object - if ([prefs objectForKey:@"tableColumnWidths"] != nil) { - tableColumnWidths = [NSMutableDictionary dictionaryWithDictionary:[prefs objectForKey:@"tableColumnWidths"]]; + if ([prefs objectForKey:SPTableColumnWidths] != nil) { + tableColumnWidths = [NSMutableDictionary dictionaryWithDictionary:[prefs objectForKey:SPTableColumnWidths]]; } else { tableColumnWidths = [NSMutableDictionary dictionary]; } @@ -1713,7 +1714,7 @@ // Save the column size [[[tableColumnWidths objectForKey:host_db] objectForKey:table] setObject:[NSNumber numberWithFloat:[[[aNotification userInfo] objectForKey:@"NSTableColumn"] width]] forKey:col]; - [prefs setObject:tableColumnWidths forKey:@"tableColumnWidths"]; + [prefs setObject:tableColumnWidths forKey:SPTableColumnWidths]; } @@ -1762,7 +1763,7 @@ if ( [aNotification object] != textView ) return; // Remove all background color attributes used by highlighting the current query - if([prefs boolForKey:@"CustomQueryHighlightCurrentQuery"]) { + if([prefs boolForKey:SPCustomQueryHighlightCurrentQuery]) { // Remove only the background attribute for the current range if still valid NSRange textRange = NSMakeRange(0,[[textView string] length]); NSRange r = NSIntersectionRange(currentQueryRange, textRange); @@ -1786,9 +1787,9 @@ // Highlight by setting a background color the current query // if nothing is selected if(qRange.length && !currentSelection.length) { - if([prefs boolForKey:@"CustomQueryHighlightCurrentQuery"]) { + if([prefs boolForKey:SPCustomQueryHighlightCurrentQuery]) { [[textView textStorage] addAttribute: NSBackgroundColorAttributeName - value: [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorHighlightQueryColor"]] + value: [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorHighlightQueryColor]] range: qRange ]; hasBackgroundAttribute = YES; } @@ -1846,7 +1847,7 @@ // Only save the font if prefs have been loaded, ensuring the saved font has been applied once. // And check for [textView font] != nil which occurs while awaking from nib. if (prefs && [textView font] != nil) - [prefs setObject:[NSArchiver archivedDataWithRootObject:[textView font]] forKey:@"CustomQueryEditorFont"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[textView font]] forKey:SPCustomQueryEditorFont]; } @@ -2425,7 +2426,7 @@ [headerMenuItem setIndentationLevel:0]; [menu addItem:headerMenuItem]; [headerMenuItem release]; - for (NSDictionary *favorite in [prefs objectForKey:@"queryFavorites"]) { + for (NSDictionary *favorite in [prefs objectForKey:SPQueryFavorites]) { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithString:[favorite objectForKey:@"name"]] action:NULL keyEquivalent:@""]; [item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]]; [item setIndentationLevel:1]; @@ -2453,7 +2454,7 @@ */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if ([keyPath isEqualToString:@"DisplayTableViewVerticalGridlines"]) { + if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { [customQueryView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } } @@ -2468,7 +2469,7 @@ // Add the new query favorite directly the user's preferences here instead of asking the manager to do it // as it may not have been fully initialized yet. - NSMutableArray *favorites = [NSMutableArray arrayWithArray:[prefs objectForKey:@"queryFavorites"]]; + NSMutableArray *favorites = [NSMutableArray arrayWithArray:[prefs objectForKey:SPQueryFavorites]]; // What should be saved NSString *queryToBeAddded; @@ -2492,7 +2493,7 @@ [NSArray arrayWithObjects:[queryFavoriteNameTextField stringValue], queryToBeAddded, nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]]]; - [prefs setObject:favorites forKey:@"queryFavorites"]; + [prefs setObject:favorites forKey:SPQueryFavorites]; } else { [[SPQueryController sharedQueryController] addFavorite:[NSMutableDictionary dictionaryWithObjects: [NSArray arrayWithObjects:[queryFavoriteNameTextField stringValue], [queryToBeAddded mutableCopy], nil] @@ -2608,7 +2609,7 @@ [queryFavoritesSaveAllMenuItem setTag:SP_SAVE_ALL_FAVORTITE_MENUITEM_TAG]; // Set the structure and index view's vertical gridlines if required - [customQueryView setGridStyleMask:([prefs boolForKey:@"DisplayTableViewVerticalGridlines"]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + [customQueryView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } - (void)dealloc diff --git a/Source/SPAppController.m b/Source/SPAppController.m index b0cf4ed5..3b8cde01 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -29,15 +29,10 @@ #import "SPPreferenceController.h" #import "TableDump.h" #import "SPEncodingPopupAccessory.h" +#import "SPConstants.h" #import <Sparkle/Sparkle.h> -#define SEQUEL_PRO_HOME_PAGE_URL @"http://www.sequelpro.com/" -#define SEQUEL_PRO_DONATIONS_URL @"http://www.sequelpro.com/donate.html" -#define SEQUEL_PRO_FAQ_URL @"http://www.sequelpro.com/frequently-asked-questions.html" -#define SEQUEL_PRO_DOCS_URL @"http://www.sequelpro.com/docs" -#define SEQUEL_PRO_CONTACT_URL @"http://www.sequelpro.com/docs/Contact_the_developers" - @implementation SPAppController /** @@ -137,12 +132,12 @@ [panel setResolvesAliases:YES]; // If no lastSqlFileEncoding in prefs set it to UTF-8 - if(![[NSUserDefaults standardUserDefaults] integerForKey:@"lastSqlFileEncoding"]) { - [[NSUserDefaults standardUserDefaults] setInteger:4 forKey:@"lastSqlFileEncoding"]; + if(![[NSUserDefaults standardUserDefaults] integerForKey:SPLastSQLFileEncoding]) { + [[NSUserDefaults standardUserDefaults] setInteger:4 forKey:SPLastSQLFileEncoding]; [[NSUserDefaults standardUserDefaults] synchronize]; } - [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[[NSUserDefaults standardUserDefaults] integerForKey:@"lastSqlFileEncoding"] + [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[[NSUserDefaults standardUserDefaults] integerForKey:SPLastSQLFileEncoding] includeDefaultEntry:NO encodingPopUp:&encodingPopUp]]; // it will enabled if user selects a *.sql file @@ -233,7 +228,7 @@ // if encodingPopUp is defined the filename comes from an openPanel and // the encodingPopUp contains the chosen encoding; otherwise autodetect encoding if(encodingPopUp) - [[NSUserDefaults standardUserDefaults] setInteger:[[encodingPopUp selectedItem] tag] forKey:@"lastSqlFileEncoding"]; + [[NSUserDefaults standardUserDefaults] setInteger:[[encodingPopUp selectedItem] tag] forKey:SPLastSQLFileEncoding]; // Check if at least one document exists if (![[[NSDocumentController sharedDocumentController] documents] count]) { diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 3eed2c83..d6779050 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -28,6 +28,7 @@ #import "SPPreferenceController.h" #import "ImageAndTextCell.h" #import "RegexKitLite.h" +#import "SPConstants.h" @implementation SPConnectionController @@ -87,7 +88,7 @@ [self updateFavorites]; // Register an observer for changes within the favorites - [prefs addObserver:self forKeyPath:@"favorites" options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:self forKeyPath:SPFavorites options:NSKeyValueObservingOptionNew context:NULL]; // Register double click for the favorites view (double click favorite to connect) [favoritesTable setTarget:self]; @@ -96,8 +97,8 @@ // Set the focus to the favorites table and select the appropriate row [documentWindow setInitialFirstResponder:favoritesTable]; int tableRow; - if ([prefs boolForKey:@"SelectLastFavoriteUsed"] == YES) { - tableRow = [prefs integerForKey:@"LastFavoriteIndex"] + 1; + if ([prefs boolForKey:SPSelectLastFavoriteUsed] == YES) { + tableRow = [prefs integerForKey:SPLastFavoriteIndex] + 1; } else { tableRow = [prefs integerForKey:@"DefaultFavorite"] + 1; } @@ -291,12 +292,12 @@ [mySQLConnection setDelegate:tableDocument]; // Set whether or not we should enable delegate logging according to the prefs - [mySQLConnection setDelegateQueryLogging:[prefs boolForKey:@"ConsoleEnableLogging"]]; + [mySQLConnection setDelegateQueryLogging:[prefs boolForKey:SPConsoleEnableLogging]]; // Set options from preferences - [mySQLConnection setConnectionTimeout:[[prefs objectForKey:@"ConnectionTimeoutValue"] intValue]]; - [mySQLConnection setUseKeepAlive:[[prefs objectForKey:@"UseKeepAlive"] boolValue]]; - [mySQLConnection setKeepAliveInterval:[[prefs objectForKey:@"KeepAliveInterval"] floatValue]]; + [mySQLConnection setConnectionTimeout:[[prefs objectForKey:SPConnectionTimeoutValue] intValue]]; + [mySQLConnection setUseKeepAlive:[[prefs objectForKey:SPUseKeepAlive] boolValue]]; + [mySQLConnection setKeepAliveInterval:[[prefs objectForKey:SPKeepAliveInterval] floatValue]]; // Connect [mySQLConnection connect]; @@ -334,7 +335,7 @@ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect via the socket, or the request timed out.\n\nDouble-check that the socket path is correct and that you have the necessary privileges, and that the server is running.\n\nMySQL said: %@", @"message of panel when connection to host failed"), [mySQLConnection getLastErrorMessage]]; [self failConnectionWithTitle:NSLocalizedString(@"Socket connection failed!", @"socket connection failed title") errorMessage:errorMessage detail:nil]; } else { - errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %i seconds).\n\nMySQL said: %@", @"message of panel when connection to host failed"), [self host], [[prefs objectForKey:@"ConnectionTimeoutValue"] intValue], [mySQLConnection getLastErrorMessage]]; + errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %i seconds).\n\nMySQL said: %@", @"message of panel when connection to host failed"), [self host], [[prefs objectForKey:SPConnectionTimeoutValue] intValue], [mySQLConnection getLastErrorMessage]]; [self failConnectionWithTitle:NSLocalizedString(@"Connection failed!", @"connection failed title") errorMessage:errorMessage detail:nil]; } @@ -621,8 +622,8 @@ { [favoritesTable deselectAll:self]; if (favorites) [favorites release]; - if ([prefs objectForKey:@"favorites"]) { - favorites = [[NSMutableArray alloc] initWithArray:[prefs objectForKey:@"favorites"]]; + if ([prefs objectForKey:SPFavorites]) { + favorites = [[NSMutableArray alloc] initWithArray:[prefs objectForKey:SPFavorites]]; } else { favorites = [[NSMutableArray alloc] init]; } @@ -678,7 +679,7 @@ [connectionSSHKeychainItemAccount release], connectionSSHKeychainItemAccount = nil; } - [prefs setInteger:([favoritesTable selectedRow] - 1) forKey:@"LastFavoriteIndex"]; + [prefs setInteger:([favoritesTable selectedRow] - 1) forKey:SPLastFavoriteIndex]; } /** @@ -736,13 +737,13 @@ // Add the new favorite to the user defaults array NSMutableArray *currentFavorites; - if ([prefs objectForKey:@"favorites"]) { - currentFavorites = [[NSMutableArray alloc] initWithArray:[prefs objectForKey:@"favorites"]]; + if ([prefs objectForKey:SPFavorites]) { + currentFavorites = [[NSMutableArray alloc] initWithArray:[prefs objectForKey:SPFavorites]]; } else { currentFavorites = [[NSMutableArray alloc] init]; } [currentFavorites addObject:newFavorite]; - [prefs setObject:[NSArray arrayWithArray:currentFavorites] forKey:@"favorites"]; + [prefs setObject:[NSArray arrayWithArray:currentFavorites] forKey:SPFavorites]; [currentFavorites release]; // Add the password to keychain as appropriate @@ -781,7 +782,7 @@ */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if ([keyPath isEqualToString:@"favorites"]) { + if ([keyPath isEqualToString:SPFavorites]) { [self updateFavorites]; } } diff --git a/Source/SPConstants.h b/Source/SPConstants.h new file mode 100644 index 00000000..8ab19b02 --- /dev/null +++ b/Source/SPConstants.h @@ -0,0 +1,110 @@ +// +// $Id$ +// +// SPConstants.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on October 16, 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> + +// Extensions +#define DEFAULT_SEQUEL_PRO_FILE_EXTENSION @"spf" +#define DEFAULT_QUERY_FAVORITE_FILE_EXTENSION @"sql" +#define DEFAULT_CONSOLE_LOG_FILE_EXTENSION @"sql" + +// Tableview drag types +#define FAVORITES_PB_DRAG_TYPE @"SequelProPreferencesPasteboard" +#define CONTENT_FILTER_PB_DRAG_TYPE @"SequelProContentFilterPasteboard" +#define QUERY_FAVORITES_PB_DRAG_TYPE @"SequelProQueryFavoritesPasteboard" + +// URLs +#define SEQUEL_PRO_HOME_PAGE_URL @"http://www.sequelpro.com/" +#define SEQUEL_PRO_DONATIONS_URL @"http://www.sequelpro.com/donate.html" +#define SEQUEL_PRO_FAQ_URL @"http://www.sequelpro.com/frequently-asked-questions.html" +#define SEQUEL_PRO_DOCS_URL @"http://www.sequelpro.com/docs" +#define SEQUEL_PRO_CONTACT_URL @"http://www.sequelpro.com/docs/Contact_the_developers" + +// Preference key constants +extern NSString *SPDefaultEncoding; +extern NSString *SPUseMonospacedFonts; +extern NSString *SPDisplayTableViewVerticalGridlines; +extern NSString *SPReloadAfterAddingRow; +extern NSString *SPReloadAfterEditingRow; +extern NSString *SPReloadAfterRemovingRow; +extern NSString *SPLoadBlobsAsNeeded; +extern NSString *SPFetchCorrectRowCount; +extern NSString *SPNewFieldsAllowNulls; +extern NSString *SPLimitResults; +extern NSString *SPLimitResultsValue; +extern NSString *SPNullValue; +extern NSString *SPShowNoAffectedRowsError; +extern NSString *SPGrowlEnabled; +extern NSString *SPConnectionTimeoutValue; +extern NSString *SPUseKeepAlive; +extern NSString *SPKeepAliveInterval; +extern NSString *SPEditInSheetEnabled; +extern NSString *SPQueryFavoriteReplacesContent; +extern NSString *SPQueryHistoryReplacesContent; +extern NSString *SPCustomQueryEditorFont; +extern NSString *SPCustomQueryEditorBackgroundColor; +extern NSString *SPCustomQueryEditorBacktickColor; +extern NSString *SPCustomQueryEditorCommentColor; +extern NSString *SPCustomQueryEditorNumericColor; +extern NSString *SPCustomQueryEditorQuoteColor; +extern NSString *SPCustomQueryEditorSQLKeywordColor; +extern NSString *SPCustomQueryEditorTextColor; +extern NSString *SPCustomQueryEditorHighlightQueryColor; +extern NSString *SPCustomQueryEditorCaretColor; +extern NSString *SPCustomQueryEditorVariableColor; +extern NSString *SPCustomQueryHighlightCurrentQuery; +extern NSString *SPCustomQueryAutoIndent; +extern NSString *SPCustomQueryAutoPairCharacters; +extern NSString *SPCustomQueryAutoUppercaseKeywords; +extern NSString *SPCustomQueryUpdateAutoHelp; +extern NSString *SPCustomQueryAutoHelpDelay; +extern NSString *SPCustomQueryMaxHistoryItems; +extern NSString *SPLastSQLFileEncoding; +extern NSString *SPSelectLastFavoriteUsed; +extern NSString *SPLastFavoriteIndex; +extern NSString *SPTableInformationPanelCollapsed; +extern NSString *SPConsoleEnableLogging; +extern NSString *SPConsoleEnableInterfaceLogging; +extern NSString *SPConsoleEnableCustomQueryLogging; +extern NSString *SPConsoleEnableImportExportLogging; +extern NSString *SPEnableErrorLogging; +extern NSString *SPConsoleShowTimestamps; +extern NSString *SPConsoleShowSelectsAndShows; +extern NSString *SPConsoleShowHelps; +extern NSString *SPPrintBackground; +extern NSString *SPPrintImagePreviews; +extern NSString *SPContentFilters; +extern NSString *SPCSVImportFieldTerminator; +extern NSString *SPCSVImportLineTerminator; +extern NSString *SPCSVImportFieldEnclosedBy; +extern NSString *SPCSVImportFieldEscapeCharacter; +extern NSString *SPCSVImportFirstLineIsHeader; +extern NSString *SPLastUsedVersion; +extern NSString *SPFieldEditorSheetFont; +extern NSString *SPQuickLookTypes; +extern NSString *SPQueryFavorites; +extern NSString *SPFavorites; +extern NSString *SPTableColumnWidths; +extern NSString *SPQueryHistory; diff --git a/Source/SPConstants.m b/Source/SPConstants.m new file mode 100644 index 00000000..50e9496f --- /dev/null +++ b/Source/SPConstants.m @@ -0,0 +1,93 @@ +// +// $Id$ +// +// SPConstants.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on October 16, 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 "SPConstants.h" + +// Preference key constants +NSString *SPDefaultEncoding = @"SPDefaultEncoding"; +NSString *SPUseMonospacedFonts = @"UseMonospacedFonts"; +NSString *SPDisplayTableViewVerticalGridlines = @"DisplayTableViewVerticalGridlines"; +NSString *SPReloadAfterAddingRow = @"ReloadAfterAddingRow"; +NSString *SPReloadAfterEditingRow = @"ReloadAfterEditingRow"; +NSString *SPReloadAfterRemovingRow = @"ReloadAfterRemovingRow"; +NSString *SPLoadBlobsAsNeeded = @"LoadBlobsAsNeeded"; +NSString *SPFetchCorrectRowCount = @"FetchCorrectRowCount"; +NSString *SPNewFieldsAllowNulls = @"NewFieldsAllowNulls"; +NSString *SPLimitResults = @"LimitResults"; +NSString *SPLimitResultsValue = @"LimitResultsValue"; +NSString *SPNullValue = @"NullValue"; +NSString *SPShowNoAffectedRowsError = @"ShowNoAffectedRowsError"; +NSString *SPGrowlEnabled = @"GrowlEnabled"; +NSString *SPConnectionTimeoutValue = @"ConnectionTimeoutValue"; +NSString *SPUseKeepAlive = @"UseKeepAlive"; +NSString *SPKeepAliveInterval = @"KeepAliveInterval"; +NSString *SPEditInSheetEnabled = @"EditInSheetEnabled"; +NSString *SPQueryFavoriteReplacesContent = @"QueryFavoriteReplacesContent"; +NSString *SPQueryHistoryReplacesContent = @"QueryHistoryReplacesContent"; +NSString *SPCustomQueryEditorFont = @"CustomQueryEditorFont"; +NSString *SPCustomQueryEditorBackgroundColor = @"CustomQueryEditorBackgroundColor"; +NSString *SPCustomQueryEditorBacktickColor = @"CustomQueryEditorBacktickColor"; +NSString *SPCustomQueryEditorCommentColor = @"CustomQueryEditorCommentColor"; +NSString *SPCustomQueryEditorNumericColor = @"CustomQueryEditorNumericColor"; +NSString *SPCustomQueryEditorQuoteColor = @"CustomQueryEditorQuoteColor"; +NSString *SPCustomQueryEditorSQLKeywordColor = @"CustomQueryEditorSQLKeywordColor"; +NSString *SPCustomQueryEditorTextColor = @"CustomQueryEditorTextColor"; +NSString *SPCustomQueryEditorHighlightQueryColor = @"CustomQueryEditorHighlightQueryColor"; +NSString *SPCustomQueryEditorCaretColor = @"CustomQueryEditorCaretColor"; +NSString *SPCustomQueryEditorVariableColor = @"CustomQueryEditorVariableColor"; +NSString *SPCustomQueryHighlightCurrentQuery = @"CustomQueryHighlightCurrentQuery"; +NSString *SPCustomQueryAutoIndent = @"CustomQueryAutoIndent"; +NSString *SPCustomQueryAutoPairCharacters = @"CustomQueryAutoPairCharacters"; +NSString *SPCustomQueryAutoUppercaseKeywords = @"CustomQueryAutoUppercaseKeywords"; +NSString *SPCustomQueryUpdateAutoHelp = @"CustomQueryUpdateAutoHelp"; +NSString *SPCustomQueryAutoHelpDelay = @"CustomQueryAutoHelpDelay"; +NSString *SPCustomQueryMaxHistoryItems = @"CustomQueryMaxHistoryItems"; +NSString *SPLastSQLFileEncoding = @"lastSqlFileEncoding"; +NSString *SPSelectLastFavoriteUsed = @"SelectLastFavoriteUsed"; +NSString *SPLastFavoriteIndex = @"LastFavoriteIndex"; +NSString *SPTableInformationPanelCollapsed = @"TableInformationPanelCollapsed"; +NSString *SPConsoleEnableLogging = @"ConsoleEnableLogging"; +NSString *SPConsoleEnableInterfaceLogging = @"ConsoleEnableInterfaceLogging"; +NSString *SPConsoleEnableCustomQueryLogging = @"ConsoleEnableCustomQueryLogging"; +NSString *SPConsoleEnableImportExportLogging = @"ConsoleEnableImportExportLogging"; +NSString *SPEnableErrorLogging = @"EnableErrorLogging"; +NSString *SPConsoleShowTimestamps = @"ConsoleShowTimestamps"; +NSString *SPConsoleShowSelectsAndShows = @"ConsoleShowSelectsAndShows"; +NSString *SPConsoleShowHelps = @"ConsoleShowHelps"; +NSString *SPPrintBackground = @"PrintBackground"; +NSString *SPPrintImagePreviews = @"PrintImagePreviews"; +NSString *SPContentFilters = @"ContentFilters"; +NSString *SPCSVImportFieldTerminator = @"CSVImportFieldTerminator"; +NSString *SPCSVImportLineTerminator = @"CSVImportLineTerminator"; +NSString *SPCSVImportFieldEnclosedBy = @"CSVImportFieldEnclosedBy"; +NSString *SPCSVImportFieldEscapeCharacter = @"CSVImportFieldEscapeCharacter"; +NSString *SPCSVImportFirstLineIsHeader = @"CSVImportFirstLineIsHeader"; +NSString *SPLastUsedVersion = @"LastUsedVersion"; +NSString *SPFieldEditorSheetFont = @"FieldEditorSheetFont"; +NSString *SPQuickLookTypes = @"QuickLookTypes"; +NSString *SPQueryFavorites = @"queryFavorites"; +NSString *SPFavorites = @"favorites"; +NSString *SPTableColumnWidths = @"tableColumnWidths"; +NSString *SPQueryHistory = @"queryHistory"; diff --git a/Source/SPContentFilterManager.m b/Source/SPContentFilterManager.m index 79c629bc..d6a7f1e3 100644 --- a/Source/SPContentFilterManager.m +++ b/Source/SPContentFilterManager.m @@ -28,14 +28,11 @@ #import "RegexKitLite.h" #import "SPQueryController.h" #import "TableContent.h" - -#define DEFAULT_SEQUELPRO_FILE_EXTENSION @"spf" +#import "SPConstants.h" #define SP_MULTIPLE_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[multiple selection]", @"[multiple selection]") #define SP_NO_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[no selection]", @"[no selection]") -#define CONTENT_FILTER_PB_DRAG_TYPE @"SequelProContentFilterPasteboard" - @interface SPContentFilterManager (Private) - (void)_initWithNoSelection; @end @@ -100,8 +97,8 @@ // Build data source for global content filter (as mutable copy! otherwise each // change will be stored in the prefs at once) - if([[prefs objectForKey:@"ContentFilters"] objectForKey:filterType]) { - for(id fav in [[prefs objectForKey:@"ContentFilters"] objectForKey:filterType]) { + if([[prefs objectForKey:SPContentFilters] objectForKey:filterType]) { + for(id fav in [[prefs objectForKey:SPContentFilters] objectForKey:filterType]) { id f = [[fav mutableCopy] autorelease]; if([f objectForKey:@"ConjunctionLabels"]) [f setObject:[[f objectForKey:@"ConjunctionLabels"] objectAtIndex:0] forKey:@"ConjunctionLabel"]; @@ -301,7 +298,7 @@ { NSSavePanel *panel = [NSSavePanel savePanel]; - [panel setRequiredFileType:DEFAULT_SEQUELPRO_FILE_EXTENSION]; + [panel setRequiredFileType:DEFAULT_SEQUEL_PRO_FILE_EXTENSION]; [panel setExtensionHidden:NO]; [panel setAllowsOtherFileTypes:NO]; @@ -363,9 +360,9 @@ [self contentFilterForFileURL:delegatesFileURL] ofType:filterType forFileURL:delegatesFileURL]; // Update global preferences' list - id cf = [[prefs objectForKey:@"ContentFilters"] mutableCopy]; + id cf = [[prefs objectForKey:SPContentFilters] mutableCopy]; [cf setObject:[self contentFilterForFileURL:nil] forKey:filterType]; - [prefs setObject:cf forKey:@"ContentFilters"]; + [prefs setObject:cf forKey:SPContentFilters]; [cf release]; // Inform all opened documents to update the query favorites list @@ -765,17 +762,17 @@ return; } - if([[spf objectForKey:@"ContentFilters"] objectForKey:filterType] && [[[spf objectForKey:@"ContentFilters"] objectForKey:filterType] count]) { + if([[spf objectForKey:SPContentFilters] objectForKey:filterType] && [[[spf objectForKey:SPContentFilters] objectForKey:filterType] count]) { // if([contentFilterTableView numberOfSelectedRows] > 0) { // // Insert imported filters after the last selected filter // NSUInteger insertIndex = [[contentFilterTableView selectedRowIndexes] lastIndex] + 1; // NSUInteger i; - // for(i=0; i<[[[spf objectForKey:@"ContentFilters"] objectForKey:filterType] count]; i++) { - // [contentFilters insertObject:[[spf objectForKey:@"queryFavorites"] objectAtIndex:i] atIndex:insertIndex+i]; + // for(i=0; i<[[[spf objectForKey:SPContentFilters] objectForKey:filterType] count]; i++) { + // [contentFilters insertObject:[[spf objectForKey:SPQueryFavorites] objectAtIndex:i] atIndex:insertIndex+i]; // } // } else { // // If no selection add them - [contentFilters addObjectsFromArray:[[spf objectForKey:@"ContentFilters"] objectForKey:filterType]]; + [contentFilters addObjectsFromArray:[[spf objectForKey:SPContentFilters] objectForKey:filterType]]; // } [contentFilterArrayController rearrangeObjects]; [contentFilterTableView reloadData]; @@ -823,7 +820,7 @@ [filterData addObject:[contentFilters objectAtIndex:i]]; [cfdata setObject:filterData forKey:filterType]; - [spfdata setObject:cfdata forKey:@"ContentFilters"]; + [spfdata setObject:cfdata forKey:SPContentFilters]; NSString *err = nil; NSData *plist = [NSPropertyListSerialization dataFromPropertyList:spfdata diff --git a/Source/SPDataCellFormatter.m b/Source/SPDataCellFormatter.m index 916568ca..86cbdce6 100644 --- a/Source/SPDataCellFormatter.m +++ b/Source/SPDataCellFormatter.m @@ -25,6 +25,7 @@ #import "SPDataCellFormatter.h" #import "SPTooltip.h" +#import "SPConstants.h" @implementation SPDataCellFormatter @@ -77,7 +78,7 @@ - (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error { // No limit set or partialString is NULL value string allow editing - if (textLimit == 0 || [partialString isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"NullValue"]]) + if (textLimit == 0 || [partialString isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:SPNullValue]]) return YES; // A single character over the length of the string - likely typed. Prevent the change. diff --git a/Source/SPExportController.m b/Source/SPExportController.m index e4079877..19d794ae 100644 --- a/Source/SPExportController.m +++ b/Source/SPExportController.m @@ -29,6 +29,7 @@ #import "TableDocument.h" #import "SPArrayAdditions.h" #import "SPStringAdditions.h" +#import "SPConstants.h" @interface SPExportController (PrivateAPI) @@ -461,7 +462,7 @@ [csvExporter setCsvEscapeString:[exportCSVFieldsEscapedField stringValue]]; [csvExporter setExportOutputEncoding:[MCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]]]; - [csvExporter setCsvNULLString:[[NSUserDefaults standardUserDefaults] objectForKey:@"NullValue"]]; + [csvExporter setCsvNULLString:[[NSUserDefaults standardUserDefaults] objectForKey:SPNullValue]]; [csvExporter setCsvTableColumnNumericStatus:tableColumnNumericStatus]; diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index 83a63d6b..9ecf4815 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -32,6 +32,7 @@ #import "RegexKitLite.h" #import "SPDataCellFormatter.h" #import "SPTooltip.h" +#import "SPConstants.h" @implementation SPFieldEditorController @@ -91,8 +92,8 @@ } } // Load user-defined QL types - if([prefs objectForKey:@"QuickLookTypes"]) { - for(id type in [prefs objectForKey:@"QuickLookTypes"]) { + if([prefs objectForKey:SPQuickLookTypes]) { + for(id type in [prefs objectForKey:SPQuickLookTypes]) { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithString:[type objectForKey:@"MenuLabel"]] action:NULL keyEquivalent:@""]; [item setTag:tag]; [item setAction:@selector(quickLookFormatButton:)]; @@ -102,7 +103,7 @@ [qlTypesItems addObject:type]; } } - qlTypes = [NSDictionary dictionaryWithObject:[qlTypesItems retain] forKey:@"QuickLookTypes"]; + qlTypes = [NSDictionary dictionaryWithObject:[qlTypesItems retain] forKey:SPQuickLookTypes]; [qlTypesItems release]; } return self; @@ -131,8 +132,8 @@ isObjectBlob:(BOOL)isFieldBlob isEditable:(BOOL)isEditable withWindow:(NSWindow *)tableWindow { - if ( ![prefs objectForKey:@"FieldEditorSheetFont"] ) - if ( [prefs boolForKey:@"UseMonospacedFonts"] ) { + if ( ![prefs objectForKey:SPFieldEditorSheetFont] ) + if ( [prefs boolForKey:SPUseMonospacedFonts] ) { [editTextView setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; } else { [editTextView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; @@ -253,7 +254,7 @@ [editTextView setSelectedRange:NSMakeRange(0,0)]; // If the string content is NULL select NULL for convenience - if([stringValue isEqualToString:[prefs objectForKey:@"NullValue"]]) + if([stringValue isEqualToString:[prefs objectForKey:SPNullValue]]) [editTextView setSelectedRange:NSMakeRange(0,[[editTextView string] length])]; // Set focus @@ -349,7 +350,7 @@ // - for max text length (except for NULL value string) select the part which won't be saved // and suppress closing the sheet if(sender == editSheetOkButton) { - if (maxTextLength > 0 && [[editTextView textStorage] length] > maxTextLength && ![[[editTextView textStorage] string] isEqualToString:[prefs objectForKey:@"NullValue"]]) { + if (maxTextLength > 0 && [[editTextView textStorage] length] > maxTextLength && ![[[editTextView textStorage] string] isEqualToString:[prefs objectForKey:SPNullValue]]) { [editTextView setSelectedRange:NSMakeRange(maxTextLength, [[editTextView textStorage] length] - maxTextLength)]; [editTextView scrollRangeToVisible:NSMakeRange([editTextView selectedRange].location,0)]; [SPTooltip showWithObject:[NSString stringWithFormat:NSLocalizedString(@"Text is too long. Maximum text length is set to %d.", @"Text is too long. Maximum text length is set to %d."), maxTextLength]]; @@ -839,7 +840,7 @@ { if(textView == editTextView && maxTextLength > 0 - && ![ [[[editTextView textStorage] string] stringByAppendingString:replacementString] isEqualToString:[prefs objectForKey:@"NullValue"]]) { + && ![ [[[editTextView textStorage] string] stringByAppendingString:replacementString] isEqualToString:[prefs objectForKey:SPNullValue]]) { int newLength; diff --git a/Source/SPGrowlController.m b/Source/SPGrowlController.m index b939d878..f96602cd 100644 --- a/Source/SPGrowlController.m +++ b/Source/SPGrowlController.m @@ -24,6 +24,8 @@ // More info at <http://code.google.com/p/sequel-pro/> #import "SPGrowlController.h" +#import "SPConstants.h" + #include <mach/mach_time.h> static SPGrowlController *sharedGrowlController = nil; @@ -141,7 +143,7 @@ static SPGrowlController *sharedGrowlController = nil; } // Post notification only if preference is set and visibility has been confirmed - if (postNotification && [[NSUserDefaults standardUserDefaults] boolForKey:@"GrowlEnabled"]) { + if (postNotification && [[NSUserDefaults standardUserDefaults] boolForKey:SPGrowlEnabled]) { [GrowlApplicationBridge notifyWithTitle:title description:description notificationName:name diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index 27850bae..10274d73 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -31,6 +31,7 @@ #import "SPNarrowDownCompletion.h" #import "SPArrayAdditions.h" #import "ImageAndTextCell.h" +#import "SPConstants.h" @interface NSTableView (MovingSelectedRow) - (BOOL)SP_NarrowDownCompletion_canHandleEvent:(NSEvent*)anEvent; @@ -98,7 +99,7 @@ caseSensitive = YES; filtered = nil; - tableFont = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:@"CustomQueryEditorFont"]]; + tableFont = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:SPCustomQueryEditorFont]]; [self setupInterface]; } return self; diff --git a/Source/SPNotLoaded.h b/Source/SPNotLoaded.h index e2026525..611a3f91 100644 --- a/Source/SPNotLoaded.h +++ b/Source/SPNotLoaded.h @@ -25,9 +25,7 @@ #import <Cocoa/Cocoa.h> -@interface SPNotLoaded : NSObject { - -} +@interface SPNotLoaded : NSObject + (SPNotLoaded *) notLoaded; diff --git a/Source/SPOutlineView.h b/Source/SPOutlineView.h index c361f788..8f1b581e 100644 --- a/Source/SPOutlineView.h +++ b/Source/SPOutlineView.h @@ -25,9 +25,6 @@ #import <Foundation/Foundation.h> - -@interface SPOutlineView : NSOutlineView { - -} +@interface SPOutlineView : NSOutlineView @end diff --git a/Source/SPOutlineView.m b/Source/SPOutlineView.m index 97f8cab3..cfbb0cc2 100644 --- a/Source/SPOutlineView.m +++ b/Source/SPOutlineView.m @@ -22,10 +22,8 @@ // // More info at <http://code.google.com/p/sequel-pro/> - #import "SPOutlineView.h" - @implementation SPOutlineView - (BOOL)acceptsFirstResponder @@ -33,9 +31,9 @@ return YES; } --(void)keyDown:(NSEvent *)theEvent +- (void)keyDown:(NSEvent *)theEvent { - if([self numberOfSelectedRows] == 1 && ([theEvent keyCode] == 36 || [theEvent keyCode] == 76)) + if ([self numberOfSelectedRows] == 1 && ([theEvent keyCode] == 36 || [theEvent keyCode] == 76)) { [self editColumn:0 row:[self selectedRow] withEvent:nil select:YES]; } @@ -43,4 +41,5 @@ [super keyDown:theEvent]; } } + @end diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index 36834616..d9fd38eb 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -29,8 +29,7 @@ #import "SPKeychain.h" #import "TableDocument.h" #import "SPConnectionController.h" - -#define FAVORITES_PB_DRAG_TYPE @"SequelProPreferencesPasteboard" +#import "SPConstants.h" #define PREFERENCE_TOOLBAR_GENERAL @"Preference Toolbar General" #define PREFERENCE_TOOLBAR_TABLES @"Preference Toolbar Tables" @@ -118,35 +117,35 @@ // Get the current revision if ([prefs objectForKey:@"lastUsedVersion"]) recordedVersionNumber = [[prefs objectForKey:@"lastUsedVersion"] intValue]; - if ([prefs objectForKey:@"LastUsedVersion"]) recordedVersionNumber = [[prefs objectForKey:@"LastUsedVersion"] intValue]; + if ([prefs objectForKey:SPLastUsedVersion]) recordedVersionNumber = [[prefs objectForKey:SPLastUsedVersion] intValue]; // Skip processing if the current version matches or is less than recorded version if (currentVersionNumber <= recordedVersionNumber) return; // If no recorded version, update to current revision and skip processing if (!recordedVersionNumber) { - [prefs setObject:[NSNumber numberWithInt:currentVersionNumber] forKey:@"LastUsedVersion"]; + [prefs setObject:[NSNumber numberWithInt:currentVersionNumber] forKey:SPLastUsedVersion]; return; } // For versions prior to r336 (0.9.4), where column widths have been saved, walk through them and remove // any table widths set to 15 or less (fix for mangled columns caused by Issue #140) - if (recordedVersionNumber < 336 && [prefs objectForKey:@"tableColumnWidths"] != nil) { + if (recordedVersionNumber < 336 && [prefs objectForKey:SPTableColumnWidths] != nil) { NSEnumerator *databaseEnumerator, *tableEnumerator, *columnEnumerator; NSString *databaseKey, *tableKey, *columnKey; NSMutableDictionary *newDatabase, *newTable; float columnWidth; NSMutableDictionary *newTableColumnWidths = [[NSMutableDictionary alloc] init]; - databaseEnumerator = [[prefs objectForKey:@"tableColumnWidths"] keyEnumerator]; + databaseEnumerator = [[prefs objectForKey:SPTableColumnWidths] keyEnumerator]; while (databaseKey = [databaseEnumerator nextObject]) { newDatabase = [[NSMutableDictionary alloc] init]; - tableEnumerator = [[[prefs objectForKey:@"tableColumnWidths"] objectForKey:databaseKey] keyEnumerator]; + tableEnumerator = [[[prefs objectForKey:SPTableColumnWidths] objectForKey:databaseKey] keyEnumerator]; while (tableKey = [tableEnumerator nextObject]) { newTable = [[NSMutableDictionary alloc] init]; - columnEnumerator = [[[[prefs objectForKey:@"tableColumnWidths"] objectForKey:databaseKey] objectForKey:tableKey] keyEnumerator]; + columnEnumerator = [[[[prefs objectForKey:SPTableColumnWidths] objectForKey:databaseKey] objectForKey:tableKey] keyEnumerator]; while (columnKey = [columnEnumerator nextObject]) { - columnWidth = [[[[[prefs objectForKey:@"tableColumnWidths"] objectForKey:databaseKey] objectForKey:tableKey] objectForKey:columnKey] floatValue]; + columnWidth = [[[[[prefs objectForKey:SPTableColumnWidths] objectForKey:databaseKey] objectForKey:tableKey] objectForKey:columnKey] floatValue]; if (columnWidth >= 15) { [newTable setObject:[NSNumber numberWithFloat:columnWidth] forKey:[NSString stringWithString:columnKey]]; } @@ -161,7 +160,7 @@ } [newDatabase release]; } - [prefs setObject:[NSDictionary dictionaryWithDictionary:newTableColumnWidths] forKey:@"tableColumnWidths"]; + [prefs setObject:[NSDictionary dictionaryWithDictionary:newTableColumnWidths] forKey:SPTableColumnWidths]; [newTableColumnWidths release]; } @@ -170,20 +169,20 @@ NSEnumerator *keyEnumerator; NSString *oldKey, *newKey; NSDictionary *keysToUpgrade = [NSDictionary dictionaryWithObjectsAndKeys: - @"encoding", @"DefaultEncoding", - @"useMonospacedFonts", @"UseMonospacedFonts", - @"reloadAfterAdding", @"ReloadAfterAddingRow", - @"reloadAfterEditing", @"ReloadAfterEditingRow", - @"reloadAfterRemoving", @"ReloadAfterRemovingRow", - @"dontShowBlob", @"LoadBlobsAsNeeded", - @"fetchRowCount", @"FetchCorrectRowCount", - @"limitRows", @"LimitResults", - @"limitRowsValue", @"LimitResultsValue", - @"nullValue", @"NullValue", - @"showError", @"ShowNoAffectedRowsError", - @"connectionTimeout", @"ConnectionTimeoutValue", - @"keepAliveInterval", @"KeepAliveInterval", - @"lastFavoriteIndex", @"LastFavoriteIndex", + @"encoding", SPDefaultEncoding, + @"useMonospacedFonts", SPUseMonospacedFonts, + @"reloadAfterAdding", SPReloadAfterAddingRow, + @"reloadAfterEditing", SPReloadAfterEditingRow, + @"reloadAfterRemoving", SPReloadAfterRemovingRow, + @"dontShowBlob", SPLoadBlobsAsNeeded, + @"fetchRowCount", SPFetchCorrectRowCount, + @"limitRows", SPLimitResults, + @"limitRowsValue", SPLimitResultsValue, + @"nullValue", SPNullValue, + @"showError", SPShowNoAffectedRowsError, + @"connectionTimeout", SPConnectionTimeoutValue, + @"keepAliveInterval", SPKeepAliveInterval, + @"lastFavoriteIndex", SPLastFavoriteIndex, nil]; keyEnumerator = [keysToUpgrade keyEnumerator]; @@ -201,8 +200,8 @@ } // For versions prior to r567 (0.9.5), add a timestamp-based identifier to favorites and keychain entries - if (recordedVersionNumber < 567 && [prefs objectForKey:@"favorites"]) { - NSMutableArray *favoritesArray = [NSMutableArray arrayWithArray:[prefs objectForKey:@"favorites"]]; + if (recordedVersionNumber < 567 && [prefs objectForKey:SPFavorites]) { + NSMutableArray *favoritesArray = [NSMutableArray arrayWithArray:[prefs objectForKey:SPFavorites]]; NSMutableDictionary *favorite; NSString *password, *keychainName, *keychainAccount; SPKeychain *upgradeKeychain = [[SPKeychain alloc] init]; @@ -223,14 +222,14 @@ } [favoritesArray replaceObjectAtIndex:i withObject:[NSDictionary dictionaryWithDictionary:favorite]]; } - [prefs setObject:[NSArray arrayWithArray:favoritesArray] forKey:@"favorites"]; + [prefs setObject:[NSArray arrayWithArray:favoritesArray] forKey:SPFavorites]; [upgradeKeychain release]; password = nil; } // For versions prior to r981 (~0.9.6), upgrade the favourites to include a connection type for each - if (recordedVersionNumber < 981 && [prefs objectForKey:@"favorites"]) { - NSMutableArray *favoritesArray = [NSMutableArray arrayWithArray:[prefs objectForKey:@"favorites"]]; + if (recordedVersionNumber < 981 && [prefs objectForKey:SPFavorites]) { + NSMutableArray *favoritesArray = [NSMutableArray arrayWithArray:[prefs objectForKey:SPFavorites]]; NSMutableDictionary *favorite; // Cycle through the favorites @@ -258,7 +257,7 @@ [favoritesArray replaceObjectAtIndex:i withObject:[NSDictionary dictionaryWithDictionary:favorite]]; } - [prefs setObject:[NSArray arrayWithArray:favoritesArray] forKey:@"favorites"]; + [prefs setObject:[NSArray arrayWithArray:favoritesArray] forKey:SPFavorites]; } // For versions prior to r1128 (~0.9.6), reset the main window toolbar items to add new items @@ -269,8 +268,8 @@ } // For versions prior to r1263 (~0.9.7), convert the query favorites array to an array of dictionaries - if (recordedVersionNumber < 1263 && [prefs objectForKey:@"queryFavorites"]) { - NSMutableArray *queryFavoritesArray = [NSMutableArray arrayWithArray:[prefs objectForKey:@"queryFavorites"]]; + if (recordedVersionNumber < 1263 && [prefs objectForKey:SPQueryFavorites]) { + NSMutableArray *queryFavoritesArray = [NSMutableArray arrayWithArray:[prefs objectForKey:SPQueryFavorites]]; for (i = 0; i < [queryFavoritesArray count]; i++) { @@ -285,11 +284,11 @@ [queryFavoritesArray replaceObjectAtIndex:i withObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:favoriteName, favorite, nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]]]; } - [prefs setObject:queryFavoritesArray forKey:@"queryFavorites"]; + [prefs setObject:queryFavoritesArray forKey:SPQueryFavorites]; } // Update the prefs revision - [prefs setObject:[NSNumber numberWithInt:currentVersionNumber] forKey:@"LastUsedVersion"]; + [prefs setObject:[NSNumber numberWithInt:currentVersionNumber] forKey:SPLastUsedVersion]; } #pragma mark - @@ -342,13 +341,13 @@ account:[keychain accountForSSHUser:sshUser sshHost:sshHost]]; // Reset last used favorite - if ([favoritesTableView selectedRow] == [prefs integerForKey:@"LastFavoriteIndex"]) { - [prefs setInteger:0 forKey:@"LastFavoriteIndex"]; + if ([favoritesTableView selectedRow] == [prefs integerForKey:SPLastFavoriteIndex]) { + [prefs setInteger:0 forKey:SPLastFavoriteIndex]; } // Reset default favorite if ([favoritesTableView selectedRow] == [prefs integerForKey:@"DefaultFavorite"]) { - [prefs setInteger:[prefs integerForKey:@"LastFavoriteIndex"] forKey:@"DefaultFavorite"]; + [prefs setInteger:[prefs integerForKey:SPLastFavoriteIndex] forKey:@"DefaultFavorite"]; } [favoritesController removeObjectAtArrangedObjectIndex:[favoritesTableView selectedRow]]; @@ -419,9 +418,9 @@ - (IBAction)updateDefaultFavorite:(id)sender { if ([defaultFavoritePopup indexOfSelectedItem] == 0) { - [prefs setBool:YES forKey:@"SelectLastFavoriteUsed"]; + [prefs setBool:YES forKey:SPSelectLastFavoriteUsed]; } else { - [prefs setBool:NO forKey:@"SelectLastFavoriteUsed"]; + [prefs setBool:NO forKey:SPSelectLastFavoriteUsed]; // Minus 2 from index to account for the "Last Used" and separator items [prefs setInteger:[defaultFavoritePopup indexOfSelectedItem]-2 forKey:@"DefaultFavorite"]; @@ -455,7 +454,7 @@ - (IBAction)displayEditorPreferences:(id)sender { [toolbar setSelectedItemIdentifier:PREFERENCE_TOOLBAR_EDITOR]; - NSFont *nf = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorFont"]]; + NSFont *nf = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]; [editorFontName setStringValue:[NSString stringWithFormat:@"%@, %.1f pt", [nf displayName], [nf pointSize]]]; [self _resizeWindowForContentView:editorView]; } @@ -470,7 +469,7 @@ // Set the default favorite popup back to preference if (sender == [defaultFavoritePopup lastItem]) { - if (![prefs boolForKey:@"SelectLastFavoriteUsed"]) { + if (![prefs boolForKey:SPSelectLastFavoriteUsed]) { [defaultFavoritePopup selectItemAtIndex:[prefs integerForKey:@"DefaultFavorite"]+2]; } else { [defaultFavoritePopup selectItemAtIndex:0]; @@ -590,7 +589,7 @@ draggedRow = [NSMutableDictionary dictionaryWithDictionary:[[favoritesController arrangedObjects] objectAtIndex:originalRow]]; //Before deleting this favorite, we need to save the current index. //because removeObjectAtArrangedObjectIndex will set prefs LastFavoriteIndex to 0 - lastFavoriteIndexCached = [prefs integerForKey:@"LastFavoriteIndex"]; + lastFavoriteIndexCached = [prefs integerForKey:SPLastFavoriteIndex]; [favoritesController removeObjectAtArrangedObjectIndex:originalRow]; [favoritesController insertObject:draggedRow atArrangedObjectIndex:destinationRow]; @@ -600,7 +599,7 @@ // Update default favorite to take on new value if (lastFavoriteIndexCached == originalRow) { - [prefs setInteger:destinationRow forKey:@"LastFavoriteIndex"]; + [prefs setInteger:destinationRow forKey:SPLastFavoriteIndex]; } // Update default favorite to take on new value @@ -964,12 +963,12 @@ ); } - [prefs setBool:value forKey:@"GrowlEnabled"]; + [prefs setBool:value forKey:SPGrowlEnabled]; } - (BOOL)growlEnabled { - return [prefs boolForKey:@"GrowlEnabled"]; + return [prefs boolForKey:SPGrowlEnabled]; } @@ -1002,7 +1001,7 @@ [[[defaultFavoritePopup menu] itemWithTitle:@"Edit Favorites…"] setTarget:self]; // Select the default favorite from prefs - if (![prefs boolForKey:@"SelectLastFavoriteUsed"]) { + if (![prefs boolForKey:SPSelectLastFavoriteUsed]) { [defaultFavoritePopup selectItemAtIndex:[prefs integerForKey:@"DefaultFavorite"] + 2]; } else { [defaultFavoritePopup selectItemAtIndex:0]; @@ -1038,23 +1037,23 @@ // show the font panel - (IBAction)showCustomQueryFontPanel:(id)sender { - [[NSFontPanel sharedFontPanel] setPanelFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorFont"]] isMultiple:NO]; + [[NSFontPanel sharedFontPanel] setPanelFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]] isMultiple:NO]; [[NSFontPanel sharedFontPanel] makeKeyAndOrderFront:self]; } // reset syntax highlighting colors - (IBAction)setDefaultColors:(id)sender { - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.000 green:0.455 blue:0.000 alpha:1.000]] forKey:@"CustomQueryEditorCommentColor"]; - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.769 green:0.102 blue:0.086 alpha:1.000]] forKey:@"CustomQueryEditorQuoteColor"]; - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.200 green:0.250 blue:1.000 alpha:1.000]] forKey:@"CustomQueryEditorSQLKeywordColor"]; - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.000 green:0.000 blue:0.658 alpha:1.000]] forKey:@"CustomQueryEditorBacktickColor"]; - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.506 green:0.263 blue:0.000 alpha:1.000]] forKey:@"CustomQueryEditorNumericColor"]; - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.500 green:0.500 blue:0.500 alpha:1.000]] forKey:@"CustomQueryEditorVariableColor"]; - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.950 green:0.950 blue:0.950 alpha:1.000]] forKey:@"CustomQueryEditorHighlightQueryColor"]; - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:@"CustomQueryEditorTextColor"]; - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:@"CustomQueryEditorCaretColor"]; - [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor whiteColor]] forKey:@"CustomQueryEditorBackgroundColor"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.000 green:0.455 blue:0.000 alpha:1.000]] forKey:SPCustomQueryEditorCommentColor]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.769 green:0.102 blue:0.086 alpha:1.000]] forKey:SPCustomQueryEditorQuoteColor]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.200 green:0.250 blue:1.000 alpha:1.000]] forKey:SPCustomQueryEditorSQLKeywordColor]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.000 green:0.000 blue:0.658 alpha:1.000]] forKey:SPCustomQueryEditorBacktickColor]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.506 green:0.263 blue:0.000 alpha:1.000]] forKey:SPCustomQueryEditorNumericColor]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.500 green:0.500 blue:0.500 alpha:1.000]] forKey:SPCustomQueryEditorVariableColor]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor colorWithDeviceRed:0.950 green:0.950 blue:0.950 alpha:1.000]] forKey:SPCustomQueryEditorHighlightQueryColor]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:SPCustomQueryEditorTextColor]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:SPCustomQueryEditorCaretColor]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[NSColor whiteColor]] forKey:SPCustomQueryEditorBackgroundColor]; } // set font panel's valid modes @@ -1065,8 +1064,8 @@ // Action receiver for a font change in the font panel - (void)changeFont:(id)sender { - NSFont *nf = [[NSFontPanel sharedFontPanel] panelConvertFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"CustomQueryEditorFont"]]]; - [prefs setObject:[NSArchiver archivedDataWithRootObject:nf] forKey:@"CustomQueryEditorFont"]; + NSFont *nf = [[NSFontPanel sharedFontPanel] panelConvertFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:nf] forKey:SPCustomQueryEditorFont]; [editorFontName setStringValue:[NSString stringWithFormat:@"%@, %.1f pt", [nf displayName], [nf pointSize]]]; } diff --git a/Source/SPPrintAccessory.m b/Source/SPPrintAccessory.m index cf0e7ef2..f4b68574 100644 --- a/Source/SPPrintAccessory.m +++ b/Source/SPPrintAccessory.m @@ -76,4 +76,4 @@ [super dealloc]; } -@end
\ No newline at end of file +@end diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h index d030014a..e5b4c557 100644 --- a/Source/SPQueryController.h +++ b/Source/SPQueryController.h @@ -27,7 +27,6 @@ @interface SPQueryController : NSWindowController { - // QueryConsoleController IBOutlet NSView *saveLogView; IBOutlet NSTableView *consoleTableView; diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index c1e632d1..422e1f59 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -26,12 +26,12 @@ #import "SPQueryController.h" #import "SPConsoleMessage.h" #import "SPArrayAdditions.h" +#import "SPConstants.h" #define MESSAGE_TRUNCATE_CHARACTER_LENGTH 256 #define MESSAGE_TIME_STAMP_FORMAT @"%H:%M:%S" #define DEFAULT_CONSOLE_LOG_FILENAME @"untitled" -#define DEFAULT_CONSOLE_LOG_FILE_EXTENSION @"sql" #define CONSOLE_WINDOW_AUTO_SAVE_NAME @"QueryConsole" @@ -131,13 +131,13 @@ static SPQueryController *sharedQueryController = nil; prefs = [NSUserDefaults standardUserDefaults]; [self setWindowFrameAutosaveName:CONSOLE_WINDOW_AUTO_SAVE_NAME]; - [[consoleTableView tableColumnWithIdentifier:TABLEVIEW_DATE_COLUMN_IDENTIFIER] setHidden:![prefs boolForKey:@"ConsoleShowTimestamps"]]; - showSelectStatementsAreDisabled = ![prefs boolForKey:@"ConsoleShowSelectsAndShows"]; - showHelpStatementsAreDisabled = ![prefs boolForKey:@"ConsoleShowHelps"]; + [[consoleTableView tableColumnWithIdentifier:TABLEVIEW_DATE_COLUMN_IDENTIFIER] setHidden:![prefs boolForKey:SPConsoleShowTimestamps]]; + showSelectStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowSelectsAndShows]; + showHelpStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowHelps]; [self _updateFilterState]; - [loggingDisabledTextField setStringValue:([prefs boolForKey:@"ConsoleEnableLogging"]) ? @"" : @"Query logging is currently disabled"]; + [loggingDisabledTextField setStringValue:([prefs boolForKey:SPConsoleEnableLogging]) ? @"" : @"Query logging is currently disabled"]; } /** @@ -158,7 +158,7 @@ static SPQueryController *sharedQueryController = nil; [super dealloc]; } -#pragma mark ---------------------- +#pragma mark - #pragma mark QueryConsoleController @@ -381,7 +381,7 @@ static SPQueryController *sharedQueryController = nil; */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if ([keyPath isEqualToString:@"ConsoleEnableLogging"]) { + if ([keyPath isEqualToString:SPConsoleEnableLogging]) { [loggingDisabledTextField setStringValue:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? @"" : @"Query logging is currently disabled"]; } } @@ -421,7 +421,7 @@ static SPQueryController *sharedQueryController = nil; return @"QueryConsole"; } -#pragma mark ---------------------- +#pragma mark - #pragma mark DocumentsController - (NSURL *)registerDocumentWithFileURL:(NSURL *)fileURL andContextInfo:(NSMutableDictionary *)contextInfo @@ -440,9 +440,9 @@ static SPQueryController *sharedQueryController = nil; // Set the global history coming from the Prefs as default if available if(![historyContainer objectForKey:[new absoluteString]]) { - if([prefs objectForKey:@"queryHistory"]) { + if([prefs objectForKey:SPQueryHistory]) { NSMutableArray *arr = [[NSMutableArray alloc] init]; - [arr addObjectsFromArray:[prefs objectForKey:@"queryHistory"]]; + [arr addObjectsFromArray:[prefs objectForKey:SPQueryHistory]]; [historyContainer setObject:arr forKey:[new absoluteString]]; [arr release]; } else { @@ -464,9 +464,9 @@ static SPQueryController *sharedQueryController = nil; // Register a spf file to manage all query favorites and query history items // file path based (incl. Untitled docs) in a dictionary whereby the key represents the file URL as string. if(![favoritesContainer objectForKey:[fileURL absoluteString]]) { - if(contextInfo != nil && [contextInfo objectForKey:@"queryFavorites"] && [[contextInfo objectForKey:@"queryFavorites"] count]) { + if(contextInfo != nil && [contextInfo objectForKey:SPQueryFavorites] && [[contextInfo objectForKey:SPQueryFavorites] count]) { NSMutableArray *arr = [[NSMutableArray alloc] init]; - [arr addObjectsFromArray:[contextInfo objectForKey:@"queryFavorites"]]; + [arr addObjectsFromArray:[contextInfo objectForKey:SPQueryFavorites]]; [favoritesContainer setObject:arr forKey:[fileURL absoluteString]]; [arr release]; } else { @@ -476,9 +476,9 @@ static SPQueryController *sharedQueryController = nil; } } if(![historyContainer objectForKey:[fileURL absoluteString]]) { - if(contextInfo != nil && [contextInfo objectForKey:@"queryHistory"] && [[contextInfo objectForKey:@"queryHistory"] count]) { + if(contextInfo != nil && [contextInfo objectForKey:SPQueryHistory] && [[contextInfo objectForKey:SPQueryHistory] count]) { NSMutableArray *arr = [[NSMutableArray alloc] init]; - [arr addObjectsFromArray:[contextInfo objectForKey:@"queryHistory"]]; + [arr addObjectsFromArray:[contextInfo objectForKey:SPQueryHistory]]; [historyContainer setObject:arr forKey:[fileURL absoluteString]]; [arr release]; } else { @@ -488,8 +488,8 @@ static SPQueryController *sharedQueryController = nil; } } if(![contentFilterContainer objectForKey:[fileURL absoluteString]]) { - if(contextInfo != nil && [contextInfo objectForKey:@"ContentFilters"]) { - [contentFilterContainer setObject:[contextInfo objectForKey:@"ContentFilters"] forKey:[fileURL absoluteString]]; + if(contextInfo != nil && [contextInfo objectForKey:SPContentFilters]) { + [contentFilterContainer setObject:[contextInfo objectForKey:SPContentFilters] forKey:[fileURL absoluteString]]; } else { NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; [contentFilterContainer setObject:dict forKey:[fileURL absoluteString]]; @@ -558,7 +558,7 @@ static SPQueryController *sharedQueryController = nil; - (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL { - NSUInteger maxHistoryItems = [[prefs objectForKey:@"CustomQueryMaxHistoryItems"] intValue]; + NSUInteger maxHistoryItems = [[prefs objectForKey:SPCustomQueryMaxHistoryItems] intValue]; // Save each history item due to its document source if([historyContainer objectForKey:[fileURL absoluteString]]) { @@ -582,13 +582,13 @@ static SPQueryController *sharedQueryController = nil; // Remove all duplicates by using a NSPopUpButton NSPopUpButton *uniquifier = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0,0,0,0) pullsDown:YES]; - [uniquifier addItemsWithTitles:[prefs objectForKey:@"queryHistory"]]; + [uniquifier addItemsWithTitles:[prefs objectForKey:SPQueryHistory]]; [uniquifier insertItemWithTitle:history atIndex:0]; while ( [uniquifier numberOfItems] > maxHistoryItems ) [uniquifier removeItemAtIndex:[uniquifier numberOfItems]-1]; - [prefs setObject:[uniquifier itemTitles] forKey:@"queryHistory"]; + [prefs setObject:[uniquifier itemTitles] forKey:SPQueryHistory]; [uniquifier release]; } @@ -633,8 +633,8 @@ static SPQueryController *sharedQueryController = nil; [result addObject:fav]; } - if(includeGlobals && [prefs objectForKey:@"queryFavorites"]) { - for(id fav in [prefs objectForKey:@"queryFavorites"]) { + if(includeGlobals && [prefs objectForKey:SPQueryFavorites]) { + for(id fav in [prefs objectForKey:SPQueryFavorites]) { if([fav objectForKey:@"tabtrigger"] && [[fav objectForKey:@"tabtrigger"] isEqualToString:tabTrigger]) [result addObject:fav]; } diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m index eb409500..c499f742 100644 --- a/Source/SPQueryFavoriteManager.m +++ b/Source/SPQueryFavoriteManager.m @@ -27,15 +27,11 @@ #import "ImageAndTextCell.h" #import "SPEncodingPopupAccessory.h" #import "SPQueryController.h" - -#define DEFAULT_QUERY_FAVORITE_FILE_EXTENSION @"sql" -#define DEFAULT_SEQUELPRO_FILE_EXTENSION @"spf" +#import "SPConstants.h" #define SP_MULTIPLE_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[multiple selection]", @"[multiple selection]") #define SP_NO_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[no selection]", @"[no selection]") -#define QUERY_FAVORITES_PB_DRAG_TYPE @"SequelProQueryFavoritesPasteboard" - @interface SPQueryFavoriteManager (Private) - (void)_initWithNoSelection; @end @@ -96,8 +92,8 @@ // Build data source for global queryFavorites (as mutable copy! otherwise each // change will be stored in the prefs at once) - if([prefs objectForKey:@"queryFavorites"]) { - for(id fav in [prefs objectForKey:@"queryFavorites"]) + if([prefs objectForKey:SPQueryFavorites]) { + for(id fav in [prefs objectForKey:SPQueryFavorites]) [favorites addObject:[[fav mutableCopy] autorelease]]; } @@ -294,7 +290,7 @@ [panel setCanSelectHiddenExtension:YES]; [panel setCanCreateDirectories:YES]; - [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[prefs integerForKey:@"lastSqlFileEncoding"] includeDefaultEntry:NO encodingPopUp:&encodingPopUp]]; + [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[prefs integerForKey:SPLastSQLFileEncoding] includeDefaultEntry:NO encodingPopUp:&encodingPopUp]]; [encodingPopUp setEnabled:YES]; @@ -305,7 +301,7 @@ { NSSavePanel *panel = [NSSavePanel savePanel]; - [panel setRequiredFileType:DEFAULT_SEQUELPRO_FILE_EXTENSION]; + [panel setRequiredFileType:DEFAULT_SEQUEL_PRO_FILE_EXTENSION]; [panel setExtensionHidden:NO]; [panel setAllowsOtherFileTypes:NO]; @@ -368,7 +364,7 @@ [self queryFavoritesForFileURL:delegatesFileURL] forFileURL:delegatesFileURL]; // Update global preferences' list - [prefs setObject:[self queryFavoritesForFileURL:nil] forKey:@"queryFavorites"]; + [prefs setObject:[self queryFavoritesForFileURL:nil] forKey:SPQueryFavorites]; // Inform all opened documents to update the query favorites list for(id doc in [[NSDocumentController sharedDocumentController] documents]) @@ -730,17 +726,17 @@ return; } - if([spf objectForKey:@"queryFavorites"] && [[spf objectForKey:@"queryFavorites"] count]) { + if([spf objectForKey:SPQueryFavorites] && [[spf objectForKey:SPQueryFavorites] count]) { // if([favoritesTableView numberOfSelectedRows] > 0) { // // Insert imported queries after the last selected favorite // NSUInteger insertIndex = [[favoritesTableView selectedRowIndexes] lastIndex] + 1; // NSUInteger i; - // for(i=0; i<[[spf objectForKey:@"queryFavorites"] count]; i++) { - // [favorites insertObject:[[spf objectForKey:@"queryFavorites"] objectAtIndex:i] atIndex:insertIndex+i]; + // for(i=0; i<[[spf objectForKey:SPQueryFavorites] count]; i++) { + // [favorites insertObject:[[spf objectForKey:SPQueryFavorites] objectAtIndex:i] atIndex:insertIndex+i]; // } // } else { // // If no selection add them - [favorites addObjectsFromArray:[spf objectForKey:@"queryFavorites"]]; + [favorites addObjectsFromArray:[spf objectForKey:SPQueryFavorites]]; // } [favoritesArrayController rearrangeObjects]; [favoritesTableView reloadData]; @@ -770,7 +766,7 @@ if (returnCode == NSOKButton) { NSError *error = nil; - [prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:@"lastSqlFileEncoding"]; + [prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:SPLastSQLFileEncoding]; [prefs synchronize]; [[favoriteQueryTextView string] writeToFile:[panel filename] atomically:YES encoding:[[encodingPopUp selectedItem] tag] error:&error]; @@ -798,7 +794,7 @@ if([indexes containsIndex:i]) [favoriteData addObject:[favorites objectAtIndex:i]]; - [spfdata setObject:favoriteData forKey:@"queryFavorites"]; + [spfdata setObject:favoriteData forKey:SPQueryFavorites]; NSString *err = nil; NSData *plist = [NSPropertyListSerialization dataFromPropertyList:spfdata diff --git a/Source/SPSSHTunnel.m b/Source/SPSSHTunnel.m index 843acb89..d6a5756f 100644 --- a/Source/SPSSHTunnel.m +++ b/Source/SPSSHTunnel.m @@ -26,6 +26,8 @@ #import "SPSSHTunnel.h" #import "RegexKitLite.h" #import "SPKeychain.h" +#import "SPConstants.h" + #import <netinet/in.h> @implementation SPSSHTunnel @@ -193,10 +195,10 @@ return; } - int connectionTimeout = [[[NSUserDefaults standardUserDefaults] objectForKey:@"ConnectionTimeoutValue"] intValue]; + int connectionTimeout = [[[NSUserDefaults standardUserDefaults] objectForKey:SPConnectionTimeoutValue] intValue]; if (!connectionTimeout) connectionTimeout = 10; - BOOL useKeepAlive = [[[NSUserDefaults standardUserDefaults] objectForKey:@"UseKeepAlive"] doubleValue]; - double keepAliveInterval = [[[NSUserDefaults standardUserDefaults] objectForKey:@"KeepAliveInterval"] doubleValue]; + BOOL useKeepAlive = [[[NSUserDefaults standardUserDefaults] objectForKey:SPUseKeepAlive] doubleValue]; + double keepAliveInterval = [[[NSUserDefaults standardUserDefaults] objectForKey:SPKeepAliveInterval] doubleValue]; if (!keepAliveInterval) keepAliveInterval = 0; // If no local port has yet been chosen, choose one @@ -415,7 +417,7 @@ connectionState = PROXY_STATE_IDLE; [task terminate]; if (lastError) [lastError release]; - lastError = [[NSString alloc] initWithFormat:NSLocalizedString(@"The SSH Tunnel was unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %i seconds).", @"SSH tunnel failed or timed out message"), sshHost, [[[NSUserDefaults standardUserDefaults] objectForKey:@"ConnectionTimeoutValue"] intValue]]; + lastError = [[NSString alloc] initWithFormat:NSLocalizedString(@"The SSH Tunnel was unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %i seconds).", @"SSH tunnel failed or timed out message"), sshHost, [[[NSUserDefaults standardUserDefaults] objectForKey:SPConnectionTimeoutValue] intValue]]; if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO]; } } diff --git a/Source/SPTableData.m b/Source/SPTableData.m index 52911330..efb97540 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -31,6 +31,7 @@ #import "TablesList.h" #import "SPStringAdditions.h" #import "SPArrayAdditions.h" +#import "SPConstants.h" @implementation SPTableData @@ -689,7 +690,7 @@ // Select the column default if available if ([resultRow objectForKey:@"Default"]) { if ([[resultRow objectForKey:@"Default"] isNSNull]) { - [tableColumn setValue:[NSString stringWithString:[[NSUserDefaults standardUserDefaults] objectForKey:@"NullValue"]] forKey:@"default"]; + [tableColumn setValue:[NSString stringWithString:[[NSUserDefaults standardUserDefaults] objectForKey:SPNullValue]] forKey:@"default"]; } else { [tableColumn setValue:[NSString stringWithString:[resultRow objectForKey:@"Default"]] forKey:@"default"]; } diff --git a/Source/SPTableView.m b/Source/SPTableView.m index 1727494a..6e9ccd65 100644 --- a/Source/SPTableView.m +++ b/Source/SPTableView.m @@ -25,6 +25,7 @@ #import "SPTableView.h" #import "SPQueryFavoriteManager.h" #import "SPArrayAdditions.h" +#import "SPConstants.h" @implementation SPTableView @@ -48,7 +49,7 @@ return nil; } if([[[[self delegate] class] description] isEqualToString:@"SPQueryFavoriteManager"]) { - if([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:@"favorites"], row) objectForKey:@"headerOfFileURL"]) + if([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:SPFavorites], row) objectForKey:@"headerOfFileURL"]) return nil; } if([[[[self delegate] class] description] isEqualToString:@"SPContentFilterManager"]) { diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index f3c41fa8..c547c4a5 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -24,6 +24,7 @@ #import "SPStringAdditions.h" #import "SPTextViewAdditions.h" +#import "SPConstants.h" @implementation NSTextView (SPTextViewAdditions) @@ -392,8 +393,8 @@ { id prefs = [NSUserDefaults standardUserDefaults]; if([self respondsToSelector:@selector(insertText:)]) - if([prefs objectForKey:@"NullValue"] && [[prefs objectForKey:@"NullValue"] length]) - [self insertText:[prefs objectForKey:@"NullValue"]]; + if([prefs objectForKey:SPNullValue] && [[prefs objectForKey:SPNullValue] length]) + [self insertText:[prefs objectForKey:SPNullValue]]; else [self insertText:@"NULL"]; diff --git a/Source/TableContent.m b/Source/TableContent.m index 1c5551c6..ed74a005 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -47,7 +47,7 @@ #import "RegexKitLite.h" #import "SPContentFilterManager.h" #import "SPNotLoaded.h" - +#import "SPConstants.h" @implementation TableContent @@ -118,7 +118,7 @@ - (void)awakeFromNib { // Set the table content view's vertical gridlines if required - [tableContentView setGridStyleMask:([prefs boolForKey:@"DisplayTableViewVerticalGridlines"]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + [tableContentView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } #pragma mark - @@ -237,7 +237,7 @@ } } - NSString *nullValue = [prefs objectForKey:@"NullValue"]; + NSString *nullValue = [prefs objectForKey:SPNullValue]; // Add the new columns to the table for ( i = 0 ; i < [dataColumns count] ; i++ ) { @@ -283,7 +283,7 @@ } // Set the data cell font according to the preferences - if ( [prefs boolForKey:@"UseMonospacedFonts"] ) { + if ( [prefs boolForKey:SPUseMonospacedFonts] ) { [dataCell setFont:[NSFont fontWithName:@"Monaco" size:10]]; } else { [dataCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; @@ -293,7 +293,7 @@ [theCol setDataCell:dataCell]; // Set the width of this column to saved value if exists - colWidth = [[[[prefs objectForKey:@"tableColumnWidths"] objectForKey:[NSString stringWithFormat:@"%@@%@", [tableDocumentInstance database], [tableDocumentInstance host]]] objectForKey:[tablesListInstance tableName]] objectForKey:[columnDefinition objectForKey:@"name"]]; + colWidth = [[[[prefs objectForKey:SPTableColumnWidths] objectForKey:[NSString stringWithFormat:@"%@@%@", [tableDocumentInstance database], [tableDocumentInstance host]]] objectForKey:[tablesListInstance tableName]] objectForKey:[columnDefinition objectForKey:@"name"]]; if ( colWidth ) { [theCol setWidth:[colWidth floatValue]]; } @@ -371,7 +371,7 @@ [tableWindow makeFirstResponder:currentFirstResponder]; // Enable or disable the limit fields according to preference setting - if ( [prefs boolForKey:@"LimitResults"] ) { + if ( [prefs boolForKey:SPLimitResults] ) { // Preserve the limit field - if this is beyond the current number of rows, // reloadData will reset as necessary. @@ -464,7 +464,7 @@ } // Check to see if a limit needs to be applied - if ([prefs boolForKey:@"LimitResults"]) { + if ([prefs boolForKey:SPLimitResults]) { // Ensure the limit isn't negative if ([limitRowsField intValue] <= 0) { @@ -478,11 +478,11 @@ } // Append the limit settings - [queryString appendFormat:@" LIMIT %d,%d", [limitRowsField intValue]-1, [prefs integerForKey:@"LimitResultsValue"]]; + [queryString appendFormat:@" LIMIT %d,%d", [limitRowsField intValue]-1, [prefs integerForKey:SPLimitResultsValue]]; // Update the approximate count of the rows to load rowsToLoad = rowsToLoad - ([limitRowsField intValue]-1); - if (rowsToLoad > [prefs integerForKey:@"LimitResultsValue"]) rowsToLoad = [prefs integerForKey:@"LimitResultsValue"]; + if (rowsToLoad > [prefs integerForKey:SPLimitResultsValue]) rowsToLoad = [prefs integerForKey:SPLimitResultsValue]; } // Perform and process the query @@ -492,18 +492,18 @@ [streamingResult release]; // If the result is empty, and a limit is active, reset the limit - if ([prefs boolForKey:@"LimitResults"] && queryStringBeforeLimit && ![tableValues count]) { + if ([prefs boolForKey:SPLimitResults] && queryStringBeforeLimit && ![tableValues count]) { [limitRowsField setStringValue:@"1"]; - queryString = [NSMutableString stringWithFormat:@"%@ LIMIT 0,%d", queryStringBeforeLimit, [prefs integerForKey:@"LimitResultsValue"]]; + queryString = [NSMutableString stringWithFormat:@"%@ LIMIT 0,%d", queryStringBeforeLimit, [prefs integerForKey:SPLimitResultsValue]]; [self setUsedQuery:queryString]; streamingResult = [mySQLConnection streamingQueryString:queryString]; - [self processResultIntoDataStorage:streamingResult approximateRowCount:[prefs integerForKey:@"LimitResultsValue"]]; + [self processResultIntoDataStorage:streamingResult approximateRowCount:[prefs integerForKey:SPLimitResultsValue]]; [streamingResult release]; } - if ([prefs boolForKey:@"LimitResults"] + if ([prefs boolForKey:SPLimitResults] && ([limitRowsField intValue] > 1 - || [tableValues count] == [prefs integerForKey:@"LimitResultsValue"])) + || [tableValues count] == [prefs integerForKey:SPLimitResultsValue])) { isLimited = YES; } else { @@ -756,8 +756,8 @@ } // If limitRowsField > number of total table rows show the last limitRowsValue rows - if ([prefs boolForKey:@"LimitResults"] && [limitRowsField intValue] >= maxNumRows) { - int newLimit = maxNumRows - [prefs integerForKey:@"LimitResultsValue"]; + if ([prefs boolForKey:SPLimitResults] && [limitRowsField intValue] >= maxNumRows) { + int newLimit = maxNumRows - [prefs integerForKey:SPLimitResultsValue]; [limitRowsField setStringValue:[[NSNumber numberWithInt:(newLimit<1)?1:newLimit] stringValue]]; } @@ -894,7 +894,7 @@ [tableValues insertObject:tempRow atIndex:[tableContentView selectedRow]+1]; //if we don't show blobs, read data for this duplicate column from db - if ([prefs boolForKey:@"LoadBlobsAsNeeded"]) { + if ([prefs boolForKey:SPLoadBlobsAsNeeded]) { // Abort if there are no indices on this table - argumentForRow will display an error. if (![[self argumentForRow:[tableContentView selectedRow]] length]){ return; @@ -911,7 +911,7 @@ row = [queryResult fetchRowAsDictionary]; if ( [[row objectForKey:@"Extra"] isEqualToString:@"auto_increment"] ) { [tempRow replaceObjectAtIndex:i withObject:[NSNull null]]; - } else if ( [tableDataInstance columnIsBlobOrText:[row objectForKey:@"Field"]] && [prefs boolForKey:@"LoadBlobsAsNeeded"] && dbDataRow) { + } else if ( [tableDataInstance columnIsBlobOrText:[row objectForKey:@"Field"]] && [prefs boolForKey:SPLoadBlobsAsNeeded] && dbDataRow) { [tempRow replaceObjectAtIndex:i withObject:[dbDataRow objectAtIndex:i]]; } } @@ -1076,7 +1076,7 @@ [tableContentView setVerticalMotionCanBeginDrag:NO]; - if ( [prefs boolForKey:@"UseMonospacedFonts"] ) { + if ( [prefs boolForKey:SPUseMonospacedFonts] ) { [argumentField setFont:[NSFont fontWithName:@"Monaco" size:10]]; [limitRowsField setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; } else { @@ -1084,7 +1084,7 @@ [argumentField setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; } [limitRowsStepper setEnabled:NO]; - if ( ![prefs boolForKey:@"LimitResults"] ) { + if ( ![prefs boolForKey:SPLimitResults] ) { [limitRowsField setStringValue:@""]; } } @@ -1215,11 +1215,11 @@ } // Load global user-defined content filters - if([prefs objectForKey:@"ContentFilters"] + if([prefs objectForKey:SPContentFilters] && [contentFilters objectForKey:compareType] - && [[prefs objectForKey:@"ContentFilters"] objectForKey:compareType]) + && [[prefs objectForKey:SPContentFilters] objectForKey:compareType]) { - [[contentFilters objectForKey:compareType] addObjectsFromArray:[[prefs objectForKey:@"ContentFilters"] objectForKey:compareType]]; + [[contentFilters objectForKey:compareType] addObjectsFromArray:[[prefs objectForKey:SPContentFilters] objectForKey:compareType]]; } // Load doc-based user-defined content filters @@ -1295,14 +1295,14 @@ */ { if ( [limitRowsStepper intValue] > 0 ) { - int newStep = [limitRowsField intValue]+[prefs integerForKey:@"LimitResultsValue"]; + int newStep = [limitRowsField intValue]+[prefs integerForKey:SPLimitResultsValue]; // if newStep > the total number of rows in the current table retain the old value [limitRowsField setIntValue:(newStep>maxNumRows)?[limitRowsField intValue]:newStep]; } else { - if ( ([limitRowsField intValue]-[prefs integerForKey:@"LimitResultsValue"]) < 1 ) { + if ( ([limitRowsField intValue]-[prefs integerForKey:SPLimitResultsValue]) < 1 ) { [limitRowsField setIntValue:1]; } else { - [limitRowsField setIntValue:[limitRowsField intValue]-[prefs integerForKey:@"LimitResultsValue"]]; + [limitRowsField setIntValue:[limitRowsField intValue]-[prefs integerForKey:SPLimitResultsValue]]; } } [limitRowsStepper setIntValue:0]; @@ -1329,7 +1329,7 @@ NSAutoreleasePool *dataLoadingPool; NSProgressIndicator *dataLoadingIndicator = [tableDocumentInstance valueForKey:@"queryProgressBar"]; - BOOL prefsLoadBlobsAsNeeded = [prefs boolForKey:@"LoadBlobsAsNeeded"]; + BOOL prefsLoadBlobsAsNeeded = [prefs boolForKey:SPLoadBlobsAsNeeded]; // Build up an array of which columns are blobs for faster iteration for ( i = 0; i < columnsCount ; i++ ) { @@ -1403,7 +1403,7 @@ id rowObject; NSMutableString *rowValue = [NSMutableString string]; NSString *currentTime = [[NSDate date] descriptionWithCalendarFormat:@"%H:%M:%S" timeZone:nil locale:nil]; - BOOL prefsLoadBlobsAsNeeded = [prefs boolForKey:@"LoadBlobsAsNeeded"]; + BOOL prefsLoadBlobsAsNeeded = [prefs boolForKey:SPLoadBlobsAsNeeded]; int i; if ( !isEditingRow || currentlyEditingRow == -1) { @@ -1500,7 +1500,7 @@ // If no rows have been changed, show error if appropriate. if ( ![mySQLConnection affectedRows] && ![mySQLConnection getLastErrorMessage] && ![[mySQLConnection getLastErrorMessage] length]) { - if ( [prefs boolForKey:@"ShowNoAffectedRowsError"] ) { + if ( [prefs boolForKey:SPShowNoAffectedRowsError] ) { NSBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, NSLocalizedString(@"The row was not written to the MySQL database. You probably haven't changed anything.\nReload the table to be sure that the row exists and use a primary key for your table.\n(This error can be turned off in the preferences.)", @"message of panel when no rows have been affected after writing to the db")); } else { @@ -1519,7 +1519,7 @@ // New row created successfully if ( isEditingNewRow ) { - if ( [prefs boolForKey:@"ReloadAfterAddingRow"] ) { + if ( [prefs boolForKey:SPReloadAfterAddingRow] ) { [self loadTableValues]; [tableWindow endEditingFor:nil]; [tableContentView reloadData]; @@ -1538,7 +1538,7 @@ } else { // Reload table if set to - otherwise no action required. - if ( [prefs boolForKey:@"ReloadAfterEditingRow"] ) { + if ( [prefs boolForKey:SPReloadAfterEditingRow] ) { [self loadTableValues]; [tableWindow endEditingFor:nil]; [tableContentView reloadData]; @@ -1629,7 +1629,7 @@ // When the option to not show blob or text options is set, we have a problem - we don't have // the right values to use in the WHERE statement. Throw an error if this is the case. - if ( [prefs boolForKey:@"LoadBlobsAsNeeded"] && [self tableContainsBlobOrTextColumns] ) { + if ( [prefs boolForKey:SPLoadBlobsAsNeeded] && [self tableContainsBlobOrTextColumns] ) { NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, NSLocalizedString(@"You can't hide blob and text fields when working with tables without index.", @"message of panel when trying to edit tables without index and with hidden blob/text fields")); [keys removeAllObjects]; @@ -1701,7 +1701,7 @@ NSMutableArray *fields = [NSMutableArray array]; NSArray *columnNames = [tableDataInstance columnNames]; - if ( [prefs boolForKey:@"LoadBlobsAsNeeded"] ) { + if ( [prefs boolForKey:SPLoadBlobsAsNeeded] ) { for ( i = 0 ; i < [columnNames count] ; i++ ) { if (![tableDataInstance columnIsBlobOrText:[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"name"]] ) { [fields addObject:[NSArrayObjectAtIndex(columnNames, i) backtickQuotedString]]; @@ -1730,7 +1730,7 @@ NSString *wherePart; NSInteger i, errors; BOOL consoleUpdateStatus; - BOOL reloadAfterRemovingRow = [prefs boolForKey:@"ReloadAfterRemovingRow"]; + BOOL reloadAfterRemovingRow = [prefs boolForKey:SPReloadAfterRemovingRow]; if([sheet respondsToSelector:@selector(orderOut:)]) [sheet orderOut:self]; @@ -1837,7 +1837,7 @@ } index = [selectedRows indexGreaterThanIndex:index]; } - } else if ([primaryKeyFieldNames count] == 1) { + } else if ([primaryKeyFieldNames count] == 1) { // if table has only one PRIMARY KEY // delete the fast way by using the PRIMARY KEY in an IN clause NSMutableString *deleteQuery = [NSMutableString string]; @@ -1884,18 +1884,18 @@ // delete the row by using all PRIMARY KEYs in an OR clause NSMutableString *deleteQuery = [NSMutableString string]; NSInteger affectedRows = 0; - + [deleteQuery setString:[NSString stringWithFormat:@"DELETE FROM %@ WHERE ", [selectedTable backtickQuotedString]]]; - + while (index != NSNotFound) { - + // Build the AND clause of PRIMARY KEYS [deleteQuery appendString:@"("]; for(NSString *primaryKeyFieldName in primaryKeyFieldNames) { - - + + id keyValue = [NSArrayObjectAtIndex(tableValues, index) objectAtIndex:[[[tableDataInstance columnWithName:primaryKeyFieldName] objectForKey:@"datacolumnindex"] intValue]]; - + [deleteQuery appendString:[primaryKeyFieldName backtickQuotedString]]; if ([keyValue isKindOfClass:[NSData class]]) { [deleteQuery appendString:@"=X'"]; @@ -1910,7 +1910,7 @@ // Remove the trailing AND and add the closing bracket [deleteQuery deleteCharactersInRange:NSMakeRange([deleteQuery length]-5, 5)]; [deleteQuery appendString:@")"]; - + // Split deletion query into 64k chunks if([deleteQuery length] > 64000) { [mySQLConnection queryString:deleteQuery]; @@ -1921,10 +1921,10 @@ } else { [deleteQuery appendString:@" OR "]; } - + index = [selectedRows indexGreaterThanIndex:index]; } - + // Check if deleteQuery's maximal length was reached for the last index // if yes omit the empty query if(![deleteQuery hasSuffix:@"WHERE "]) { @@ -1944,21 +1944,21 @@ NSArray *message; if(errors < 0) { message = [NSArray arrayWithObjects:NSLocalizedString(@"Warning", @"warning"), - [NSString stringWithFormat:NSLocalizedString(@"%d row%@ more %@ removed! Please check the Console and inform the Sequel Pro team!", @"message of panel when more rows were deleted"), errors*-1, ((errors*-1)>1)?@"s":@"", (errors>1)?@"were":@"was"], - nil]; + [NSString stringWithFormat:NSLocalizedString(@"%d row%@ more %@ removed! Please check the Console and inform the Sequel Pro team!", @"message of panel when more rows were deleted"), errors*-1, ((errors*-1)>1)?@"s":@"", (errors>1)?@"were":@"was"], + nil]; } else { if(primaryKeyFieldNames == nil) message = [NSArray arrayWithObjects:NSLocalizedString(@"Warning", @"warning"), - [NSString stringWithFormat:NSLocalizedString(@"%d row%@ ha%@ not been removed. Reload the table to be sure that the rows exist and use a primary key for your table.", @"message of panel when not all selected fields have been deleted"), errors, (errors>1)?@"s":@"", (errors>1)?@"ve":@"s"], - nil]; + [NSString stringWithFormat:NSLocalizedString(@"%d row%@ ha%@ not been removed. Reload the table to be sure that the rows exist and use a primary key for your table.", @"message of panel when not all selected fields have been deleted"), errors, (errors>1)?@"s":@"", (errors>1)?@"ve":@"s"], + nil]; else message = [NSArray arrayWithObjects:NSLocalizedString(@"Warning", @"warning"), - [NSString stringWithFormat:NSLocalizedString(@"%d row%@ ha%@ not been removed. Reload the table to be sure that the rows exist and check the Console for possible errors inside the primary key%@ for your table.", @"message of panel when not all selected fields have been deleted by using primary keys"), errors, (errors>1)?@"s":@"", (errors>1)?@"ve":@"s", (errors>1)?@"s":@""], - nil]; + [NSString stringWithFormat:NSLocalizedString(@"%d row%@ ha%@ not been removed. Reload the table to be sure that the rows exist and check the Console for possible errors inside the primary key%@ for your table.", @"message of panel when not all selected fields have been deleted by using primary keys"), errors, (errors>1)?@"s":@"", (errors>1)?@"ve":@"s", (errors>1)?@"s":@""], + nil]; } [self performSelector:@selector(showErrorSheetWith:) - withObject:message - afterDelay:0.3]; + withObject:message + afterDelay:0.3]; } // Refresh table content @@ -2188,7 +2188,7 @@ maxNumRowsIsEstimate = NO; // Choose whether to display an estimate, or to fetch the correct row count, based on prefs - } else if ([prefs boolForKey:@"FetchCorrectRowCount"]) { + } else if ([prefs boolForKey:SPFetchCorrectRowCount]) { maxNumRows = [self fetchNumberOfRows]; maxNumRowsIsEstimate = NO; [tableDataInstance setStatusValue:[NSString stringWithFormat:@"%d", maxNumRows] forKey:@"Rows"]; @@ -2269,7 +2269,7 @@ return [theValue shortStringRepresentationUsingEncoding:[mySQLConnection encoding]]; if ([theValue isNSNull]) - return [prefs objectForKey:@"NullValue"]; + return [prefs objectForKey:SPNullValue]; if ([theValue isSPNotLoaded]) return NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields"); @@ -2319,7 +2319,7 @@ if (anObject) { // Restore NULLs if necessary - if ([anObject isEqualToString:[prefs objectForKey:@"NullValue"]] && [[column objectForKey:@"null"] boolValue]) + if ([anObject isEqualToString:[prefs objectForKey:SPNullValue]] && [[column objectForKey:@"null"] boolValue]) anObject = [NSNull null]; [NSArrayObjectAtIndex(tableValues, rowIndex) replaceObjectAtIndex:[[aTableColumn identifier] intValue] withObject:anObject]; @@ -2414,8 +2414,8 @@ NSString *table = [tablesListInstance tableName]; // get tableColumnWidths object - if ( [prefs objectForKey:@"tableColumnWidths"] != nil ) { - tableColumnWidths = [NSMutableDictionary dictionaryWithDictionary:[prefs objectForKey:@"tableColumnWidths"]]; + if ( [prefs objectForKey:SPTableColumnWidths] != nil ) { + tableColumnWidths = [NSMutableDictionary dictionaryWithDictionary:[prefs objectForKey:SPTableColumnWidths]]; } else { tableColumnWidths = [NSMutableDictionary dictionary]; } @@ -2435,7 +2435,7 @@ } // save column size [[[tableColumnWidths objectForKey:database] objectForKey:table] setObject:[NSNumber numberWithFloat:[[[aNotification userInfo] objectForKey:@"NSTableColumn"] width]] forKey:[[[[aNotification userInfo] objectForKey:@"NSTableColumn"] headerCell] stringValue]]; - [prefs setObject:tableColumnWidths forKey:@"tableColumnWidths"]; + [prefs setObject:tableColumnWidths forKey:SPTableColumnWidths]; } /** @@ -2478,7 +2478,7 @@ [fieldEditor setTextMaxLength:[[[aTableColumn dataCellForRow:rowIndex] formatter] textLimit]]; id cellValue = [[tableValues objectAtIndex:rowIndex] objectAtIndex:[[aTableColumn identifier] intValue]]; - if ([cellValue isNSNull]) cellValue = [NSString stringWithString:[prefs objectForKey:@"NullValue"]]; + if ([cellValue isNSNull]) cellValue = [NSString stringWithString:[prefs objectForKey:SPNullValue]]; id editData = [[fieldEditor editWithObject:cellValue fieldName:[[aTableColumn headerCell] stringValue] @@ -2494,7 +2494,7 @@ currentlyEditingRow = rowIndex; } - if ([editData isEqualToString:[prefs objectForKey:@"NullValue"]] + if ([editData isEqualToString:[prefs objectForKey:SPNullValue]] && [[NSArrayObjectAtIndex(dataColumns, [[aTableColumn identifier] intValue]) objectForKey:@"null"] boolValue]) { [editData release]; @@ -2638,7 +2638,7 @@ */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if ([keyPath isEqualToString:@"DisplayTableViewVerticalGridlines"]) { + if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { [tableContentView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } } diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 46423f2c..82092668 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -50,6 +50,7 @@ #import "QLPreviewPanel.h" #import "SPUserManager.h" #import "SPEncodingPopupAccessory.h" +#import "SPConstants.h" // Used for printing #import "MGTemplateEngine.h" @@ -152,15 +153,15 @@ connectionController = [[SPConnectionController alloc] initWithDocument:self]; // 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]; + [prefs addObserver:tableSourceInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:tableContentInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:customQueryInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL]; // Register observers for when the logging preference changes - [prefs addObserver:[SPQueryController sharedQueryController] forKeyPath:@"ConsoleEnableLogging" options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:[SPQueryController sharedQueryController] forKeyPath:SPConsoleEnableLogging options:NSKeyValueObservingOptionNew context:NULL]; // Register a second observer for when the logging preference changes so we can tell the current connection about it - [prefs addObserver:self forKeyPath:@"ConsoleEnableLogging" options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:self forKeyPath:SPConsoleEnableLogging options:NSKeyValueObservingOptionNew context:NULL]; // 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]; @@ -447,12 +448,12 @@ [self setFileURL:[NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:path]]; - if([spf objectForKey:@"queryFavorites"]) - [spfPreferences setObject:[spf objectForKey:@"queryFavorites"] forKey:@"queryFavorites"]; - if([spf objectForKey:@"queryHistory"]) - [spfPreferences setObject:[spf objectForKey:@"queryHistory"] forKey:@"queryHistory"]; - if([spf objectForKey:@"ContentFilters"]) - [spfPreferences setObject:[spf objectForKey:@"ContentFilters"] forKey:@"ContentFilters"]; + if([spf objectForKey:SPQueryFavorites]) + [spfPreferences setObject:[spf objectForKey:SPQueryFavorites] forKey:SPQueryFavorites]; + if([spf objectForKey:SPQueryHistory]) + [spfPreferences setObject:[spf objectForKey:SPQueryHistory] forKey:SPQueryHistory]; + if([spf objectForKey:SPContentFilters]) + [spfPreferences setObject:[spf objectForKey:SPContentFilters] forKey:SPContentFilters]; [spfDocData setObject:[NSNumber numberWithBool:([connection objectForKey:@"password"]) ? YES : NO] forKey:@"save_password"]; @@ -580,7 +581,7 @@ [spfPreferences release]; // Set the connection encoding - NSString *encodingName = [prefs objectForKey:@"DefaultEncoding"]; + NSString *encodingName = [prefs objectForKey:SPDefaultEncoding]; if ( [encodingName isEqualToString:@"Autodetect"] ) { [self setConnectionEncoding:[self databaseEncoding] reloadingViews:NO]; } else { @@ -1988,7 +1989,7 @@ */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if ([keyPath isEqualToString:@"ConsoleEnableLogging"]) { + if ([keyPath isEqualToString:SPConsoleEnableLogging]) { [mySQLConnection setDelegateQueryLogging:[[change objectForKey:NSKeyValueChangeNewKey] boolValue]]; } } @@ -2137,7 +2138,7 @@ if( sender != nil && [sender tag] == 1006 ) { // Save the editor's content as SQL file - [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[prefs integerForKey:@"lastSqlFileEncoding"] + [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[prefs integerForKey:SPLastSQLFileEncoding] includeDefaultEntry:NO encodingPopUp:&encodingPopUp]]; // [panel setMessage:NSLocalizedString(@"Save SQL file", @"Save SQL file")]; [panel setAllowedFileTypes:[NSArray arrayWithObjects:@"sql", nil]]; @@ -2150,8 +2151,8 @@ contextInfo = @"saveSQLfile"; // If no lastSqlFileEncoding in prefs set it to UTF-8 - if(![prefs integerForKey:@"lastSqlFileEncoding"]) { - [prefs setInteger:4 forKey:@"lastSqlFileEncoding"]; + if(![prefs integerForKey:SPLastSQLFileEncoding]) { + [prefs setInteger:4 forKey:SPLastSQLFileEncoding]; [prefs synchronize]; } @@ -2253,7 +2254,7 @@ // Save file as SQL file by using the chosen encoding if(contextInfo == @"saveSQLfile") { - [prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:@"lastSqlFileEncoding"]; + [prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:SPLastSQLFileEncoding]; [prefs setObject:[fileName lastPathComponent] forKey:@"lastSqlFileName"]; [prefs synchronize]; @@ -2354,9 +2355,9 @@ } // Update the keys - [spf setObject:[[SPQueryController sharedQueryController] favoritesForFileURL:[self fileURL]] forKey:@"queryFavorites"]; - [spf setObject:[[SPQueryController sharedQueryController] historyForFileURL:[self fileURL]] forKey:@"queryHistory"]; - [spf setObject:[[SPQueryController sharedQueryController] contentFilterForFileURL:[self fileURL]] forKey:@"ContentFilters"]; + [spf setObject:[[SPQueryController sharedQueryController] favoritesForFileURL:[self fileURL]] forKey:SPQueryFavorites]; + [spf setObject:[[SPQueryController sharedQueryController] historyForFileURL:[self fileURL]] forKey:SPQueryHistory]; + [spf setObject:[[SPQueryController sharedQueryController] contentFilterForFileURL:[self fileURL]] forKey:SPContentFilters]; // Save it again NSString *err = nil; @@ -2405,9 +2406,9 @@ [spfdata setObject:[self mySQLVersion] forKey:@"rdbms_version"]; // Store the preferences - take them from the current document URL to catch renaming - [spfdata setObject:[[SPQueryController sharedQueryController] favoritesForFileURL:[self fileURL]] forKey:@"queryFavorites"]; - [spfdata setObject:[[SPQueryController sharedQueryController] historyForFileURL:[self fileURL]] forKey:@"queryHistory"]; - [spfdata setObject:[[SPQueryController sharedQueryController] contentFilterForFileURL:[self fileURL]] forKey:@"ContentFilters"]; + [spfdata setObject:[[SPQueryController sharedQueryController] favoritesForFileURL:[self fileURL]] forKey:SPQueryFavorites]; + [spfdata setObject:[[SPQueryController sharedQueryController] historyForFileURL:[self fileURL]] forKey:SPQueryHistory]; + [spfdata setObject:[[SPQueryController sharedQueryController] contentFilterForFileURL:[self fileURL]] forKey:SPContentFilters]; [spfdata setObject:[spfDocData_temp objectForKey:@"encrypted"] forKey:@"encrypted"]; @@ -2560,9 +2561,9 @@ // Register and update query favorites, content filter, and history for the (new) file URL NSMutableDictionary *preferences = [[NSMutableDictionary alloc] init]; - [preferences setObject:[spfdata objectForKey:@"queryHistory"] forKey:@"queryHistory"]; - [preferences setObject:[spfdata objectForKey:@"queryFavorites"] forKey:@"queryFavorites"]; - [preferences setObject:[spfdata objectForKey:@"ContentFilters"] forKey:@"ContentFilters"]; + [preferences setObject:[spfdata objectForKey:SPQueryHistory] forKey:SPQueryHistory]; + [preferences setObject:[spfdata objectForKey:SPQueryFavorites] forKey:SPQueryFavorites]; + [preferences setObject:[spfdata objectForKey:SPContentFilters] forKey:SPContentFilters]; [[SPQueryController sharedQueryController] registerDocumentWithFileURL:[NSURL URLWithString:[fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] andContextInfo:preferences]; [self setFileURL:[NSURL URLWithString:[fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; @@ -3187,7 +3188,7 @@ name:@"NSApplicationWillTerminateNotification" object:nil]; //set up interface - if ( [prefs boolForKey:@"UseMonospacedFonts"] ) { + if ( [prefs boolForKey:SPUseMonospacedFonts] ) { [[SPQueryController sharedQueryController] setConsoleFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; while ( (theCol = [theCols nextObject]) ) { @@ -3299,10 +3300,10 @@ */ - (void)willQueryString:(NSString *)query connection:(id)connection { - if ([prefs boolForKey:@"ConsoleEnableLogging"]) { - if ((_queryMode == SP_QUERYMODE_INTERFACE && [prefs boolForKey:@"ConsoleEnableInterfaceLogging"]) - || (_queryMode == SP_QUERYMODE_CUSTOMQUERY && [prefs boolForKey:@"ConsoleEnableCustomQueryLogging"]) - || (_queryMode == SP_QUERYMODE_IMPORTEXPORT && [prefs boolForKey:@"ConsoleEnableImportExportLogging"])) + if ([prefs boolForKey:SPConsoleEnableLogging]) { + if ((_queryMode == SP_QUERYMODE_INTERFACE && [prefs boolForKey:SPConsoleEnableInterfaceLogging]) + || (_queryMode == SP_QUERYMODE_CUSTOMQUERY && [prefs boolForKey:SPConsoleEnableCustomQueryLogging]) + || (_queryMode == SP_QUERYMODE_IMPORTEXPORT && [prefs boolForKey:SPConsoleEnableImportExportLogging])) { [[SPQueryController sharedQueryController] showMessageInConsole:query]; } @@ -3314,7 +3315,7 @@ */ - (void)queryGaveError:(NSString *)error connection:(id)connection { - if ([prefs boolForKey:@"ConsoleEnableLogging"] && [prefs boolForKey:@"ConsoleEnableErrorLogging"]) { + if ([prefs boolForKey:SPConsoleEnableLogging] && [prefs boolForKey:SPEnableErrorLogging]) { [[SPQueryController sharedQueryController] showErrorInConsole:error]; } } diff --git a/Source/TableDump.m b/Source/TableDump.m index d5e6d563..abb2e258 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -36,6 +36,7 @@ #import "SPStringAdditions.h" #import "SPArrayAdditions.h" #import "RegexKitLite.h" +#import "SPConstants.h" @implementation TableDump @@ -426,11 +427,11 @@ } // Preset the accessory view with prefs defaults - [importFieldsTerminatedField setStringValue:[prefs objectForKey:@"CSVImportFieldTerminator"]]; - [importLinesTerminatedField setStringValue:[prefs objectForKey:@"CSVImportLineTerminator"]]; - [importFieldsEscapedField setStringValue:[prefs objectForKey:@"CSVImportFieldEscapeCharacter"]]; - [importFieldsEnclosedField setStringValue:[prefs objectForKey:@"CSVImportFieldEnclosedBy"]]; - [importFieldNamesSwitch setState:[[prefs objectForKey:@"CSVImportFirstLineIsHeader"] boolValue]]; + [importFieldsTerminatedField setStringValue:[prefs objectForKey:SPCSVImportFieldTerminator]]; + [importLinesTerminatedField setStringValue:[prefs objectForKey:SPCSVImportLineTerminator]]; + [importFieldsEscapedField setStringValue:[prefs objectForKey:SPCSVImportFieldEscapeCharacter]]; + [importFieldsEnclosedField setStringValue:[prefs objectForKey:SPCSVImportFieldEnclosedBy]]; + [importFieldNamesSwitch setState:[[prefs objectForKey:SPCSVImportFirstLineIsHeader] boolValue]]; [openPanel setAccessoryView:importCSVView]; [openPanel setDelegate:self]; @@ -780,18 +781,18 @@ csvParser = [[SPCSVParser alloc] init]; // Store settings in prefs - [prefs setObject:[importFieldsEnclosedField stringValue] forKey:@"CSVImportFieldEnclosedBy"]; - [prefs setObject:[importFieldsEscapedField stringValue] forKey:@"CSVImportFieldEscapeCharacter"]; - [prefs setObject:[importLinesTerminatedField stringValue] forKey:@"CSVImportLineTerminator"]; - [prefs setObject:[importFieldsTerminatedField stringValue] forKey:@"CSVImportFieldTerminator"]; - [prefs setBool:[importFieldNamesSwitch state] forKey:@"CSVImportFirstLineIsHeader"]; + [prefs setObject:[importFieldsEnclosedField stringValue] forKey:SPCSVImportFieldEnclosedBy]; + [prefs setObject:[importFieldsEscapedField stringValue] forKey:SPCSVImportFieldEscapeCharacter]; + [prefs setObject:[importLinesTerminatedField stringValue] forKey:SPCSVImportLineTerminator]; + [prefs setObject:[importFieldsTerminatedField stringValue] forKey:SPCSVImportFieldTerminator]; + [prefs setBool:[importFieldNamesSwitch state] forKey:SPCSVImportFirstLineIsHeader]; // Take CSV import setting from accessory view [csvParser setFieldTerminatorString:[importFieldsTerminatedField stringValue] convertDisplayStrings:YES]; [csvParser setLineTerminatorString:[importLinesTerminatedField stringValue] convertDisplayStrings:YES]; [csvParser setFieldQuoteString:[importFieldsEnclosedField stringValue] convertDisplayStrings:YES]; [csvParser setEscapeString:[importFieldsEscapedField stringValue] convertDisplayStrings:YES]; - [csvParser setNullReplacementString:[prefs objectForKey:@"NullValue"]]; + [csvParser setNullReplacementString:[prefs objectForKey:SPNullValue]]; csvDataBuffer = [[NSMutableData alloc] init]; importPool = [[NSAutoreleasePool alloc] init]; @@ -1178,7 +1179,7 @@ [fieldMappingButtonOptions setArray:[fieldMappingImportArray objectAtIndex:fieldMappingCurrentRow]]; for (i = 0; i < [fieldMappingButtonOptions count]; i++) { if ([[fieldMappingButtonOptions objectAtIndex:i] isNSNull]) { - [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, [prefs objectForKey:@"NullValue"]]]; + [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, [prefs objectForKey:SPNullValue]]]; } else { [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, NSArrayObjectAtIndex(fieldMappingButtonOptions, i)]]; } @@ -1762,7 +1763,7 @@ NSArray *csvRow; id csvCell; NSMutableString *csvString = [NSMutableString string]; - NSString *nullString = [NSString stringWithString:[prefs objectForKey:@"NullValue"]]; + NSString *nullString = [NSString stringWithString:[prefs objectForKey:SPNullValue]]; NSString *escapedEscapeString, *escapedFieldSeparatorString, *escapedEnclosingString, *escapedLineEndString; NSString *dataConversionString; NSInteger currentRowIndex; @@ -2496,7 +2497,7 @@ [[exportMultipleCSVTableView tableColumnWithIdentifier:@"switch"] setDataCell:switchButton]; [[exportMultipleXMLTableView tableColumnWithIdentifier:@"switch"] setDataCell:switchButton]; [switchButton release]; - if ( [prefs boolForKey:@"UseMonospacedFonts"] ) { + if ( [prefs boolForKey:SPUseMonospacedFonts] ) { [[[exportDumpTableView tableColumnWithIdentifier:@"tables"] dataCell] setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; [[[exportMultipleCSVTableView tableColumnWithIdentifier:@"tables"] dataCell] @@ -2537,7 +2538,7 @@ forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { - if ( [[NSUserDefaults standardUserDefaults] boolForKey:@"UseMonospacedFonts"] ) { + if ( [[NSUserDefaults standardUserDefaults] boolForKey:SPUseMonospacedFonts] ) { [aCell setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; } else diff --git a/Source/TableSource.m b/Source/TableSource.m index bc4a9810..48ae859f 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -29,6 +29,7 @@ #import "SPSQLParser.h" #import "SPStringAdditions.h" #import "SPArrayAdditions.h" +#import "SPConstants.h" @implementation TableSource @@ -212,7 +213,7 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab NSEnumerator *fieldColumnsEnumerator = [[tableSourceView tableColumns] objectEnumerator]; id indexColumn; id fieldColumn; - BOOL useMonospacedFont = [prefs boolForKey:@"UseMonospacedFonts"]; + BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts]; while ( (indexColumn = [indexColumnsEnumerator nextObject]) ) if ( useMonospacedFont ) @@ -270,7 +271,7 @@ reloads the table (performing a new mysql-query) int insertIndex = ([tableSourceView numberOfSelectedRows] == 0 ? [tableSourceView numberOfRows] : [tableSourceView selectedRow] + 1); [tableFields insertObject:[NSMutableDictionary - dictionaryWithObjects:[NSArray arrayWithObjects:@"", @"int", @"", @"0", @"0", @"0", ([prefs boolForKey:@"NewFieldsAllowNulls"]) ? @"1" : @"0", @"", [prefs stringForKey:@"NullValue"], @"None", nil] + dictionaryWithObjects:[NSArray arrayWithObjects:@"", @"int", @"", @"0", @"0", @"0", ([prefs boolForKey:SPNewFieldsAllowNulls]) ? @"1" : @"0", @"", [prefs stringForKey:SPNullValue], @"None", nil] forKeys:[NSArray arrayWithObjects:@"Field", @"Type", @"Length", @"unsigned", @"zerofill", @"binary", @"Null", @"Key", @"Default", @"Extra", nil]] atIndex:insertIndex]; @@ -548,7 +549,7 @@ sets the connection (received from TableDocument) and makes things that have to [tableSourceView registerForDraggedTypes:[NSArray arrayWithObjects:@"SequelProPasteboard", nil]]; while ( (indexColumn = [indexColumnsEnumerator nextObject]) ) { - if ( [prefs boolForKey:@"UseMonospacedFonts"] ) { + if ( [prefs boolForKey:SPUseMonospacedFonts] ) { [[indexColumn dataCell] setFont:[NSFont fontWithName:@"Monaco" size:10]]; } else @@ -557,7 +558,7 @@ sets the connection (received from TableDocument) and makes things that have to } } while ( (fieldColumn = [fieldColumnsEnumerator nextObject]) ) { - if ( [prefs boolForKey:@"UseMonospacedFonts"] ) { + if ( [prefs boolForKey:SPUseMonospacedFonts] ) { [[fieldColumn dataCell] setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; } else @@ -579,7 +580,7 @@ fetches the result as an array with a dictionary for each row in it id key; int i; Class nullClass = [NSNull class]; - id prefsNullValue = [prefs objectForKey:@"NullValue"]; + id prefsNullValue = [prefs objectForKey:SPNullValue]; if (numOfRows) [theResult dataSeek:0]; for ( i = 0 ; i < numOfRows ; i++ ) { @@ -726,7 +727,7 @@ fetches the result as an array with a dictionary for each row in it } else { // If a null value has been specified, and null is allowed, specify DEFAULT NULL - if ([[theRow objectForKey:@"Default"] isEqualToString:[prefs objectForKey:@"NullValue"]]) { + if ([[theRow objectForKey:@"Default"] isEqualToString:[prefs objectForKey:SPNullValue]]) { if ([[theRow objectForKey:@"Null"] intValue] == 1) { [queryString appendString:@" DEFAULT NULL "]; } @@ -950,7 +951,7 @@ fetches the result as an array with a dictionary for each row in it */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if ([keyPath isEqualToString:@"DisplayTableViewVerticalGridlines"]) { + if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { [tableSourceView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; [indexView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } @@ -988,9 +989,9 @@ get the default value for a specified field - (NSString *)defaultValueForField:(NSString *)field { if ( ![defaultValues objectForKey:field] ) { - return [prefs objectForKey:@"NullValue"]; + return [prefs objectForKey:SPNullValue]; } else if ( [[defaultValues objectForKey:field] isMemberOfClass:[NSNull class]] ) { - return [prefs objectForKey:@"NullValue"]; + return [prefs objectForKey:SPNullValue]; } else { return [defaultValues objectForKey:field]; } @@ -1190,7 +1191,7 @@ would result in a position change. } // Add the default value - if ([[originalRow objectForKey:@"Default"] isEqualToString:[prefs objectForKey:@"NullValue"]]) { + if ([[originalRow objectForKey:@"Default"] isEqualToString:[prefs objectForKey:SPNullValue]]) { if ([[originalRow objectForKey:@"Null"] intValue] == 1) { [queryString appendString:@" DEFAULT NULL"]; } @@ -1402,8 +1403,8 @@ would result in a position change. - (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]; + [tableSourceView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + [indexView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } - (void)dealloc diff --git a/Source/TablesList.m b/Source/TablesList.m index 11a931ec..348fb033 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -35,6 +35,7 @@ #import "RegexKitLite.h" #import "SPDatabaseData.h" #import "NSMutableArray-MultipleSort.h" +#import "SPConstants.h" @interface TablesList (PrivateAPI) @@ -483,7 +484,7 @@ - (IBAction)togglePaneCollapse:(id)sender { [tableListSplitView toggleCollapse:sender]; - [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:([tableInfoCollapseButton state] == NSOffState)] forKey:@"TableInformationPanelCollapsed"]; + [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:([tableInfoCollapseButton state] == NSOffState)] forKey:SPTableInformationPanelCollapsed]; [tableInfoCollapseButton setToolTip:([tableInfoCollapseButton state] == NSOffState) ? NSLocalizedString(@"Show Table Information", @"Show Table Information") : NSLocalizedString(@"Hide Table Information", @"Hide Table Information")]; } @@ -632,7 +633,7 @@ // If encoding is set to Autodetect, update the connection character set encoding // based on the newly selected table's encoding - but only if it differs from the current encoding. - if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultEncoding"] isEqualToString:@"Autodetect"]) { + if ([[[NSUserDefaults standardUserDefaults] objectForKey:SPDefaultEncoding] isEqualToString:@"Autodetect"]) { if (tableEncoding != nil && ![tableEncoding isEqualToString:[tableDocumentInstance connectionEncoding]]) { [tableDocumentInstance setConnectionEncoding:tableEncoding reloadingViews:NO]; [tableDataInstance resetAllData]; @@ -1575,7 +1576,7 @@ { // Collapse the table information pane if preference to do so is set - if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"TableInformationPanelCollapsed"] boolValue] + if ([[[NSUserDefaults standardUserDefaults] objectForKey:SPTableInformationPanelCollapsed] boolValue] && [tableListSplitView collapsibleSubview]) { [tableInfoCollapseButton setNextState]; [tableInfoCollapseButton setToolTip:NSLocalizedString(@"Show Table Information",@"Show Table Information")]; |