macoslib dilemma?

Hi,
I use the following code to add a button with dropdown options to my toolbar (via macoslib):

[code]// ADD THE DROP DOWN MENU / BUTTON HYBRID
dim ntiOPTIONS as new NSToolbarDropMenuItem(“Options”)
ntiOPTIONS.image = New Cocoa.NSImage(retinaKit.imageNamed( “OptionsButtonImage” ).NSImageRef)
ntiOPTIONS.itemLabel = “Options”
ntiOPTIONS.paletteLabel = “Options”

// ADD THE MENU CHOICES
ntiOPTIONS.AddItem(“Option1”)
ntiOPTIONS.AddItem(“Option2”)
ntiOPTIONS.AddSeparator
ntiOPTIONS.AddItem(“Option3”)
ntiOPTIONS.AddSeparator
ntiOPTIONS.AddItem(“Option4”)

// ADD THE OPTIONS BUTTON TO THE TOOLBAR
nt.addItem ntiOPTIONS[/code]

This works perfectly, but how do I disable the button until it is needed?

This line of code below causes a NilObjectException:

Window1.ntiOPTIONS.enabled = False

Thank you all in advance.

You do it with single menu items. In PseudoCode:

dim theMenuItem as NSMenuitem theMenuItem.Name = "Option1" theMenuItem.enabled = false ntiOptions.AddItem(theMenuItem)

You need to check how the name of the menu item class is. My code with MBS is similar. Or you get a reference after adding and then disable the menu item.

Here is my code for MBS:

[code] me.AddRow “Evernote”
me.AddRow “Filemaker”
me.AddRow “MBOX”
me.AddRow “PDF”
me.AddRow “RTF”
me.AddRow “Text”

dim thePopup as NSPopUpButtonMBS = me.NSPopUpButtonMBS
thePopup.autoenablesItems = False
dim theItem as NSMenuItemMBS
for currentItem as Integer = 0 to me.ListCount - 1
  if currentItem <> 2 then
    theItem = thePopup.itematindex(currentItem)
    theItem.Enabled = False
  end if
next[/code]

Hmm, I’m not using MBS, and macoslib created the toolbar, so I’m presuming I need to disable the button / all the items, using macoslib style code?

Your first code segment looks like it disables a single item when it is initially created?
I need to disable the entire button (and all the options) dependant upon if a listbox row is selected.

It seems strange that an entire button cannot be disabled?

Thanks anyway.

Maybe something like this works?
(I just dug it out from my repo so it’s taken out of context…)

item1 is an NSStatusItem

item1.Menu.ItemWithTitle("Current project").Enabled = False

???
Is that macoslib style code for disabling a toolbar button?

The only part I understood was .Enabled = False :slight_smile:
What does ItemWithTitle refer to??

hmm, I guess by Toolbar you mean a menu in the finder toolbar on the top right by the clock and whatnot?
If not. Ignore me :wink:

My five week summer vacation starts soon so I’m currently shutting down.

Albin,
No - I created a normal window toolbar (using macoslib), and I now need to disable a toolbar button completely, but because it is not a standard button (it looks like a button, but has a dropdown list), I cannot seem to disable it.

The style of code below works to disable all other buttons - but not one with a dropdown list:

Window1.ntiOPTIONS.enabled = False

The first code segment which Beatrix kindly provided, looks like it disables 1 option from the dropdown list, but then adds something to it??? Makes no sense to me at all.

I want to disable the WHOLE button.

Hope that made more sense :slight_smile:

Found my mistake!
My first line was dimmed, but I already had a property with that name.

I removed the Dim and it now works as expected :slight_smile: