aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CustomQuery.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-09-04 08:45:47 +0000
committerBibiko <bibiko@eva.mpg.de>2009-09-04 08:45:47 +0000
commit931a46891ac3f0610363105419b01eb7b40b034f (patch)
tree26c68003589c07e2bdd8ebad53111e778c54f13d /Source/CustomQuery.m
parenta8bee6d7815cf9431cc53522f74bed648087a674 (diff)
downloadsequelpro-931a46891ac3f0610363105419b01eb7b40b034f.tar.gz
sequelpro-931a46891ac3f0610363105419b01eb7b40b034f.tar.bz2
sequelpro-931a46891ac3f0610363105419b01eb7b40b034f.zip
• implementation of a new history controller
- each history is doc-based even if you have opened not only one instance of the same spf file - for each SPF file identified by its file URL SP remembers each history item regardless from which doc instance it comes from internally ( to make sure that after closing the last instance of a doc all executed queries are saved in that file - if the user wants to change that s/he has to save that file under a different name ) - the history list for each Untitled doc will be initialized by the items stored in the global SP's prefs - the history list for each SPF doc will be initialized by the items stored in the SPF file unless an instance of the same file is already open - then the new instance inherits the history list from the opened one(s) - all history items executed in any Untitled docs will be added to SP's prefs - in other words SP's global prefs plist is the historyrepository for each new Untitled doc - if the user saves an untitled doc or rename an opened SPF file the _current_ history list for that doc will be saved to the chosen file unless an other doc instance is still open - all history lists are saved automatically if SP quits or the user closes a doc window Note: This should be tested for any logical pitfalls - each desired logic can be implemented :)
Diffstat (limited to 'Source/CustomQuery.m')
-rw-r--r--Source/CustomQuery.m50
1 files changed, 14 insertions, 36 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 8b8a8968..d679a1de 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -38,6 +38,7 @@
#import "SPTextAndLinkCell.h"
#import "SPTooltip.h"
#import "SPQueryFavoriteManager.h"
+#import "SPQueryController.h"
#define SP_MYSQL_DEV_SEARCH_URL @"http://search.mysql.com/search?q=%@&site=refman-%@"
#define SP_HELP_SEARCH_IN_MYSQL 0
@@ -238,13 +239,14 @@
{
// "Clear History" menu item - clear query history
if (sender == clearHistoryMenuItem) {
- // Remove all history buttons beginning from the end
+
+ // Remove all history buttons except the search field beginning from the end
while([queryHistoryButton numberOfItems] > 2)
[queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1];
- // [queryHistoryButton addItemWithTitle:NSLocalizedString(@"Query History…",@"Title of query history popup button")];
- [prefs setObject:[NSArray array] forKey:@"queryHistory"];
- [prefs synchronize];
+ // Remove all items from the queryController
+ [[SPQueryController sharedQueryController] replaceHistoryByArray:[NSMutableArray array] forFileURL:[tableDocumentInstance fileURL]];
+
}
// "Shift Right" menu item - indent the selection with an additional tab.
@@ -340,7 +342,6 @@
NSArray *theColumns;
NSTableColumn *theCol;
MCPStreamingResult *streamingResult = nil;
- NSMutableArray *menuItems = [NSMutableArray array];
NSMutableString *errors = [NSMutableString string];
int i, totalQueriesRun = 0, totalAffectedRows = 0;
@@ -491,17 +492,17 @@
// if(!queriesSeparatedByDelimiter) { // TODO only add to history if no “delimiter” command was used
if(!tableReloadAfterEditing && [usedQuery length]) {
- [queryHistoryButton insertItemWithTitle:usedQuery atIndex:2];
+ // Register new history item
+ [[SPQueryController sharedQueryController] addHistory:usedQuery forFileURL:[tableDocumentInstance fileURL]];
- int maxHistoryItems = [[prefs objectForKey:@"CustomQueryMaxHistoryItems"] intValue];
+ // Add it to the document's current popup list
+ [queryHistoryButton insertItemWithTitle:usedQuery atIndex:2];
+ // Check for max history
+ NSUInteger maxHistoryItems = [[prefs objectForKey:@"CustomQueryMaxHistoryItems"] intValue];
while ( [queryHistoryButton numberOfItems] > maxHistoryItems + 2 )
[queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1];
- for ( i = 2 ; i < [queryHistoryButton numberOfItems] ; i++ )
- [menuItems addObject:[queryHistoryButton itemTitleAtIndex:i]];
-
- [prefs setObject:menuItems forKey:@"queryHistory"];
}
// Error checking
@@ -1057,23 +1058,6 @@
return currentResult;
}
-/*
- * Return the document-based favourites
- */
-- (NSArray *)localFavorites
-{
- return localFavorites;
-}
-
-/*
- * Return the document-based history items
- */
-- (NSArray *)localHistoryItems
-{
- return localHistoryItems;
-}
-
-
#pragma mark -
#pragma mark Additional methods
@@ -1113,9 +1097,9 @@
[autouppercaseKeywordsMenuItem setState:([prefs boolForKey:@"CustomQueryAutoUppercaseKeywords"]?NSOnState:NSOffState)];
[textView setAutouppercaseKeywords:[prefs boolForKey:@"CustomQueryAutoUppercaseKeywords"]];
- if ( [prefs objectForKey:@"queryHistory"] )
+ if ( [[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] )
{
- [queryHistoryButton addItemsWithTitles:[prefs objectForKey:@"queryHistory"]];
+ [queryHistoryButton addItemsWithTitles:[[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]]];
}
// Disable runSelectionMenuItem in the gear menu
@@ -2575,10 +2559,6 @@
// init tableView's data source
fullResult = [[NSMutableArray alloc] init];
- // init local favorite and history item array
- localHistoryItems = [[NSMutableArray alloc] init];
- localFavorites = [[NSMutableArray alloc] init];
-
prefs = [NSUserDefaults standardUserDefaults];
}
@@ -2627,8 +2607,6 @@
[usedQuery release];
[fullResult release];
[favoritesManager release];
- if (localFavorites) [localFavorites release];
- if (localHistoryItems) [localHistoryItems release];
if (sortField) [sortField release];
[super dealloc];