Applications extension: add icons to categories

Hello,

I do not know if this is the right place to post this, yet I’m using the Applications extension (Apps Menu) under ubuntu gnome.

For many versions I had to edit myself the code in order to add icons to the applications categories, as they used to have icons under older ubuntu versions, prior to gnome shell era.

The thing is that I have to copy paste the code I created every time a new update comes. So I thought to share this code and if possible to get it implemented to this extension. What I haven’t achieved is the translation of the code, meaning to work for different languages: e.g. I use different wording for English or Hellenic language. I provide here the English version.

Here is the folder:

/usr/share/gnome-shell/extensions/apps-menu@gnome-shell-extensions.gcampax.github.com/

Here is the file:

extension.js

Here is the code:

const APPLICATION_ICON_SIZE = 24; /changes the size of subcategory application e.g. from Games Chess/(if we want bigger icons then change 24 to 32 and change also the line):const MENU_HEIGHT_OFFSET = 182; /changes height of menu 132/

class CategoryMenuItem extends PopupMenu.PopupBaseMenuItem {static {GObject.registerClass(this);}

constructor(button, category) {
    super();
    this._category = category;
    this._button = button;
    
    this._oldX = -1;
    this._oldY = -1;
         
    //Add icons to categories
    //in newer shell versions could start from here 
    let Icon = new St.Icon();

    if (this._category)
        {var catname = this._category.get_name();
        if (catname==='Accessories') 
            Icon = new St.Icon({icon_name: `applications-accessories-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'}); 
        if (catname==='CrossOver') 
            Icon = new St.Icon({icon_name: `cxmenu-cxoffice-0-crossover-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Games')  
            Icon = new St.Icon({icon_name: `applications-games-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Graphics') 
            Icon = new St.Icon({icon_name: `applications-graphics-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Internet') 
            Icon = new St.Icon({icon_name: `applications-internet-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Office') 
            Icon = new St.Icon({icon_name: `applications-office-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Other') 
            Icon = new St.Icon({icon_name: `applications-other-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Programming') 
            Icon = new St.Icon({icon_name: `applications-engineering-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Science') 
            Icon = new St.Icon({icon_name: `applications-science-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Electronics') 
            Icon = new St.Icon({icon_name: `applications-electronics-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Education') 
            Icon = new St.Icon({icon_name: `applications-libraries-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'}); 
        if (catname==='Sound & Video') 
            Icon = new St.Icon({icon_name: `applications-multimedia-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='System Tools') 
            Icon = new St.Icon({icon_name: `applications-system-tools-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Utilities') 
            Icon = new St.Icon({icon_name: `applications-utilities-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Windows Applications') 
            Icon = new St.Icon({icon_name: `cxmenu-cxoffice-0-cxmenu-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});
        if (catname==='Wine') 
            Icon = new St.Icon({icon_name: `wine-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '24'});}                             
    else
        Icon = new St.Icon({icon_name: 'emblem-favorite-symbolic.symbolic.png', style_class: 'system-status-icon', icon_size: '24'})            
    this.add_child(Icon);

//from here on the same
    let name;
    if (this._category)
        name = this._category.get_name();

    else
        name = _('Favorites');
        
    this.add_child(new St.Label({text: name}));
    this.connect('motion-event', this._onMotionEvent.bind(this));
    this.connect('notify::active', this._onActiveChanged.bind(this));

Regards!

Hello,

I’m providing also the code for the Hellenic language. I suppose that in order to work for different languages you could change the corresponding string, that’s why I have added comments for the English translation as well.

For some reason though Science wasn’t translated. In order to achieve that I had to open alacarte (κυρίως μενού) and changed the string “Science” to «Επιστήμη».

Here is the code:

class CategoryMenuItem extends PopupMenu.PopupBaseMenuItem {static {GObject.registerClass(this);}

constructor(button, category) {
    super();
    this._category = category;
    this._button = button;

    this._oldX = -1;
    this._oldY = -1;

    let Icon = new St.Icon();

    if (this._category)
        {var catname = this._category.get_name();
        //print (catname)
        if (catname==='Βοηθήματα') /*Accessories*/
            Icon = new St.Icon({icon_name: `applications-accessories-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'}); 
        if (catname==='CrossOver') 
            Icon = new St.Icon({icon_name: `cxmenu-cxoffice-0-crossover-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Παιχνίδια') /*Games*/   
            Icon = new St.Icon({icon_name: `applications-games-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Γραφικά') /*Graphics*/
            Icon = new St.Icon({icon_name: `applications-graphics-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Διαδίκτυο') /*Internet*/
            Icon = new St.Icon({icon_name: `applications-internet-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Γραφείο') /*Office*/
            Icon = new St.Icon({icon_name: `applications-office-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Άλλα') /*Other*/
            Icon = new St.Icon({icon_name: `applications-other-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Προγραμματισμός') /*Programming*/
            Icon = new St.Icon({icon_name: `applications-engineering-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Επιστήμη') /*Science*/
            Icon = new St.Icon({icon_name: `applications-science-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Electronics') /*not such menu exists, kept it as is*/
            Icon = new St.Icon({icon_name: `applications-electronics-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Εκπαίδευση') /*Education*/
            Icon = new St.Icon({icon_name: `applications-libraries-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'}); 
        if (catname==='Ήχος και βίντεο') /*Sound & Video*/
            Icon = new St.Icon({icon_name: `applications-multimedia-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Εργαλεία συστήματος') /*System Tools*/
            Icon = new St.Icon({icon_name: `applications-system-tools-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Εργαλεία') /*Utilities*/
            Icon = new St.Icon({icon_name: `applications-utilities-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Windows Applications') 
            Icon = new St.Icon({icon_name: `cxmenu-cxoffice-0-cxmenu-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});
        if (catname==='Wine') 
            Icon = new St.Icon({icon_name: `wine-symbolic.symbolic.png`, style_class: 'system-status-icon', icon_size: '32'});}                             
    else
        Icon = new St.Icon({icon_name: 'emblem-favorite-symbolic.symbolic.png', style_class: 'system-status-icon', icon_size: '32'})            
    this.add_child(Icon);

//from here on the same
    let name;
    if (this._category)
        name = this._category.get_name();

    else
        name = _('Αγαπημένα'); /*Favorites*/

Regards!

Hello,

for those interested, I created a bug report:

Regards!