[gnome-shell-extensions] New Extension: applications menu on the panel



commit bdbf44805d969746be121b9de550f41d5767684c
Author: Vamsi Krishna Brahmajosyula <vamsikrishna brahmajosyula gmail com>
Date:   Wed May 11 20:19:25 2011 +0530

    New Extension: applications menu on the panel

 README                                |    4 ++
 configure.ac                          |    5 +-
 extensions/apps-menu/Makefile.am      |    3 +
 extensions/apps-menu/extension.js     |   97 +++++++++++++++++++++++++++++++++
 extensions/apps-menu/metadata.json.in |    8 +++
 extensions/apps-menu/stylesheet.css   |    1 +
 6 files changed, 116 insertions(+), 2 deletions(-)
---
diff --git a/README b/README
index 38e612d..bb41cbf 100644
--- a/README
+++ b/README
@@ -30,6 +30,10 @@ alternative-status-menu
 status menu with one featuring separate Suspend and Power Off. Adds the ability to
 hibernate as well.
 
+apps-menu
+
+  Lets you reach an application using gnome 2.x style menu on the panel.
+
 auto-move-windows
 
   Lets you manage your workspaces more easily, assigning a specific workspace to
diff --git a/configure.ac b/configure.ac
index b18b56a..2133799 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,7 @@ dnl keep this in alphabetic order
 dnl by default, install only extensions that do not change completely the shell experience,
 dnl that don't require GSettings and that don't require external packages for typelibs
 dnl (so basically only menus, status icons, search providers, overview tabs, message tray sources, etc.)
-DEFAULT_EXTENSIONS="alternative-status-menu dock drive-menu gajim places-menu windowsNavigator"
+DEFAULT_EXTENSIONS="alternative-status-menu apps-menu dock drive-menu gajim places-menu windowsNavigator"
 ALL_EXTENSIONS="$DEFAULT_EXTENSIONS alternate-tab auto-move-windows example native-window-placement systemMonitor user-theme xrandr-indicator"
 AC_SUBST(ALL_EXTENSIONS, [$ALL_EXTENSIONS])
 AC_ARG_ENABLE([extensions],
@@ -50,7 +50,7 @@ for e in $enable_extensions; do
 					[AC_MSG_WARN([gnome-desktop-3.0 not found, disabling xrandr-indicator])])
 			;;
 dnl		keep this in alphabetic order
-		alternate-tab|alternative-status-menu|auto-move-windows|dock|drive-menu|example|gajim|native-window-placement|places-menu|user-theme|windowsNavigator)
+		alternate-tab|alternative-status-menu|apps-menu|auto-move-windows|dock|drive-menu|example|gajim|native-window-placement|places-menu|user-theme|windowsNavigator)
 			ENABLED_EXTENSIONS="$ENABLED_EXTENSIONS $e"
 			;;
 		*)
