#1807 fwt::CommandMode.toggle initial selected value

SlimerDude Sun 4 Mar 2012

It does not appear to be possible to set the selected value of a fwt::Command in the constructor. i.e. The following always prints Toggle Selected = false

class ToggleCommand : Command {

  new make() : super("Toggle Test") {
    super.selected = true
    echo("Toggle Selected = $selected")		
    mode = CommandMode.toggle
  }

  override Void invoked(Event? event) { }
}

I guess a static constructor method would work - but this threw me for a while...

dobesv Mon 5 Mar 2012

Looks like it's got some kind of protection in the setter for selected so it only works if it's in CommandMode.toggle:

**
** If this command is using toggle mode, then set the
** selected state and update all the registered widgets.
**
Bool selected := false
{
  set
  {
    newVal := it
    if (mode != CommandMode.toggle) return
    this.&selected = newVal
    widgets.each |Widget w|
    {
      try { w->selected = newVal } catch {}
    }
  }
}

Perhaps setting mode before setting selected would work?

SlimerDude Mon 5 Mar 2012

Yes and Argh!

Thanks, yeah, I did look at the setter... but then messed up my logic and decided I had to set the toggle mode after selected. That'll learn me to stay up late coding!

Login or Signup to reply.