如何在 Qooxdoo 上分离快捷命令?
how to detach a shortcut command on Qooxdoo?
我有这个代码:
qx.Class.define('my.Window', {
extend: qx.ui.window.Window,
construct: function(caption, icon) {
this.base(arguments, caption, icon);
this.setLayout(new qx.ui.layout.Basic());
this.__btn = new qx.ui.form.Button('Shortcut Test');
this.__cmd = new qx.ui.command.Command('Alt+T');
this.__cmd.addListener("execute", function() { alert('FOOBAR'); });
this.__btn.setCommand(this.__cmd);
this.add(this.__btn);
},
members: {
__btn: null,
__cmd: null
}
});
qx.Class.define('my.Compo', {
extend: qx.ui.container.Composite,
construct: function() {
this.base(arguments);
this.setLayout(new qx.ui.layout.HBox());
this.__btnShow = new qx.ui.form.Button("Show Window", "icon/22/apps/internet-web-browser.png");
this.__btnDestroy = new qx.ui.form.Button('Destroy window');
this.__btnNull = new qx.ui.form.Button('Null window');
this.__btnDestroy.addListener('execute', function(){
this.__window.destroy();
}, this);
this.__btnNull.addListener('execute', function(){
this.__window = null;
}, this);
this.__btnShow.addListener("execute", function(e){
if(this.__window) {
console.info('Window exist');
this.__window.open();
this.__window.center();
}
else {
console.info('Window do not exist!');
this.__window = new my.Window("Shortcut test window");
this.__window.setWidth(300);
this.__window.setHeight(200);
this.__window.setShowMinimize(false);
this.__window.open();
this.__window.center();
}
}, this);
this.add(this.__btnShow);
this.add(this.__btnDestroy);
this.add(this.__btnNull);
},
members: {
__btnShow: null,
__btnDestroy: null,
__window: null
}
});
var compo = new my.Compo();
this.getRoot().add(compo);
因此,如果您在单击 "Show Window" 按钮之前尝试 "Alt+T" 快捷方式,则不会发生任何事情。显示 Window 后,快捷方式可用并显示警告。
嗯,对我来说,问题是在快捷方式必须不再存在的情况下,快捷方式的剩余可用性:
- 当window正常关闭时
- 当 Null window 按钮被执行时,之后如果你使用 "Alt+T" 则警告显示两次,以此类推在 Null 和 Show 按钮之间切换的次数。
- 与 (2) 相同的行为,即使显式调用了 window 的
destroy()
方法。
- 在 playground 上,如果 "Run" 按钮被点击几次,使用快捷方式后也会显示相同次数的警报。
感谢您的宝贵时间。 :)
qx.ui.command.Command将attaches 2 listeners的qx.bom.Shortcut包裹到文档元素中。当您关闭 window qx.ui.command.Command 实例时,未将其设置为非活动或已销毁。您必须正确处理 window 关闭事件。
destruct: function()
{
this.__cmd = null;
}
它不会破坏命令。如果你尝试:
qx.core.ObjectRegistry.fromHashCode("the command object hash code").getActive()
你会发现它存在并且是活跃的。你忘了销毁命令调用
this.__cmd.dispose()
每次有人推送时,Qooxdoo Playground App 对象注册表都不会初始化 "Run"。因此,qooxdoo 对象的生命周期绑定到页面生命周期或处置事件。
我有这个代码:
qx.Class.define('my.Window', {
extend: qx.ui.window.Window,
construct: function(caption, icon) {
this.base(arguments, caption, icon);
this.setLayout(new qx.ui.layout.Basic());
this.__btn = new qx.ui.form.Button('Shortcut Test');
this.__cmd = new qx.ui.command.Command('Alt+T');
this.__cmd.addListener("execute", function() { alert('FOOBAR'); });
this.__btn.setCommand(this.__cmd);
this.add(this.__btn);
},
members: {
__btn: null,
__cmd: null
}
});
qx.Class.define('my.Compo', {
extend: qx.ui.container.Composite,
construct: function() {
this.base(arguments);
this.setLayout(new qx.ui.layout.HBox());
this.__btnShow = new qx.ui.form.Button("Show Window", "icon/22/apps/internet-web-browser.png");
this.__btnDestroy = new qx.ui.form.Button('Destroy window');
this.__btnNull = new qx.ui.form.Button('Null window');
this.__btnDestroy.addListener('execute', function(){
this.__window.destroy();
}, this);
this.__btnNull.addListener('execute', function(){
this.__window = null;
}, this);
this.__btnShow.addListener("execute", function(e){
if(this.__window) {
console.info('Window exist');
this.__window.open();
this.__window.center();
}
else {
console.info('Window do not exist!');
this.__window = new my.Window("Shortcut test window");
this.__window.setWidth(300);
this.__window.setHeight(200);
this.__window.setShowMinimize(false);
this.__window.open();
this.__window.center();
}
}, this);
this.add(this.__btnShow);
this.add(this.__btnDestroy);
this.add(this.__btnNull);
},
members: {
__btnShow: null,
__btnDestroy: null,
__window: null
}
});
var compo = new my.Compo();
this.getRoot().add(compo);
因此,如果您在单击 "Show Window" 按钮之前尝试 "Alt+T" 快捷方式,则不会发生任何事情。显示 Window 后,快捷方式可用并显示警告。
嗯,对我来说,问题是在快捷方式必须不再存在的情况下,快捷方式的剩余可用性:
- 当window正常关闭时
- 当 Null window 按钮被执行时,之后如果你使用 "Alt+T" 则警告显示两次,以此类推在 Null 和 Show 按钮之间切换的次数。
- 与 (2) 相同的行为,即使显式调用了 window 的
destroy()
方法。
- 与 (2) 相同的行为,即使显式调用了 window 的
- 在 playground 上,如果 "Run" 按钮被点击几次,使用快捷方式后也会显示相同次数的警报。
感谢您的宝贵时间。 :)
qx.ui.command.Command将attaches 2 listeners的qx.bom.Shortcut包裹到文档元素中。当您关闭 window qx.ui.command.Command 实例时,未将其设置为非活动或已销毁。您必须正确处理 window 关闭事件。
destruct: function()
{
this.__cmd = null;
}
它不会破坏命令。如果你尝试:
qx.core.ObjectRegistry.fromHashCode("the command object hash code").getActive()
你会发现它存在并且是活跃的。你忘了销毁命令调用
this.__cmd.dispose()
每次有人推送时,Qooxdoo Playground App 对象注册表都不会初始化 "Run"。因此,qooxdoo 对象的生命周期绑定到页面生命周期或处置事件。