From 6a8f423169cb76dec7e672ba8e34f5e5196f7283 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 26 Aug 2009 08:42:53 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed/improved=20several=20things=20for=20t?= =?UTF-8?q?he=20SPQueryFavoriteManager:=20-=20allow=20favorites=20with=20t?= =?UTF-8?q?he=20same=20name=20(it's=20the=20user's=20responsibility)=20-?= =?UTF-8?q?=20fixed=20removing=20of=20all=20menu=20items=20(beginning=20fr?= =?UTF-8?q?om=20the=20end)=20-=20"Save=20Query=20to=20Favorites"=20will=20?= =?UTF-8?q?save=20the=20selected=20text,=20or=20if=20no=20selection=20the?= =?UTF-8?q?=20CURRENT=20query,=20or=20if=20no=20current=20query=20can=20be?= =?UTF-8?q?=20detected=20the=20entire=20textView=20string=20(since=20the?= =?UTF-8?q?=20tooltip=20says=20'...or=20save=20the=20current=20query...)?= =?UTF-8?q?=20-=20ensure=20after=20editing=20the=20favorites=20ALL=20chang?= =?UTF-8?q?es=20will=20be=20saved=20first=20before=20closing=20the=20sheet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CustomQuery.m | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'Source/CustomQuery.m') diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index c8ded233..4e02fd53 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -2338,20 +2338,23 @@ */ - (void)queryFavoritesHaveBeenUpdated:(id)manager { - NSInteger i; + // NSInteger i; NSMutableArray *favorites = ([favoritesManager queryFavorites]) ? [favoritesManager queryFavorites] : [prefs objectForKey:@"queryFavorites"]; - - // Remove all favorites - for (i = 4; i < [queryFavoritesButton numberOfItems]; i++) - { - [queryFavoritesButton removeItemAtIndex:i]; + + // Remove all favorites beginning from the end + while([queryFavoritesButton numberOfItems] > 4) + [queryFavoritesButton removeItemAtIndex:[queryFavoritesButton numberOfItems]-1]; + + // Re-add favorites and allow menu items with the same name + NSMenu *menu = [queryFavoritesButton menu]; + int i = 4; + for (NSDictionary *favorite in favorites) { + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[favorite objectForKey:@"name"] action:NULL keyEquivalent:@""]; + [item setTag:i++]; + [menu addItem:item]; + [item release]; } - // Re-add favorites - for (NSDictionary *favorite in favorites) - { - [queryFavoritesButton addItemWithTitle:[favorite objectForKey:@"name"]]; - } } #pragma mark - @@ -2386,8 +2389,20 @@ // 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"]]; - - [favorites addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[queryFavoriteNameTextField stringValue], [textView string], nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]]]; + + // What should be saved + NSString *queryToBeAddded; + // First check for a selection + if([textView selectedRange].length) + queryToBeAddded = [[textView string] substringWithRange:[textView selectedRange]]; + // then for a current query + else if(currentQueryRange.length) + queryToBeAddded = [[textView string] substringWithRange:currentQueryRange]; + // otherwise take the entire string + else + queryToBeAddded = [textView string]; + + [favorites addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[queryFavoriteNameTextField stringValue], queryToBeAddded, nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]]]; [prefs setObject:favorites forKey:@"queryFavorites"]; [prefs synchronize]; @@ -2460,11 +2475,17 @@ // Set the structure and index view's vertical gridlines if required [customQueryView setGridStyleMask:([prefs boolForKey:@"DisplayTableViewVerticalGridlines"]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; - // Populate the query favorites popup button + // Populate the query favorites popup button + NSMenu *menu = [queryFavoritesButton menu]; + int i = 4; for (NSDictionary *favorite in [prefs objectForKey:@"queryFavorites"]) { - [queryFavoritesButton addItemWithTitle:[favorite objectForKey:@"name"]]; + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[favorite objectForKey:@"name"] action:NULL keyEquivalent:@""]; + [item setTag:i++]; + [menu addItem:item]; + [item release]; } + } - (void)dealloc -- cgit v1.2.3