From cf83a507b6732f20f3b49b453333b7e20e80037b Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sun, 5 Apr 2009 16:12:30 +0000 Subject: =?UTF-8?q?=E2=80=A2=20ADDED=20to=20SPTextViewAdditions:=20-=20(NS?= =?UTF-8?q?Range)getRangeForCurrentWord=20-=20(IBAction)selectCurrentWord:?= =?UTF-8?q?(id)sender;=20-=20(IBAction)selectCurrentLine:(id)sender;=20-?= =?UTF-8?q?=20(IBAction)doSelectionUpperCase:(id)sender;=20-=20(IBAction)d?= =?UTF-8?q?oSelectionLowerCase:(id)sender;=20-=20(IBAction)doSelectionTitl?= =?UTF-8?q?eCase:(id)sender;=20-=20(IBAction)doDecomposedStringWithCanonic?= =?UTF-8?q?alMapping:(id)sender;=20-=20(IBAction)doDecomposedStringWithCom?= =?UTF-8?q?patibilityMapping:(id)sender;=20-=20(IBAction)doPrecomposedStri?= =?UTF-8?q?ngWithCanonicalMapping:(id)sender;=20-=20(IBAction)doPrecompose?= =?UTF-8?q?dStringWithCompatibilityMapping:(id)sender;=20=E2=80=A2=20BOUND?= =?UTF-8?q?ED=20these=20IBAction=20to=20mainmenu.xib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/MainMenu.xib | 504 +++++++--------------------------- Source/CMTextView.m | 147 ---------- Source/SPTextViewAdditions.h | 10 + Source/SPTextViewAdditions.m | 180 ++++++++++++ 4 files changed, 286 insertions(+), 555 deletions(-) diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib index 2b06210a..50e6e528 100644 --- a/Interfaces/English.lproj/MainMenu.xib +++ b/Interfaces/English.lproj/MainMenu.xib @@ -8,7 +8,7 @@ 353.00 YES - + YES @@ -4128,6 +4128,78 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 866 + + + selectCurrentWord: + + + + 895 + + + + selectCurrentLine: + + + + 896 + + + + doSelectionUpperCase: + + + + 897 + + + + doSelectionLowerCase: + + + + 898 + + + + doSelectionTitleCase: + + + + 899 + + + + doDecomposedStringWithCanonicalMapping: + + + + 900 + + + + doPrecomposedStringWithCanonicalMapping: + + + + 901 + + + + doDecomposedStringWithCompatibilityMapping: + + + + 902 + + + + doPrecomposedStringWithCompatibilityMapping: + + + + 903 + @@ -6156,7 +6228,6 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA YES - @@ -6164,6 +6235,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA + @@ -6935,7 +7007,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA com.apple.InterfaceBuilder.CocoaPlugin - {{232, 439}, {157, 253}} + {{234, 225}, {157, 253}} com.apple.InterfaceBuilder.CocoaPlugin {{654, 613}, {157, 223}} @@ -7145,7 +7217,7 @@ Y2hhbmdlIHRoZSBvcmRlcg com.apple.InterfaceBuilder.CocoaPlugin - {{84, 692}, {511, 20}} + {{86, 478}, {511, 20}} com.apple.InterfaceBuilder.CocoaPlugin {{506, 836}, {511, 20}} @@ -7534,7 +7606,7 @@ Y2hhbmdlIHRoZSBvcmRlcg com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{389, 499}, {213, 143}} + {{391, 285}, {213, 143}} com.apple.InterfaceBuilder.CocoaPlugin ToolTip @@ -7576,7 +7648,7 @@ Y2hhbmdlIHRoZSBvcmRlcg com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{602, 429}, {304, 93}} + {{604, 215}, {304, 93}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -7630,23 +7702,11 @@ w6gg4oaSIGZhY2FkZV0 - 894 + 903 YES - - CMCopyTable - NSTableView - - copy: - id - - - IBProjectSource - Source/CMCopyTable.h - - FirstResponder NSObject @@ -7716,14 +7776,6 @@ w6gg4oaSIGZhY2FkZV0 - - KeyChain - NSObject - - IBProjectSource - Source/KeyChain.h - - KeyChain NSObject @@ -7732,108 +7784,6 @@ w6gg4oaSIGZhY2FkZV0 - - MainController - NSObject - - YES - - YES - addFavorite: - checkForUpdates: - chooseLimitRows: - closeFavoriteSheet: - copyFavorite: - donate: - openPreferences: - removeFavorite: - toggleUseSSH: - visitHelpWebsite: - visitWebsite: - - - YES - id - id - id - id - id - id - id - id - id - id - id - - - - YES - - YES - databaseField - dontShowBlobSwitch - encodingPopUpButton - favoriteSheet - fetchRowCountSwitch - hostField - keyChainInstance - limitRowsField - limitRowsSwitch - nameField - nullValueField - passwordField - portField - preferencesWindow - reloadAfterAddingSwitch - reloadAfterEditingSwitch - reloadAfterRemovingSwitch - showErrorSwitch - socketField - sshCheckbox - sshHostField - sshPasswordField - sshPortField - sshUserField - tableView - useMonospacedFontsSwitch - userField - - - YES - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - - - - IBProjectSource - Source/MainController.h - - MainController NSObject @@ -7854,243 +7804,31 @@ w6gg4oaSIGZhY2FkZV0 + + + YES NSObject - - IBProjectSource - Source/CMImageView.h - - - - NSObject - - IBProjectSource - Source/CMMCPConnection.h - - - - SPQueryConsole - NSWindowController - - YES - - YES - clearConsole: - copy: - saveConsoleAs: - toggleShowSelectShowStatements: - toggleShowTimeStamps: - - - YES - id - id - id - id - id - - - - YES - - YES - clearConsoleButton - consoleSearchField - consoleTableView - includeTimeStampsButton - progressIndicator - saveConsoleButton - saveLogView - - - YES - NSButton - NSSearchField - NSTableView - NSButton - NSProgressIndicator - NSButton - NSView - - - - IBProjectSource - Source/SPQueryConsole.h - - - - TableDocument - NSDocument - - YES - - YES - addDatabase: - analyzeTable: - cancelConnectSheet: - checkTable: - checksumTable: - chooseDatabase: - chooseEncoding: - chooseFavorite: - closeDatabaseSheet: - closeSheet: - connect: - connectSheetAddToFavorites: - connectToDB: - copyCreateTableSyntax: - export: - exportMultipleTables: - exportTable: - flushPrivileges: - flushTable: - import: - optimizeTable: - removeDatabase: - removeFavorite: - repairTable: - setDatabases: - showCreateTableSyntax: - showVariables: - viewContent: - viewQuery: - viewStatus: - viewStructure: - - - YES - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - - - - YES - - YES - addDatabaseButton - chooseDatabaseButton - connectFavoritesTableView - connectProgressBar - connectProgressStatusText - connectSheet - createTableSyntaxWindow - customQueryInstance - customQueryTextView - databaseEncodingButton - databaseField - databaseNameField - databaseSheet - dbTablesTableView - favoritesButton - favoritesController - hostField - keyChainInstance - passwordField - portField - queryProgressBar - sidebarGrabber - socketField - syntaxView - syntaxViewContent - tableContentInstance - tableDataInstance - tableDumpInstance - tableSourceInstance - tableStatusInstance - tableTabView - tableWindow - tablesListInstance - userField - variablesSheet - variablesTableView - - - YES - id - id - NSTableView - id - id - id - NSWindow - id - NSTextView - id - id - id - id - NSTableView - id - NSArrayController - id - id - id - id - id - id - id - id - id - id - id - id - id - id - NSTabView - id - id - id - id - id - - - - IBProjectSource - Source/TableDocument.h + + IBDocumentRelativeSource + ../../Frameworks/Sparkle.framework/Versions/A/Headers/SUUpdater.h - TablesList - NSObject + NSTextView YES YES - addTable: - closeCopyTableSheet: - closeTableSheet: - copyTable: - removeTable: - updateTables: + doDecomposedStringWithCanonicalMapping: + doDecomposedStringWithCompatibilityMapping: + doPrecomposedStringWithCanonicalMapping: + doPrecomposedStringWithCompatibilityMapping: + doSelectionLowerCase: + doSelectionTitleCase: + doSelectionUpperCase: + selectCurrentLine: + selectCurrentWord: YES @@ -8100,64 +7838,14 @@ w6gg4oaSIGZhY2FkZV0 id id id - - - - YES - - YES - addTableButton - copyTableContentSwitch - copyTableNameField - copyTableSheet - customQueryInstance - tabView - tableContentInstance - tableDataInstance - tableDocumentInstance - tableDumpInstance - tableEncodingButton - tableNameField - tableSheet - tableSourceInstance - tableStatusInstance - tableWindow - tablesListView - - - YES - id - id - id - id - id - id - id - id - id - id - id - id - id - id id id id - IBProjectSource - Source/TablesList.h - - - - - YES - - NSObject - IBDocumentRelativeSource - ../../Frameworks/Sparkle.framework/Versions/A/Headers/SUUpdater.h + ../../Source/SPTextViewAdditions.h diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 49aee2cf..0493f0c8 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -116,46 +116,6 @@ YY_BUFFER_STATE yy_scan_string (const char *); return YES; } -/* - * Select current line and returns found NSRange. - */ -- (NSRange)selectCurrentLine -{ - [self doCommandBySelector:@selector(moveToBeginningOfLine:)]; - [self doCommandBySelector:@selector(moveToEndOfLineAndModifySelection:)]; - - return([self selectedRange]); -} - -/* - * Select current word and returns found NSRange. - * finds: [| := caret] |word wo|rd word| - * If | is in between whitespaces nothing will be selected. - */ -- (NSRange)selectCurrentWord -{ - NSRange curRange = [self selectedRange]; - unsigned long curLocation = curRange.location; - [self doCommandBySelector:@selector(moveWordLeft:)]; - [self doCommandBySelector:@selector(moveWordRightAndModifySelection:)]; - - unsigned long newStartRange = [self selectedRange].location; - unsigned long newEndRange = newStartRange + [self selectedRange].length; - - // if current location does not intersect with found range - // then caret is at the begin of a word -> change strategy - if(curLocation < newStartRange || curLocation > newEndRange) - { - [self setSelectedRange:curRange]; - [self doCommandBySelector:@selector(moveWordRightAndModifySelection:)]; - } - - if([[[self string] substringWithRange:[self selectedRange]] rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].location != NSNotFound) - [self setSelectedRange:curRange]; - - return([self selectedRange]); -} - /* * Copy selected text chunk as RTF to preserve syntax highlighting */ @@ -175,76 +135,6 @@ YY_BUFFER_STATE yy_scan_string (const char *); } -/* - * Change selection or current word to upper case and preserves the selection. - */ -- (void)doSelectionUpperCase -{ - NSRange curRange = [self selectedRange]; - [self insertText:[[[self string] substringWithRange:(curRange.length)?curRange:[self selectCurrentWord]] uppercaseString]]; - [self setSelectedRange:curRange]; -} - -/* - * Change selection or current word to lower case and preserves the selection. - */ -- (void)doSelectionLowerCase -{ - NSRange curRange = [self selectedRange]; - [self insertText:[[[self string] substringWithRange:(curRange.length)?curRange:[self selectCurrentWord]] lowercaseString]]; - [self setSelectedRange:curRange]; -} - -/* - * Change selection or current word to title case and preserves the selection. - */ -- (void)doSelectionTitleCase -{ - NSRange curRange = [self selectedRange]; - [self insertText:[[[self string] substringWithRange:(curRange.length)?curRange:[self selectCurrentWord]] capitalizedString]]; - [self setSelectedRange:curRange]; -} - -/* - * Change selection or current word according to Unicode's NFD and preserves the selection. - */ -- (void)doDecomposedStringWithCanonicalMapping -{ - NSRange curRange = [self selectedRange]; - [self insertText:[[[self string] substringWithRange:(curRange.length)?curRange:[self selectCurrentWord]] decomposedStringWithCanonicalMapping]]; - [self setSelectedRange:curRange]; -} - -/* - * Change selection or current word according to Unicode's NFKD and preserves the selection. - */ -- (void)doDecomposedStringWithCompatibilityMapping -{ - NSRange curRange = [self selectedRange]; - [self insertText:[[[self string] substringWithRange:(curRange.length)?curRange:[self selectCurrentWord]] decomposedStringWithCompatibilityMapping]]; - [self setSelectedRange:curRange]; -} - -/* - * Change selection or current word according to Unicode's NFC and preserves the selection. - */ -- (void)doPrecomposedStringWithCanonicalMapping -{ - NSRange curRange = [self selectedRange]; - [self insertText:[[[self string] substringWithRange:(curRange.length)?curRange:[self selectCurrentWord]] precomposedStringWithCanonicalMapping]]; - [self setSelectedRange:curRange]; -} - -/* - * Change selection or current word according to Unicode's NFKC to title case and preserves the selection. - */ -- (void)doPrecomposedStringWithCompatibilityMapping -{ - NSRange curRange = [self selectedRange]; - [self insertText:[[[self string] substringWithRange:(curRange.length)?curRange:[self selectCurrentWord]] precomposedStringWithCompatibilityMapping]]; - [self setSelectedRange:curRange]; -} - /* * Handle some keyDown events in order to provide autopairing functionality (if enabled). @@ -271,20 +161,6 @@ YY_BUFFER_STATE yy_scan_string (const char *); // Note: switch(insertedCharacter) {} does not work instead use charactersIgnoringModifiers - if([charactersIgnMod isEqualToString:@"w"]) // ^W select current word - if(curFlags==(NSControlKeyMask)) - { - [self selectCurrentWord]; - return; - } - - if([charactersIgnMod isEqualToString:@"l"]) // ^L select current line - if(curFlags==(NSControlKeyMask)) - { - [self selectCurrentLine]; - return; - } - if([charactersIgnMod isEqualToString:@"c"]) // ^C copy as RTF if(curFlags==(NSControlKeyMask)) { @@ -292,29 +168,6 @@ YY_BUFFER_STATE yy_scan_string (const char *); return; } - if([charactersIgnMod isEqualToString:@"u"]) - // ^U upper case - if(curFlags==(NSControlKeyMask)) - { - [self doSelectionUpperCase]; - return; - } - // ^⌥U title case - if(curFlags==(NSControlKeyMask|NSAlternateKeyMask)) - { - [self doSelectionTitleCase]; - return; - } - - if([charactersIgnMod isEqualToString:@"U"]) // ^⇧U lower case - if(([theEvent modifierFlags] - & (NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask))==(NSControlKeyMask)) - { - [self doSelectionLowerCase]; - return; - } - - // Only process for character autopairing if autopairing is enabled and a single character is being added. if (autopairEnabled && characters && [characters length] == 1) { diff --git a/Source/SPTextViewAdditions.h b/Source/SPTextViewAdditions.h index eacd7724..0aaa4cde 100644 --- a/Source/SPTextViewAdditions.h +++ b/Source/SPTextViewAdditions.h @@ -24,4 +24,14 @@ @interface NSTextView (SPTextViewAdditions) +- (IBAction)selectCurrentWord:(id)sender; +- (IBAction)selectCurrentLine:(id)sender; +- (IBAction)doSelectionUpperCase:(id)sender; +- (IBAction)doSelectionLowerCase:(id)sender; +- (IBAction)doSelectionTitleCase:(id)sender; +- (IBAction)doDecomposedStringWithCanonicalMapping:(id)sender; +- (IBAction)doDecomposedStringWithCompatibilityMapping:(id)sender; +- (IBAction)doPrecomposedStringWithCanonicalMapping:(id)sender; +- (IBAction)doPrecomposedStringWithCompatibilityMapping:(id)sender; + @end \ No newline at end of file diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 426cc1b5..6031399d 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -24,5 +24,185 @@ @implementation NSTextView (SPTextViewAdditions) +/* + * Returns the range of the current word. + * finds: [| := caret] |word wo|rd word| + * If | is in between whitespaces nothing will be selected. + */ +- (NSRange)getRangeForCurrentWord +{ + + NSRange curRange = [self selectedRange]; + unsigned long curLocation = curRange.location; + + [self moveWordLeft:self]; + [self moveWordRightAndModifySelection:self]; + + unsigned long newStartRange = [self selectedRange].location; + unsigned long newEndRange = newStartRange + [self selectedRange].length; + + // if current location does not intersect with found range + // then caret is at the begin of a word -> change strategy + if(curLocation < newStartRange || curLocation > newEndRange) + { + [self setSelectedRange:curRange]; + [self moveWordRightAndModifySelection:self]; + } + + if([[[self string] substringWithRange:[self selectedRange]] rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].location != NSNotFound) + [self setSelectedRange:curRange]; + + NSRange wordRange = [self selectedRange]; + + [self setSelectedRange:curRange]; + + return(wordRange); + +} + +/* + * Select current word. + * finds: [| := caret] |word wo|rd word| + * If | is in between whitespaces nothing will be selected. + */ +- (IBAction)selectCurrentWord:(id)sender +{ + [self setSelectedRange:[self getRangeForCurrentWord]]; +} + +/* + * Select current line. + */ +- (IBAction)selectCurrentLine:(id)sender +{ + [self doCommandBySelector:@selector(moveToBeginningOfLine:)]; + [self doCommandBySelector:@selector(moveToEndOfLineAndModifySelection:)]; +} + +/* + * Change selection or current word to upper case and preserves the selection. + */ +- (IBAction)doSelectionUpperCase:(id)sender +{ + NSRange curRange = [self selectedRange]; + NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord]; + [self setSelectedRange:selRange]; + [self insertText:[[[self string] substringWithRange:selRange] uppercaseString]]; + [self setSelectedRange:curRange]; +} + +/* + * Change selection or current word to lower case and preserves the selection. + */ +- (IBAction)doSelectionLowerCase:(id)sender +{ + NSRange curRange = [self selectedRange]; + NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord]; + [self setSelectedRange:selRange]; + [self insertText:[[[self string] substringWithRange:selRange] lowercaseString]]; + [self setSelectedRange:curRange]; +} + +/* + * Change selection or current word to title case and preserves the selection. + */ +- (IBAction)doSelectionTitleCase:(id)sender +{ + NSRange curRange = [self selectedRange]; + NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord]; + [self setSelectedRange:selRange]; + [self insertText:[[[self string] substringWithRange:selRange] capitalizedString]]; + [self setSelectedRange:curRange]; +} + +/* + * Change selection or current word according to Unicode's NFD and preserves the selection. + */ +- (IBAction)doDecomposedStringWithCanonicalMapping:(id)sender +{ + NSRange curRange = [self selectedRange]; + NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord]; + [self setSelectedRange:selRange]; + NSString* convString = [[[self string] substringWithRange:selRange] decomposedStringWithCanonicalMapping]; + [self insertText:convString]; + + // correct range for combining characters + if(curRange.length) + [self setSelectedRange:NSMakeRange(selRange.location, [convString length])]; + else + // if no selection place the caret at the end of the current word + { + NSRange newRange = [self getRangeForCurrentWord]; + [self setSelectedRange:NSMakeRange(newRange.location + newRange.length, 0)]; + } +} + +/* + * Change selection or current word according to Unicode's NFKD and preserves the selection. + */ +- (IBAction)doDecomposedStringWithCompatibilityMapping:(id)sender +{ + NSRange curRange = [self selectedRange]; + NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord]; + [self setSelectedRange:selRange]; + NSString* convString = [[[self string] substringWithRange:selRange] decomposedStringWithCompatibilityMapping]; + [self insertText:convString]; + + // correct range for combining characters + if(curRange.length) + [self setSelectedRange:NSMakeRange(selRange.location, [convString length])]; + else + // if no selection place the caret at the end of the current word + { + NSRange newRange = [self getRangeForCurrentWord]; + [self setSelectedRange:NSMakeRange(newRange.location + newRange.length, 0)]; + } +} + +/* + * Change selection or current word according to Unicode's NFC and preserves the selection. + */ +- (IBAction)doPrecomposedStringWithCanonicalMapping:(id)sender +{ + NSRange curRange = [self selectedRange]; + NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord]; + [self setSelectedRange:selRange]; + NSString* convString = [[[self string] substringWithRange:selRange] precomposedStringWithCanonicalMapping]; + [self insertText:convString]; + + // correct range for combining characters + if(curRange.length) + [self setSelectedRange:NSMakeRange(selRange.location, [convString length])]; + else + // if no selection place the caret at the end of the current word + { + NSRange newRange = [self getRangeForCurrentWord]; + [self setSelectedRange:NSMakeRange(newRange.location + newRange.length, 0)]; + } +} + +/* + * Change selection or current word according to Unicode's NFKC to title case and preserves the selection. + */ +- (IBAction)doPrecomposedStringWithCompatibilityMapping:(id)sender +{ + NSRange curRange = [self selectedRange]; + NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord]; + [self setSelectedRange:selRange]; + NSString* convString = [[[self string] substringWithRange:selRange] precomposedStringWithCompatibilityMapping]; + [self insertText:convString]; + + // correct range for combining characters + if(curRange.length) + [self setSelectedRange:NSMakeRange(selRange.location, [convString length])]; + else + // if no selection place the caret at the end of the current word + { + NSRange newRange = [self getRangeForCurrentWord]; + [self setSelectedRange:NSMakeRange(newRange.location + newRange.length, 0)]; + } +} + + @end -- cgit v1.2.3