Re: popup menu not grabbing focus problems



To add clarity here are some pieces of code:
Mail will mess up the code a little...

In the enable() method of the main extension object I have the following
code:
-------------------------------------------------
// quicklink button box
this.actor = new St.BoxLayout({ name: 'qlContainer',
                                        style_class: 'qlcontainer' });
                 
this.actor._delegate = this;

-------------------------------------------------


Then a piece of code to populate some arrays with the
paths of .desktop files which works and is not relevant here...

After that the following piece of code, which use the arrays to
populate the buttons into the St.BoxLayout and populate the menus and
attach them to the buttons, then it adds the St.BoxLayout to the main
panel:
-------------------------------------------------
for (let category in this.items) {
            if (this.items[category].length > 0) {
                
                let directory = this.directories[category];
                let appInfo =
		Gio.DesktopAppInfo.new_from_filename(directory);
                if (!appInfo) {
                    global.log('App for desktop file ' + directoryPath
			+ ' could not be loaded!');
                    return;
                }
                
                let button = new QuickLaunchButton(appInfo);
                this.actor.add(button.actor);

                let item = this.items[category];
                for (let i = 0; i < item.length; i++) {
                    this._addAppItem(item[i], button.menu);
                }
            }
        }
        Main.panel._leftBox.insert_child_at_index(this.actor, 1);
-------------------------------------------------

These pieces of code is part of the main extension object and makes a
menu item and glues it to the menu in the QuickLaunchButton 
-------------------------------------------------
/*
     * add menu item to popup
     */
    _addAppItem: function(desktopPath, buttonMenu) {
        // from http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/
        let appInfo = Gio.DesktopAppInfo.new_from_filename(desktopPath);
        if (!appInfo) {
            global.log('App for desktop file ' + desktopPath + ' could
		not be loaded!');
            return null;
        }

        let menuItem = this._createAppItem(appInfo, function(w, ev) {
                if(!appInfo.launch([], null)) {
                    global.log('Failed to launch ' +
        appInfo.get_commandline);
                }
            });

        // alphabetically sort list by app name
        let sortKey = String( appInfo.get_name() || desktopPath
        ).toUpperCase()
        let pos = 0;
        //let children = this.menu._getMenuItems();
        let children = buttonMenu._getMenuItems();
        for (let i = 0; i < children.length; i++) {
            let item = children[i];
            if ( String(item.label.text).toUpperCase() > sortKey) {
                // add before item and leave early
                //this.menu.addMenuItem(menuItem, pos);
                buttonMenu.addMenuItem(menuItem, pos);
                return menuItem;
            }
            pos++;
        }
        // append at end of list
        //this.menu.addMenuItem(menuItem, pos);
        buttonMenu.addMenuItem(menuItem, pos);
        return menuItem;
    },
    
    /*
     * create popoup menu item with callback
     */
    _createAppItem: function(appInfo, callback) {
        let menuItem = new PopupGiconMenuItem(appInfo.get_name(),
        appInfo.get_icon(), {});
        menuItem.connect('activate', Lang.bind(this, function
        (menuItem, event) {
                    callback(menuItem, event);
                }));

        return menuItem;
    },
-------------------------------------------------

This piece of code is the PopupGiconMenuItem object that uses
(becomes) __proto__: PopupMenu.PopupBaseMenuItem.prototype:
-------------------------------------------------
/*
 * Gicon Menu Item Object
 */
function PopupGiconMenuItem() {
    this._init.apply(this, arguments);
}

PopupGiconMenuItem.prototype = {
    __proto__: PopupMenu.PopupBaseMenuItem.prototype,

    _init: function (text, gIcon, params) {
        PopupMenu.PopupBaseMenuItem.prototype._init.call(this, params);

        this._icon = new St.Icon({
                gicon: gIcon,
                style_class: 'popup-menu-icon' });
        this.addActor(this._icon, { align: St.Align.END });
        this.label = new St.Label({ text: text });
        this.addActor(this.label);
    },
};
-------------------------------------------------


This piece of code is the QuickLaunchButton object that uses
(becomes) __proto__: PanelMenu.Button.prototype:
-------------------------------------------------
// A panelmenu button to place in the quickllaunch bar
// clicking the button will toggle the menu
function QuickLaunchButton(appInfo) {
    this._init(appInfo);
}

QuickLaunchButton.prototype = {
    
    __proto__: PanelMenu.Button.prototype,
    
    _init: function(appInfo) {
        PanelMenu.Button.prototype._init.call(this, 0.0);
        
        let container = new Shell.GenericContainer();
        container.connect('get-preferred-width', Lang.bind(this,
	this._containerGetPreferredWidth));
	container.connect('get-preferred-height', Lang.bind(this,
	this._containerGetPreferredHeight));
	container.connect('allocate', Lang.bind(this,
	this._containerAllocate));
	this.actor.add_actor(container);
	this._boxActor = new St.BoxLayout();

        this._iconBox = new St.Bin();
        this._boxActor.add(this._iconBox, { y_align: St.Align.MIDDLE,
        y_fill: false }); 
        let logo = new St.Icon({ gicon: appInfo.get_icon(),
                                 icon_type: St.IconType.FULLCOLOR,
                                 icon_size: 20,
                                 style_class:
	'applications-menu-button-icon'});
	
	this._iconBox.child = logo;
        
        container.add_actor(this._boxActor);
    },
    _containerGetPreferredWidth: function(actor, forHeight, alloc) {
        [alloc.min_size, alloc.natural_size] =
        this._boxActor.get_preferred_width(forHeight); },

    _containerGetPreferredHeight: function(actor, forWidth, alloc) {
        [alloc.min_size, alloc.natural_size] =
    this._boxActor.get_preferred_height(forWidth); },

    _containerAllocate: function(actor, box, flags) {
        this._boxActor.allocate(box, flags);
    }
};
-------------------------------------------------


-- 
(o_
//\  Regards, Groeten,
V_/_ Bas Burger.


On Wed, 20 Jun 2012 23:21:27 +0200
Florian Müllner <fmuellner gnome org> wrote:

> On Wed, Jun 20, 2012 at 11:09 PM, Yaa101 <yaa101 xs4all nl> wrote:
> > I am writing an extension that is a variation to both quicklaunch
> > extensions, mine is a buttonbar that collects the XDG category of
> > a .desktop file and defines a button for each found Main XDG
> > category, when clicked on the button a popup menu becomes visible
> > with all the .desktop files that carry the category.
> >
> > This is where things go rough on me, [...] clicking the button
> > brings up the menu but the menu does not want to grab the focus and
> > sits there, when clicking on the menu, anything that is under it
> > will be activated but not the items on the menu.
> 
> I'm not entirely sure what you are trying to do, but it sounds like
> you are missing a call to
> 
> global.set_stage_input_mode (Shell.StageInputMode.FOCUSED)
> 
> 
> Regards,
> Florian



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