Translate

Archives

GNOME 3.2 Simple Popup Menu Example

GNOME 3.2 is about to be released. There are major changes in the way GNOME Shell extensions must to be written in order to work with this version of GNOME.

Here is a simple GNOME 3.2 Shell extension which demonstrates a simple popup menu on the right hand side of the panel (top bar.) Once loaded, it can be enabled (displayed) or disabled (removed) without restarting the GNOME Shell. This is a major improvement over GNOME 3.0 and 3.1.

//
// Copyright (c) 2011 Finnbarr P. Murphy.  All rights reserved.
//

const St = imports.gi.St;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const Panel = imports.ui.panel;
const Main = imports.ui.main;


function DemoButton() {
   this._init();
}

DemoButton.prototype = {
    __proto__: PanelMenu.SystemStatusButton.prototype,

    _init: function() {
        PanelMenu.SystemStatusButton.prototype._init.call(this, 'folder');

        let item = new PopupMenu.PopupMenuItem(_("Hello"));
        this.menu.addMenuItem(item);
        item = new PopupMenu.PopupMenuItem(_("Goodbye"));
        this.menu.addMenuItem(item);
    },

    enable: function() {
        let _children = Main.panel._rightBox.get_children();
        Main.panel._rightBox.insert_actor(this.actor, _children.length - 1);
        Main.panel._menus.addMenu(this.menu);
    },

    disable: function() {
        Main.panel._menus.removeMenu(this.menu);
        Main.panel._rightBox.remove_actor(this.actor);
    }
}


function init() {
    return new DemoButton();
}


There are no changes to the format or contents of metadata.json. Read my main blog for more information.

A ready-to-use tarball of this extension can be downloaded from here.

Comments are closed.