@@ -64,6 +64,7 @@ dnl Please keep this sorted alphabetically
 AC_CONFIG_FILES([
   extensions/alternate-tab/Makefile
   extensions/alternative-status-menu/Makefile
+  extensions/apps-menu/Makefile
   extensions/auto-move-windows/Makefile
   extensions/dock/Makefile
   extensions/drive-menu/Makefile
diff --git a/extensions/apps-menu/Makefile.am b/extensions/apps-menu/Makefile.am
new file mode 100644
index 0000000..86431d7
--- /dev/null
+++ b/extensions/apps-menu/Makefile.am
@@ -0,0 +1,3 @@
+EXTENSION_ID = apps-menu
+
+include ../../extension.mk
diff --git a/extensions/apps-menu/extension.js b/extensions/apps-menu/extension.js
new file mode 100644
index 0000000..a867986
--- /dev/null
+++ b/extensions/apps-menu/extension.js
@@ -0,0 +1,97 @@
+/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+const St = imports.gi.St;
+const Main = imports.ui.main;
+const PopupMenu = imports.ui.popupMenu;
+const PanelMenu = imports.ui.panelMenu;
+const Shell = imports.gi.Shell;
+const Lang = imports.lang;
+const ICON_SIZE = 28;
+const Gettext = imports.gettext.domain('gnome-shell-extensions');
+const _ = Gettext.gettext;
+
+let appsys = Shell.AppSystem.get_default();
+
+function AppMenuItem(appInfo,params) {
+    this._init(appInfo,params);
+}
+
+AppMenuItem.prototype = {
+    __proto__: PopupMenu.PopupBaseMenuItem.prototype,
+    _init: function (appInfo, params) {
+        PopupMenu.PopupBaseMenuItem.prototype._init.call(this, params);
+        let app = appsys.get_app(appInfo.get_id());
+        this.label = new St.Label({ text: appInfo.get_name() });
+        this.addActor(this.label);
+        this._icon = app.create_icon_texture(ICON_SIZE);
+        this.addActor(this._icon,{expand : false});
+        this._appInfo = appInfo;
+    },
+    _onButtonReleaseEvent: function (actor, event) {
+        let id = this._appInfo.get_id();
+        appsys.get_app(id).activate(-1);
+        this.activate(event);
+    }
+
+};
+
+function ApplicationsButton() {
+    this._init();
+}
+
+ApplicationsButton.prototype = {
+    __proto__: PanelMenu.SystemStatusButton.prototype,
+
+    _init: function() {
+        PanelMenu.SystemStatusButton.prototype._init.call(this, 'start-here');
+        this._display();
+        appsys.connect('installed-changed', Lang.bind(this,this.reDisplay));
+    },
+
+    reDisplay : function() {
+        this._clearAll();
+        this._display();
+    },
+
+    _clearAll : function() {
+        this.menu.removeAll();
+    },
+
+    _display : function() {
+        let id;
+        this.appItems = [];
+        this.categories =  appsys.get_sections();
+        for ( id = 0; id < this.categories.length; id++) {
+            this.appItems[this.categories[id]] = new PopupMenu.PopupSubMenuMenuItem(this.categories[id]);
+            this.menu.addMenuItem(this.appItems[this.categories[id]]);
+        }
+        this._addSubMenuItems();
+        for ( id = 0; id < this.categories.length; id++) {
+            let item = this.appItems[this.categories[id]];
+            if(item.menu._getMenuItems().length == 0){
+                item.actor.hide();
+            }
+        }
+    },
+    _addSubMenuItems: function() {
+        let appInfos = appsys.get_flattened_apps().filter(function(app) {
+            return !app.get_is_nodisplay();
+        });
+        for (let appid = appInfos.length-1 ; appid >= 0; appid--) {
+            let appInfo = appInfos[appid];
+            let appItem = new AppMenuItem(appInfo);
+            this.appItems[appInfo.get_section()].menu.addMenuItem(appItem);
+        }
+    },
+    _onDestroy: function() {
+        this._clearAll();
+    }
+};
+
+
+function main(metadata) {
+    let  appsMenuButton = new ApplicationsButton();
+    Main.panel._leftBox.insert_actor(appsMenuButton.actor, 1);
+    Main.panel._leftBox.child_set(appsMenuButton.actor, { y_fill : true } );
+    Main.panel._menus.addMenu(appsMenuButton.menu);
+}
\ No newline at end of file
diff --git a/extensions/apps-menu/metadata.json.in b/extensions/apps-menu/metadata.json.in
new file mode 100644
index 0000000..aa86fda
--- /dev/null
+++ b/extensions/apps-menu/metadata.json.in
@@ -0,0 +1,8 @@
+{
+"uuid": "@uuid@",
+"name": "Applications Menu",
+"description": "Add a gnome 2.x style menu for applications",
+"shell-version": [ "@shell_current@" ],
+"localedir": "@LOCALEDIR@",
+"url": "@url@"
+}
diff --git a/extensions/apps-menu/stylesheet.css b/extensions/apps-menu/stylesheet.css
new file mode 100644
index 0000000..db99e0c
--- /dev/null
+++ b/extensions/apps-menu/stylesheet.css
@@ -0,0 +1 @@
+/* none used*/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]