Re: set menu item's state
Re: set menu item's state
- Subject: Re: set menu item's state
- From: phil03 <email@hidden>
- Date: Wed, 19 Mar 2014 00:33:15 +0700
Problem solved. Though I'm not sure why.
Seems I needed to have a script property that was bound to the menu
item's state and which I can query in the
applicationWillFinishLaunching_ method , but NOT to modify that same
property in the target-action method. So the code, which now appears to
function, looks something like this, where 'someOtherProperty' is
checking for the existence of some other condition, and 'someMenuItem'
is the model key path bound to the menu item's value in IB.
parent property : class "NSObject"
property someMenuItem : missing value
property someOtherProperty : "yes value"
on applicationWillFinishLaunching_(aNotification)
if someExternalCondition is true then
set my someOtherProperty to "no value"
set my someMenuItem to 0
else
set my someOtherProperty to "yes value"
set my someMenuItem to 1
end if
applicationWillFinishLaunching_
on menuItemCall_(sender)
if sender's state() = 1 --'on'
set sender's state to 0 --'off'
set my someOtherProperty to "no value"
else
set sender's state to 1 -- 'on'
set my someOtherProperty to "yes value"
end if
end menuItemCall
On 18/03/2014 23:29, phil03 wrote:
Oops, Mea culpa. I missed the trailing 'then' out of the first line in
the pseudo-code, but that's not the problem. It's there in the real
code, and indeed the script compiles and runs. It just doesn't update
the status of the menu item.
On 18/03/2014 23:23, phil03 wrote:
(Building on Xcode 5.1, OSX 10.9.2; deployment target = 10.9)
Here's some pseudo-code for an action method that's called by a menu
bar menu item with the intent of simply toggling a property:
on menuItemCall_(sender)
if sender's state() = 1 --'on'
set sender's state to 0 --'off'
set my someProperty to "no value"
else
set sender's state to 1 -- 'on'
set my someProperty to "yes value"
end if
end menuItemCall
This code does what I want it to - toggle a property on and off.
However, the problem is the menu in the GUI remains in the same
visual state as it was before the call (i.e., if it was 'ticked' it's
still ticked even after its state is set to 0. I logged it and
checked that it was in fact 0 too, but the ticked state is still seen
by the user in the menu list. Likewise if it wasn't ticked and then
toggled, it changed values in my properties accordingly but visually
remained the same).
How do I get the GUI to update the state of the menu list item? (BTW,
I tried doing this by binding it to a Value & Model Key Path and
checking 'Validates Immediately' but that didn't work either).
TIA for any help
Best
P
_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden