1. Alessio Caiazza
  2. CloudGnome

Commits

Alessio Caiazza  committed 2e9a705

SystemStatusButton example

  • Participants
  • Parent commits 31099b9
  • Branches default

Comments (0)

Files changed (1)

File extension.js

View file
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
 const St = imports.gi.St;
+const Lang = imports.lang;
+
 const Main = imports.ui.main;
 const Tweener = imports.ui.tweener;
 
-let text, button;
+const PanelMenu = imports.ui.panelMenu;
+const PopupMenu = imports.ui.popupMenu;
 
-function _hideHello() {
-    Main.uiGroup.remove_actor(text);
-    text = null;
-}
+const CloudGnome = new Lang.Class({
+    Name: 'CloudGnome',
+    Extends: PanelMenu.SystemStatusButton,
 
-function _showHello() {
-    if (!text) {
-        text = new St.Label({ style_class: 'helloworld-label', text: "Hello, world!" });
-        Main.uiGroup.add_actor(text);
+    _init: function() {
+        log("parto!");
+        this.parent('folder-publicshare-symbolic', _("Battery"));
+
+        this._deviceItems = [ ];
+        this._hasPrimary = false;
+        this._primaryDeviceId = null;
+
+        this._batteryItem = new PopupMenu.PopupMenuItem('', { reactive: false });
+        this._primaryPercentage = new St.Label({ style_class: 'popup-battery-percentage' });
+        this._batteryItem.addActor(this._primaryPercentage, { align: St.Align.END });
+        this.menu.addMenuItem(this._batteryItem);
+
+        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
+        this._otherDevicePosition = 2;
+
+        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
+        this.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop');
     }
+});
 
-    text.opacity = 255;
 
-    let monitor = Main.layoutManager.primaryMonitor;
-
-    text.set_position(Math.floor(monitor.width / 2 - text.width / 2),
-                      Math.floor(monitor.height / 2 - text.height / 2));
-
-    Tweener.addTween(text,
-                     { opacity: 0,
-                       time: 2,
-                       transition: 'easeOutQuad',
-                       onComplete: _hideHello });
-}
-
+let cloudgnomeMenu;
 function init() {
-    button = new St.Bin({ style_class: 'panel-button',
-                          reactive: true,
-                          can_focus: true,
-                          x_fill: true,
-                          y_fill: false,
-                          track_hover: true });
-    let icon = new St.Icon({ icon_name: 'system-run-symbolic',
-                             style_class: 'system-status-icon' });
-
-    button.set_child(icon);
-    button.connect('button-press-event', _showHello);
+    log("init function");
 }
 
 function enable() {
-    Main.panel._rightBox.insert_child_at_index(button, 0);
+    cloudgnomeMenu = new CloudGnome();
+    Main.panel.addToStatusArea('cloudgnomeMenu', cloudgnomeMenu);
 }
 
+
 function disable() {
-    Main.panel._rightBox.remove_child(button);
+    cloudgnomeMenu.destroy();
+    delete Main.panel.statusArea.cloudgnomeMenu;
 }