├── rsrc
├── InfoPlist.strings
├── url map.plist
├── Info
└── Info.plist
├── src
├── Edit in TextMate.h
├── NSTextView: Edit in TextMate.mm
├── Edit in TextMate.mm
└── WebView: Edit in TextMate.mm
└── Makefile
/rsrc/InfoPlist.strings:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/textmate/edit-in-textmate/master/rsrc/InfoPlist.strings
--------------------------------------------------------------------------------
/rsrc/url map.plist:
--------------------------------------------------------------------------------
1 | {
2 | 'macromates.com/blog/' = 'markdown';
3 | 'blacktree.cocoaforge.com/forums/' = 'bbcode';
4 | 'mail.google.com/' = 'mail';
5 | }
--------------------------------------------------------------------------------
/rsrc/Info:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | BundleName
6 | Edit in TextMate.bundle
7 | LoadBundleOnLaunch
8 | YES
9 | LocalizedNames
10 |
11 | English
12 | Edit in TextMate
13 |
14 | NoMenuEntry
15 | YES
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/Edit in TextMate.h:
--------------------------------------------------------------------------------
1 | //
2 | // Edit in TextMate.h
3 | //
4 | // Created by Allan Odgaard on 2005-11-26.
5 | // See /trunk/LICENSE for license details
6 | //
7 |
8 | #import
9 |
10 | bool debug_enabled ();
11 |
12 | #define D(format, args...) if(debug_enabled()) NSLog(format, ##args);
13 |
14 | @interface EditInTextMate : NSObject
15 | {
16 | }
17 | + (void)externalEditString:(NSString*)aString startingAtLine:(int)aLine forView:(NSView*)aView;
18 | + (void)externalEditString:(NSString*)aString startingAtLine:(int)aLine forView:(NSView*)aView withObject:(NSObject*)anObject;
19 | @end
20 |
--------------------------------------------------------------------------------
/rsrc/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | Edit in TextMate
9 | CFBundleName
10 | Edit in TextMate
11 | CFBundleIconFile
12 |
13 | CFBundleIdentifier
14 | com.macromates.edit_in_textmate
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundlePackageType
18 | BNDL
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | NSPrincipalClass
24 | EditInTextMate
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | NAME = Edit\ in\ TextMate
2 | DST = /tmp/$(NAME)
3 | DST_BUNDLE = $(DST)/$(NAME).bundle
4 | DST_CONTENTS = $(DST_BUNDLE)/Contents
5 | DST_BIN = $(DST_CONTENTS)/MacOS
6 | DST_RSRC = $(DST_CONTENTS)/Resources
7 | DST_LANG = $(DST_RSRC)/English.lproj
8 |
9 | CFLAGS = -pipe -fPIC -Os -DNDEBUG
10 | CFLAGS += -m32 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk
11 | CFLAGS += -funsigned-char -fvisibility=hidden
12 | CFLAGS += -DNS_BUILD_32_LIKE_64
13 | CFLAGS += -Wall -Wwrite-strings -Wformat=2 -Winit-self -Wmissing-include-dirs -Wno-parentheses -Wno-sign-compare -Wno-switch
14 |
15 | all: $(DST)/Info $(DST_CONTENTS)/Info.plist $(DST_BIN)/$(NAME) $(DST_LANG)/InfoPlist.strings $(DST_RSRC)/url\ map.plist
16 |
17 | $(DST): ; mkdir '$@'
18 | $(DST_BUNDLE): $(DST); mkdir '$@'
19 | $(DST_CONTENTS): $(DST_BUNDLE); mkdir '$@'
20 | $(DST_BIN): $(DST_CONTENTS); mkdir '$@'
21 | $(DST_RSRC): $(DST_CONTENTS); mkdir '$@'
22 | $(DST_LANG): $(DST_RSRC); mkdir '$@'
23 |
24 | $(DST)/Info: rsrc/Info $(DST); cp '$<' '$@'
25 | $(DST_CONTENTS)/Info.plist: rsrc/Info.plist $(DST_CONTENTS); cp '$<' '$@'
26 | $(DST_LANG)/InfoPlist.strings: rsrc/InfoPlist.strings $(DST_LANG); cp '$<' '$@'
27 | $(DST_RSRC)/url\ map.plist: rsrc/url\ map.plist $(DST_RSRC); cp '$<' '$@'
28 |
29 | $(DST_BIN)/$(NAME): src/Edit\ in\ TextMate.mm $(DST_BIN)
30 | g++ -bundle $(CFLAGS) -o '$@' src/*.mm -framework Cocoa -framework Carbon -framework WebKit
31 |
32 | install: $(DST_BIN)/$(NAME)
33 | cp -pR $(DST) /Library/InputManagers/$(NAME) && chown -R root /Library/InputManagers/$(NAME)
34 |
35 | uninstall:
36 | rm -rf /Library/InputManagers/$(NAME)
37 |
38 | clean:
39 | rm -rf $(DST)
40 |
41 | .PHONY: all clean install uninstall
42 |
--------------------------------------------------------------------------------
/src/NSTextView: Edit in TextMate.mm:
--------------------------------------------------------------------------------
1 | //
2 | // NSTextView: Edit in TextMate.mm
3 | //
4 | // Created by Allan Odgaard on 2005-11-27.
5 | // See /trunk/LICENSE for license details
6 | //
7 |
8 | #import "Edit in TextMate.h"
9 |
10 | @interface NSTextView (EditInTextMate)
11 | - (void)editInTextMate:(id)sender;
12 | @end
13 |
14 | @implementation NSTextView (EditInTextMate)
15 | - (void)editInTextMate:(id)sender
16 | {
17 | D(@"editInTextMate: view: %@", self);
18 | if(![self isEditable])
19 | return (void)NSBeep();
20 |
21 | NSString* str = [[self textStorage] string];
22 | NSRange selectedRange = [self selectedRange];
23 | int lineNumber = 0;
24 | if(selectedRange.length == 0)
25 | {
26 | NSRange range = NSMakeRange(0, 0);
27 | do {
28 | NSRange oldRange = range;
29 | range = [str lineRangeForRange:NSMakeRange(NSMaxRange(range), 0)];
30 | if(NSMaxRange(oldRange) == NSMaxRange(range) || selectedRange.location < NSMaxRange(range))
31 | break;
32 | lineNumber++;
33 | } while(true);
34 | selectedRange = NSMakeRange(0, [str length]);
35 | }
36 | D(@"%s editing %u bytes from view: %@", _cmd, [[str substringWithRange:selectedRange] length], self);
37 | [EditInTextMate externalEditString:[str substringWithRange:selectedRange] startingAtLine:lineNumber forView:self];
38 | }
39 |
40 | - (void)textMateDidModifyString:(NSString*)newString
41 | {
42 | NSLog(@"[%@ textMateDidModifyString:%@]", [self class], newString);
43 | NSRange selectedRange = [self selectedRange];
44 | BOOL hadSelection = selectedRange.length != 0;
45 | selectedRange = hadSelection ? selectedRange : NSMakeRange(0, [[self textStorage] length]);
46 | if([self shouldChangeTextInRange:selectedRange replacementString:newString])
47 | {
48 | if(!hadSelection)
49 | [self setSelectedRange:NSMakeRange(0, [[self textStorage] length])];
50 | [self insertText:newString];
51 | if(hadSelection)
52 | [self setSelectedRange:NSMakeRange(selectedRange.location, [newString length])];
53 | [self didChangeText];
54 | }
55 | else
56 | {
57 | NSBeep();
58 | NSLog(@"%s couldn't edit text", SELNAME(_cmd));
59 | }
60 | }
61 | @end
62 |
--------------------------------------------------------------------------------
/src/Edit in TextMate.mm:
--------------------------------------------------------------------------------
1 | //
2 | // Edit in TextMate.mm
3 | //
4 | // Created by Allan Odgaard on 2005-11-26.
5 | // See /trunk/LICENSE for license details
6 | //
7 |
8 | #import
9 | #import
10 | #import