aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-09-07 11:09:19 +0000
committerBibiko <bibiko@eva.mpg.de>2009-09-07 11:09:19 +0000
commit4693139403ba538559a939e776ee3d65d5c74598 (patch)
tree078f59a88750739894108f6ed563ddd839cb4db8 /Source
parent252ac0be49bf409b1eda3726f4f4a47bd6b5b5b6 (diff)
downloadsequelpro-4693139403ba538559a939e776ee3d65d5c74598.tar.gz
sequelpro-4693139403ba538559a939e776ee3d65d5c74598.tar.bz2
sequelpro-4693139403ba538559a939e776ee3d65d5c74598.zip
• after "Apply Changes" in a Query Favorite Manager update the Query Favorites of all opened documents to synchronize changes in global favorites
• "Import Favorites" in the Query Favorite Manager adds the imported favorites after the last selected item, if no selected item is found it adds them
Diffstat (limited to 'Source')
-rw-r--r--Source/SPQueryFavoriteManager.h5
-rw-r--r--Source/SPQueryFavoriteManager.m34
2 files changed, 25 insertions, 14 deletions
diff --git a/Source/SPQueryFavoriteManager.h b/Source/SPQueryFavoriteManager.h
index 4268ffe0..1546186e 100644
--- a/Source/SPQueryFavoriteManager.h
+++ b/Source/SPQueryFavoriteManager.h
@@ -33,13 +33,8 @@
@interface SPQueryFavoriteManager : NSWindowController
{
- id delegate;
-
NSUserDefaults *prefs;
- BOOL delegateRespondsToFavoriteUpdates;
-
- NSDocument *tableDocumentInstance;
NSURL *delegatesFileURL;
IBOutlet NSPopUpButton *encodingPopUp;
IBOutlet NSTableView *favoritesTableView;
diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m
index ce10bfa7..545d0317 100644
--- a/Source/SPQueryFavoriteManager.m
+++ b/Source/SPQueryFavoriteManager.m
@@ -48,15 +48,17 @@
- (id)initWithDelegate:(id)managerDelegate
{
if ((self = [super initWithWindowNibName:@"QueryFavoriteManager"])) {
- delegate = managerDelegate;
prefs = [NSUserDefaults standardUserDefaults];
favorites = [[NSMutableArray alloc] init];
- delegateRespondsToFavoriteUpdates = [delegate respondsToSelector:@selector(queryFavoritesHaveBeenUpdated:)];
- tableDocumentInstance = [delegate valueForKeyPath:@"tableDocumentInstance"];
- delegatesFileURL = [[delegate valueForKeyPath:@"tableDocumentInstance"] fileURL];
+ if(managerDelegate == nil) {
+ NSBeep();
+ NSLog(@"Query Favorite Manger was called without a delegate.");
+ return nil;
+ }
+ delegatesFileURL = [[managerDelegate valueForKeyPath:@"tableDocumentInstance"] fileURL];
}
return self;
@@ -358,14 +360,18 @@
[[self window] makeFirstResponder:favoritesTableView];
}
- // Update current document's and global query favorites
+ // Update current document's query favorites in the SPQueryController
[[SPQueryController sharedQueryController] replaceFavoritesByArray:
[self queryFavoritesForFileURL:delegatesFileURL] forFileURL:delegatesFileURL];
+
+ // Update global preferences' list
[prefs setObject:[self queryFavoritesForFileURL:nil] forKey:@"queryFavorites"];
- // Inform delegate to update
- if(delegateRespondsToFavoriteUpdates)
- [delegate queryFavoritesHaveBeenUpdated:self];
+ // Inform all opened documents to update the query favorites list
+ for(id doc in [[NSDocumentController sharedDocumentController] documents])
+ if([[doc valueForKeyPath:@"customQueryInstance"] respondsToSelector:@selector(queryFavoritesHaveBeenUpdated:)])
+ [[doc valueForKeyPath:@"customQueryInstance"] queryFavoritesHaveBeenUpdated:self];
+
}
@@ -693,7 +699,17 @@
}
if([spf objectForKey:@"queryFavorites"] && [[spf objectForKey:@"queryFavorites"] count]) {
- [favorites addObjectsFromArray:[spf objectForKey:@"queryFavorites"]];
+ if([favoritesTableView numberOfSelectedRows] > 0) {
+ // Insert imported queries after the last selected favorite
+ NSUInteger insertIndex = [[favoritesTableView selectedRowIndexes] lastIndex] + 1;
+ NSUInteger i;
+ for(i=0; i<[[spf objectForKey:@"queryFavorites"] count]; i++) {
+ [favorites insertObject:[[spf objectForKey:@"queryFavorites"] objectAtIndex:i] atIndex:insertIndex+i];
+ }
+ } else {
+ // If no selection add them
+ [favorites addObjectsFromArray:[spf objectForKey:@"queryFavorites"]];
+ }
[favoritesArrayController rearrangeObjects];
[favoritesTableView reloadData];
} else {