From c213d86c13973d280e43bb4c5c380e72c50b703e Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 15 Jul 2009 15:35:42 +0000 Subject: =?UTF-8?q?=E2=80=A2=20initial=20support=20for=20=E2=8C=98/=20in?= =?UTF-8?q?=20CustomQuery=20editor=20to=20(un)comment=20out=20the=20curren?= =?UTF-8?q?t=20query=20or=20selection=20by=20inserting=20"#=20"=20at=20the?= =?UTF-8?q?=20begin=20of=20each=20line=20-=20Note:=20not=20yet=20finished?= =?UTF-8?q?=20completely?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 6 +++++- Source/CustomQuery.h | 1 + Source/CustomQuery.m | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) (limited to 'Source') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index ecca0721..27fb0dab 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -531,6 +531,11 @@ 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. @@ -685,7 +690,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } - /* * Handle special commands - see NSResponder.h for a sample list. * This subclass currently handles insertNewline: in order to preserve indentation diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index ddd47e0e..56f56f0d 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -148,6 +148,7 @@ - (void)setFavorites; - (void)doPerformQueryService:(NSString *)query; - (void)selectCurrentQuery; +- (void)commentOutQuery; - (NSString *)usedQuery; - (NSString *)argumentForRow:(NSUInteger)rowIndex ofTable:(NSString *)tableForColumn; diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 7dc8e4dc..00834f80 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -927,6 +927,36 @@ [textView setSelectedRange:currentQueryRange]; } +- (void)commentOutQuery +{ + + if(!currentQueryRange.length && ![textView selectedRange].length) { + NSBeep(); + return; + } + + NSRange workingRange; + + NSRange oldRange = [textView selectedRange]; + + if(oldRange.length) + workingRange = oldRange; + else + 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:@""]; + + [textView setSelectedRange:workingRange]; + + [textView insertText:n]; + + [textView setSelectedRange:NSMakeRange(NSMaxRange(currentQueryRange),0)]; +} + #pragma mark - #pragma mark Accessors -- cgit v1.2.3