nsmenuitem

How to flash a custom NSMenuItem view after selection?

放肆的年华 提交于 2019-12-11 02:43:25
问题 I need to assign a view to an NSMenuItem and do some custom drawing. Basically, I'm adding a little delete button next to the currently selected menu item, among other things. But I want my custom menu item to look and behave like a regular menu item in all other ways. According to the doc: A menu item with a view does not draw its title, state, font, or other standard drawing attributes, and assigns drawing responsibility entirely to the view. Ok, so I had to duplicate the look of the state

NSMenuDelegate not called for submenu in NSMenuItem created by another NSMenuDelegate

杀马特。学长 韩版系。学妹 提交于 2019-12-10 21:09:43
问题 I have an NSStatusItem with an NSMenu that has a delegate. This delegate dynamically updates the menu based on a few factors. So per the documentation, to quickly update the menu, I use the method: - (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel; At the appropriate time in this method I call the following: NSMenu *submenu = [[NSMenu alloc] init]; SomeSubmenuDelegate *submenuDelegate = [[SomeSubmenuDelegate alloc] init];

Using NSProgressIndicator inside an NSMenuItem

自作多情 提交于 2019-12-09 11:25:46
问题 I'm trying to use a NSProgressIndicator (indeterminate) inside of a statusbar-menu. I'm using an NSView-object as view for the menuitem, and then subviews the progress indicator to display it. But whenever i try to call the startAnimation: for the progress, nothing happens. When i try do the very same thing on a normal NSWindow it works perfectly, just not when inside a menuitem. I'm new to both cocoa and objective-c so I might've overlooked something "obvious" but I've searched quite a bit

Custom NSView in NSMenuItem not receiving mouse events

二次信任 提交于 2019-12-09 04:46:40
问题 I have an NSMenu popping out of an NSStatusItem using popUpStatusItemMenu. These NSMenuItems show a bunch of different links, and each one is connected with setAction: to the openLink: method of a target. This arrangement has been working fine for a long time. The user chooses a link from the menu and the openLink: method then deals with it. Unfortunately, I recently decided to experiment with using NSMenuItem's setView: method to provide a nicer/slicker interface. Basically, I just stopped

Animated progress bar in NSMenuItem

∥☆過路亽.° 提交于 2019-12-08 08:51:28
I want to put an animated progress bar in an NSMenuItem custom view. This is demonstrated in Apple's MenuItemView sample, but it doesn't animate (at least not in 10.5, and the sample is apparently from 10.4). I have tried setting a timer that calls setNeedsDisplay:YES , scheduled as NSEventTrackingRunLoopMode like the docs say. This works, but only for a determinate progress bar if I change the value, and only the first time the menu opens. The second and successive times, the bar redraws twice and then remains frozen. For an indeterminate progress bar, the barber pole stripes never animate.

Animated progress bar in NSMenuItem

心不动则不痛 提交于 2019-12-08 08:10:59
问题 I want to put an animated progress bar in an NSMenuItem custom view. This is demonstrated in Apple's MenuItemView sample, but it doesn't animate (at least not in 10.5, and the sample is apparently from 10.4). I have tried setting a timer that calls setNeedsDisplay:YES , scheduled as NSEventTrackingRunLoopMode like the docs say. This works, but only for a determinate progress bar if I change the value, and only the first time the menu opens. The second and successive times, the bar redraws

Adding item to NSMenu with action selector preset

坚强是说给别人听的谎言 提交于 2019-12-08 07:32:32
问题 I'm new to Obj-C/Cocoa programming, and I'm having an issue trying to dynamically add menu items to an NSMenu instance and have the items action selector already set upon insertion. I can, add the dynamic menu items fine, but the action selector doesn't trigger when the item is clicked via the menu. The first line below is the line of code I am using to add the menu item. You can set I'm setting the action:(SEL)aSelector to the "openEchowavesURL" function. This function is in the same

How to add icons to the right hand side of NSMenuItem

↘锁芯ラ 提交于 2019-12-06 22:02:25
问题 I'm trying to add some icons to the right hand side of a menu next to a menu item, ideally all right justified. I'm aware that NSMenuItem allows you to add menu items (for instance, see the MenuMadness example). I'm really looking for something like the security / signal strength indicators in the OS X Wifi menu. One approach that I've seen is to add items to the menu, and use setView to provide an NSView for each item. However, that seems to be more complicated than it should be. Is there a

Adding item to NSMenu with action selector preset

≯℡__Kan透↙ 提交于 2019-12-06 14:49:12
I'm new to Obj-C/Cocoa programming, and I'm having an issue trying to dynamically add menu items to an NSMenu instance and have the items action selector already set upon insertion. I can, add the dynamic menu items fine, but the action selector doesn't trigger when the item is clicked via the menu. The first line below is the line of code I am using to add the menu item. You can set I'm setting the action:(SEL)aSelector to the "openEchowavesURL" function. This function is in the same controller class file and I've included the function definition below. Am I just calling the wrong selector

Connecting Multiple NSMenuItems with Actions and State Variables

陌路散爱 提交于 2019-12-06 13:35:59
问题 I'm not sure how to describe what I need but I'll give it a try, via an example : Let's say we have a window and a sidebar, and want to toggle it (I mean the sidebar : on/off). Now, let's also say that : The user may toggle the sidebar via an item at the Main menu (e.g. Show Sidebar / Hide Sidebar) The user may also toggle the sidebar via a button And there is also another item, in some other menu, to do the very same thing (Show/Hide Sidebar) What would be the most practical Cocoa-friendly