diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-04-20 14:01:50 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-04-20 14:01:50 +0000 |
commit | 6e83f452684330b881cc2d57c57ea981934ba18a (patch) | |
tree | 78b076f3cd9d3c51bdba92c30cd54888fb3a9aca /Source/CustomQuery.m | |
parent | f821d5595b90517b20243610233dcf45f7f02d73 (diff) | |
download | sequelpro-6e83f452684330b881cc2d57c57ea981934ba18a.tar.gz sequelpro-6e83f452684330b881cc2d57c57ea981934ba18a.tar.bz2 sequelpro-6e83f452684330b881cc2d57c57ea981934ba18a.zip |
• added selectLineNumber:x to CMTextView to be able to select the line x
• added error highlighting of the first mentioned error
- if a "near message" error is provided select that message otherwise select the entire error line and scrolls to it
- if no "at line x" and no "near message" is given do nothing
- if a selection was given and the user pressed "runAll" destroy the selection before error checking; if no error was found reconstruct that selection (to be able to distinguish between "runSelection" and "runAll" plus selection)
* changed slightly the trigger for syntax highlighting/auto-uppercasing for better scrollToRange behaviour
Diffstat (limited to 'Source/CustomQuery.m')
-rw-r--r-- | Source/CustomQuery.m | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 3d8b5383..980116a3 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -54,14 +54,23 @@ queries = [queryParser splitStringByCharacter:';']; [queryParser release]; + NSRange curRange = [textView selectedRange]; + // Unselect a selection if given to avoid interferring with error highlighting + [textView setSelectedRange:NSMakeRange(curRange.location, 0)]; [self performQueries:queries]; + // If no error was selected reconstruct a given selection + if([textView selectedRange].length == 0) + [textView setSelectedRange:curRange]; // Invoke textStorageDidProcessEditing: for syntax highlighting and auto-uppercase - [textView setSelectedRange:NSMakeRange(0,0)]; + NSRange oldRange = [textView selectedRange]; + [textView setSelectedRange:NSMakeRange(oldRange.location,0)]; [textView insertText:@""]; + [textView setSelectedRange:oldRange]; + // Select the text of the query textView for re-editing - [textView selectAll:self]; + //[textView selectAll:self]; } /* @@ -93,7 +102,7 @@ // Invoke textStorageDidProcessEditing: for syntax highlighting and auto-uppercase // and preserve the selection - [textView setSelectedRange:NSMakeRange(0,0)]; + [textView setSelectedRange:NSMakeRange(selectedRange.location,0)]; [textView insertText:@""]; [textView setSelectedRange:selectedRange]; @@ -430,8 +439,36 @@ sets the tableView columns corresponding to the mysql-result } [prefs setObject:menuItems forKey:@"queryHistory"]; + // Error checking if ( [errors length] ) { + // set the error text [errorText setStringValue:errors]; + // select the line x of the first error if error message contains "at line x" + NSError *err1 = NULL; + NSRange errorLineNumberRange = [errors rangeOfRegex:@"at line ([0-9]+)" options:RKLNoOptions inRange:NSMakeRange(0, [errors length]) capture:1 error:&err1]; + if(errorLineNumberRange.length) // if a line number was found + { + // Get the line number + unsigned int errorAtLine = [[errors substringWithRange:errorLineNumberRange] intValue]; + [textView selectLineNumber:errorAtLine ignoreLeadingNewLines:YES]; + + // Check for near message + NSRange errorNearMessageRange = [errors rangeOfRegex:@"use near '(.*?)'" options:(RKLMultiline|RKLDotAll) inRange:NSMakeRange(0, [errors length]) capture:1 error:&err1]; + if(errorNearMessageRange.length) // if a "near message" was found + { + // Get the line of the first error via the current selected line + NSRange lineRange = [[textView string] lineRangeForRange:NSMakeRange([textView selectedRange].location, 0)]; + // Build the range to search for nearMessage (beginning from the error line to try to avoid mismatching) + NSRange theRange = NSMakeRange(lineRange.location, [[textView string] length]-lineRange.location); + // Get the range in textView of the near message + NSRange textNearMessageRange = [[[textView string] substringWithRange:theRange] rangeOfString:[errors substringWithRange:errorNearMessageRange] options:NSLiteralSearch]; + // Correct the near message range + textNearMessageRange = NSMakeRange(textNearMessageRange.location+lineRange.location, textNearMessageRange.length); + // Select the near message and scroll to it + [textView setSelectedRange:textNearMessageRange]; + [textView scrollRangeToVisible:textNearMessageRange]; + } + } } else { [errorText setStringValue:NSLocalizedString(@"There were no errors.", @"text shown when query was successfull")]; } |