nstoolbar

Adding a custom view to toolbar

那年仲夏 提交于 2019-12-03 05:38:39
I'm struggling with Cocoa for 2 hours now without success. I want to add a custom view to the toolbar. So, I added a NSToolbar to the window (with IB), and added my view (which works perfectly). IB automatically created a NSToolbarItem. I followed the instructions from Apple here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Toolbars/Tasks/AddRemoveToolbarItems.html#//apple_ref/doc/uid/20000755-BBCGJCDJ The problem is that I don't know what to do now, the view doesn't show although it's label is displayed in the window. Here's the code I use to draw (very simple, it's

Is it possible to draw in the label area of NSToolbar?

▼魔方 西西 提交于 2019-12-02 22:09:22
I have a NSToolbarItem that uses a view similar to the Xcode status view. It currently has no label, but I can't figure out a way to draw into the area where the item label would normally be drawn. I would like the view to extend into that area just as the Xcode status view does. I know the very bottom portion of pixels of NSToolbar is out of bounds, but I have seen other applications draw into the label area. Any ideas? Edit: For clarification, this is the status view I'm referring to in Xcode: I want the bounds of my view to extend past the label area of the toolbar just as the view in Xcode

Align NSToolbarItems with NSSplitView columns

旧城冷巷雨未停 提交于 2019-12-01 18:37:32
Finder and Notes have a peculiar behaviour that I am seeking to reproduce. The ‘flexible space’ in the NSToolbar seems to take the dimensions of the split view into account. For instance, the first group of buttons aligns on the left side with the right side of the sidebar. The second group of icons aligns with the right side of the first column. When I widen the sidebar, the toolbar items move along with it. Is it possible to reproduce this? Solution With the solution provided by @KenThomases, I have implemented this as follows: final class MainWindowController: NSWindowController { override

How to customize the context menu of NSToolbar?

梦想的初衷 提交于 2019-12-01 15:02:54
I need to remove some items from right-click context menu, but the toolbar does not contain a public API to access 'toolbarView'. Is it possible to customize the menu without using private API? You can access and modify a toolbar contextual menu when the toolbar is created, i.e. in -[awakeFromNib] : - (NSMenu *)toolbarMenuInWindow:(NSWindow *)window { NSView *contentView = window.contentView; NSView *toolbarView = contentView.superview.subviews.lastObject; NSMenu *toolbarMenu = toolbarView.menu; return toolbarMenu; } Now you can directly edit menu items and hide or disable them. 来源: https:/

How to customize the context menu of NSToolbar?

﹥>﹥吖頭↗ 提交于 2019-12-01 12:48:25
问题 I need to remove some items from right-click context menu, but the toolbar does not contain a public API to access 'toolbarView'. Is it possible to customize the menu without using private API? 回答1: You can access and modify a toolbar contextual menu when the toolbar is created, i.e. in -[awakeFromNib] : - (NSMenu *)toolbarMenuInWindow:(NSWindow *)window { NSView *contentView = window.contentView; NSView *toolbarView = contentView.superview.subviews.lastObject; NSMenu *toolbarMenu =

Highlight NSToolbarItems

空扰寡人 提交于 2019-11-30 19:53:09
I want to highlight the selected NSToolbarItem like e.g. in Adium (see screenshot). highlight http://a2.s3.p.quickshareit.com/files/screenshot_b28b67ba9411513d6.png Is there an easy way? If not, tell me the difficult one. =) To expand upon Chuck's answer, you simply need to make your controller the delegate of your NSToolBar and implement the toolbarSelectableItemIdentifiers: delegate method in it. For example, the following implementation will let you retain the selection highlight on every toolbar item except for the one labeled "Inspect": - (NSArray *)toolbarSelectableItemIdentifiers:

how to enable/disable NSToolbarItem

自古美人都是妖i 提交于 2019-11-30 02:40:41
问题 I have a project that needs to disable/enable some NSToolbarItem s depends on different options. I checked and found no parameter for this. Is there a way to enable/disable a given NSToolbarItem ? 回答1: Implement NSToolbarItemValidation Protocol in your window, view or document controller. The documentation gives the following sample code: -(BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem { BOOL enable = NO; if ([[toolbarItem itemIdentifier] isEqual:SaveDocToolbarItemIdentifier]) { // We

How to use NSToolBar in Xcode 6 and Storyboard?

拟墨画扇 提交于 2019-11-27 12:54:21
I've been trying to build on a Cocoa app that uses Swift and Storyboard in Xcode 6, but how can I use NSToolbar there? In Xcode 5 and xib, you can add NSToolbar from within Object Library to any .xib files and then click on the added toolbar to expand it and drag and drop a connection from any items there to a AppDelegate.h file. In this way you can create a IBAction or IBOutlet connection. I confirmed that this can also be done if you use Swift and non-storyboard in Xcode 6. However, it looks like this is not the case in Xcode 6 and Storyboard environment. I first created a project that uses

How to use NSToolBar in Xcode 6 and Storyboard?

允我心安 提交于 2019-11-26 16:09:06
问题 I've been trying to build on a Cocoa app that uses Swift and Storyboard in Xcode 6, but how can I use NSToolbar there? In Xcode 5 and xib, you can add NSToolbar from within Object Library to any .xib files and then click on the added toolbar to expand it and drag and drop a connection from any items there to a AppDelegate.h file. In this way you can create a IBAction or IBOutlet connection. I confirmed that this can also be done if you use Swift and non-storyboard in Xcode 6. However, it