From 9683c9df3cb0b1128429f42f108d4e03ca4550f1 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 4 Sep 2009 17:40:56 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20behavior=20while=20closing=20a?= =?UTF-8?q?=20document=20window=20-=20if=20not=20connected=20close=20it=20?= =?UTF-8?q?without=20any=20checks=20-=20if=20an=20Untitled=20document=20co?= =?UTF-8?q?ntains=20stored=20query=20favorites=20-=20What=20should=20be=20?= =?UTF-8?q?done=3F=20-=20up=20to=20now=20it=20saves=20them=20to=20the=20gl?= =?UTF-8?q?obal=20prefs=20=E2=80=A2=20header=20in=20query=20favorites=20li?= =?UTF-8?q?st=20keep=20visible=20while=20filtering=20=E2=80=A2=20code=20cl?= =?UTF-8?q?eaning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DBView.xib | 74 ++++++------------------------------- Source/CustomQuery.h | 26 ++++++++++--- Source/CustomQuery.m | 55 ++++++++++++++------------- Source/TableDocument.m | 27 ++++++++++++-- 4 files changed, 85 insertions(+), 97 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 4e1298ea..6ac089b9 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -46,7 +46,7 @@ {3.40282e+38, 3.40282e+38} {780, 480} - + 256 YES @@ -100,7 +100,6 @@ 266 {{5, 2}, {202, 19}} - YES 343014976 @@ -181,13 +180,11 @@ {212, 26} - NSView {212, 26} - @@ -206,7 +203,6 @@ 256 {{-100, -100}, {15, 94}} - _doScroller: 1.000000e+00 @@ -217,7 +213,6 @@ 256 {{-100, -100}, {166, 15}} - 1 _doScroller: @@ -226,7 +221,6 @@ {212, 26} - 0 @@ -236,7 +230,6 @@ {212, 26} - NSView @@ -259,7 +252,6 @@ 4352 {212, 354} - YES @@ -344,7 +336,6 @@ {212, 354} - @@ -360,7 +351,6 @@ -2147483392 {{197, 0}, {15, 292}} - _doScroller: 9.965870e-01 @@ -370,7 +360,6 @@ 256 {{-100, -100}, {141, 11}} - 257 _doScroller: @@ -379,7 +368,6 @@ {212, 354} - 528 @@ -390,13 +378,11 @@ {{0, 27}, {212, 354}} - NSView {212, 381} - 2 YES @@ -422,7 +408,6 @@ {212, 381} - NSView @@ -445,7 +430,6 @@ 4352 {212, 145} - YES @@ -509,7 +493,6 @@ {212, 145} - @@ -520,7 +503,6 @@ -2147483392 {{-100, -100}, {15, 20}} - _doScroller: 9.473684e-01 @@ -530,7 +512,6 @@ 256 {{-100, -100}, {141, 11}} - 257 _doScroller: @@ -539,7 +520,6 @@ {212, 145} - 512 @@ -550,13 +530,11 @@ {{0, 382}, {212, 145}} - NSView {{0, 23}, {212, 527}} - 2 NO @@ -607,7 +585,6 @@ 268 {{-1, -1}, {32, 24}} - YES 67239424 @@ -632,7 +609,6 @@ 268 {{30, -1}, {32, 24}} - YES 71433792 @@ -742,7 +718,6 @@ 268 {{61, -1}, {32, 24}} - YES 67239424 @@ -767,7 +742,6 @@ 268 {{92, -1}, {32, 24}} - YES -2080244224 @@ -794,7 +768,6 @@ {212, 23} - YES YES NO @@ -803,7 +776,6 @@ {212, 550} - NSView @@ -816,7 +788,6 @@ 274 {{-7, -10}, {735, 564}} - YES @@ -2915,7 +2886,6 @@ {688, 14} - @@ -2974,7 +2944,6 @@ {{1, 1}, {688, 155}} - @@ -2989,7 +2958,6 @@ -2147483392 {{598, 1}, {15, 68}} - _doScroller: 1.000000e+00 @@ -2999,7 +2967,6 @@ 256 {{-100, -100}, {601, 11}} - 257 _doScroller: @@ -3009,7 +2976,6 @@ {690, 157} - 530 @@ -3019,7 +2985,6 @@ {690, 156} - NSView @@ -3042,14 +3007,12 @@ 4352 {688, 228} - YES 256 {688, 17} - @@ -3057,7 +3020,6 @@ -2147483392 {{-26, 0}, {16, 17}} - YES @@ -3101,7 +3063,6 @@ {{1, 17}, {688, 228}} - @@ -3112,7 +3073,6 @@ -2147483392 {{611, 17}, {15, 30}} - _doScroller: 9.375000e-01 @@ -3122,7 +3082,6 @@ -2147483392 {{1, 47}, {610, 15}} - 1 _doScroller: @@ -3137,7 +3096,6 @@ {{1, 0}, {688, 17}} - @@ -3147,7 +3105,6 @@ {690, 246} - 562 @@ -3162,7 +3119,6 @@ 268 {{156, 246}, {98, 22}} - YES -2076049856 @@ -3222,7 +3178,6 @@ 264 {{38, 246}, {108, 22}} - YES -2076049856 @@ -3325,7 +3280,6 @@ 268 {{-10, 245}, {46, 25}} - YES -2076049856 @@ -3619,7 +3573,6 @@ 265 {{591, 248}, {90, 17}} - YES -2080244224 @@ -3641,7 +3594,6 @@ 265 {{473, 248}, {110, 17}} - YES 604110336 @@ -3674,7 +3626,6 @@ {{32, 246}, {658, 23}} - YES 130560 @@ -3690,7 +3641,6 @@ {{0, 165}, {690, 269}} - NSView @@ -3703,7 +3653,6 @@ 266 {{242, 64}, {431, 17}} - YES 67239424 @@ -3720,7 +3669,6 @@ 264 {{17, 67}, {143, 14}} - YES 67239424 @@ -3737,7 +3685,6 @@ 274 {{17, 20}, {656, 43}} - YES 67239424 @@ -3752,18 +3699,15 @@ {{0, 443}, {690, 87}} - NSView {{6, 10}, {690, 530}} - {{10, 7}, {700, 544}} - Custom Query @@ -4816,20 +4760,16 @@ {{221, 0}, {723, 550}} - NSView {944, 550} - YES DBViewSplitter {944, 550} - - {{0, 0}, {1920, 1178}} {780, 502} @@ -15565,6 +15505,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 6518 + + + queryFavoritesSaveAllMenuItem + + + + 6519 + @@ -25221,7 +25169,7 @@ dXJyZW50IHF1ZXJ5IG9yIHNlbGVjdGlvbi4 - 6518 + 6519 @@ -26624,6 +26572,7 @@ dXJyZW50IHF1ZXJ5IG9yIHNlbGVjdGlvbi4 multipleLineEditingButton queryFavoriteNameTextField queryFavoritesButton + queryFavoritesSaveAllMenuItem queryFavoritesSaveAsMenuItem queryFavoritesSearchField queryFavoritesSearchFieldView @@ -26670,6 +26619,7 @@ dXJyZW50IHF1ZXJ5IG9yIHNlbGVjdGlvbi4 NSTextField id NSMenuItem + NSMenuItem NSSearchField id NSMenuItem diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index 9d1559e6..a9d4f670 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -32,6 +32,20 @@ #import "RegexKitLite.h" #define SP_HELP_TOC_SEARCH_STRING @"contents" +#define SP_HELP_SEARCH_IN_MYSQL 0 +#define SP_HELP_SEARCH_IN_PAGE 1 +#define SP_HELP_SEARCH_IN_WEB 2 +#define SP_HELP_GOBACK_BUTTON 0 +#define SP_HELP_SHOW_TOC_BUTTON 1 +#define SP_HELP_GOFORWARD_BUTTON 2 +#define SP_HELP_NOT_AVAILABLE @"__no_help_available" + +#define SP_MYSQL_DEV_SEARCH_URL @"http://search.mysql.com/search?q=%@&site=refman-%@" + +#define SP_SAVE_ALL_FAVORTITE_MENUITEM_TAG 100001 +#define SP_SAVE_SELECTION_FAVORTITE_MENUITEM_TAG 100000 +#define SP_FAVORITE_HEADER_MENUITEM_TAG 200000 + @class SPQueryFavoriteManager; @@ -43,8 +57,15 @@ IBOutlet id queryFavoritesButton; IBOutlet NSMenuItem *queryFavoritesSearchMenuItem; IBOutlet NSMenuItem *queryFavoritesSaveAsMenuItem; + IBOutlet NSMenuItem *queryFavoritesSaveAllMenuItem; IBOutlet id queryFavoritesSearchFieldView; IBOutlet NSSearchField *queryFavoritesSearchField; + + IBOutlet NSWindow *queryFavoritesSheet; + IBOutlet NSButton *saveQueryFavoriteButton; + IBOutlet NSTextField *queryFavoriteNameTextField; + IBOutlet id saveQueryFavoriteGlobal; + IBOutlet id queryHistoryButton; IBOutlet NSMenuItem *queryHistorySearchMenuItem; IBOutlet id queryHistorySearchFieldView; @@ -73,11 +94,6 @@ IBOutlet NSMenuItem *commentCurrentQueryMenuItem; IBOutlet NSMenuItem *commentLineOrSelectionMenuItem; - IBOutlet NSWindow *queryFavoritesSheet; - IBOutlet NSButton *saveQueryFavoriteButton; - IBOutlet NSTextField *queryFavoriteNameTextField; - IBOutlet id saveQueryFavoriteGlobal; - IBOutlet NSWindow *helpWebViewWindow; IBOutlet WebView *helpWebView; IBOutlet NSSearchField *helpSearchField; diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 67741669..155113d9 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -40,15 +40,6 @@ #import "SPQueryFavoriteManager.h" #import "SPQueryController.h" -#define SP_MYSQL_DEV_SEARCH_URL @"http://search.mysql.com/search?q=%@&site=refman-%@" -#define SP_HELP_SEARCH_IN_MYSQL 0 -#define SP_HELP_SEARCH_IN_PAGE 1 -#define SP_HELP_SEARCH_IN_WEB 2 -#define SP_HELP_GOBACK_BUTTON 0 -#define SP_HELP_SHOW_TOC_BUTTON 1 -#define SP_HELP_GOFORWARD_BUTTON 2 -#define SP_HELP_NOT_AVAILABLE @"__no_help_available" - @implementation CustomQuery #pragma mark IBAction methods @@ -2426,34 +2417,32 @@ // Insert new favorites and allow menu items with the same name NSMenu *menu = [queryFavoritesButton menu]; - int i = 6; - NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"Global" action:NULL keyEquivalent:@""]; - [item setTag:200000]; - [item setToolTip:@"All global favorites"]; + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"Document" action:NULL keyEquivalent:@""]; + [item setTag:SP_FAVORITE_HEADER_MENUITEM_TAG]; + [item setToolTip:[NSString stringWithFormat:@"‘%@’ based favorites", + [[[[tableDocumentInstance fileURL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] lastPathComponent]]]; [item setIndentationLevel:0]; [menu addItem:item]; [item release]; - for (NSDictionary *favorite in globalFavorites) { + for (NSDictionary *favorite in [[SPQueryController sharedQueryController] favoritesForFileURL:[tableDocumentInstance fileURL]]) { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithString:[favorite objectForKey:@"name"]] action:NULL keyEquivalent:@""]; - [item setTag:i++]; [item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]]; [item setIndentationLevel:1]; [menu addItem:item]; [item release]; } - item = [[NSMenuItem alloc] initWithTitle:@"Document" action:NULL keyEquivalent:@""]; - [item setTag:200000]; - [item setToolTip:@"All document-based favorites"]; + item = [[NSMenuItem alloc] initWithTitle:@"Global" action:NULL keyEquivalent:@""]; + [item setTag:SP_FAVORITE_HEADER_MENUITEM_TAG]; + [item setToolTip:@"Globally stored favorites"]; [item setIndentationLevel:0]; [menu addItem:item]; [item release]; - for (NSDictionary *favorite in [[SPQueryController sharedQueryController] favoritesForFileURL:[tableDocumentInstance fileURL]]) { + for (NSDictionary *favorite in globalFavorites) { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithString:[favorite objectForKey:@"name"]] action:NULL keyEquivalent:@""]; - [item setTag:i++]; [item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]]; [item setIndentationLevel:1]; [menu addItem:item]; @@ -2545,8 +2534,9 @@ */ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { - // Control "Save ... to Favorites" = tag is set to 1000 - if ( [menuItem tag] == 100000 ) { + + // Control "Save ... to Favorites" + if ( [menuItem tag] == SP_SAVE_SELECTION_FAVORTITE_MENUITEM_TAG ) { if ([[textView string] length] < 1) return NO; if([textView selectedRange].length) [menuItem setTitle:NSLocalizedString(@"Save Selection to Favorites",@"Save Selection to Favorites")]; @@ -2555,14 +2545,19 @@ else [menuItem setTitle:NSLocalizedString(@"Save All to Favorites",@"Save All to Favorites")]; } - // Control "Save All to Favorites" = tag is set to 1001 - if ( [menuItem tag] == 100001 ) { + + // Control "Save All to Favorites" + if ( [menuItem tag] == SP_SAVE_ALL_FAVORTITE_MENUITEM_TAG ) { if ([[textView string] length] < 1) return NO; } - if ( [menuItem tag] == 200000 ) { + + // Avoid selecting button list headers + if ( [menuItem tag] == SP_FAVORITE_HEADER_MENUITEM_TAG ) { return NO; } + return YES; + } @@ -2609,8 +2604,10 @@ { int i; NSMenu *menu = [queryFavoritesButton menu]; + NSString *searchPattern = [queryFavoritesSearchField stringValue]; for (i=6; i< [menu numberOfItems]; i++) - [[menu itemAtIndex:i] setHidden:(![[[menu itemAtIndex:i] title] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", [queryFavoritesSearchField stringValue]]])]; + [[menu itemAtIndex:i] setHidden:([[menu itemAtIndex:i] tag] != SP_FAVORITE_HEADER_MENUITEM_TAG + && ![[[menu itemAtIndex:i] title] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", searchPattern]])]; } @@ -2618,6 +2615,7 @@ { int i; NSMenu *menu = [queryHistoryButton menu]; + NSString *searchPattern = [queryHistorySearchField stringValue]; for (i=2; i< [menu numberOfItems]; i++) [[menu itemAtIndex:i] setHidden:(![[[menu itemAtIndex:i] title] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", [queryHistorySearchField stringValue]]])]; @@ -2625,6 +2623,11 @@ - (void)awakeFromNib { + + // Set pre-defined menu tags + [queryFavoritesSaveAsMenuItem setTag:SP_SAVE_SELECTION_FAVORTITE_MENUITEM_TAG]; + [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]; } diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 9c56ff04..a546333a 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -1925,7 +1925,7 @@ { // Auto-save preferences to spf file based connection if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"]) - if(![self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES]) { + if(_isConnected && ![self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES]) { NSLog(@"Preference data for file ‘%@’ could not be saved.", [[[self fileURL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]); NSBeep(); } @@ -2128,9 +2128,12 @@ // Update only query favourites, history, etc. by reading the file again if(saveOnlyPreferences) { - // Check for save file URL - // TODO maybe alert ? - if(![[[self fileURL] absoluteString] length] && ![[[self fileURL] absoluteString] hasPrefix:@"/"]) return NO; + // Check URL for safety reasons + if(![[[self fileURL] absoluteString] length] || ![[[self fileURL] absoluteString] hasPrefix:@"/"]) { + NSLog(@"Couldn't save data. No file URL found!"); + NSBeep(); + return NO; + } NSError *readError = nil; NSString *convError = nil; @@ -2976,13 +2979,29 @@ if ( ![tablesListInstance selectionShouldChangeInTableView:nil] ) { return NO; } else { + + if(!_isConnected) return YES; + // Auto-save spf file based connection if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"]) { BOOL isSaved = [self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES]; if(isSaved) [[SPQueryController sharedQueryController] removeRegisteredDocumentWithFileURL:[self fileURL]]; return isSaved; + + // Before removing an Untitled doc check if it contains any defined query favorites. + // If so save them globally. TODO: How to do it better ? } else if([self fileURL] && [[[self fileURL] absoluteString] length] && ![[[self fileURL] absoluteString] hasPrefix:@"/"]) { + if([[[SPQueryController sharedQueryController] favoritesForFileURL:[self fileURL]] count]) { + + NSMutableArray *favs = [[[NSMutableArray alloc] init] autorelease]; + [favs addObjectsFromArray:[prefs objectForKey:@"queryFavorites"]]; + [favs addObjectsFromArray:[[SPQueryController sharedQueryController] favoritesForFileURL:[self fileURL]]]; + [prefs setObject:favs forKey:@"queryFavorites"]; + + if(![prefs synchronize]) + NSLog(@"Sorry, couldn't backup query favorites from Untitled document."); + } [[SPQueryController sharedQueryController] removeRegisteredDocumentWithFileURL:[self fileURL]]; return YES; } -- cgit v1.2.3