-
Notifications
You must be signed in to change notification settings - Fork 0
/
FinderPatch.m
79 lines (62 loc) · 2.3 KB
/
FinderPatch.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
75
76
77
78
//
// FinderPatch.m
// FinderPatch
//
// Created by toy on 10.01.11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "FinderPatch.h"
@implementation FinderPatch
+ (void) loadPatch {
if ([self class] == [FinderPatch class]) {
NSString *finderPatchIconPath = [[self thisBundle] pathForImageResource:@"FinderPatch"];
NSImage *finderPatchIcon = [[NSImage alloc] initByReferencingFile:finderPatchIconPath];
[NSApp setApplicationIconImage:finderPatchIcon];
[finderPatchIcon release];
}
}
+ (NSMenu *) fileMenu {
return [[[NSApp mainMenu] itemWithTitle:@"File"] submenu];
}
+ (NSMenu *) patchMenu {
static NSMenu *finderPatchMenu = nil;
if (!finderPatchMenu) {
NSMenuItem *finderPatchItem = [[self fileMenu] addItemWithTitle:@"Finder Patch" action:nil keyEquivalent:@""];
finderPatchMenu = [[NSMenu alloc] init];
[finderPatchItem setSubmenu:finderPatchMenu];
}
return finderPatchMenu;
}
+ (NSBundle *) thisBundle {
return [NSBundle bundleForClass:[self class]];
}
+ (void) insertSeparatorInPatchMenu {
if ([[self patchMenu] numberOfItems] > 0) {
[[self patchMenu] addItem:[NSMenuItem separatorItem]];
}
}
+ (NSDictionary *) environment {
static NSMutableDictionary *env = nil;
if (env == nil) {
NSString *lines = [NSTask stdoutForCommand:[NSArray arrayWithObjects:@"sh", @"-c", @". ~/.bashrc; printenv", nil]];
env = [[NSMutableDictionary dictionary] retain];
[lines enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) {
NSUInteger equalLocation = [line rangeOfString:@"="].location;
[env setObject:[line substringFromIndex:equalLocation + 1] forKey:[line substringToIndex:equalLocation]];
}];
}
return [NSDictionary dictionaryWithDictionary:env];
}
+ (void) shiftItemWithKeyEquivalent:(NSString *)keyEquivalent andModifierMask:(NSUInteger)modifierMask {
NSMenuItem *keyEquivalentOwner = [[NSApp mainMenu] itemWithKeyEquivalent:keyEquivalent andModifierMask:modifierMask];
if (keyEquivalentOwner) {
[keyEquivalentOwner setKeyEquivalentModifierMask:NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask];
}
}
+ (NSArray *) refUrls:(FNReference *)ref {
return [[ref getListOfType:typeFSRef] mapUsingSelector:@selector(url)];
}
+ (NSArray *) refPaths:(FNReference *)ref {
return [[ref getListOfType:typeFSRef] mapUsingSelector:@selector(path)];
}
@end