Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for selecting between Sublime Text 2 and Sublime Text 3 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Classes/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

@interface App : NSObject {
NSString *path;
NSString *version;

IBOutlet NSWindow *prefPanel;
IBOutlet NSTextField *textField;
IBOutlet NSPopUpButton *versionSelector;
}

-(IBAction)showPrefPanel:(id)sender;
-(IBAction)applyChange:(id)sender;

-(void)populatePopUp;
-(NSString *)applicationBundleName;

@end
36 changes: 34 additions & 2 deletions Classes/App.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ @implementation App
-(void)awakeFromNib {
NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
path = [d objectForKey:@"path"];
version = [d objectForKey:@"version"];

NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];

[self populatePopUp];
}

-(void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
Expand Down Expand Up @@ -39,7 +42,7 @@ -(void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSApple
[task launch];
[task release];
NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
NSString *appPath = [sharedWorkspace fullPathForApplication:@"Sublime Text 2"];
NSString *appPath = [sharedWorkspace fullPathForApplication:[self applicationBundleName]];
NSString *identifier = [[NSBundle bundleWithPath:appPath] bundleIdentifier];
NSArray *selectedApps =
[NSRunningApplication runningApplicationsWithBundleIdentifier:identifier];
Expand All @@ -54,23 +57,52 @@ -(void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSApple
// }
}

-(void)populatePopUp {
[versionSelector removeAllItems];
[versionSelector addItemsWithTitles:[NSArray arrayWithObjects:@"Sublime Text 2", @"Sublime Text 3", nil]];
}

-(NSString *)applicationBundleName {
NSString* appName;

if (version == nil) {
appName = @"Sublime Text 2";
} else if ([version isEqual: @"Sublime Text 3"]) {
appName = @"Sublime Text";
} else {
appName = version;
}

return appName;
}

-(IBAction)showPrefPanel:(id)sender {
if (path) {
[textField setStringValue:path];
} else {
[textField setStringValue:defaultPath];
}

if (version) {
[versionSelector selectItemWithTitle:version];
}

[prefPanel makeKeyAndOrderFront:nil];
}

-(IBAction)applyChange:(id)sender {
NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
path = [textField stringValue];
version = [[versionSelector selectedItem] title];

if (path) {
NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
[d setObject:path forKey:@"path"];
}

if (version) {
[d setObject:version forKey:@"version"];
}

[prefPanel orderOut:nil];
}

Expand Down
Loading