From 6380481880bf44e8f50a47e606a6c8357c71afa5 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 15 Jul 2009 17:33:28 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Comment=20current=20Query/Selection=20-=20c?= =?UTF-8?q?hanged=20comment=20string=20to=20"--=20"=20-=20fixed=20bug=20in?= =?UTF-8?q?=20uncomment=20-=20added=20gear=20menu=20item=20--=20TODO:=20ch?= =?UTF-8?q?ange=20menu=20item=20title=20according=20to=20selection/current?= =?UTF-8?q?=20query=20(coming=20soon)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 5 ----- Source/CustomQuery.h | 1 + Source/CustomQuery.m | 20 ++++++++++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 27fb0dab..3720a521 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -531,11 +531,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [self makeTextSizeSmaller]; return; } - if([charactersIgnMod isEqualToString:@"/"]) - { - [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] commentOutQuery]; - return; - } } // Only process for character autopairing if autopairing is enabled and a single character is being added. diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index 56f56f0d..9d6ea2df 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -63,6 +63,7 @@ IBOutlet NSMenuItem *autopairMenuItem; IBOutlet NSMenuItem *autohelpMenuItem; IBOutlet NSMenuItem *autouppercaseKeywordsMenuItem; + IBOutlet NSMenuItem *commentCurrentQueryOrSelectionMenuItem; IBOutlet NSWindow *helpWebViewWindow; IBOutlet WebView *helpWebView; 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]; -- cgit v1.2.3