From 7baf6b3c55d8a697bee72b846596ff371dbea8ac Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 7 Apr 2009 13:05:09 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20auto-uppercasing=20for:=20pastin?= =?UTF-8?q?g=20queries=20from=20favourites=20&=20history=20and=20before=20?= =?UTF-8?q?performQueries=20=E2=80=A2=20improved=20undo=20behaviour=20of?= =?UTF-8?q?=20auto-uppercasing=20=E2=80=A2=20added=20undo=20behaviour=20fo?= =?UTF-8?q?r=20pasting=20queries=20from=20favourites=20&=20history?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 18 +++++++++++------- Source/CustomQuery.m | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 0493f0c8..e8bb59ba 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -976,14 +976,18 @@ SYNTAX HIGHLIGHTING! unsigned long tokenEnd = tokenRange.location+tokenRange.length-1; // Check the end of the token if (autouppercaseKeywordsEnabled && [[self textStorage] attribute:kSQLkeyword atIndex:tokenEnd effectiveRange:nil]) - // check if next char is not a kSQLkeyword; if so then upper case keyword + // check if next char is not a kSQLkeyword; if so then upper case keyword if not already done // @try catch() for catching valid index esp. after deleteBackward: - @try { - if(![[self textStorage] attribute:kSQLkeyword atIndex:tokenEnd+1 effectiveRange:nil]) - // Register it for undo - // [self shouldChangeTextInRange:tokenRange replacementString:[[[self string] substringWithRange:tokenRange] uppercaseString]]; - // NOTE: If one does this registering it ends up in single-character-undo - [self replaceCharactersInRange:tokenRange withString:[[[self string] substringWithRange:tokenRange] uppercaseString]]; + @try + { + NSString* curTokenString = [[self string] substringWithRange:tokenRange]; + if(![[self textStorage] attribute:kSQLkeyword atIndex:tokenEnd+1 effectiveRange:nil] && + ![[curTokenString uppercaseString] isEqualToString:curTokenString]) + { + // Register it for undo works only partly for now, at least the uppercased keyword will be selected + [self shouldChangeTextInRange:tokenRange replacementString:[curTokenString uppercaseString]]; + [self replaceCharactersInRange:tokenRange withString:[curTokenString uppercaseString]]; + } } @catch(id ae) { } [textStore addAttribute: NSForegroundColorAttributeName diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 23590fa7..39f961c6 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -56,6 +56,9 @@ [self performQueries:queries]; + // Invoke textStorageDidProcessEditing: for syntax highlighting and auto-uppercase + [textView insertText:@""]; + // Select the text of the query textView for re-editing [textView selectAll:self]; } @@ -87,6 +90,12 @@ [queryParser release]; } + // Invoke textStorageDidProcessEditing: for syntax highlighting and auto-uppercase + // and preserve the selection + [textView setSelectedRange:NSMakeRange(0,0)]; + [textView insertText:@""]; + [textView setSelectedRange:selectedRange]; + [self performQueries:queries]; } @@ -128,7 +137,11 @@ insert the choosen favorite query in the query textView or save query to favorit [queryFavoritesSheet orderOut:nil]; } else if ( [queryFavoritesButton indexOfSelectedItem] != 3) { //choose favorite + // Register the next action for undo + [textView shouldChangeTextInRange:[textView selectedRange] replacementString:[queryFavoritesButton titleOfSelectedItem]]; [textView replaceCharactersInRange:[textView selectedRange] withString:[queryFavoritesButton titleOfSelectedItem]]; + // invoke textStorageDidProcessEditing: for syntax highlighting and auto-uppercase + [textView insertText:@""]; } } @@ -137,7 +150,11 @@ insert the choosen favorite query in the query textView or save query to favorit insert the choosen history query in the query textView */ { + // Register the next action for undo + [textView shouldChangeTextInRange:NSMakeRange(0,[[textView string] length]) replacementString:[queryHistoryButton titleOfSelectedItem]]; [textView setString:[queryHistoryButton titleOfSelectedItem]]; + // Invoke textStorageDidProcessEditing: for syntax highlighting and auto-uppercase + [textView insertText:@""]; [textView selectAll:self]; } -- cgit v1.2.3