aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/CustomQuery.m51
-rw-r--r--Source/SPQueryFavoriteManager.m22
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 -