From e00013ffbf5fb252a11fc6e2c68a1af0b9886317 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 4 Sep 2009 13:44:32 +0000 Subject: =?UTF-8?q?=E2=80=A2=C2=A0first=20steps=20to=20support=20global/do?= =?UTF-8?q?cument-based=20query=20favorites=20-=20not=20yet=20fully=20impl?= =?UTF-8?q?emented=20but=20workable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DBView.xib | 89 +++++++++++++++++++++++++++++++++++-- Source/CustomQuery.m | 70 ++++++++++++++++++----------- Source/SPQueryController.h | 3 ++ Source/SPQueryController.m | 11 ++--- 4 files changed, 140 insertions(+), 33 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index fa2e8746..4e1298ea 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,6 +100,7 @@ 266 {{5, 2}, {202, 19}} + YES 343014976 @@ -180,11 +181,13 @@ {212, 26} + NSView {212, 26} + @@ -203,6 +206,7 @@ 256 {{-100, -100}, {15, 94}} + _doScroller: 1.000000e+00 @@ -213,6 +217,7 @@ 256 {{-100, -100}, {166, 15}} + 1 _doScroller: @@ -221,6 +226,7 @@ {212, 26} + 0 @@ -230,6 +236,7 @@ {212, 26} + NSView @@ -252,6 +259,7 @@ 4352 {212, 354} + YES @@ -336,6 +344,7 @@ {212, 354} + @@ -351,6 +360,7 @@ -2147483392 {{197, 0}, {15, 292}} + _doScroller: 9.965870e-01 @@ -360,6 +370,7 @@ 256 {{-100, -100}, {141, 11}} + 257 _doScroller: @@ -368,6 +379,7 @@ {212, 354} + 528 @@ -378,11 +390,13 @@ {{0, 27}, {212, 354}} + NSView {212, 381} + 2 YES @@ -408,6 +422,7 @@ {212, 381} + NSView @@ -430,6 +445,7 @@ 4352 {212, 145} + YES @@ -493,6 +509,7 @@ {212, 145} + @@ -503,6 +520,7 @@ -2147483392 {{-100, -100}, {15, 20}} + _doScroller: 9.473684e-01 @@ -512,6 +530,7 @@ 256 {{-100, -100}, {141, 11}} + 257 _doScroller: @@ -520,6 +539,7 @@ {212, 145} + 512 @@ -530,11 +550,13 @@ {{0, 382}, {212, 145}} + NSView {{0, 23}, {212, 527}} + 2 NO @@ -585,6 +607,7 @@ 268 {{-1, -1}, {32, 24}} + YES 67239424 @@ -609,6 +632,7 @@ 268 {{30, -1}, {32, 24}} + YES 71433792 @@ -718,6 +742,7 @@ 268 {{61, -1}, {32, 24}} + YES 67239424 @@ -742,6 +767,7 @@ 268 {{92, -1}, {32, 24}} + YES -2080244224 @@ -768,6 +794,7 @@ {212, 23} + YES YES NO @@ -776,6 +803,7 @@ {212, 550} + NSView @@ -788,6 +816,7 @@ 274 {{-7, -10}, {735, 564}} + YES @@ -2861,8 +2890,32 @@ 6418 + + YES + + YES + Apple HTML pasteboard type + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + Apple URL pasteboard type + CorePasteboardFlavorType 0x6D6F6F76 + CorePasteboardFlavorType 0x75726C20 + NSColor pasteboard type + NSFilenamesPboardType + NSStringPboardType + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT RTFD pasteboard type + NeXT Rich Text Format v1.0 pasteboard type + NeXT TIFF v4.0 pasteboard type + NeXT font pasteboard type + NeXT ruler pasteboard type + WebURLsWithTitlesPboardType + + {688, 14} + @@ -2921,6 +2974,7 @@ {{1, 1}, {688, 155}} + @@ -2935,6 +2989,7 @@ -2147483392 {{598, 1}, {15, 68}} + _doScroller: 1.000000e+00 @@ -2944,6 +2999,7 @@ 256 {{-100, -100}, {601, 11}} + 257 _doScroller: @@ -2953,6 +3009,7 @@ {690, 157} + 530 @@ -2962,6 +3019,7 @@ {690, 156} + NSView @@ -2984,12 +3042,14 @@ 4352 {688, 228} + YES 256 {688, 17} + @@ -2997,6 +3057,7 @@ -2147483392 {{-26, 0}, {16, 17}} + YES @@ -3040,6 +3101,7 @@ {{1, 17}, {688, 228}} + @@ -3050,6 +3112,7 @@ -2147483392 {{611, 17}, {15, 30}} + _doScroller: 9.375000e-01 @@ -3059,6 +3122,7 @@ -2147483392 {{1, 47}, {610, 15}} + 1 _doScroller: @@ -3073,6 +3137,7 @@ {{1, 0}, {688, 17}} + @@ -3082,6 +3147,7 @@ {690, 246} + 562 @@ -3096,6 +3162,7 @@ 268 {{156, 246}, {98, 22}} + YES -2076049856 @@ -3155,6 +3222,7 @@ 264 {{38, 246}, {108, 22}} + YES -2076049856 @@ -3195,7 +3263,7 @@ _popUpItemAction: - 1000 + 100000 @@ -3207,7 +3275,7 @@ _popUpItemAction: - 1001 + 100001 @@ -3257,6 +3325,7 @@ 268 {{-10, 245}, {46, 25}} + YES -2076049856 @@ -3550,6 +3619,7 @@ 265 {{591, 248}, {90, 17}} + YES -2080244224 @@ -3571,6 +3641,7 @@ 265 {{473, 248}, {110, 17}} + YES 604110336 @@ -3603,6 +3674,7 @@ {{32, 246}, {658, 23}} + YES 130560 @@ -3618,6 +3690,7 @@ {{0, 165}, {690, 269}} + NSView @@ -3630,6 +3703,7 @@ 266 {{242, 64}, {431, 17}} + YES 67239424 @@ -3646,6 +3720,7 @@ 264 {{17, 67}, {143, 14}} + YES 67239424 @@ -3662,6 +3737,7 @@ 274 {{17, 20}, {656, 43}} + YES 67239424 @@ -3676,15 +3752,18 @@ {{0, 443}, {690, 87}} + NSView {{6, 10}, {690, 530}} + {{10, 7}, {700, 544}} + Custom Query @@ -4737,16 +4816,20 @@ {{221, 0}, {723, 550}} + NSView {944, 550} + YES DBViewSplitter {944, 550} + + {{0, 0}, {1920, 1178}} {780, 502} diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index bbad9edc..67741669 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -1103,6 +1103,10 @@ [queryHistoryButton addItemsWithTitles:[[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]]]; } + // Populate query favorites + [self queryFavoritesHaveBeenUpdated:nil]; + + // Disable runSelectionMenuItem in the gear menu [runSelectionMenuItem setEnabled:NO]; } @@ -2403,36 +2407,60 @@ - (void)queryFavoritesHaveBeenUpdated:(id)manager { - NSMutableArray *favorites = [[NSMutableArray alloc] init]; + NSMutableArray *globalFavorites = [[NSMutableArray alloc] init]; // Invoked after adding a favorite from inside CustomQuery if(manager == nil) { - [favorites addObjectsFromArray:[prefs objectForKey:@"queryFavorites"]]; + [globalFavorites addObjectsFromArray:[prefs objectForKey:@"queryFavorites"]]; } // Invoked by the query favorite manager else if(manager == favoritesManager){ - // Update global query favorites - [favorites addObjectsFromArray:[favoritesManager globalQueryFavorites]]; - [prefs setObject:favorites forKey:@"queryFavorites"]; - [prefs synchronize]; + // Update global query favorites + [globalFavorites addObjectsFromArray:[favoritesManager globalQueryFavorites]]; + [prefs setObject:globalFavorites forKey:@"queryFavorites"]; } // Remove all favorites beginning from the end while([queryFavoritesButton numberOfItems] > 6) [queryFavoritesButton removeItemAtIndex:[queryFavoritesButton numberOfItems]-1]; - // Re-add favorites and allow menu items with the same name + // Insert new favorites and allow menu items with the same name NSMenu *menu = [queryFavoritesButton menu]; int i = 6; - for (NSDictionary *favorite in favorites) { + + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"Global" action:NULL keyEquivalent:@""]; + [item setTag:200000]; + [item setToolTip:@"All global favorites"]; + [item setIndentationLevel:0]; + [menu addItem:item]; + [item release]; + + 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]; + [item release]; + } + + item = [[NSMenuItem alloc] initWithTitle:@"Document" action:NULL keyEquivalent:@""]; + [item setTag:200000]; + [item setToolTip:@"All document-based favorites"]; + [item setIndentationLevel:0]; + [menu addItem:item]; + [item release]; + + 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]; } - [favorites release]; + [globalFavorites release]; [prefs synchronize]; @@ -2497,7 +2525,9 @@ [prefs setObject:favorites forKey:@"queryFavorites"]; } else { - [SPTooltip showWithObject:@"Not yet implemented"]; + [[SPQueryController sharedQueryController] addFavorite:[NSDictionary dictionaryWithObjects: + [NSArray arrayWithObjects:[queryFavoriteNameTextField stringValue], queryToBeAddded, nil] + forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]] forFileURL:[tableDocumentInstance fileURL]]; } [saveQueryFavoriteGlobal setState:NSOffState]; @@ -2516,7 +2546,7 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { // Control "Save ... to Favorites" = tag is set to 1000 - if ( [menuItem tag] == 1000 ) { + if ( [menuItem tag] == 100000 ) { if ([[textView string] length] < 1) return NO; if([textView selectedRange].length) [menuItem setTitle:NSLocalizedString(@"Save Selection to Favorites",@"Save Selection to Favorites")]; @@ -2526,9 +2556,12 @@ [menuItem setTitle:NSLocalizedString(@"Save All to Favorites",@"Save All to Favorites")]; } // Control "Save All to Favorites" = tag is set to 1001 - if ( [menuItem tag] == 1001 ) { + if ( [menuItem tag] == 100001 ) { if ([[textView string] length] < 1) return NO; } + if ( [menuItem tag] == 200000 ) { + return NO; + } return YES; } @@ -2594,19 +2627,6 @@ { // Set the structure and index view's vertical gridlines if required [customQueryView setGridStyleMask:([prefs boolForKey:@"DisplayTableViewVerticalGridlines"]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; - - // Populate the query favorites popup button - NSMenu *menu = [queryFavoritesButton menu]; - int i = 6; - for (NSDictionary *favorite in [prefs objectForKey:@"queryFavorites"]) - { - NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[favorite objectForKey:@"name"] action:NULL keyEquivalent:@""]; - [item setTag:i++]; - [item setToolTip:[favorite objectForKey:@"query"]]; - [menu addItem:item]; - [item release]; - } - } - (void)dealloc diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h index bce03109..df842745 100644 --- a/Source/SPQueryController.h +++ b/Source/SPQueryController.h @@ -81,10 +81,13 @@ // DocumentsController - (NSURL *)registerDocumentWithFileURL:(NSURL *)fileURL andContextInfo:(NSMutableDictionary *)contextInfo; - (void)removeRegisteredDocumentWithFileURL:(NSURL *)fileURL; + - (void)addFavorite:(NSDictionary *)favorite forFileURL:(NSURL *)fileURL; - (void)replaceFavoritesByArray:(NSArray *)favoritesArray forFileURL:(NSURL *)fileURL; + - (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL; - (void)replaceHistoryByArray:(NSArray *)historyArray forFileURL:(NSURL *)fileURL; + - (NSMutableArray *)favoritesForFileURL:(NSURL *)fileURL; - (NSMutableArray *)historyForFileURL:(NSURL *)fileURL; diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index 807f5444..4345f616 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -493,11 +493,6 @@ static SPQueryController *sharedQueryController = nil; } -- (void)addFavorite:(NSDictionary *)favorite forFileURL:(NSURL *)fileURL -{ - -} - - (void)replaceFavoritesByArray:(NSArray *)favoritesArray forFileURL:(NSURL *)fileURL { if([favoritesContainer objectForKey:[fileURL absoluteString]]) @@ -510,6 +505,12 @@ static SPQueryController *sharedQueryController = nil; [historyContainer setObject:historyArray forKey:[fileURL absoluteString]]; } +- (void)addFavorite:(NSDictionary *)favorite forFileURL:(NSURL *)fileURL +{ + if([favoritesContainer objectForKey:[fileURL absoluteString]]) + [[favoritesContainer objectForKey:[fileURL absoluteString]] addObject:favorite]; +} + - (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL { -- cgit v1.2.3