Use WeakMap to store objects as key and rename MonitorWidget signals field into signalManager to avoid confusions
This commit is contained in:
parent
4d6fe82790
commit
45d0cc9d11
46
extension.js
46
extension.js
|
@ -63,7 +63,8 @@ class SignalMgt {
|
|||
this.fullname = this.name + '@' + this.group;
|
||||
this.dbus = dbus;
|
||||
this.menu = menu;
|
||||
this.signals = {}
|
||||
this.signals = new WeakMap();
|
||||
this.widgets = new Array();
|
||||
|
||||
this.nbClicks = 0;
|
||||
this.button = -1;
|
||||
|
@ -78,8 +79,8 @@ class SignalMgt {
|
|||
}
|
||||
|
||||
destructor() {
|
||||
for(let widgetIdx in this.signals)
|
||||
this.disconnectWidgetSignals(this.signals[widgetIdx]);
|
||||
for(let widgetIdx in this.widgets)
|
||||
this.disconnectWidgetSignals(this.widgets[widgetIdx]);
|
||||
}
|
||||
|
||||
updateSignals(item) {
|
||||
|
@ -93,23 +94,26 @@ class SignalMgt {
|
|||
}
|
||||
|
||||
connectWidgetSignals(widget) {
|
||||
this.signals[widget] = [];
|
||||
this.widgets.push(widget);
|
||||
let array = new Array();
|
||||
this.signals.set(widget, array);
|
||||
let id;
|
||||
id = widget.connect('enter-event', this._onEnter.bind(this));
|
||||
this.signals[widget].push(id);
|
||||
array.push(id);
|
||||
id = widget.connect('leave-event', this._onLeave.bind(this));
|
||||
this.signals[widget].push(id);
|
||||
array.push(id);
|
||||
id = widget.connect('scroll-event', this._onScroll.bind(this));
|
||||
this.signals[widget].push(id);
|
||||
array.push(id);
|
||||
widget.set_reactive(true);
|
||||
id = widget.connect('button-release-event', Lang.bind(this, this._clicked));
|
||||
this.signals[widget].push(id);
|
||||
array.push(id);
|
||||
}
|
||||
|
||||
disconnectWidgetSignals(widget) {
|
||||
for(let idx in this.signals[widget])
|
||||
widget.disconnect(this.signals[widget][idx]);
|
||||
this.signals[widget] = null;
|
||||
let array = this.signals.get(widget);
|
||||
for(let idx in array)
|
||||
widget.disconnect(array[idx]);
|
||||
this.signals.set(widget, null);
|
||||
}
|
||||
|
||||
_manageEventAction(action, signalName) {
|
||||
|
@ -222,8 +226,9 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
this.group = group;
|
||||
this.fullname = this.name + '@' + this.group;
|
||||
this.dbus = dbus;
|
||||
this.signals = new SignalMgt(item, this.name, group, dbus, this.menu);
|
||||
this.popup_signals = {};
|
||||
this.signalManager = new SignalMgt(item, this.name, group, dbus, this.menu);
|
||||
this.popup_signals = null;
|
||||
this.popup_widgets = null;
|
||||
|
||||
if (item.hasOwnProperty('icon'))
|
||||
{
|
||||
|
@ -232,7 +237,7 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
else
|
||||
this.icon = this._createIcon(item['icon']);
|
||||
if (this.icon !== null) {
|
||||
this.signals.connectWidgetSignals(this.icon);
|
||||
this.signalManager.connectWidgetSignals(this.icon);
|
||||
this.add_child(this.icon);
|
||||
}
|
||||
} else
|
||||
|
@ -246,7 +251,7 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
this.widget = this._createText(item['text']);
|
||||
|
||||
if (this.widget !== null) {
|
||||
this.signals.connectWidgetSignals(this.widget);
|
||||
this.signalManager.connectWidgetSignals(this.widget);
|
||||
this.add_child(this.widget);
|
||||
}
|
||||
} else
|
||||
|
@ -320,7 +325,7 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
}
|
||||
|
||||
if (prevIcon) {
|
||||
this.signals.disconnectWidgetSignals(prevIcon);
|
||||
this.signalManager.disconnectWidgetSignals(prevIcon);
|
||||
this.insert_child_above(this.icon, prevIcon);
|
||||
this.remove_child(prevIcon);
|
||||
//delete prevIcon;
|
||||
|
@ -338,8 +343,8 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
if (this.menuItem) {
|
||||
if (menuOpen)
|
||||
this.menu.close();
|
||||
for(let widgetIdx in this.popup_signals)
|
||||
this.signals.disconnectWidgetSignals(this.popup_signals[widgetIdx]);
|
||||
for(let widgetIdx in this.popup_widgets)
|
||||
this.signalManager.disconnectWidgetSignals(this.popup_widgets[widgetIdx]);
|
||||
this.menu.removeAll();
|
||||
//delete this.menuItem;
|
||||
}
|
||||
|
@ -349,7 +354,7 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
this.menu.open(true);
|
||||
}
|
||||
|
||||
this.signals.updateSignals(item);
|
||||
this.signalManager.updateSignals(item);
|
||||
}
|
||||
|
||||
openPopup() {
|
||||
|
@ -381,6 +386,8 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
}
|
||||
|
||||
let widgets = [];
|
||||
this.popup_signals = new WeakMap();
|
||||
this.popup_widgets = new Array();
|
||||
for (let itemIndex in item['items']) {
|
||||
let widget = null;
|
||||
let widgetDict = item['items'][itemIndex];
|
||||
|
@ -406,6 +413,7 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
this.fullname, this.dbus,
|
||||
this.menu);
|
||||
this.popup_signals[widget].connectWidgetSignals(widget);
|
||||
this.popup_widgets.push(widget);
|
||||
}
|
||||
|
||||
if (widgets.length > 0) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user