Gnome shell status area menu

pull/16/head
brl 9 years ago
parent f299a75b65
commit 5d4e2561be

@ -3,6 +3,7 @@ const Gio = imports.gi.Gio;
const Extension = imports.misc.extensionUtils.getCurrentExtension(); const Extension = imports.misc.extensionUtils.getCurrentExtension();
const Dialog = Extension.imports.dialog; const Dialog = Extension.imports.dialog;
const Menu = Extension.imports.menu;
function init() { function init() {
return new FirewallSupport(); return new FirewallSupport();
@ -12,6 +13,7 @@ const FirewallSupport = new Lang.Class({
Name: 'FirewallSupport', Name: 'FirewallSupport',
_init: function() { _init: function() {
this.menu = new Menu.FirewallMenu();
this.handler = null; this.handler = null;
}, },
@ -24,8 +26,10 @@ const FirewallSupport = new Lang.Class({
enable: function() { enable: function() {
this._destroyHandler(); this._destroyHandler();
this.handler = new FirewallPromptHandler(); this.handler = new FirewallPromptHandler();
this.menu.install();
}, },
disable: function() { disable: function() {
this.menu.destroy();
this._destroyHandler(); this._destroyHandler();
} }
}); });

@ -0,0 +1,70 @@
const Lang = imports.lang;
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;
const FirewallMenu = new Lang.Class({
Name: 'FirewallSupport',
_init: function() {
this.aggregate = Main.panel.statusArea.aggregateMenu;
},
install: function() {
this.createMenu();
let idx = this.findMenu(this.aggregate._power.menu);
if(idx >= 0) {
this.aggregate.menu.addMenuItem(this.menu, idx);
}
},
destroy: function() {
if(this.menu) {
this.menu.destroy();
this.menu = null;
}
},
findMenu: function(menu) {
let items = this.aggregate.menu._getMenuItems();
for(let i = 0; i < items.length; i++) {
if(items[i] == menu) {
return i;
}
}
return -1;
},
createMenu: function() {
if(this.menu) {
this.menu.destroy();
}
this.menu = new PopupMenu.PopupMenuSection();
this.item = new PopupMenu.PopupSubMenuMenuItem("Firewall", true);
this.item.icon.icon_name = "security-high-symbolic";
this.toggle = new PopupMenu.PopupSwitchMenuItem("Firewall Enabled", false);
this.toggle.connect('toggled', Lang.bind(this, this.onToggle));
this.item.menu.addMenuItem(this.toggle);
this.item.menu.addAction("Connection Monitor", Lang.bind(this, this.onMonitor));
this.item.menu.addAction("Firewall Settings", Lang.bind(this, this.onSettings));
this.menu.addMenuItem(this.item);
},
onToggle: function() {
if(this.toggle.state) {
log("Toggle ON");
} else {
log("Toggle OFF");
}
},
onSettings: function() {
log("Firewall Settings clicked");
},
onMonitor: function() {
log("Connection monitor clicked");
},
});
Loading…
Cancel
Save