adamontherun / xCodeGenerateDescriptionPlugin

Plugin to automatically generate the description for your class in XCode
103 stars 11 forks source link

Menu item not visible in Xcode 6.3.2 #16

Open jstuth opened 9 years ago

jstuth commented 9 years ago

Hey there,

today i was testing your plugin, and was not able to find the menu entry "Make Description" in my Xcode 6.3.2. So i was asking google for help, checked the UUIDs in the plist, reinstalled the plugin in Alcatraz. But nothing worked for me.... So i was asking google again and figured out what's "wrong" with the plugin on Xcode 6.3 an above. I checked the sources of the plugin "Backlight" which is showing in the edit menu of Xcode.

And according to this stack overflow post, there are some code changes necessary since Xcode is loading custom plugins first.

here is the solution that worked (sorry, i din't forked this project so have to post the changed source code as an issue):

- (id)initWithBundle:(NSBundle *)plugin
{
    if (self = [super init]) {
        // reference to plugin's bundle, for resource access
        self.bundle = plugin;

        // Create menu items, initialize UI, etc.

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuDidChange:)
                                                     name:NSMenuDidChangeItemNotification object:nil];
    }
    return self;
}

- (void)menuDidChange:(NSNotification *)notification
{
    // NOTE: This is just a workaround. We remove and re-add the observer.
    // In 10.11 DP, the NSMenuDidChangeItemNotification fires everytime a new menu item is "adding",
    // of course including the item we're trying to add now.
    // It is supposed to be a system bug because "DidChange" should be notified AFTER the changes.
    // Similar bug is reported in Xcode plug-in "FuzzyAutoComplete"'s issue, which is considered as
    // a bug introduced by 10.10.2-dp:
    //   https://github.com/FuzzyAutocomplete/FuzzyAutocompletePlugin/pull/57
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:NSMenuDidChangeItemNotification
                                                  object:nil];
    if (![self hasMenuBuilt]) {
        [self buildMenus];
    }

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuDidChange:)
                                                 name:NSMenuDidChangeItemNotification object:nil];
}

- (BOOL)hasMenuBuilt
{
    NSMenuItem *editMenuItem = [[NSApp mainMenu] itemWithTitle:@"Edit"];
    if (!editMenuItem) return NO;

    BOOL result = NO;
    for (NSMenuItem *menu in editMenuItem.submenu.itemArray) {
        if ([menu.title isEqualToString:@"Make Description"]) {
            result = YES;
            break;
        }
    }
    return result;
}

- (void)buildMenus
{
    // Sample Menu Item:
    NSMenuItem *menuItem = [[NSApp mainMenu] itemWithTitle:@"Edit"];
    if (menuItem) {
        [[menuItem submenu] addItem:[NSMenuItem separatorItem]];
        NSMenuItem *actionMenuItem = [[NSMenuItem alloc] initWithTitle:@"Make Description" action:@selector(doMenuAction) keyEquivalent:@"p"];
        [actionMenuItem setTarget:self];
        [actionMenuItem setKeyEquivalentModifierMask:NSControlKeyMask];
        [[menuItem submenu] addItem:actionMenuItem];
    }
}

regards

tuantm2014 commented 9 years ago

Thanks @Triipaxx It works for me!

ingocraft commented 9 years ago

works for me.

iKazakov commented 8 years ago

Menu item not visible in Xcode 7 too.

jstuth commented 8 years ago

Have you tried my approach listed above? You also have to add the new Xcode UUID "0420B86A-AA43-4792-9ED0-6FE0F2B16A13" to the DVTPlugInCompatibilityUUIDs property in the plist of the plugin.

iKazakov commented 8 years ago

sorry, i am a newbee in xcode and do not understand that text above (my english so bad).

jstuth commented 8 years ago

download and compile the version of @ajjnix https://github.com/ajjnix/xCodeGenerateDescriptionPlugin he made a similar fix of this issue. He also included support for the Xcode versions 7.0 and 7.1 Beta. Hope that helps :)

iKazakov commented 8 years ago

@Triipaxx so thank you :) it's work, but not great - insert code to the begin of the .h file :)

ajjnix commented 8 years ago

@Triipaxx sorry, i don't see that comment ( i fix it soon