Permalink
Browse files

add setting panel

  • Loading branch information...
typester committed Oct 31, 2009
1 parent 1214500 commit b337d4c1662e84421ed9b2bf1172727a0d8c22ca
Showing with 375 additions and 30 deletions.
  1. +6 −0 Classes/App.h
  2. +27 −1 Classes/App.m
  3. +332 −15 English.lproj/MainMenu.xib
  4. +10 −14 emacs-handler.xcodeproj/project.pbxproj
View
@@ -1,7 +1,13 @@
#import <Cocoa/Cocoa.h>
@interface App : NSObject {
+ NSString *path;
+ IBOutlet NSWindow *prefPanel;
+ IBOutlet NSTextField *textField;
}
+-(IBAction)showPrefPanel:(id)sender;
+-(IBAction)applyChange:(id)sender;
+
@end
View
@@ -5,11 +5,16 @@
@implementation App
-(void)awakeFromNib {
+ NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
+ path = [d objectForKey:@"path"];
+
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
}
-(void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
+ if (nil == path) return;
+
// emacs://open/?url=file://~/.bash_profile&line=11&column=2
NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
@@ -24,7 +29,7 @@ -(void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSApple
if (file) {
NSTask *task = [[NSTask alloc] init];
- [task setLaunchPath:@"/Applications/CarbonEmacs.app/Contents/MacOS/bin/emacsclient"];
+ [task setLaunchPath:path];
[task setArguments:[NSArray arrayWithObjects:@"-n", [NSString stringWithFormat:@"+%d:%d", [line integerValue], [column integerValue]], file, nil]];
[task launch];
[task release];
@@ -33,4 +38,25 @@ -(void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSApple
}
}
+-(IBAction)showPrefPanel:(id)sender {
+ if (path) {
+ [textField setStringValue:path];
+ }
+ else {
+ [textField setStringValue:@""];
+ }
+ [prefPanel makeKeyAndOrderFront:nil];
+}
+
+-(IBAction)applyChange:(id)sender {
+ path = [textField stringValue];
+
+ if (path) {
+ NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
+ [d setObject:path forKey:@"path"];
+ }
+
+ [prefPanel orderOut:nil];
+}
+
@end
Oops, something went wrong.

0 comments on commit b337d4c

Please sign in to comment.