This repository has been archived by the owner on Jul 20, 2018. It is now read-only.
/
STEAppDelegate.m
74 lines (57 loc) · 2.38 KB
/
STEAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// ATEAppDelegate.m
// AwesomeTextEditor
//
// Created by Steven Degutis on 3/24/10.
// Copyright 2010 Big Nerd Ranch, Inc. All rights reserved.
//
#import "STEAppDelegate.h"
#import "STEPluginManager.h"
@implementation STEAppDelegate
// when we finish launching, try to launch our python interface
- (void) applicationDidFinishLaunching:(NSNotification *)notification {
if (![[STEPluginManager sharedManager] setupPythonEnvironment])
NSLog(@"error: python environment could not be set up.");
}
// get all files on the desktop that have the .py extension
- (NSArray*) validScriptFiles {
// use the desktop for our simple purposes
NSString *desktopPath = [@"~/Desktop" stringByStandardizingPath];
// get all files on the desktop
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *desktopFiles = [fileManager contentsOfDirectoryAtPath:desktopPath
error:NULL];
NSMutableArray *paths = [NSMutableArray array];
// only find files that have .py extension, and add their full filenames
for (NSString *desktopFile in desktopFiles)
if ([[desktopFile pathExtension] caseInsensitiveCompare: @"py"] == NSOrderedSame)
[paths addObject:[desktopPath stringByAppendingPathComponent:desktopFile]];
// sort files alphabetically by their filename
[paths sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
id name1 = [[obj1 lastPathComponent] stringByDeletingPathExtension];
id name2 = [[obj1 lastPathComponent] stringByDeletingPathExtension];
return [name1 caseInsensitiveCompare: name2];
}];
return paths;
}
// when the Scripts menu is being shown, show the list of available scripts
- (void)menuNeedsUpdate:(NSMenu*)menu {
[menu removeAllItems];
for (NSString *fullPath in [self validScriptFiles]) {
// add a menu item for each script
NSString *scriptTitle = [[[fullPath lastPathComponent] stringByDeletingPathExtension] capitalizedString];
// our document subclass implements the -runScript: selector
NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:scriptTitle
action:@selector(runScript:)
keyEquivalent:@""] autorelease];
[item setRepresentedObject:fullPath];
[menu addItem:item];
}
if ([menu numberOfItems] == 0) {
NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:@"No Scripts"
action:NULL
keyEquivalent:@""] autorelease];
[menu addItem:item];
}
}
@end