Hi Marc,

I tried something slightly differently, seems to work out:

I removed the button.setCommand(this._command) line in _getMenu(), but 
instead added a listener
button.addListener("execute", function(e){
          this.toggleShowLabel();
}, this);
in the same place.
With this tiny modification, the removeListener() line seems obsolete.

Maybe you give it a try,

HTH,
greetings
Stefan

On 11.07.2010 13:39, Marc Puts wrote:
> Hi all,
>
> I have a command object which toggles the value of a boolean property
> "showLabel".
> I also have a qx.ui.menu.CheckBox, which toggles "showLabel" indirectly
> by using the command object.
>
> Whenever the property value is changed, whether that's done by the
> command object, the checkbox or some external source, I need the
> checkbox state to reflect the new value. Obviously, this is easy to do
> using data binding. Everything is fine when the property change is
> initiated from the command object, or from the outside world.
>
> But trouble arises when the change is initiated from the CheckBox. The
> CheckBox automatically changes its checked state whenever its execute
> event is fired. However, since the CheckBox uses the command object, the
> execute itself changes the value of "showLabel", which (due to the data
> binding) changes the checked state of the CheckBox. Chicken or the egg?
> Not surprisingly, this results in strange/unwanted behaviour.
>
> To prevent this the unwanted behaviour, I want to suppress the checkbox
> behaviour of changing its checked state on execution. This can be done
> by removing its internal "execute" listener right after creating the
> checkbox:
>
>         button.removeListener("execute", button._onExecute, button, false);
>
> This works, but since this makes use of unexposed CheckBox interiors: is
> there's a better way of handling it?
>
>
>
>
> Code example below:
> ********************************************************
>
>
> qx.Class.define("test.Window", {
>
>     extend : qx.ui.window.Window,
>
>     construct : function() {
>       this.base(arguments);
>
>       this.setLayout(new qx.ui.layout.Canvas());
>       this.setWidth(300);
>       this.setHeight(200);
>
>       this._label = new qx.ui.basic.Label("Rightclick or press L to hide
> this text.");
>       this.add(this._label);
>
>       this._command = new qx.ui.core.Command("L");
>       this._command.addListener("execute", this.toggleShowLabel, this);
>
>       this.initShowLabel(true);
>
>       this.setContextMenu(this._getMenu());
>     },
>
>     properties :
>     {
>       showLabel : {
>         deferredInit: true,
>         check: "Boolean",
>         apply: "_applyShowLabel",
>         event: "showLabelChanged"
>       }
>     },
>
>     members :
>     {
>       _label: null,
>       _command : null,
>
>       _applyShowLabel : function(value, old) {
>         this._label.setVisibility(value ? "visible" : "excluded");
>       },
>
>       _getMenu : function() {
>         var menu = new qx.ui.menu.Menu;
>
>         var button = new qx.ui.menu.CheckBox("Show label");
>
>         //suppress default behaviour of toggling checked value on execute
>         button.removeListener("execute", button._onExecute, button, false);
>
>         button.setCommand(this._command);
>         this.bind("showLabel", button, "value");
>
>         menu.add(button);
>         return menu;
>       }
>     }
> });
>
> ********************************************************
>
> If you comment out the removeListener line, you will notice that the
> checkbox state will not be updated on the first "showLabel" change. All
> subsequent showLabel changes will be passed to the checkbox, but its
> state will be inverted.
>
>
> Thanks,
>
> Marc

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to