Skip to content

Commit

Permalink
feat: Add "LayoutChanged" event to DockPanel
Browse files Browse the repository at this point in the history
Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed Dec 20, 2023
1 parent 16ee388 commit 98e5f42
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
19 changes: 15 additions & 4 deletions packages/phosphor/src/DockPanel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HTMLWidget, Widget } from "@hpcc-js/common";
import { HTMLWidget, Widget, Utility } from "@hpcc-js/common";
import { DockPanel as PhosphorDockPanel, IMessageHandler, IMessageHook, Message, MessageLoop, Widget as PWidget } from "@hpcc-js/phosphor-shim";
import { select as d3Select } from "d3-selection";
import { PDockPanel } from "./PDockPanel";
Expand Down Expand Up @@ -145,25 +145,36 @@ export class DockPanel extends HTMLWidget implements IMessageHandler, IMessageHo
return true;
}

private _lazyLayoutChanged = Utility.debounce(async () => {
this.layoutChanged();
}, 1000);

_prevActive: Widget;
processMessage(msg: Message): void {
switch (msg.type) {
case "wa-activate-request":
case Msg.WAActivateRequest.type:
const wa = (msg as Msg.WAActivateRequest).wa;
const widget = wa.widget;
if (this._prevActive !== widget) {
this._prevActive = widget;
this.childActivation(widget, wa);
}
break;
case Msg.WALayoutChanged.type:
this._lazyLayoutChanged();
break;
}
}

active(): Widget {
return this._prevActive;
}

// Events ---
childActivation(w: Widget, wa: WidgetAdapter) {
}

active(): Widget {
return this._prevActive;
layoutChanged() {
}
}
DockPanel.prototype._class += " phosphor_DockPanel";
Expand Down
31 changes: 27 additions & 4 deletions packages/phosphor/src/WidgetAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,42 @@ import { select as d3Select } from "d3-selection";
import "../src/WidgetAdapter.css";

export namespace Msg {
export class WAActivateRequest extends ConflatableMessage {

export class WAConflatableMessage extends ConflatableMessage {
private _wa: WidgetAdapter;

constructor(wa: WidgetAdapter) {
super("wa-activate-request");
constructor(wa: WidgetAdapter, msg: string) {
super(msg);
this._wa = wa;
}

get wa(): WidgetAdapter {
return this._wa;
}

conflate(other: WAActivateRequest): boolean {
conflate(other: WAConflatableMessage): boolean {
this._wa = other.wa;
return true;
}
}

export class WAActivateRequest extends WAConflatableMessage {

static type = "wa-activate-request";

constructor(wa: WidgetAdapter) {
super(wa, WAActivateRequest.type);
}
}

export class WALayoutChanged extends WAConflatableMessage {

static type = "wa-layout-changed";

constructor(wa: WidgetAdapter) {
super(wa, WALayoutChanged.type);
}
}
}

export interface IClosable {
Expand Down Expand Up @@ -93,6 +113,9 @@ export class WidgetAdapter extends PWidget {
.resize({ width: this._width - this.padding * 2 - 2, height: this._height - this.padding * 2 - 2 })
.lazyRender()
;
if (this._owner) {
MessageLoop.postMessage(this._owner, new Msg.WALayoutChanged(this));
}
}
}

Expand Down

0 comments on commit 98e5f42

Please sign in to comment.