Making a PopupMenu persist after clicking (which launches another PopupMenu)



Hi all,

I have a menu with a number of PopupMenuItems in it.

Right-clicking a PopupMenuItem is supposed to bring up another
PopupMenu, being that item's right click menu.

I can get this working, but whenever I bring up the right click menu,
the main menu closes leaving the right click menu hanging in mid-air.

Is there some way I can get the main menu to stay open even though I
right-clicked the item?
I think it has something to do with me adding the right click menu to
a popupMenuManager. Maybe only one is allowed to have focus at any one
time? But if I don't add the right click menu to the popup menu
manager, then I can't select anything from it.

I've tried various combinations of
Main.uiGroup.add_actor(rightclickmenu.actor),
St.FocusManager.get_for_stage(global.stage).add_group(rightlickmenu.actor)
and Main.layout.addChrome(rightclickmenu.actor), but either I can't
interact with the menu, or when I bring up the right click popup menu
the parent popup menu closes.

I think it has something to do with the fact that the right click menu
is a popup menu (as opposed to a St.BoxLayout or something) and
perhaps "steals" focus from the parent menu which automagically causes
the parent menu to close. Is the only way to keep the parent menu open
until something's selected from the right click menu, to make my own
PopupMenuManager class?

Relevant snippets of code are as follows:

// add a panel status button with a menu. Add some menu items to it,
// which will be right-clickable
MyMenu.prototype = {
    __proto__: PanelMenu.SystemStatusButton.prototype,
    _init: function () {
        /* ... */
        this.menu.addMenuItem(MyPopupMenuItem);
    }
};

// custom menu item. right clicking it will bring up the right click popup menu
MyPopupMenuItem.prototype = {
    __proto__: PopupMenu.PopupBaseMenuItem.prototype,
    _init: function () {
        /* ... */
        // create a right click menu which will pop up to the left of the item.
        this.rightClickMenu = new RightClickMenu(this.actor, 0, St.Side.RIGHT);
    }

    // we override this function to specify what happens when the
    // item is clicked. If it's a right click, bring up the right click menu.
    _onButtonReleaseEvent: function (actor, event) {
        if (Shell.get_event_state(event) & Clutter.ModifierType.BUTTON3_MASK) {
            // it was a right click
            this.rightClickMenu.open(true);
            // *** Want the parent menu to remain open until I select
an item but it closes!
        } else {
            this.activate(event); // let any 'activate' listeners handle it
        }
        return true;
    }
};

// The right click menu
RightClickMenu.prototype = {
    __proto__: PopupMenu.PopupMenu.prototype,
    _init: function (actor, align, side) {
        PopupMenu.PopupMenu.prototype._init.call(this, actor, align, side);
        // hide menu, add to Main.uiGroup, add to menu manager in order to
        // get all the hover/clicking/focus stuff working
        this.actor.hide();
        Main.uiGroup.add_actor(this.actor);

        this.menuManager = new PopupMenu.PopupMenuManager({actor: this.actor});
        this.menuManager.addMenu(this);

        /* now add other menu items via this.addMenuItem(...) */
};


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