Skip to content

Commit

Permalink
avoid missing bounds error onAppear and use the already available win…
Browse files Browse the repository at this point in the history
…dows center method
  • Loading branch information
peuter committed Apr 4, 2021
1 parent 5944528 commit 6a221ee
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions source/class/qxl/dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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: {
Expand Down Expand Up @@ -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);
}
});

0 comments on commit 6a221ee

Please sign in to comment.