aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CustomQuery.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-07-15 17:33:28 +0000
committerBibiko <bibiko@eva.mpg.de>2009-07-15 17:33:28 +0000
commit6380481880bf44e8f50a47e606a6c8357c71afa5 (patch)
tree67e1ffbd0913ede532c546806de7e9b481461b09 /Source/CustomQuery.m
parentc213d86c13973d280e43bb4c5c380e72c50b703e (diff)
downloadsequelpro-6380481880bf44e8f50a47e606a6c8357c71afa5.tar.gz
sequelpro-6380481880bf44e8f50a47e606a6c8357c71afa5.tar.bz2
sequelpro-6380481880bf44e8f50a47e606a6c8357c71afa5.zip
• Comment current Query/Selection
- changed comment string to "-- " - fixed bug in uncomment - added gear menu item -- TODO: change menu item title according to selection/current query (coming soon)
Diffstat (limited to 'Source/CustomQuery.m')
-rw-r--r--Source/CustomQuery.m20
1 files changed, 16 insertions, 4 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 00834f80..59be27f8 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -212,6 +212,12 @@
[textView shiftSelectionLeft];
}
+ // "Comment Current Query/Selection" menu item - Add or remove "-- " for each line
+ // in the current query or selection
+ if (sender == commentCurrentQueryOrSelectionMenuItem) {
+ [self commentOutQuery];
+ }
+
// "Completion List" menu item - used to autocomplete. Uses a different shortcut to avoid the menu button flickering
// on normal autocomplete usage.
if (sender == completionListMenuItem) {
@@ -927,6 +933,9 @@
[textView setSelectedRange:currentQueryRange];
}
+/*
+ * Add or remove "-- " for each line in the current query or selection
+ */
- (void)commentOutQuery
{
@@ -945,11 +954,14 @@
workingRange = currentQueryRange;
NSMutableString *n = [NSMutableString string];
- [n setString:[NSString stringWithFormat:@"# %@", [[textView string] substringWithRange:workingRange]]];
- [n replaceOccurrencesOfRegex:@"\\n(?=.)" withString:@"\n# "];
- [n replaceOccurrencesOfRegex:@"\\n# # " withString:@"\n"];
- [n replaceOccurrencesOfRegex:@"^# # " withString:@""];
+ [n setString:[NSString stringWithFormat:@"-- %@", [[textView string] substringWithRange:workingRange]]];
+ [n replaceOccurrencesOfRegex:@"\\n(?=.)" withString:@"\n-- "];
+ // comment out if at least one line is already commented out
+ if(!([n isMatchedByRegex:@"(\\n-- --|^-- --)"] && [n isMatchedByRegex:@"(\\n-- |^-- )(?!-)"])) {
+ [n replaceOccurrencesOfRegex:@"\\n-- -- " withString:@"\n"];
+ [n replaceOccurrencesOfRegex:@"^-- -- " withString:@""];
+ }
[textView setSelectedRange:workingRange];
[textView insertText:n];