Native macOS Toolbar

For anyone looking for a native macOS toolbar, I made one available on the Xojo store recently. You can find more information and a demo link on my website.

9 Likes

This looks great! Any chance of extending this or creating a similar project for Windows?

?
(macos 13.4.1)

You’ll need to put the dylib into the copy files step again.

1 Like

I’ll do this to test, but App crash in Window1.Opening doing ‘RebuildToolbar’ when AddItem : nstoolbar1.AddItem(MakeItem(“Trash”, “trash”))

Interesting. You’re the second person to report that and I have no idea why yet.

Could you separate that line into two like this?

Dim item as SOSToolbar.NSToolbarItem = MakeItem(“Trash”, “trash”)
nstoolbar1.AddItem(item)

And tell me it item is Nil?

Well the good news is that I can reproduce it now
 working on a solution.


and Fixed.

2 Likes

Version 1.0.2 of my Native macOS Toolbar classes are now available. A special shout out to @Valdemar_De_SOUSA for pointing out a critical toolbar selection bug.

This version adds an NSToolbarItem.IsSelectable property which indicates whether or not the toolbar item stays highlighted when it is selected. Coupled with setting the Bordered property to False, you can now have a preferences toolbar that behaves like a Tab Bar where one item is always selected.

The new version can be downloaded from here.

7 Likes

Another test problem, how do you use ‘Tag’ in SOSToolbar.NSToolbarItem ?

It always return 0 when you add a tag at construction, and -1 when you don’t.

Fixed. tag will only take integers now since that’s what macOS supports under the hood.

I get this message when launching the Demo (what do I do?)

Window1.NSToolbar1.SelectableItemIdentifiers Declaration
NSToolbar1 on Window1 implements the event “SelectableItemIdentifiers,” but its superclass SOSToolbar.NSToolbar has already implemented the event.
Function SelectableItemIdentifiers() As String()

Thanks.

It works when I remove the NSToolbar1.SelectableItemIdentifiers event !!!

Right. I moved that feature to a property of the items themselves. Now you just set the “isSelectable” property and whenever the toolbar asks for that info, it asks the items.

I’ve had a recent query about how to move add this module into a text project.

The encrypted SOSToolbar module in the sample project contains not only methods and properties, but also other classes. Because of the encryption, these files must be kept together as a binary object.

The solution is pretty straightforward:

  1. In your project, create a folder called SOS_Toolbar
  2. Copy & Paste the SOSToolbarHelpers module from the sample project to the SOS_Toolbar folder in your project.
  3. Go to the sample project and select the SOSToolbar module.
  4. Right-click on the module and select Export.
  5. Save the file into the folder where your project files are.
  6. Bring your project to the foreground
  7. Drag the exported file to your project while holding down the CMD and OPT keys so it gets added to your project as an external item.
  8. Save your project

Hmm


Somehow the toolbar icons are always disabled
also in the demo project where the itemPressed event should trigger label1.Text = "Pressed: " + item.Label.

Something missing to get the itemPressed events?