Skip to content

Commit

Permalink
null place holder & remove two menu add code
Browse files Browse the repository at this point in the history
  • Loading branch information
0hoo committed Feb 18, 2012
1 parent 7a1d255 commit 14144f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
8 changes: 6 additions & 2 deletions English.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -1127,10 +1127,14 @@
<string key="NSLabel">value: arrangedObjects.BundleID</string>
<string key="NSBinding">value</string>
<string key="NSKeyPath">arrangedObjects.BundleID</string>
<object class="NSDictionary" key="NSOptions">
<string key="NS.key.0">NSNullPlaceholder</string>
<string key="NS.object.0">com.company.editorapp</string>
</object>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
<int key="connectionID">917</int>
<int key="connectionID">918</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
Expand Down Expand Up @@ -1839,7 +1843,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">917</int>
<int key="maxID">918</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand Down
2 changes: 2 additions & 0 deletions QCAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
NSStatusItem *quickCursorStatusItem;
NSMutableSet *quickCursorSessionQCUIElements;
NSMutableArray *registeredHotKeys;

NSArray *cachedMenuItems;
}

+ (BOOL)universalAccessNeedsToBeTurnedOn;
Expand Down
41 changes: 12 additions & 29 deletions QCAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ + (BOOL)universalAccessNeedsToBeTurnedOn {
}
}


- (NSArray *)validatedEditorMenuItems:(SEL)action {
static NSArray *cachedMenuItems = nil;

if (!cachedMenuItems) {
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
NSMutableArray *menuItems = [NSMutableArray array];

for (NSString *eachBundleID in [[NSBundle mainBundle] objectForInfoDictionaryKey:@"QCEditInChoices"]) {

NSMutableArray *editInChoices = [NSMutableArray arrayWithArray:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"QCEditInChoices"]];
for (NSDictionary *customEditors in [[NSUserDefaults standardUserDefaults] objectForKey:@"CustomEditors"]) {
NSString *bundleID = [customEditors objectForKey:@"BundleID"];
if (bundleID) {
[editInChoices addObject:bundleID];
}
}

for (NSString *eachBundleID in editInChoices) {
NSString *bundlePath = [workspace absolutePathForAppBundleWithIdentifier:eachBundleID];

if (bundlePath) {
Expand All @@ -64,31 +71,7 @@ - (NSArray *)validatedEditorMenuItems:(SEL)action {
[menuItems addObject:eachMenuItem];
}
}

for (NSDictionary *customEditors in [[NSUserDefaults standardUserDefaults] objectForKey:@"CustomEditors"]) {
NSString *eachBundleID = [customEditors objectForKey:@"BundleID"];
NSString *bundlePath = [workspace absolutePathForAppBundleWithIdentifier:eachBundleID];
if (bundlePath) {
NSString *bundleName = [[NSBundle bundleWithPath:bundlePath] objectForInfoDictionaryKey:@"CFBundleName"]; // seems to be nil in some cases.
if (!bundleName) {
bundleName = [[bundlePath lastPathComponent] stringByDeletingPathExtension];
}

if ([eachBundleID isEqualToString:@"org.gnu.Aquamacs"]) {
bundleName = [bundleName stringByAppendingString:@" 2.2+"];
}

NSMenuItem *eachMenuItem = [[[NSMenuItem alloc] initWithTitle:bundleName action:NULL keyEquivalent:@""] autorelease];
[eachMenuItem setRepresentedObject:eachBundleID];
[eachMenuItem setIndentationLevel:1];
NSImage *icon = [workspace iconForFile:bundlePath];
[icon setSize:NSMakeSize(16, 16)];
[eachMenuItem setImage:icon];
[menuItems addObject:eachMenuItem];
}
}

[menuItems sortUsingDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES] autorelease]]];
[menuItems sortUsingDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES] autorelease]]];

cachedMenuItems = [menuItems retain];
}
Expand Down

0 comments on commit 14144f6

Please sign in to comment.