2013-05-09 17:35:57 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2013-05-09 16:24:40 -04:00
|
|
|
const Atk = imports.gi.Atk;
|
2013-05-09 17:35:57 -04:00
|
|
|
const GLib = imports.gi.GLib;
|
2013-05-09 12:28:44 -04:00
|
|
|
const GObject = imports.gi.GObject;
|
2013-05-09 17:35:57 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Shell = imports.gi.Shell;
|
2013-05-09 12:28:44 -04:00
|
|
|
const ShellMenu = imports.gi.ShellMenu;
|
2013-05-09 17:35:57 -04:00
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
const RemoteMenuItemMapper = new Lang.Class({
|
|
|
|
Name: 'RemoteMenuItemMapper',
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
_init: function(trackerItem) {
|
|
|
|
this._trackerItem = trackerItem;
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
this.menuItem = new PopupMenu.PopupBaseMenuItem();
|
|
|
|
this._label = new St.Label();
|
|
|
|
this.menuItem.addActor(this._label);
|
|
|
|
this.menuItem.actor.label_actor = this._label;
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
this.menuItem.connect('activate', Lang.bind(this, function() {
|
|
|
|
this._trackerItem.activated();
|
|
|
|
}));
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
this._trackerItem.bind_property('visible', this.menuItem.actor, 'visible', GObject.BindingFlags.SYNC_CREATE);
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
this._trackerItem.connect('notify::label', Lang.bind(this, this._updateLabel));
|
|
|
|
this._trackerItem.connect('notify::sensitive', Lang.bind(this, this._updateSensitivity));
|
2013-05-09 16:24:40 -04:00
|
|
|
this._trackerItem.connect('notify::role', Lang.bind(this, this._updateRole));
|
2013-05-09 12:28:44 -04:00
|
|
|
this._trackerItem.connect('notify::toggled', Lang.bind(this, this._updateDecoration));
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
this._updateLabel();
|
|
|
|
this._updateSensitivity();
|
2013-05-09 16:24:40 -04:00
|
|
|
this._updateRole();
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
this.menuItem.connect('destroy', function() {
|
|
|
|
trackerItem.run_dispose();
|
2013-05-09 17:35:57 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
_updateLabel: function() {
|
|
|
|
let label = this._trackerItem.label;
|
2013-05-09 17:35:57 -04:00
|
|
|
// remove all underscores that are not followed by another underscore
|
|
|
|
label = label.replace(/_([^_])/, '$1');
|
2013-05-09 12:28:44 -04:00
|
|
|
this._label.text = label;
|
|
|
|
},
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
_updateSensitivity: function() {
|
|
|
|
this.menuItem.setSensitive(this._trackerItem.sensitive);
|
|
|
|
},
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
_updateDecoration: function() {
|
|
|
|
let ornamentForRole = {};
|
|
|
|
ornamentForRole[ShellMenu.MenuTrackerItemRole.RADIO] = PopupMenu.Ornament.DOT;
|
|
|
|
ornamentForRole[ShellMenu.MenuTrackerItemRole.CHECK] = PopupMenu.Ornament.CHECK;
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
let ornament = PopupMenu.Ornament.NONE;
|
|
|
|
if (this._trackerItem.toggled)
|
|
|
|
ornament = ornamentForRole[this._trackerItem.role];
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
this.menuItem.setOrnament(ornament);
|
|
|
|
},
|
2013-05-09 16:24:40 -04:00
|
|
|
|
|
|
|
_updateRole: function() {
|
|
|
|
let a11yRoles = {};
|
|
|
|
a11yRoles[ShellMenu.MenuTrackerItemRole.NORMAL] = Atk.Role.MENU_ITEM;
|
|
|
|
a11yRoles[ShellMenu.MenuTrackerItemRole.RADIO] = Atk.Role.RADIO_MENU_ITEM;
|
|
|
|
a11yRoles[ShellMenu.MenuTrackerItemRole.CHECK] = Atk.Role.CHECK_MENU_ITEM;
|
|
|
|
|
|
|
|
let a11yRole = a11yRoles[this._trackerItem.role];
|
|
|
|
this.menuItem.actor.accessible_role = a11yRole;
|
|
|
|
|
|
|
|
this._updateDecoration();
|
|
|
|
},
|
2013-05-09 12:28:44 -04:00
|
|
|
});
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
const RemoteMenu = new Lang.Class({
|
|
|
|
Name: 'RemoteMenu',
|
|
|
|
Extends: PopupMenu.PopupMenu,
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
_init: function(sourceActor, model, actionGroup) {
|
|
|
|
this.parent(sourceActor, 0.0, St.Side.TOP);
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
this._model = model;
|
|
|
|
this._actionGroup = actionGroup;
|
|
|
|
this._tracker = Shell.MenuTracker.new(this._actionGroup,
|
|
|
|
this._model,
|
|
|
|
null, /* action namespace */
|
|
|
|
Lang.bind(this, this._insertItem),
|
|
|
|
Lang.bind(this, this._removeItem));
|
2013-05-09 17:35:57 -04:00
|
|
|
},
|
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
destroy: function() {
|
|
|
|
this._tracker.destroy();
|
|
|
|
this.parent();
|
2013-05-09 17:35:57 -04:00
|
|
|
},
|
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
_insertItem: function(trackerItem, position) {
|
2013-05-09 17:35:57 -04:00
|
|
|
let item;
|
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
if (trackerItem.get_is_separator()) {
|
2013-05-09 17:35:57 -04:00
|
|
|
item = new PopupMenu.PopupSeparatorMenuItem();
|
2013-05-09 12:28:44 -04:00
|
|
|
} else {
|
|
|
|
let mapper = new RemoteMenuItemMapper(trackerItem);
|
|
|
|
item = mapper.menuItem;
|
|
|
|
}
|
2013-05-09 17:35:57 -04:00
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
this.addMenuItem(item, position);
|
2013-05-09 17:35:57 -04:00
|
|
|
},
|
|
|
|
|
2013-05-09 12:28:44 -04:00
|
|
|
_removeItem: function(position) {
|
|
|
|
let items = this._getMenuItems();
|
2013-05-09 17:35:57 -04:00
|
|
|
items[position].destroy();
|
|
|
|
},
|
|
|
|
});
|