Add openPopup(), closePopup() and togglePopup() functions to DBUS interface
This commit is contained in:
parent
d3eb13994a
commit
6b1fe1dd2d
|
@ -58,6 +58,8 @@ extension emit one of the following signals :
|
|||
* onRightClick
|
||||
* onDblClick
|
||||
* onRightDblClick
|
||||
* onEnter
|
||||
* onLeave
|
||||
|
||||
Other signals are available when extension is activated/deactivated :
|
||||
|
||||
|
|
15
dbus.xml
15
dbus.xml
|
@ -9,6 +9,15 @@
|
|||
<method name="deleteGroups">
|
||||
<arg type="s" direction="in" />
|
||||
</method>
|
||||
<method name="openPopup">
|
||||
<arg type="s" direction="in" />
|
||||
</method>
|
||||
<method name="closePopup">
|
||||
<arg type="s" direction="in" />
|
||||
</method>
|
||||
<method name="togglePopup">
|
||||
<arg type="s" direction="in" />
|
||||
</method>
|
||||
<!-- Click events -->
|
||||
<signal name="onClick">
|
||||
<arg type="s" direction="out" />
|
||||
|
@ -22,6 +31,12 @@
|
|||
<signal name="onRightDblClick">
|
||||
<arg type="s" direction="out" />
|
||||
</signal>
|
||||
<signal name="onEnter">
|
||||
<arg type="s" direction="out" />
|
||||
</signal>
|
||||
<signal name="onLeave">
|
||||
<arg type="s" direction="out" />
|
||||
</signal>
|
||||
<!-- Activate/Deactivate signals -->
|
||||
<signal name="onActivate">
|
||||
</signal>
|
||||
|
|
66
extension.js
66
extension.js
|
@ -420,6 +420,18 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
this.onLeave = hash_get(item, 'on-leave', this.onLeave);
|
||||
}
|
||||
|
||||
openPopup() {
|
||||
this.menu.open(true);
|
||||
}
|
||||
|
||||
closePopup() {
|
||||
this.menu.close();
|
||||
}
|
||||
|
||||
togglePopup() {
|
||||
this.menu.toggle();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.menu.close();
|
||||
super.destroy();
|
||||
|
@ -498,6 +510,17 @@ class GenericMonitorDBUS {
|
|||
return null;
|
||||
}
|
||||
|
||||
_getItemFromFullName(fullname) {
|
||||
let splitName = fullname.split('@');
|
||||
if (splitName.length !== 2) {
|
||||
log(`Invalid name ${item}`);
|
||||
return null;
|
||||
}
|
||||
if (!this.monitor_groups.hasOwnProperty(splitName[1]))
|
||||
return null;
|
||||
return this._getItemFromGroup(this.monitor_groups[splitName[1]], splitName[0]);
|
||||
}
|
||||
|
||||
_removeFromArray(array, value) {
|
||||
for(let i=0; i<array.length; i++) {
|
||||
if (array[i] === value) {
|
||||
|
@ -573,13 +596,13 @@ class GenericMonitorDBUS {
|
|||
|
||||
for (let itemIndex in parameters['items']) {
|
||||
let itemName = parameters['items'][itemIndex];
|
||||
let fullName = itemName.split('@');
|
||||
if (fullName.length !== 2) {
|
||||
let splitName = itemName.split('@');
|
||||
if (splitName.length !== 2) {
|
||||
log(`Invalid name ${itemName}`);
|
||||
return false;
|
||||
}
|
||||
itemName = fullName[0];
|
||||
let groupName = fullName[1];
|
||||
itemName = splitName[0];
|
||||
let groupName = splitName[1];
|
||||
if (!this.monitor_groups.hasOwnProperty(groupName))
|
||||
continue;
|
||||
let group = this.monitor_groups[groupName];
|
||||
|
@ -614,6 +637,41 @@ class GenericMonitorDBUS {
|
|||
}
|
||||
}
|
||||
|
||||
_popupFunction(str) {
|
||||
let parameters = JSON.parse(str);
|
||||
|
||||
if (!parameters.hasOwnProperty('item')) {
|
||||
log('No item defined');
|
||||
return false;
|
||||
}
|
||||
|
||||
let monitorWidget = this._getItemFromFullName(parameters['item']);
|
||||
if (monitorWidget !== null)
|
||||
return monitorWidget;
|
||||
else
|
||||
log(`Item ${str} not found`);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
openPopup(str) {
|
||||
let monitorWidget = this._popupFunction(str)
|
||||
if (monitorWidget !== null)
|
||||
monitorWidget.openPopup();
|
||||
}
|
||||
|
||||
closePopup(str) {
|
||||
let monitorWidget = this._popupFunction(str)
|
||||
if (monitorWidget !== null)
|
||||
monitorWidget.closePopup();
|
||||
}
|
||||
|
||||
togglePopup(str) {
|
||||
let monitorWidget = this._popupFunction(str)
|
||||
if (monitorWidget !== null)
|
||||
monitorWidget.togglePopup();
|
||||
}
|
||||
|
||||
destructor() {
|
||||
this._dbusImpl.emit_signal('onDeactivate', null);
|
||||
for (let groupIndex in this.monitor_groups) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user