aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-09-04 17:40:56 +0000
committerBibiko <bibiko@eva.mpg.de>2009-09-04 17:40:56 +0000
commit9683c9df3cb0b1128429f42f108d4e03ca4550f1 (patch)
treee1ed970699a4d71e7dce31247ef45cc7c17e0810 /Source
parente00013ffbf5fb252a11fc6e2c68a1af0b9886317 (diff)
downloadsequelpro-9683c9df3cb0b1128429f42f108d4e03ca4550f1.tar.gz
sequelpro-9683c9df3cb0b1128429f42f108d4e03ca4550f1.tar.bz2
sequelpro-9683c9df3cb0b1128429f42f108d4e03ca4550f1.zip
• improved behavior while closing a document window
- if not connected close it without any checks - if an Untitled document contains stored query favorites - What should be done? - up to now it saves them to the global prefs • header in query favorites list keep visible while filtering • code cleaning
Diffstat (limited to 'Source')
-rw-r--r--Source/CustomQuery.h26
-rw-r--r--Source/CustomQuery.m55
-rw-r--r--Source/TableDocument.m27
3 files changed, 73 insertions, 35 deletions
diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h
index 9d1559e6..a9d4f670 100644
--- a/Source/CustomQuery.h
+++ b/Source/CustomQuery.h
@@ -32,6 +32,20 @@
#import "RegexKitLite.h"
#define SP_HELP_TOC_SEARCH_STRING @"contents"
+#define SP_HELP_SEARCH_IN_MYSQL 0
+#define SP_HELP_SEARCH_IN_PAGE 1
+#define SP_HELP_SEARCH_IN_WEB 2
+#define SP_HELP_GOBACK_BUTTON 0
+#define SP_HELP_SHOW_TOC_BUTTON 1
+#define SP_HELP_GOFORWARD_BUTTON 2
+#define SP_HELP_NOT_AVAILABLE @"__no_help_available"
+
+#define SP_MYSQL_DEV_SEARCH_URL @"http://search.mysql.com/search?q=%@&site=refman-%@"
+
+#define SP_SAVE_ALL_FAVORTITE_MENUITEM_TAG 100001
+#define SP_SAVE_SELECTION_FAVORTITE_MENUITEM_TAG 100000
+#define SP_FAVORITE_HEADER_MENUITEM_TAG 200000
+
@class SPQueryFavoriteManager;
@@ -43,8 +57,15 @@
IBOutlet id queryFavoritesButton;
IBOutlet NSMenuItem *queryFavoritesSearchMenuItem;
IBOutlet NSMenuItem *queryFavoritesSaveAsMenuItem;
+ IBOutlet NSMenuItem *queryFavoritesSaveAllMenuItem;
IBOutlet id queryFavoritesSearchFieldView;
IBOutlet NSSearchField *queryFavoritesSearchField;
+
+ IBOutlet NSWindow *queryFavoritesSheet;
+ IBOutlet NSButton *saveQueryFavoriteButton;
+ IBOutlet NSTextField *queryFavoriteNameTextField;
+ IBOutlet id saveQueryFavoriteGlobal;
+
IBOutlet id queryHistoryButton;
IBOutlet NSMenuItem *queryHistorySearchMenuItem;
IBOutlet id queryHistorySearchFieldView;
@@ -73,11 +94,6 @@
IBOutlet NSMenuItem *commentCurrentQueryMenuItem;
IBOutlet NSMenuItem *commentLineOrSelectionMenuItem;
- IBOutlet NSWindow *queryFavoritesSheet;
- IBOutlet NSButton *saveQueryFavoriteButton;
- IBOutlet NSTextField *queryFavoriteNameTextField;
- IBOutlet id saveQueryFavoriteGlobal;
-
IBOutlet NSWindow *helpWebViewWindow;
IBOutlet WebView *helpWebView;
IBOutlet NSSearchField *helpSearchField;
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 67741669..155113d9 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -40,15 +40,6 @@
#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
-#define SP_HELP_SEARCH_IN_PAGE 1
-#define SP_HELP_SEARCH_IN_WEB 2
-#define SP_HELP_GOBACK_BUTTON 0
-#define SP_HELP_SHOW_TOC_BUTTON 1
-#define SP_HELP_GOFORWARD_BUTTON 2
-#define SP_HELP_NOT_AVAILABLE @"__no_help_available"
-
@implementation CustomQuery
#pragma mark IBAction methods
@@ -2426,34 +2417,32 @@
// Insert new favorites and allow menu items with the same name
NSMenu *menu = [queryFavoritesButton menu];
- int i = 6;
- NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"Global" action:NULL keyEquivalent:@""];
- [item setTag:200000];
- [item setToolTip:@"All global favorites"];
+ NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"Document" action:NULL keyEquivalent:@""];
+ [item setTag:SP_FAVORITE_HEADER_MENUITEM_TAG];
+ [item setToolTip:[NSString stringWithFormat:@"‘%@’ based favorites",
+ [[[[tableDocumentInstance fileURL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] lastPathComponent]]];
[item setIndentationLevel:0];
[menu addItem:item];
[item release];
- for (NSDictionary *favorite in globalFavorites) {
+ for (NSDictionary *favorite in [[SPQueryController sharedQueryController] favoritesForFileURL:[tableDocumentInstance fileURL]]) {
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithString:[favorite objectForKey:@"name"]] action:NULL keyEquivalent:@""];
- [item setTag:i++];
[item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]];
[item setIndentationLevel:1];
[menu addItem:item];
[item release];
}
- item = [[NSMenuItem alloc] initWithTitle:@"Document" action:NULL keyEquivalent:@""];
- [item setTag:200000];
- [item setToolTip:@"All document-based favorites"];
+ item = [[NSMenuItem alloc] initWithTitle:@"Global" action:NULL keyEquivalent:@""];
+ [item setTag:SP_FAVORITE_HEADER_MENUITEM_TAG];
+ [item setToolTip:@"Globally stored favorites"];
[item setIndentationLevel:0];
[menu addItem:item];
[item release];
- for (NSDictionary *favorite in [[SPQueryController sharedQueryController] favoritesForFileURL:[tableDocumentInstance fileURL]]) {
+ for (NSDictionary *favorite in globalFavorites) {
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithString:[favorite objectForKey:@"name"]] action:NULL keyEquivalent:@""];
- [item setTag:i++];
[item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]];
[item setIndentationLevel:1];
[menu addItem:item];
@@ -2545,8 +2534,9 @@
*/
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{
- // Control "Save ... to Favorites" = tag is set to 1000
- if ( [menuItem tag] == 100000 ) {
+
+ // Control "Save ... to Favorites"
+ if ( [menuItem tag] == SP_SAVE_SELECTION_FAVORTITE_MENUITEM_TAG ) {
if ([[textView string] length] < 1) return NO;
if([textView selectedRange].length)
[menuItem setTitle:NSLocalizedString(@"Save Selection to Favorites",@"Save Selection to Favorites")];
@@ -2555,14 +2545,19 @@
else
[menuItem setTitle:NSLocalizedString(@"Save All to Favorites",@"Save All to Favorites")];
}
- // Control "Save All to Favorites" = tag is set to 1001
- if ( [menuItem tag] == 100001 ) {
+
+ // Control "Save All to Favorites"
+ if ( [menuItem tag] == SP_SAVE_ALL_FAVORTITE_MENUITEM_TAG ) {
if ([[textView string] length] < 1) return NO;
}
- if ( [menuItem tag] == 200000 ) {
+
+ // Avoid selecting button list headers
+ if ( [menuItem tag] == SP_FAVORITE_HEADER_MENUITEM_TAG ) {
return NO;
}
+
return YES;
+
}
@@ -2609,8 +2604,10 @@
{
int i;
NSMenu *menu = [queryFavoritesButton menu];
+ NSString *searchPattern = [queryFavoritesSearchField stringValue];
for (i=6; i< [menu numberOfItems]; i++)
- [[menu itemAtIndex:i] setHidden:(![[[menu itemAtIndex:i] title] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", [queryFavoritesSearchField stringValue]]])];
+ [[menu itemAtIndex:i] setHidden:([[menu itemAtIndex:i] tag] != SP_FAVORITE_HEADER_MENUITEM_TAG
+ && ![[[menu itemAtIndex:i] title] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", searchPattern]])];
}
@@ -2618,6 +2615,7 @@
{
int i;
NSMenu *menu = [queryHistoryButton menu];
+ NSString *searchPattern = [queryHistorySearchField stringValue];
for (i=2; i< [menu numberOfItems]; i++)
[[menu itemAtIndex:i] setHidden:(![[[menu itemAtIndex:i] title] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", [queryHistorySearchField stringValue]]])];
@@ -2625,6 +2623,11 @@
- (void)awakeFromNib
{
+
+ // Set pre-defined menu tags
+ [queryFavoritesSaveAsMenuItem setTag:SP_SAVE_SELECTION_FAVORTITE_MENUITEM_TAG];
+ [queryFavoritesSaveAllMenuItem setTag:SP_SAVE_ALL_FAVORTITE_MENUITEM_TAG];
+
// Set the structure and index view's vertical gridlines if required
[customQueryView setGridStyleMask:([prefs boolForKey:@"DisplayTableViewVerticalGridlines"]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
}
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 9c56ff04..a546333a 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -1925,7 +1925,7 @@
{
// Auto-save preferences to spf file based connection
if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"])
- if(![self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES]) {
+ if(_isConnected && ![self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES]) {
NSLog(@"Preference data for file ‘%@’ could not be saved.", [[[self fileURL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);
NSBeep();
}
@@ -2128,9 +2128,12 @@
// Update only query favourites, history, etc. by reading the file again
if(saveOnlyPreferences) {
- // Check for save file URL
- // TODO maybe alert ?
- if(![[[self fileURL] absoluteString] length] && ![[[self fileURL] absoluteString] hasPrefix:@"/"]) return NO;
+ // Check URL for safety reasons
+ if(![[[self fileURL] absoluteString] length] || ![[[self fileURL] absoluteString] hasPrefix:@"/"]) {
+ NSLog(@"Couldn't save data. No file URL found!");
+ NSBeep();
+ return NO;
+ }
NSError *readError = nil;
NSString *convError = nil;
@@ -2976,13 +2979,29 @@
if ( ![tablesListInstance selectionShouldChangeInTableView:nil] ) {
return NO;
} else {
+
+ if(!_isConnected) return YES;
+
// Auto-save spf file based connection
if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"]) {
BOOL isSaved = [self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES];
if(isSaved)
[[SPQueryController sharedQueryController] removeRegisteredDocumentWithFileURL:[self fileURL]];
return isSaved;
+
+ // Before removing an Untitled doc check if it contains any defined query favorites.
+ // If so save them globally. TODO: How to do it better ?
} else if([self fileURL] && [[[self fileURL] absoluteString] length] && ![[[self fileURL] absoluteString] hasPrefix:@"/"]) {
+ if([[[SPQueryController sharedQueryController] favoritesForFileURL:[self fileURL]] count]) {
+
+ NSMutableArray *favs = [[[NSMutableArray alloc] init] autorelease];
+ [favs addObjectsFromArray:[prefs objectForKey:@"queryFavorites"]];
+ [favs addObjectsFromArray:[[SPQueryController sharedQueryController] favoritesForFileURL:[self fileURL]]];
+ [prefs setObject:favs forKey:@"queryFavorites"];
+
+ if(![prefs synchronize])
+ NSLog(@"Sorry, couldn't backup query favorites from Untitled document.");
+ }
[[SPQueryController sharedQueryController] removeRegisteredDocumentWithFileURL:[self fileURL]];
return YES;
}