Permalink
Browse files

greatly improved

  • Loading branch information...
1 parent 195a835 commit 8c5952d1d6413be9f436637cb890b6680103161e Bastien Dejean committed Jun 13, 2010
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -8,12 +8,14 @@
{
NSString* wordCharacters;
NSCharacterSet* finalCharSet;
- NSMenu* windowMenu;
- NSMenuItem* updateFlexibleWordsMenuItem;
+ NSDictionary* wordCharactersDictionary;
}
+
+ (FlexibleWords*)instance;
- (id)initWithPlugInController:(id <TMPlugInController>)aController;
+- (void) updateWordCharactersDictionary;
- (NSString*)getWordCharacters;
- (NSCharacterSet*)getFinalCharSet;
- (void)updateWordCharacters;
+- (void)updateWordCharactersWithMode:(NSString*)mode;
@end
View
@@ -6,7 +6,7 @@
// ' ' `-' ' ` ' `-' ' `-' ' ' `-' ' `-' `-'
//
// Bastien Dejean
-// May 2010
+// June 2010
//
#import "FlexibleWords.h"
@@ -15,8 +15,8 @@
#import "objc/runtime.h"
@interface FlexibleWords (Private_FlexibleWords)
-- (void)installMenuItem;
- (void)dealloc;
+- (void)installMenuItem;
@end
@implementation FlexibleWords
@@ -37,37 +37,26 @@ - (id)initWithPlugInController:(id <TMPlugInController>)aController
{
if (self = [super init]) {
- [self installMenuItem];
+ [self installMenuItem];
+ [self updateWordCharactersDictionary];
[OakTextView jr_swizzleMethod:@selector(setCurrentMode:) withMethod:@selector(FW_setCurrentMode:) error:NULL];
- [OakTextView jr_swizzleMethod:@selector(preferencesDidChange:) withMethod:@selector(FW_preferencesDidChange:) error:NULL];
- [OakWordCharacters jr_swizzleMethod:@selector(isWordCharacter:) withMethod:@selector(FW_isWordCharacter:) error:NULL];
+ [OakWindow jr_swizzleMethod:@selector(becomeMainWindow) withMethod:@selector(FW_becomeMainWindow) error:NULL];
+
+ [OakWordCharacters jr_swizzleMethod:@selector(isWordCharacter:) withMethod:@selector(FW_isWordCharacter:) error:NULL];
}
return self;
}
-- (void)installMenuItem
+- (void) updateWordCharactersDictionary
{
- if(windowMenu = [[[[NSApp mainMenu] itemWithTitle:@"Edit"] submenu] retain])
- {
- NSArray* items = [windowMenu itemArray];
-
- int index = 0;
- for (NSMenuItem* item in items)
- {
- if ([[item title] isEqualToString:@"Special Characters…"])
- {
- index = [items indexOfObject:item]+1;
- }
- }
- updateFlexibleWordsMenuItem = [[NSMenuItem alloc] initWithTitle:@"Flexible Words" action:@selector(updateWordCharacters) keyEquivalent:@"u"];
- [updateFlexibleWordsMenuItem setKeyEquivalentModifierMask:NSControlKeyMask|NSCommandKeyMask];
- [updateFlexibleWordsMenuItem setTarget:self];
- [windowMenu insertItem:updateFlexibleWordsMenuItem atIndex:index];
- }
+ NSString* plistPath = [@"~/.TM_WordCharacters.plist" stringByExpandingTildeInPath];
+ wordCharactersDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
+ [self updateWordCharacters];
}
+
- (NSString*)getWordCharacters
{
return wordCharacters;
@@ -80,17 +69,25 @@ - (NSCharacterSet*)getFinalCharSet
- (void)updateWordCharacters
{
- NSDictionary* envVars = [[NSApp targetForAction:@selector(allEnvironmentVariables)] allEnvironmentVariables];
- wordCharacters = [envVars objectForKey:@"TM_WORD_CHARACTERS"];
-
- if (wordCharacters) {
- NSLog(@"wordCharacters: %@", wordCharacters);
- NSMutableCharacterSet *workingSet;
- workingSet = [[NSCharacterSet alphanumericCharacterSet] mutableCopy];
- [workingSet addCharactersInString:wordCharacters];
- finalCharSet = [workingSet copy];
- [workingSet release];
- }
+ NSString* mode;
+ object_getInstanceVariable([NSApp targetForAction:@selector(document)], "currentMode", (void**)&mode);
+ [self updateWordCharactersWithMode:mode];
+}
+
+- (void)updateWordCharactersWithMode:(NSString*)mode
+{
+ if (mode) {
+ wordCharacters = [wordCharactersDictionary objectForKey:mode];
+
+ if (wordCharacters) {
+ // NSLog(@"---> WordCharacters: %@", wordCharacters);
+ NSMutableCharacterSet *workingSet;
+ workingSet = [[NSCharacterSet alphanumericCharacterSet] mutableCopy];
+ [workingSet addCharactersInString:wordCharacters];
+ finalCharSet = [workingSet copy];
+ [workingSet release];
+ }
+ }
}
- (void)dealloc
@@ -100,6 +97,30 @@ - (void)dealloc
[super dealloc];
}
+- (void)installMenuItem
+{
+ NSMenu* windowMenu;
+
+ if (windowMenu = [[[[NSApp mainMenu] itemWithTitle:@"Bundles"] submenu] retain])
+ {
+ NSArray* items = [windowMenu itemArray];
+
+ int index = 0;
+ for (NSMenuItem* item in items)
+ {
+ if ([[item title] isEqualToString:@"Select Bundle Item…"])
+ {
+ index = [items indexOfObject:item]+1;
+ }
+ }
+
+ NSMenuItem* mi = [[NSMenuItem alloc] initWithTitle:@"Update FlexibleWords" action:@selector(updateWordCharactersDictionary) keyEquivalent:@"u"];
+ [mi setKeyEquivalentModifierMask:NSControlKeyMask|NSCommandKeyMask];
+ [mi setTarget:self];
+ [windowMenu insertItem:mi atIndex:index];
+ }
+}
+
+ (id)allocWithZone:(NSZone *)zone
{
@synchronized(self) {
@@ -128,7 +149,7 @@ - (NSUInteger)retainCount
- (void)release
{
- //do nothing
+ ;
}
- (id)autorelease
@@ -304,40 +304,42 @@
<key>Dock</key>
<array>
<dict>
- <key>BecomeActive</key>
- <true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>1CE0B20306471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
- <string>FlexibleWords.m</string>
+ <string>NSWindow+FlexibleWords.m</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>1CE0B20406471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
- <string>FlexibleWords.m</string>
+ <string>NSWindow+FlexibleWords.m</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
- <string>9F5F4BEA11B0596300BED343</string>
+ <string>9FDDF0BC11C5077C00D9BA4D</string>
<key>history</key>
<array>
<string>9F23111511AEA58700447964</string>
<string>9F23114A11AEA73400447964</string>
<string>9F23114B11AEA73400447964</string>
- <string>9F2311E011AF008D00447964</string>
- <string>9F2311E111AF008D00447964</string>
- <string>9F2311E211AF008D00447964</string>
<string>9F2311E311AF008D00447964</string>
- <string>9F23120711AF151400447964</string>
- <string>9FEB78EC11AFB5F200D18061</string>
<string>9FEB78ED11AFB5F200D18061</string>
- <string>9FEB791311AFEDCA00D18061</string>
- <string>9F8F547D11B055FF0027CD68</string>
+ <string>9FC9036F11C395440091AFA0</string>
+ <string>9FC903E511C3D4530091AFA0</string>
+ <string>9FDDF06711C4C6AB00D9BA4D</string>
+ <string>9FDDF09811C4FE4300D9BA4D</string>
+ <string>9FDDF0B411C5042000D9BA4D</string>
+ <string>9FDDF0B511C5042000D9BA4D</string>
+ <string>9FDDF0B611C5042000D9BA4D</string>
+ <string>9FDDF0B711C5042000D9BA4D</string>
+ <string>9FDDF0B811C5042000D9BA4D</string>
+ <string>9FDDF0BA11C5077C00D9BA4D</string>
+ <string>9FDDF0BB11C5077C00D9BA4D</string>
</array>
</dict>
<key>SplitCount</key>
@@ -349,16 +351,18 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
- <string>{{0, 0}, {1396, 655}}</string>
+ <string>{{0, 0}, {1396, 616}}</string>
<key>RubberWindowFrame</key>
<string>33 117 1604 916 0 0 1920 1058 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
- <string>655pt</string>
+ <string>616pt</string>
</dict>
<dict>
+ <key>BecomeActive</key>
+ <true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
@@ -369,14 +373,14 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
- <string>{{0, 660}, {1396, 215}}</string>
+ <string>{{0, 621}, {1396, 254}}</string>
<key>RubberWindowFrame</key>
<string>33 117 1604 916 0 0 1920 1058 </string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
<key>Proportion</key>
- <string>215pt</string>
+ <string>254pt</string>
</dict>
</array>
<key>Proportion</key>
@@ -395,9 +399,9 @@
</array>
<key>TableOfContents</key>
<array>
- <string>9F5F4BE711B0596200BED343</string>
+ <string>9FDDF0AF11C4FE5800D9BA4D</string>
<string>1CE0B1FE06471DED0097A5F4</string>
- <string>9F5F4BE811B0596200BED343</string>
+ <string>9FDDF0B011C4FE5800D9BA4D</string>
<string>1CE0B20306471E060097A5F4</string>
<string>1CE0B20506471E060097A5F4</string>
</array>
@@ -536,7 +540,7 @@
<key>WindowOrderList</key>
<array>
<string>9FE8EBFD11AE9CA1004DAEEA</string>
- <string>/Users/bloom/Documents/Source/Objective-C/FlexibleWords/FlexibleWords.xcodeproj</string>
+ <string>/Users/bloom/Documents/Source/Objective-C/Flexible-Words-TextMate/FlexibleWords.xcodeproj</string>
</array>
<key>WindowString</key>
<string>33 117 1604 916 0 0 1920 1058 </string>
@@ -616,7 +620,7 @@
<key>TableOfContents</key>
<array>
<string>9FE8EBFD11AE9CA1004DAEEA</string>
- <string>9F5F4BE911B0596200BED343</string>
+ <string>9FDDF0B111C4FE5800D9BA4D</string>
<string>1CD0528F0623707200166675</string>
<string>XCMainBuildResultsModuleGUID</string>
</array>
Oops, something went wrong.

0 comments on commit 8c5952d

Please sign in to comment.