diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-12-08 12:39:45 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-12-08 12:39:45 +0000 |
commit | 8b4ae2928e82097e1957ef1873988d8677ac5426 (patch) | |
tree | 3b8c984cd2176af981e4d7e95ca402bb2b21167c | |
parent | d51530a48813b08d9694fed3a7a24998d495d5b5 (diff) | |
download | sequelpro-8b4ae2928e82097e1957ef1873988d8677ac5426.tar.gz sequelpro-8b4ae2928e82097e1957ef1873988d8677ac5426.tar.bz2 sequelpro-8b4ae2928e82097e1957ef1873988d8677ac5426.zip |
• Bundle Editor
- added completion support for shell variables via ESC or F5 or ⌘.
- added chance to select something and wrap it into corresponding closing char for ( ' " ` {
-rw-r--r-- | Source/SPBundleCommandTextView.h | 3 | ||||
-rw-r--r-- | Source/SPBundleCommandTextView.m | 57 | ||||
-rw-r--r-- | Source/SPBundleEditorController.h | 2 | ||||
-rw-r--r-- | Source/SPBundleEditorController.m | 57 |
4 files changed, 117 insertions, 2 deletions
diff --git a/Source/SPBundleCommandTextView.h b/Source/SPBundleCommandTextView.h index 78e6a02a..119121da 100644 --- a/Source/SPBundleCommandTextView.h +++ b/Source/SPBundleCommandTextView.h @@ -38,10 +38,11 @@ - (NSUInteger)characterIndexOfPoint:(NSPoint)aPoint; - (void)insertFileContentOfFile:(NSString *)aPath; - (void)saveChangedFontInUserDefaults; -- (void) setTabStops; +- (void)setTabStops; - (BOOL)shiftSelectionRight; - (BOOL)shiftSelectionLeft; - (void)commentOut; +- (BOOL)wrapSelectionWithPrefix:(unichar)prefix; @end diff --git a/Source/SPBundleCommandTextView.m b/Source/SPBundleCommandTextView.m index d5a649bb..2f9066b6 100644 --- a/Source/SPBundleCommandTextView.m +++ b/Source/SPBundleCommandTextView.m @@ -337,7 +337,7 @@ [super cut:sender]; } -- (void) setTabStops +- (void)setTabStops { NSFont *tvFont = [self font]; NSInteger i; @@ -395,6 +395,54 @@ [paragraphStyle release]; } +/** + * If the textview has a selection, wrap it with the supplied prefix and suffix strings; + * return whether or not any wrap was performed. + */ +- (BOOL)wrapSelectionWithPrefix:(unichar)prefix +{ + + NSRange currentRange = [self selectedRange]; + + // Only proceed if a selection is active + if (currentRange.length == 0 || ![self isEditable]) + return NO; + + unichar matchingCharacter; + + // Set matchingCharacter due to prefix. + switch (prefix) + { + case '(': + matchingCharacter = ')'; + break; + case '"': + matchingCharacter = '"'; + break; + case '`': + matchingCharacter = '`'; + break; + case '\'': + matchingCharacter = '\''; + break; + case '{': + matchingCharacter = '}'; + default: + return NO; + } + + NSString *selString = [[self string] substringWithRange:currentRange]; + + // Replace the current selection with the selected string wrapped in prefix and suffix + [self insertText:[NSString stringWithFormat:@"%c%@%c", prefix, selString, matchingCharacter]]; + + // Re-select original selection + NSRange innerSelectionRange = NSMakeRange(currentRange.location+1, [selString length]); + [self setSelectedRange:innerSelectionRange]; + + return YES; +} + - (void)keyDown:(NSEvent *)theEvent { @@ -410,7 +458,9 @@ return; } + NSString *characters = [theEvent characters]; NSString *charactersIgnMod = [theEvent charactersIgnoringModifiers]; + unichar insertedCharacter = [characters characterAtIndex:0]; long curFlags = ([theEvent modifierFlags] & allFlags); if(curFlags & NSCommandKeyMask) { @@ -452,6 +502,11 @@ [[self delegate] setDoGroupDueToChars]; } + // Check to see whether several characters are selected, and if so, wrap them with + // the auto-paired characters. This returns false if the selection has zero length. + if ([self wrapSelectionWithPrefix:insertedCharacter]) + return; + [super keyDown: theEvent]; } diff --git a/Source/SPBundleEditorController.h b/Source/SPBundleEditorController.h index ff475bb0..d586e5bc 100644 --- a/Source/SPBundleEditorController.h +++ b/Source/SPBundleEditorController.h @@ -106,6 +106,8 @@ BOOL selectionChanged; NSUndoManager *esUndoManager; + NSArray *shellVariableSuggestions; + } - (IBAction)inputPopupButtonChanged:(id)sender; diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 8fbf8e94..7c213a6f 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -95,6 +95,8 @@ [triggerGeneralArray release]; [withBlobDataTableArray release]; + [shellVariableSuggestions release]; + if(touchedBundleArray) [touchedBundleArray release], touchedBundleArray = nil; if(commandBundleTree) [commandBundleTree release], commandBundleTree = nil; if(sortDescriptor) [sortDescriptor release], sortDescriptor = nil; @@ -306,6 +308,48 @@ [commandBundleTreeController setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor, nil]]; + shellVariableSuggestions = [[NSArray arrayWithObjects: + @"SP_ALL_DATABASES", + @"SP_ALL_FUNCTIONS", + @"SP_ALL_PROCEDURES", + @"SP_ALL_TABLES", + @"SP_ALL_VIEWS", + @"SP_APP_RESOURCES_DIRECTORY", + @"SP_BUNDLE_EXIT_INSERT_AS_SNIPPET", + @"SP_BUNDLE_EXIT_INSERT_AS_TEXT", + @"SP_BUNDLE_EXIT_NONE", + @"SP_BUNDLE_EXIT_REPLACE_CONTENT", + @"SP_BUNDLE_EXIT_REPLACE_SELECTION", + @"SP_BUNDLE_EXIT_SHOW_AS_HTML", + @"SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP", + @"SP_BUNDLE_EXIT_SHOW_AS_TEXT_TOOLTIP", + @"SP_BUNDLE_INPUT", + @"SP_BUNDLE_INPUT_TABLE_METADATA", + @"SP_BUNDLE_PATH", + @"SP_BUNDLE_SCOPE", + @"SP_CURRENT_HOST", + @"SP_CURRENT_LINE", + @"SP_CURRENT_PORT", + @"SP_CURRENT_QUERY", + @"SP_CURRENT_USER", + @"SP_CURRENT_WORD", + @"SP_DATABASE_ENCODING", + @"SP_ICON_FILE", + @"SP_PROCESS_ID", + @"SP_QUERY_FILE", + @"SP_QUERY_RESULT_FILE", + @"SP_QUERY_RESULT_META_FILE", + @"SP_QUERY_RESULT_STATUS_FILE", + @"SP_RDBMS_TYPE", + @"SP_RDBMS_VERSION", + @"SP_SELECTED_DATABASE", + @"SP_SELECTED_ROW_INDICES", + @"SP_SELECTED_TABLE", + @"SP_SELECTED_TABLES", + @"SP_USED_QUERY_FOR_TABLE", + nil + ] retain]; + [self _initTree]; } @@ -1464,6 +1508,19 @@ } } +/** + * Add shell variable names to the completion list + */ +- (NSArray *)textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index +{ + + NSMutableArray *suggestions = [NSMutableArray array]; + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH %@ ", [[textView string] substringWithRange:charRange]]; + [suggestions addObjectsFromArray:[shellVariableSuggestions filteredArrayUsingPredicate:predicate]]; + [suggestions addObjectsFromArray:words]; + return suggestions; + +} #pragma mark - #pragma mark UndoManager methods |