aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-04 17:42:04 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-04 17:42:04 +0000
commit6d3980063a2a37d7c3310a9808312b358ebdb2d3 (patch)
treedbcb6de00b028a4b6630f03ec403cfa9d28cd179 /Source
parent4763ed6268a0c384cbd8ebbb8a324111cb7cc99d (diff)
downloadsequelpro-6d3980063a2a37d7c3310a9808312b358ebdb2d3.tar.gz
sequelpro-6d3980063a2a37d7c3310a9808312b358ebdb2d3.tar.bz2
sequelpro-6d3980063a2a37d7c3310a9808312b358ebdb2d3.zip
• fixed: suppress highlighting of the current query if something is selected
• added: "Select Active Query ^Y" context menu item to the Custom Query Editor
Diffstat (limited to 'Source')
-rw-r--r--Source/CMTextView.h1
-rw-r--r--Source/CMTextView.m30
-rw-r--r--Source/CustomQuery.h1
-rw-r--r--Source/CustomQuery.m8
4 files changed, 37 insertions, 3 deletions
diff --git a/Source/CMTextView.h b/Source/CMTextView.h
index 152ddbc9..6c4da129 100644
--- a/Source/CMTextView.h
+++ b/Source/CMTextView.h
@@ -84,5 +84,6 @@
- (void) setConnection:(CMMCPConnection *)theConnection withVersion:(int)majorVersion;
- (void) doCompletion;
- (NSArray *)suggestionsForSQLCompletionWith:(NSString *)currentWord dictMode:(BOOL)isDictMode;
+- (void) selectCurrentQuery;
@end
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 0a38712f..e519a146 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -63,6 +63,7 @@ YY_BUFFER_STATE yy_scan_string (const char *);
#define SP_CQ_SEARCH_IN_MYSQL_HELP_MENU_ITEM_TAG 1000
#define SP_CQ_COPY_AS_RTF_MENU_ITEM_TAG 1001
+#define SP_CQ_SELECT_CURRENT_QUERY_MENU_ITEM_TAG 1002
#define SP_SYNTAX_HILITE_BIAS 2000
@@ -429,6 +430,10 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
}
}
+- (void) selectCurrentQuery
+{
+ [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] selectCurrentQuery];
+}
/*
* Selects the line lineNumber relatively to a selection (if given) and scrolls to it
@@ -534,12 +539,18 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
[self copyAsRTF];
return;
}
- if([charactersIgnMod isEqualToString:@"h"]) // ^C copy as RTF
+ if([charactersIgnMod isEqualToString:@"h"]) // ^H show MySQL Help
if(curFlags==(NSControlKeyMask))
{
[self showMySQLHelpForCurrentWord:self];
return;
}
+ if([charactersIgnMod isEqualToString:@"y"]) // ⇧⌘A select current query
+ if(curFlags==(NSControlKeyMask))
+ {
+ [self selectCurrentQuery];
+ return;
+ }
if(curFlags & NSCommandKeyMask) {
if([charactersIgnMod isEqualToString:@"+"]) // increase text size by 1; ⌘+ and numpad +
{
@@ -2310,6 +2321,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
// Add the menu items for
// - MySQL Help for Word/Selection
// - Copy as RTF
+ // - Select Active Query
// if it doesn't yet exist
NSMenu *menu = [[self class] defaultMenu];
@@ -2330,6 +2342,16 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
[copyAsRTFMenuItem setKeyEquivalentModifierMask:NSControlKeyMask];
[menu insertItem:copyAsRTFMenuItem atIndex:2];
}
+ if ([[[self class] defaultMenu] itemWithTag:SP_CQ_SELECT_CURRENT_QUERY_MENU_ITEM_TAG] == nil)
+ {
+ NSMenuItem *selectCurrentQueryMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Select Active Query", @"Select Active Query") action:@selector(selectCurrentQuery) keyEquivalent:@"q"];
+ [selectCurrentQueryMenuItem setTag:SP_CQ_SELECT_CURRENT_QUERY_MENU_ITEM_TAG];
+ [selectCurrentQueryMenuItem setKeyEquivalentModifierMask:NSControlKeyMask];
+ [menu insertItem:selectCurrentQueryMenuItem atIndex:4];
+ }
+ // Hide "Select Active Query" if self is not editable
+ [[menu itemAtIndex:4] setHidden:![self isEditable]];
+
return menu;
}
@@ -2347,7 +2369,11 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
// Enable Copy as RTF if soemthing is selected
if ([menuItem action] == @selector(copyAsRTF)) {
return ([self selectedRange].length>0);
- }
+ }
+ // Validate Select Active Query
+ if ([menuItem action] == @selector(selectCurrentQuery)) {
+ return ([self isEditable]);
+ }
return YES;
}
diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h
index 68fdbf49..87f739ae 100644
--- a/Source/CustomQuery.h
+++ b/Source/CustomQuery.h
@@ -136,6 +136,7 @@
- (void)setConnection:(CMMCPConnection *)theConnection;
- (void)setFavorites;
- (void)doPerformQueryService:(NSString *)query;
+- (void)selectCurrentQuery;
- (NSString *)usedQuery;
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index cbb9a38c..63a1efd4 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -818,6 +818,11 @@
return (queryRange.length) ? [[textView string] substringWithRange:queryRange] : nil;
}
+- (void)selectCurrentQuery
+{
+ if(currentQueryRange.length)
+ [textView setSelectedRange:currentQueryRange];
+}
#pragma mark -
#pragma mark Accessors
@@ -1245,7 +1250,8 @@
NSRange qRange = [self queryRangeAtPosition:caretPosition lookBehind:&isLookBehind];
// Highlight by setting a background color the current query
- if(qRange.length) {
+ // if nothing is selected
+ if(qRange.length && !currentSelection.length) {
[[textView textStorage] addAttribute: NSBackgroundColorAttributeName
value: [NSColor colorWithDeviceRed:0.95 green:0.95 blue:0.95 alpha:1]
range: qRange ];