Is there a Reporter.xctemplate with conditionalContextMenus through xib?

The first time I tried to make a plug-in with Xcode. Is there a Reporter.xctemplate with conditionalContextMenus throung xib?

The templates are only implement a minimal API. To see what’s possible, check the corresponding Protocol header (e.g. GlyphsToolEventProtocol.h) (you should be able to open the file Command+Control click the file name in the import statement).

The conditionalContextMenus method is part of the python plugin API. The objectiveC equivalent is - (void)addMenuItemsForEvent:(NSEvent *)theEvent toMenu:(NSMenu *)theMenu;. If you know the python API, you can look into the plugin wrapper to learn about the objectiveC API.

I found this. I’m stuck in loadNib now,I not found how to load Nib,It can’t work I use

self = [super initWithNibName:@"myView" bundle:[NSBundle bundleForClass:[self class]]];

or

- (id)init 
{
    self = [super init];
    [NSBundle loadNibNamed:@"myView" owner:self error:nil];
    return self;
}

What kind of plugin are you doing?

I am working on a reporter plugin and I want to add a view from the XIB I defined in the right-click menu.

For the first example to work your class needs to be inheriting from NSViewController. The second should work regardless.

Did I miss something? A right-click with the mouse cant show the view that I customized Xib (NSView) in the context menu.
It add the view in python like

# Load .nib file from package
self.loadNib("SliderView", __file__)

# Add the view to the context menu
self.generalContextMenus = [
	{"view": self.sliderMenuView}
		]

Can you give me a simple example? I haven’t been able to correctly display the right-click menu I customized with Xib for a whole day. :sweat:

Where is you problem?
Does the view load correctly?
To get the view into the menu, you assign it to the .view property of the menu item:

NSMenuItem *item = [NSMenuItem new];
item.title = @"my item"; // the title is not shown but I would set it anyway.
item.view = self.view;

It didn’t show my NSView of xib using this method,it only show the title

-(void)addMenuItemsForEvent:(NSEvent *)theEvent toMenu:(NSMenu *)theMenu{
    NSMenuItem *item = [NSMenuItem new];
    item.title = @"my item"; // the title is not shown but I would set it anyway.
    item.view = self.thisView;
    [theMenu addItem:item];
}

Am I putting it in the wrong place or missing something?

Have you connected the “thisView” with the view in the .xib? self.thisView is most likely not that at this point.

Do you mean this place?
image
I’m connected here.

b.zip (26.1 KB)
I sent a simple example. Can you help me see what the problem is? I’m really racking my brains.

You are not calling the .nib loading code anywhere?
You can do it like this:

-(void)addMenuItemsForEvent:(NSEvent *)theEvent toMenu:(NSMenu *)theMenu {
	if (!self.thisView) {
		[NSBundle loadNibNamed:@"View" owner:self error:nil];
	}
	NSMenuItem *item = [NSMenuItem new];
	item.title = @"my item"; // the title is not shown but I would set it anyway.
	item.view = self.thisView;
	[theMenu addItem:item];
}

It’ true!Thanks so much!
I called the .nib loading code in the init,and it not work :sweat_smile:

By the way, I want to ask whether the plug-in using OC can print NSLog into the macro panel, which is the same as the print of Python

That can be done like this:

[[NSApp delegate] performSelector:@selector(printToMacro:) withObject:@"hello world"];

You can add a fake header:

@interface NSObject (private)
- (void)printToMacro:(NSString *)string;
@end

[[NSApp delegate] printToMacro:@"hello world"];
1 Like