From 6a221ee77d40e88d99356add3c1b626eeaa3c5af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Br=C3=A4utigam?= Date: Sun, 4 Apr 2021 15:48:52 +0200 Subject: [PATCH] avoid missing bounds error onAppear and use the already available windows center method --- source/class/qxl/dialog/Dialog.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/source/class/qxl/dialog/Dialog.js b/source/class/qxl/dialog/Dialog.js index e925d673..c307a384 100644 --- a/source/class/qxl/dialog/Dialog.js +++ b/source/class/qxl/dialog/Dialog.js @@ -196,20 +196,8 @@ qx.Class.define("qxl.dialog.Dialog", { // handle focus qx.ui.core.FocusHandler.getInstance().addRoot(this); // resize the window when viewport size changes - root.addListener("resize", () => { - let bounds = this.getBounds(); - this.set({ - marginTop: Math.round((qx.bom.Document.getHeight() - bounds.height)/2), - marginLeft: Math.round((qx.bom.Document.getWidth() - bounds.width)/2) - }); - }); - this.addListener("appear", () => { - let bounds = this.getBounds(); - this.set({ - marginTop: Math.round((qx.bom.Document.getHeight() - bounds.height)/2), - marginLeft: Math.round((qx.bom.Document.getWidth() - bounds.width)/2) - }); - }); + this.addListener("resize", this.center, this); + root.addListener("resize", this.center, this); this._createWidgetContent(properties); // set properties from constructor param if (typeof properties == "object") { @@ -218,7 +206,7 @@ qx.Class.define("qxl.dialog.Dialog", { this.setMessage(properties); } // escape key - qx.core.Init.getApplication().getRoot().addListener("keyup", this._handleEscape, this); + root.addListener("keyup", this._handleEscape, this); }, properties: { @@ -314,5 +302,16 @@ qx.Class.define("qxl.dialog.Dialog", { this.setVisibility("hidden"); return this; } + }, + + /* + *********************************************** + DESTRUCTOR + *********************************************** + */ + destruct: function () { + let root = qx.core.Init.getApplication().getRoot(); + root.removeListener("resize", this.center, this); + root.removeListener("keyup",this._handleEscape,this); } });