Commits

Anonymous committed f3d4640

Preferences: filter out apps that can't be found in the file system

Comments (0)

Files changed (1)

Source/MercurialApp.m

     if (!s_supportedTextEditors) {
         NSString *path = [[NSBundle mainBundle] pathForResource: @"TextEditors" ofType: @"plist"];
         s_supportedTextEditors = [NSArray arrayWithContentsOfFile: path];
+
+        // filter apps that can't be found
+        NSMutableArray *tmpSupportedTextEditors = [s_supportedTextEditors mutableCopy];
+        for (NSDictionary *value in s_supportedTextEditors) {
+            if ([[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:(NSString *)[value objectForKey:@"editorID"]] == nil)
+                [tmpSupportedTextEditors removeObject:value];
+        }
+        s_supportedTextEditors = [tmpSupportedTextEditors copy];
+
         Assert(s_supportedTextEditors);
     }
     return s_supportedTextEditors;
     [_textEditorPreferenceButton addItemsWithTitles:[[self supportedTextEditors] valueForKeyPath:@"@unionOfObjects.editorName"]];
 
     for (id item in [[self supportedTextEditors] valueForKeyPath:@"@unionOfObjects.editorID"]) {
-        NSString *path = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:(NSString *)item];
-
-        if (path != nil) { // app was found
-            NSMenuItem *menuItem = [_textEditorPreferenceButton itemAtIndex:[[[self supportedTextEditors] valueForKeyPath:@"@unionOfObjects.editorID"] indexOfObject:item]];
-            [menuItem setImage:[[NSWorkspace sharedWorkspace] iconForFile:path]];
-            [[menuItem image] setSize:NSMakeSize(16, 16)];
-        }
+        NSMenuItem *menuItem = [_textEditorPreferenceButton itemAtIndex:[[[self supportedTextEditors] valueForKeyPath:@"@unionOfObjects.editorID"] indexOfObject:item]];
+        [menuItem setImage:[[NSWorkspace sharedWorkspace] iconForFile:[[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:(NSString *)item]]];
+        [[menuItem image] setSize:NSMakeSize(16, 16)];
     }
 
    NSString *selectedEditorID = [[NSUserDefaults standardUserDefaults] stringForKey:kPrefPreferredTextEditorID];