diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-08-26 08:42:53 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-08-26 08:42:53 +0000 |
commit | 6a8f423169cb76dec7e672ba8e34f5e5196f7283 (patch) | |
tree | ecb301f956763f82f82824713abb0f1697d9307b /Source | |
parent | 58962687fd345782a012a8a4412627c691db522f (diff) | |
download | sequelpro-6a8f423169cb76dec7e672ba8e34f5e5196f7283.tar.gz sequelpro-6a8f423169cb76dec7e672ba8e34f5e5196f7283.tar.bz2 sequelpro-6a8f423169cb76dec7e672ba8e34f5e5196f7283.zip |
• fixed/improved several things for the SPQueryFavoriteManager:
- allow favorites with the same name (it's the user's responsibility)
- fixed removing of all menu items (beginning from the end)
- "Save Query to Favorites" will save the selected text, or if no selection the CURRENT query, or if no current query can be detected the entire textView string (since the tooltip says '...or save the current query...)
- ensure after editing the favorites ALL changes will be saved first before closing the sheet
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CustomQuery.m | 51 | ||||
-rw-r--r-- | Source/SPQueryFavoriteManager.m | 22 |
2 files changed, 56 insertions, 17 deletions
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 diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m index 39cae4e1..6c2c48b0 100644 --- a/Source/SPQueryFavoriteManager.m +++ b/Source/SPQueryFavoriteManager.m @@ -38,7 +38,7 @@ { if ((self = [super initWithWindowNibName:@"QueryFavoriteManager"])) { delegate = managerDelegate; - + prefs = [NSUserDefaults standardUserDefaults]; delegateRespondsToFavoriteUpdates = [delegate respondsToSelector:@selector(queryFavoritesHaveBeenUpdated:)]; @@ -105,6 +105,8 @@ [favoritesTableView reloadData]; [favoritesTableView scrollRowToVisible:[favoritesTableView selectedRow]]; + [prefs synchronize]; + // Inform the delegate that the query favorites have been updated if (delegateRespondsToFavoriteUpdates) { [delegate queryFavoritesHaveBeenUpdated:self]; @@ -120,7 +122,12 @@ [queryFavoritesController removeObjectAtArrangedObjectIndex:[favoritesTableView selectedRow]]; [favoritesTableView reloadData]; - + + [prefs synchronize]; + + // Set focus to favorite list to avoid an unstable state + [[self window] makeFirstResponder:favoritesTableView]; + // Inform the delegate that the query favorites have been updated if (delegateRespondsToFavoriteUpdates) { [delegate queryFavoritesHaveBeenUpdated:self]; @@ -196,8 +203,19 @@ */ - (IBAction)closeQueryManagerSheet:(id)sender { + + // Ensure taht last changes will be written to prefs + [[self window] makeFirstResponder:favoritesTableView]; + [prefs synchronize]; + [NSApp endSheet:[self window] returnCode:0]; [[self window] orderOut:self]; + + // Inform the delegate that the query favorites have been updated + if (delegateRespondsToFavoriteUpdates) { + [delegate queryFavoritesHaveBeenUpdated:self]; + } + } #pragma mark - |