xCodeGenerateDescriptionPlugin icon indicating copy to clipboard operation
xCodeGenerateDescriptionPlugin copied to clipboard

Menu item not visible in Xcode 6.3.2

Open jstuth opened this issue 10 years ago • 8 comments

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

jstuth avatar Jul 08 '15 13:07 jstuth

Thanks @Triipaxx It works for me!

tuantm2014 avatar Aug 18 '15 03:08 tuantm2014

works for me.

ingocraft avatar Sep 11 '15 03:09 ingocraft

Menu item not visible in Xcode 7 too.

iKazakov avatar Oct 06 '15 11:10 iKazakov

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.

jstuth avatar Oct 06 '15 13:10 jstuth

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

iKazakov avatar Oct 07 '15 03:10 iKazakov

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 :)

jstuth avatar Oct 07 '15 06:10 jstuth

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

iKazakov avatar Oct 07 '15 11:10 iKazakov

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

ajjnix avatar Oct 30 '15 02:10 ajjnix