2008-12-01 14:51:43 -05:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-04-01 15:51:17 -04:00
|
|
|
const Big = imports.gi.Big;
|
2008-11-20 19:53:11 -05:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2009-04-01 15:51:17 -04:00
|
|
|
const Pango = imports.gi.Pango;
|
2009-07-07 16:08:41 -04:00
|
|
|
const GLib = imports.gi.GLib;
|
2008-11-20 19:53:11 -05:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
2009-06-30 16:35:39 -04:00
|
|
|
const Tidy = imports.gi.Tidy;
|
2008-11-20 19:53:11 -05:00
|
|
|
const Shell = imports.gi.Shell;
|
2009-04-01 15:51:17 -04:00
|
|
|
const Lang = imports.lang;
|
2009-02-02 18:02:16 -05:00
|
|
|
const Signals = imports.signals;
|
2009-06-30 16:35:39 -04:00
|
|
|
const Mainloop = imports.mainloop;
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-06-30 16:35:39 -04:00
|
|
|
const DND = imports.ui.dnd;
|
2008-12-19 23:27:57 -05:00
|
|
|
const GenericDisplay = imports.ui.genericDisplay;
|
2009-07-02 05:04:33 -04:00
|
|
|
const Workspaces = imports.ui.workspaces;
|
2009-04-01 15:51:17 -04:00
|
|
|
|
|
|
|
const ENTERED_MENU_COLOR = new Clutter.Color();
|
|
|
|
ENTERED_MENU_COLOR.from_pixel(0x00ff0022);
|
|
|
|
|
2009-07-04 17:28:34 -04:00
|
|
|
const GLOW_COLOR = new Clutter.Color();
|
|
|
|
GLOW_COLOR.from_pixel(0x4f6ba4ff);
|
|
|
|
const GLOW_PADDING = 5;
|
|
|
|
|
2009-06-30 16:35:39 -04:00
|
|
|
const APP_ICON_SIZE = 48;
|
2009-07-02 00:35:26 -04:00
|
|
|
const APP_PADDING = 18;
|
2009-06-30 16:35:39 -04:00
|
|
|
|
2009-04-01 15:51:17 -04:00
|
|
|
const MENU_ICON_SIZE = 24;
|
|
|
|
const MENU_SPACING = 15;
|
2008-12-19 23:27:57 -05:00
|
|
|
|
2009-04-23 10:41:24 -04:00
|
|
|
const MAX_ITEMS = 30;
|
|
|
|
|
2008-12-19 23:27:57 -05:00
|
|
|
/* This class represents a single display item containing information about an application.
|
|
|
|
*
|
2009-06-16 12:20:12 -04:00
|
|
|
* appInfo - AppInfo object containing information about the application
|
2008-12-19 23:27:57 -05:00
|
|
|
* availableWidth - total width available for the item
|
|
|
|
*/
|
|
|
|
function AppDisplayItem(appInfo, availableWidth) {
|
|
|
|
this._init(appInfo, availableWidth);
|
2008-11-20 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
AppDisplayItem.prototype = {
|
2008-12-19 23:27:57 -05:00
|
|
|
__proto__: GenericDisplay.GenericDisplayItem.prototype,
|
|
|
|
|
|
|
|
_init : function(appInfo, availableWidth) {
|
2009-07-07 16:08:41 -04:00
|
|
|
GenericDisplay.GenericDisplayItem.prototype._init.call(this, availableWidth);
|
2008-12-09 17:10:43 -05:00
|
|
|
this._appInfo = appInfo;
|
2008-12-01 14:51:43 -05:00
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
this._setItemInfo(appInfo.get_name(), appInfo.get_description());
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
2008-12-19 23:27:57 -05:00
|
|
|
|
2009-07-02 00:35:26 -04:00
|
|
|
getId: function() {
|
2009-07-07 16:08:41 -04:00
|
|
|
return this._appInfo.get_id();
|
2009-07-02 00:35:26 -04:00
|
|
|
},
|
|
|
|
|
2008-12-19 23:27:57 -05:00
|
|
|
//// Public method overrides ////
|
|
|
|
|
|
|
|
// Opens an application represented by this display item.
|
|
|
|
launch : function() {
|
2009-06-16 12:20:12 -04:00
|
|
|
this._appInfo.launch();
|
2009-03-20 12:06:34 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
//// Protected method overrides ////
|
|
|
|
|
2009-06-29 15:08:48 -04:00
|
|
|
// Returns an icon for the item.
|
|
|
|
_createIcon : function() {
|
2009-07-07 16:08:41 -04:00
|
|
|
return this._appInfo.create_icon_texture(GenericDisplay.ITEM_DISPLAY_ICON_SIZE);
|
2009-06-29 15:08:48 -04:00
|
|
|
},
|
|
|
|
|
2009-03-20 12:06:34 -04:00
|
|
|
// Ensures the preview icon is created.
|
|
|
|
_ensurePreviewIconCreated : function() {
|
2009-03-21 10:37:15 -04:00
|
|
|
if (!this._showPreview || this._previewIcon)
|
2009-07-07 16:08:41 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
let gicon = this._appInfo.get_icon();
|
|
|
|
let previewIconPath = null;
|
|
|
|
if (gicon) {
|
|
|
|
let iconTheme = Gtk.IconTheme.get_default();
|
|
|
|
let previewIconInfo = iconTheme.lookup_by_gicon(gicon, GenericDisplay.PREVIEW_ICON_SIZE, 0);
|
|
|
|
if (previewIconInfo)
|
|
|
|
previewIconPath = previewIconInfo.get_filename();
|
|
|
|
}
|
2009-03-20 12:06:34 -04:00
|
|
|
|
|
|
|
if (previewIconPath) {
|
|
|
|
try {
|
2009-07-07 16:08:41 -04:00
|
|
|
this._previewIcon = new Clutter.Texture({ width: GenericDisplay.PREVIEW_ICON_SIZE, height: GenericDisplay.PREVIEW_ICON_SIZE});
|
2009-03-20 12:06:34 -04:00
|
|
|
this._previewIcon.set_from_file(previewIconPath);
|
|
|
|
} catch (e) {
|
|
|
|
// we can get an error here if the file path doesn't exist on the system
|
|
|
|
log('Error loading AppDisplayItem preview icon ' + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-19 23:27:57 -05:00
|
|
|
};
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-04-01 15:51:17 -04:00
|
|
|
const MENU_UNSELECTED = 0;
|
|
|
|
const MENU_SELECTED = 1;
|
|
|
|
const MENU_ENTERED = 2;
|
|
|
|
|
2009-05-02 18:33:13 -04:00
|
|
|
function MenuItem(name, id, iconName) {
|
|
|
|
this._init(name, id, iconName);
|
2009-04-01 15:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MenuItem:
|
|
|
|
* Shows the list of menus in the sidebar.
|
|
|
|
*/
|
|
|
|
MenuItem.prototype = {
|
2009-05-02 18:33:13 -04:00
|
|
|
_init: function(name, id, iconName) {
|
2009-04-01 15:51:17 -04:00
|
|
|
this.id = id;
|
|
|
|
|
|
|
|
this.actor = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
|
|
|
|
spacing: 4,
|
|
|
|
corner_radius: 4,
|
|
|
|
padding_right: 4,
|
|
|
|
reactive: true });
|
|
|
|
this.actor.connect('button-press-event', Lang.bind(this, function (a, e) {
|
|
|
|
this.setState(MENU_SELECTED);
|
|
|
|
}));
|
|
|
|
|
|
|
|
let iconTheme = Gtk.IconTheme.get_default();
|
|
|
|
let pixbuf = null;
|
|
|
|
this._icon = new Clutter.Texture({ width: MENU_ICON_SIZE,
|
|
|
|
height: MENU_ICON_SIZE });
|
|
|
|
// Wine manages not to have an icon
|
|
|
|
try {
|
2009-05-02 18:33:13 -04:00
|
|
|
pixbuf = iconTheme.load_icon(iconName, MENU_ICON_SIZE, 0 /* flags */);
|
2009-04-01 15:51:17 -04:00
|
|
|
} catch (e) {
|
|
|
|
pixbuf = iconTheme.load_icon('gtk-file', MENU_ICON_SIZE, 0);
|
|
|
|
}
|
|
|
|
if (pixbuf != null)
|
|
|
|
Shell.clutter_texture_set_from_pixbuf(this._icon, pixbuf);
|
2009-07-27 18:59:26 -04:00
|
|
|
this.actor.append(this._icon, Big.BoxPackFlags.NONE);
|
2009-04-01 15:51:17 -04:00
|
|
|
this._text = new Clutter.Text({ color: GenericDisplay.ITEM_DISPLAY_NAME_COLOR,
|
|
|
|
font_name: "Sans 14px",
|
|
|
|
ellipsize: Pango.EllipsizeMode.END,
|
|
|
|
text: name });
|
|
|
|
|
2009-07-27 18:59:26 -04:00
|
|
|
// We use individual boxes for the label and the arrow to ensure that they
|
|
|
|
// are aligned vertically. Just setting y_align: Big.BoxAlignment.CENTER
|
|
|
|
// on this.actor does not seem to achieve that.
|
|
|
|
let labelBox = new Big.Box({ y_align: Big.BoxAlignment.CENTER });
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2009-07-27 18:59:26 -04:00
|
|
|
labelBox.append(this._text, Big.BoxPackFlags.NONE);
|
|
|
|
|
|
|
|
this.actor.append(labelBox, Big.BoxPackFlags.EXPAND);
|
|
|
|
|
|
|
|
let arrowBox = new Big.Box({ y_align: Big.BoxAlignment.CENTER });
|
|
|
|
|
|
|
|
this._arrow = new Shell.Arrow({ surface_width: MENU_ICON_SIZE / 2,
|
|
|
|
surface_height: MENU_ICON_SIZE / 2,
|
2009-04-01 15:51:17 -04:00
|
|
|
direction: Gtk.ArrowType.RIGHT,
|
2009-07-27 18:59:26 -04:00
|
|
|
opacity: 0 });
|
|
|
|
arrowBox.append(this._arrow, Big.BoxPackFlags.NONE);
|
|
|
|
this.actor.append(arrowBox, Big.BoxPackFlags.NONE);
|
2009-04-01 15:51:17 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
getState: function() {
|
|
|
|
return this._state;
|
|
|
|
},
|
|
|
|
|
|
|
|
setState: function (state) {
|
|
|
|
if (state == this._state)
|
|
|
|
return;
|
|
|
|
this._state = state;
|
|
|
|
if (this._state == MENU_UNSELECTED) {
|
|
|
|
this.actor.background_color = null;
|
|
|
|
this._arrow.set_opacity(0);
|
|
|
|
} else if (this._state == MENU_ENTERED) {
|
|
|
|
this.actor.background_color = ENTERED_MENU_COLOR;
|
|
|
|
this._arrow.set_opacity(0xFF/2);
|
|
|
|
} else {
|
|
|
|
this.actor.background_color = GenericDisplay.ITEM_DISPLAY_SELECTED_BACKGROUND_COLOR;
|
|
|
|
this._arrow.set_opacity(0xFF);
|
|
|
|
}
|
|
|
|
this.emit('state-changed')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Signals.addSignalMethods(MenuItem.prototype);
|
|
|
|
|
2009-06-30 16:35:39 -04:00
|
|
|
|
2008-12-19 23:27:57 -05:00
|
|
|
/* This class represents a display containing a collection of application items.
|
|
|
|
* The applications are sorted based on their popularity by default, and based on
|
|
|
|
* their name if some search filter is applied.
|
|
|
|
*
|
|
|
|
* width - width available for the display
|
|
|
|
*/
|
2009-07-04 15:30:12 -04:00
|
|
|
function AppDisplay(width) {
|
|
|
|
this._init(width);
|
2008-11-20 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
AppDisplay.prototype = {
|
2008-12-19 23:27:57 -05:00
|
|
|
__proto__: GenericDisplay.GenericDisplay.prototype,
|
|
|
|
|
2009-07-04 15:30:12 -04:00
|
|
|
_init : function(width) {
|
|
|
|
GenericDisplay.GenericDisplay.prototype._init.call(this, width);
|
2009-01-21 16:50:57 -05:00
|
|
|
|
2009-04-01 15:51:17 -04:00
|
|
|
this._menus = [];
|
|
|
|
this._menuDisplays = [];
|
|
|
|
|
2009-01-21 16:50:57 -05:00
|
|
|
// map<itemId, array of category names>
|
2009-04-01 15:51:17 -04:00
|
|
|
this._appCategories = {};
|
2009-04-23 10:41:24 -04:00
|
|
|
|
2009-06-18 12:27:19 -04:00
|
|
|
this._appMonitor = Shell.AppMonitor.get_default();
|
|
|
|
this._appSystem = Shell.AppSystem.get_default();
|
2008-12-01 14:51:43 -05:00
|
|
|
this._appsStale = true;
|
2009-06-30 16:35:39 -04:00
|
|
|
this._appSystem.connect('installed-changed', Lang.bind(this, function(appSys) {
|
2009-04-23 10:41:24 -04:00
|
|
|
this._appsStale = true;
|
|
|
|
this._redisplay(false);
|
|
|
|
this._redisplayMenus();
|
|
|
|
}));
|
2009-06-30 16:35:39 -04:00
|
|
|
this._appSystem.connect('favorites-changed', Lang.bind(this, function(appSys) {
|
|
|
|
this._redisplay(false);
|
|
|
|
}));
|
2009-04-23 10:41:24 -04:00
|
|
|
this._appMonitor.connect('changed', Lang.bind(this, function(monitor) {
|
2009-05-14 14:14:18 -04:00
|
|
|
this._redisplay(false);
|
2009-04-23 10:41:24 -04:00
|
|
|
}));
|
2009-01-13 15:45:54 -05:00
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
// Load the apps now so it doesn't slow down the first
|
2009-01-13 15:45:54 -05:00
|
|
|
// transition into the overlay
|
|
|
|
this._refreshCache();
|
2009-04-01 15:51:17 -04:00
|
|
|
|
|
|
|
this._focusInMenus = true;
|
|
|
|
this._activeMenuIndex = -1;
|
|
|
|
this._activeMenu = null;
|
|
|
|
this._activeMenuApps = null;
|
|
|
|
this._menuDisplay = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
|
|
|
|
spacing: MENU_SPACING
|
|
|
|
});
|
|
|
|
this._redisplayMenus();
|
|
|
|
|
|
|
|
this.connect('expanded', Lang.bind(this, function (self) {
|
|
|
|
this._filterReset();
|
|
|
|
}));
|
2009-07-04 12:46:35 -04:00
|
|
|
this._filterReset();
|
2009-04-01 15:51:17 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
moveRight: function() {
|
|
|
|
if (this._expanded && this._focusInMenu) {
|
|
|
|
this._focusInMenu = false;
|
|
|
|
this._activeMenu.setState(MENU_ENTERED);
|
|
|
|
this.selectFirstItem();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
moveLeft: function() {
|
|
|
|
if (this._expanded && !this._focusInMenu) {
|
|
|
|
this._activeMenu.setState(MENU_SELECTED);
|
|
|
|
this.unsetSelected();
|
|
|
|
this._focusInMenu = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Override genericDisplay.js
|
2009-07-04 12:46:35 -04:00
|
|
|
getNavigationArea: function() {
|
2009-04-01 15:51:17 -04:00
|
|
|
return this._menuDisplay;
|
|
|
|
},
|
|
|
|
|
|
|
|
selectUp: function() {
|
|
|
|
if (!(this._expanded && this._focusInMenu))
|
|
|
|
return GenericDisplay.GenericDisplay.prototype.selectUp.call(this);
|
|
|
|
this._selectMenuIndex(this._activeMenuIndex - 1);
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
selectDown: function() {
|
|
|
|
if (!(this._expanded && this._focusInMenu))
|
|
|
|
return GenericDisplay.GenericDisplay.prototype.selectDown.call(this);
|
|
|
|
this._selectMenuIndex(this._activeMenuIndex+1);
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Protected overrides
|
|
|
|
|
|
|
|
_filterActive: function() {
|
2009-07-07 16:08:41 -04:00
|
|
|
// We always have a filter now since a menu must be selected
|
|
|
|
return true;
|
2009-04-01 15:51:17 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_filterReset: function() {
|
|
|
|
GenericDisplay.GenericDisplay.prototype._filterReset.call(this);
|
2009-07-04 12:46:35 -04:00
|
|
|
this._selectMenuIndex(0);
|
2009-04-01 15:51:17 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
//// Private ////
|
|
|
|
|
|
|
|
_emitStateChange: function() {
|
|
|
|
this.emit('state-changed');
|
|
|
|
},
|
|
|
|
|
|
|
|
_selectMenuIndex: function(index) {
|
|
|
|
if (index < 0 || index >= this._menus.length)
|
|
|
|
return;
|
2009-04-13 15:41:13 -04:00
|
|
|
this._menuDisplays[index].setState(MENU_SELECTED);
|
2009-04-01 15:51:17 -04:00
|
|
|
},
|
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
_getMostUsed: function() {
|
|
|
|
return this._appMonitor.get_most_used_apps(0, 30).map(Lang.bind(this, function (id) {
|
|
|
|
return this._appSystem.lookup_app(id + '.desktop');
|
|
|
|
})).filter(function (e) { return e != null });
|
|
|
|
},
|
|
|
|
|
2009-07-04 12:46:35 -04:00
|
|
|
_addMenuItem: function(name, id, icon, index) {
|
|
|
|
let display = new MenuItem(name, id, icon);
|
|
|
|
this._menuDisplays.push(display);
|
|
|
|
display.connect('state-changed', Lang.bind(this, function (display) {
|
|
|
|
let activated = display.getState() != MENU_UNSELECTED;
|
|
|
|
if (!activated && display == this._activeMenu) {
|
|
|
|
this._activeMenuIndex = -1;
|
|
|
|
this._activeMenu = null;
|
|
|
|
} else if (activated) {
|
|
|
|
if (display != this._activeMenu && this._activeMenu != null)
|
|
|
|
this._activeMenu.setState(MENU_UNSELECTED);
|
|
|
|
this._activeMenuIndex = index;
|
|
|
|
this._activeMenu = display;
|
|
|
|
if (id == null) {
|
2009-07-07 16:08:41 -04:00
|
|
|
this._activeMenuApps = this._getMostUsed();
|
2009-07-04 12:46:35 -04:00
|
|
|
} else {
|
|
|
|
this._activeMenuApps = this._appSystem.get_applications_for_menu(id);
|
|
|
|
}
|
|
|
|
}
|
2009-07-07 06:20:17 -04:00
|
|
|
this._redisplay(true);
|
2009-07-04 12:46:35 -04:00
|
|
|
}));
|
|
|
|
this._menuDisplay.append(display.actor, 0);
|
|
|
|
},
|
|
|
|
|
2009-04-01 15:51:17 -04:00
|
|
|
_redisplayMenus: function() {
|
|
|
|
this._menuDisplay.remove_all();
|
2009-07-04 12:46:35 -04:00
|
|
|
this._addMenuItem('Frequent', null, 'gtk-select-all');
|
2009-04-01 15:51:17 -04:00
|
|
|
for (let i = 0; i < this._menus.length; i++) {
|
|
|
|
let menu = this._menus[i];
|
2009-07-04 12:46:35 -04:00
|
|
|
this._addMenuItem(menu.name, menu.id, menu.icon, i+1);
|
2009-04-01 15:51:17 -04:00
|
|
|
}
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
|
|
|
|
2009-06-17 18:42:05 -04:00
|
|
|
_addApp: function(appInfo) {
|
2009-07-07 16:08:41 -04:00
|
|
|
let appId = appInfo.get_id();
|
2009-06-17 18:42:05 -04:00
|
|
|
this._allItems[appId] = appInfo;
|
|
|
|
},
|
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
//// Protected method overrides ////
|
2008-12-01 14:51:43 -05:00
|
|
|
|
2008-12-19 23:27:57 -05:00
|
|
|
// Gets information about all applications by calling Gio.app_info_get_all().
|
|
|
|
_refreshCache : function() {
|
|
|
|
let me = this;
|
2008-12-01 14:51:43 -05:00
|
|
|
if (!this._appsStale)
|
|
|
|
return;
|
2008-12-19 23:27:57 -05:00
|
|
|
this._allItems = {};
|
2009-04-01 15:51:17 -04:00
|
|
|
this._appCategories = {};
|
|
|
|
|
2009-04-22 15:21:35 -04:00
|
|
|
this._menus = this._appSystem.get_menus();
|
2009-05-14 14:14:18 -04:00
|
|
|
// Loop over the toplevel menu items, load the set of desktop file ids
|
|
|
|
// associated with each one
|
|
|
|
for (let i = 0; i < this._menus.length; i++) {
|
|
|
|
let menu = this._menus[i];
|
|
|
|
let menuApps = this._appSystem.get_applications_for_menu(menu.id);
|
|
|
|
for (let j = 0; j < menuApps.length; j++) {
|
2009-07-07 16:08:41 -04:00
|
|
|
let app = menuApps[j];
|
|
|
|
this._addApp(app);
|
2009-05-14 14:14:18 -04:00
|
|
|
}
|
2008-12-01 14:51:43 -05:00
|
|
|
}
|
2009-05-14 14:14:18 -04:00
|
|
|
|
|
|
|
// Now grab the desktop file ids for settings/preferences.
|
|
|
|
// These show up in search, but not with the rest of apps.
|
|
|
|
let settings = this._appSystem.get_all_settings();
|
|
|
|
for (let i = 0; i < settings.length; i++) {
|
2009-07-07 16:08:41 -04:00
|
|
|
let app = settings[i];
|
|
|
|
this._addApp(app);
|
2009-05-14 14:14:18 -04:00
|
|
|
}
|
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
this._appsStale = false;
|
|
|
|
},
|
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
// Stub this out; the app display always has a category selected
|
2008-12-19 23:27:57 -05:00
|
|
|
_setDefaultList : function() {
|
2009-07-07 16:08:41 -04:00
|
|
|
this._matchedItems = [];
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
|
|
|
|
2009-02-10 14:12:13 -05:00
|
|
|
// Compares items associated with the item ids based on the alphabetical order
|
|
|
|
// of the item names.
|
|
|
|
// Returns an integer value indicating the result of the comparison.
|
|
|
|
_compareItems : function(itemIdA, itemIdB) {
|
|
|
|
let appA = this._allItems[itemIdA];
|
|
|
|
let appB = this._allItems[itemIdB];
|
2009-07-07 16:08:41 -04:00
|
|
|
return appA.get_name().localeCompare(appB.get_name());
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
|
|
|
|
2008-12-19 23:27:57 -05:00
|
|
|
// Checks if the item info can be a match for the search string by checking
|
2009-07-07 16:08:41 -04:00
|
|
|
// the name, description, execution command, and categories for the application.
|
|
|
|
// Item info is expected to be Shell.AppInfo.
|
2008-12-19 23:27:57 -05:00
|
|
|
// Returns a boolean flag indicating if itemInfo is a match.
|
|
|
|
_isInfoMatching : function(itemInfo, search) {
|
2009-07-07 16:08:41 -04:00
|
|
|
// Don't show nodisplay items here
|
|
|
|
if (itemInfo.get_is_nodisplay())
|
|
|
|
return false;
|
2009-04-01 15:51:17 -04:00
|
|
|
// Search takes precedence; not typically useful to search within a
|
|
|
|
// menu
|
|
|
|
if (this._activeMenu == null || search != "")
|
|
|
|
return this._isInfoMatchingSearch(itemInfo, search);
|
|
|
|
else
|
|
|
|
return this._isInfoMatchingMenu(itemInfo, search);
|
|
|
|
},
|
|
|
|
|
|
|
|
_isInfoMatchingMenu : function(itemInfo, search) {
|
2009-07-07 16:08:41 -04:00
|
|
|
let id = itemInfo.get_id();
|
2009-04-01 15:51:17 -04:00
|
|
|
for (let i = 0; i < this._activeMenuApps.length; i++) {
|
2009-07-07 16:08:41 -04:00
|
|
|
let activeApp = this._activeMenuApps[i];
|
|
|
|
if (activeApp.get_id() == id)
|
2009-04-01 15:51:17 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_isInfoMatchingSearch: function(itemInfo, search) {
|
2008-12-01 14:51:43 -05:00
|
|
|
if (search == null || search == '')
|
|
|
|
return true;
|
2009-01-21 16:50:57 -05:00
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
let fold = function(s) {
|
|
|
|
if (!s)
|
|
|
|
return s;
|
|
|
|
return GLib.utf8_casefold(GLib.utf8_normalize(s, -1,
|
|
|
|
GLib.NormalizeMode.ALL), -1);
|
|
|
|
};
|
|
|
|
let name = fold(itemInfo.get_name());
|
2008-12-01 14:51:43 -05:00
|
|
|
if (name.indexOf(search) >= 0)
|
|
|
|
return true;
|
2009-01-21 16:50:57 -05:00
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
let description = fold(itemInfo.get_description());
|
2008-12-01 14:51:43 -05:00
|
|
|
if (description) {
|
|
|
|
if (description.indexOf(search) >= 0)
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-21 16:50:57 -05:00
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
let exec = fold(itemInfo.get_executable());
|
|
|
|
if (exec == null) {
|
2009-06-17 12:37:54 -04:00
|
|
|
log("Missing an executable for " + itemInfo.name);
|
2009-01-22 16:28:19 -05:00
|
|
|
} else {
|
|
|
|
if (exec.indexOf(search) >= 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
let categories = itemInfo.get_categories();
|
2009-05-26 12:56:38 -04:00
|
|
|
for (let i = 0; i < categories.length; i++) {
|
2009-07-07 16:08:41 -04:00
|
|
|
let category = fold(categories[i]);
|
2009-05-26 12:56:38 -04:00
|
|
|
if (category.indexOf(search) >= 0)
|
|
|
|
return true;
|
2009-01-21 16:50:57 -05:00
|
|
|
}
|
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
// Creates an AppDisplayItem based on itemInfo, which is expected be an Shell.AppInfo object.
|
2009-07-04 15:30:12 -04:00
|
|
|
_createDisplayItem: function(itemInfo, width) {
|
|
|
|
return new AppDisplayItem(itemInfo, width);
|
2009-04-01 15:51:17 -04:00
|
|
|
}
|
2008-12-01 14:51:43 -05:00
|
|
|
};
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
Signals.addSignalMethods(AppDisplay.prototype);
|
2009-06-30 16:35:39 -04:00
|
|
|
|
|
|
|
function WellDisplayItem(appInfo, isFavorite) {
|
|
|
|
this._init(appInfo, isFavorite);
|
|
|
|
}
|
|
|
|
|
|
|
|
WellDisplayItem.prototype = {
|
|
|
|
_init : function(appInfo, isFavorite) {
|
|
|
|
this.appInfo = appInfo;
|
|
|
|
|
|
|
|
this.isFavorite = isFavorite;
|
|
|
|
|
|
|
|
this.actor = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
|
2009-07-02 00:35:26 -04:00
|
|
|
corner_radius: 2,
|
|
|
|
border: 0,
|
|
|
|
padding: 1,
|
|
|
|
border_color: GenericDisplay.ITEM_DISPLAY_SELECTED_BACKGROUND_COLOR,
|
2009-06-30 16:35:39 -04:00
|
|
|
reactive: true });
|
2009-07-02 00:35:26 -04:00
|
|
|
this.actor.connect('enter-event', Lang.bind(this,
|
|
|
|
function(o, event) {
|
|
|
|
this.actor.border = 1;
|
|
|
|
this.actor.padding = 0;
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
this.actor.connect('leave-event', Lang.bind(this,
|
|
|
|
function(o, event) {
|
|
|
|
this.actor.border = 0;
|
|
|
|
this.actor.padding = 1;
|
|
|
|
return false;
|
|
|
|
}));
|
2009-06-30 16:35:39 -04:00
|
|
|
this.actor._delegate = this;
|
|
|
|
this.actor.connect('button-release-event', Lang.bind(this, function (b, e) {
|
2009-07-04 17:13:13 -04:00
|
|
|
this._handleActivate();
|
2009-06-30 16:35:39 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
let draggable = DND.makeDraggable(this.actor);
|
|
|
|
|
2009-07-02 00:35:26 -04:00
|
|
|
let iconBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
|
|
|
|
x_align: Big.BoxAlignment.CENTER });
|
2009-07-07 16:08:41 -04:00
|
|
|
this._icon = appInfo.create_icon_texture(APP_ICON_SIZE);
|
2009-07-02 00:35:26 -04:00
|
|
|
iconBox.append(this._icon, Big.BoxPackFlags.NONE);
|
2009-06-30 16:35:39 -04:00
|
|
|
|
2009-07-02 00:35:26 -04:00
|
|
|
this.actor.append(iconBox, Big.BoxPackFlags.NONE);
|
2009-06-30 16:35:39 -04:00
|
|
|
|
2009-07-07 16:08:41 -04:00
|
|
|
this._windows = Shell.AppMonitor.get_default().get_windows_for_app(appInfo.get_id());
|
2009-06-30 16:35:39 -04:00
|
|
|
|
2009-07-04 17:28:34 -04:00
|
|
|
let nameBox = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
|
2009-07-02 00:35:26 -04:00
|
|
|
x_align: Big.BoxAlignment.CENTER });
|
2009-07-04 17:28:34 -04:00
|
|
|
this._nameBox = nameBox;
|
|
|
|
|
|
|
|
this._wordWidth = Shell.Global.get().get_max_word_width(this.actor, appInfo.get_name(),
|
|
|
|
"Sans 12px");
|
2009-06-30 16:35:39 -04:00
|
|
|
this._name = new Clutter.Text({ color: GenericDisplay.ITEM_DISPLAY_NAME_COLOR,
|
|
|
|
font_name: "Sans 12px",
|
2009-07-02 00:35:26 -04:00
|
|
|
line_alignment: Pango.Alignment.CENTER,
|
2009-07-27 17:47:28 -04:00
|
|
|
ellipsize: Pango.EllipsizeMode.END,
|
2009-07-07 16:08:41 -04:00
|
|
|
text: appInfo.get_name() });
|
2009-07-04 17:28:34 -04:00
|
|
|
nameBox.append(this._name, Big.BoxPackFlags.NONE);
|
2009-07-04 17:13:13 -04:00
|
|
|
if (this._windows.length > 0) {
|
2009-07-04 17:28:34 -04:00
|
|
|
let glow = new Shell.DrawingArea({});
|
|
|
|
glow.connect('redraw', Lang.bind(this, function (e, tex) {
|
|
|
|
Shell.Global.clutter_cairo_texture_draw_glow(tex,
|
|
|
|
GLOW_COLOR.red / 255,
|
|
|
|
GLOW_COLOR.green / 255,
|
|
|
|
GLOW_COLOR.blue / 255,
|
|
|
|
GLOW_COLOR.alpha / 255);
|
|
|
|
}));
|
|
|
|
this._name.connect('notify::allocation', Lang.bind(this, function (n, alloc) {
|
|
|
|
let x = this._name.x;
|
|
|
|
let y = this._name.y;
|
|
|
|
let width = this._name.width;
|
|
|
|
let height = this._name.height;
|
|
|
|
// If we're smaller than the allocated box width, pad out the glow a bit
|
|
|
|
// to make it more visible
|
|
|
|
if ((width + GLOW_PADDING * 2) < this._nameBox.width) {
|
|
|
|
width += GLOW_PADDING * 2;
|
|
|
|
x -= GLOW_PADDING;
|
|
|
|
}
|
|
|
|
glow.set_size(width, height);
|
|
|
|
glow.set_position(x, y);
|
|
|
|
}));
|
|
|
|
nameBox.add_actor(glow);
|
|
|
|
glow.lower(this._name);
|
2009-06-30 16:35:39 -04:00
|
|
|
}
|
2009-07-04 17:28:34 -04:00
|
|
|
this.actor.append(nameBox, Big.BoxPackFlags.NONE);
|
2009-06-30 16:35:39 -04:00
|
|
|
},
|
|
|
|
|
2009-07-04 17:13:13 -04:00
|
|
|
_handleActivate: function () {
|
|
|
|
if (this._windows.length == 0)
|
|
|
|
this.launch();
|
|
|
|
else {
|
2009-07-22 18:57:33 -04:00
|
|
|
/* Pick the first window and activate it, switching to its workspace
|
|
|
|
* if necessary. In the future, we want to have a menu dropdown here. */
|
2009-07-04 17:13:13 -04:00
|
|
|
let first = this._windows[0];
|
2009-07-22 18:57:33 -04:00
|
|
|
let firstWorkspace = first.get_workspace();
|
|
|
|
let currentWorkspaceIndex = Shell.Global.get().screen.get_active_workspace_index();
|
|
|
|
let currentWorkspace = Shell.Global.get().screen.get_workspace_by_index(currentWorkspaceIndex);
|
|
|
|
let ts = Clutter.get_current_event_time();
|
|
|
|
if (currentWorkspace != firstWorkspace)
|
|
|
|
firstWorkspace.activate_with_focus(first, ts);
|
|
|
|
else
|
|
|
|
first.activate(ts);
|
2009-07-04 17:13:13 -04:00
|
|
|
}
|
|
|
|
this.emit('activated');
|
|
|
|
},
|
|
|
|
|
2009-06-30 16:35:39 -04:00
|
|
|
// Opens an application represented by this display item.
|
|
|
|
launch : function() {
|
|
|
|
this.appInfo.launch();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Draggable interface - FIXME deduplicate with GenericDisplay
|
|
|
|
getDragActor: function(stageX, stageY) {
|
2009-07-07 16:08:41 -04:00
|
|
|
this.dragActor = this.appInfo.create_icon_texture(APP_ICON_SIZE);
|
2009-06-30 16:35:39 -04:00
|
|
|
|
|
|
|
// If the user dragged from the icon itself, then position
|
|
|
|
// the dragActor over the original icon. Otherwise center it
|
|
|
|
// around the pointer
|
|
|
|
let [iconX, iconY] = this._icon.get_transformed_position();
|
|
|
|
let [iconWidth, iconHeight] = this._icon.get_transformed_size();
|
|
|
|
if (stageX > iconX && stageX <= iconX + iconWidth &&
|
|
|
|
stageY > iconY && stageY <= iconY + iconHeight)
|
|
|
|
this.dragActor.set_position(iconX, iconY);
|
|
|
|
else
|
|
|
|
this.dragActor.set_position(stageX - this.dragActor.width / 2, stageY - this.dragActor.height / 2);
|
|
|
|
return this.dragActor;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns the original icon that is being used as a source for the cloned texture
|
|
|
|
// that represents the item as it is being dragged.
|
|
|
|
getDragActorSource: function() {
|
|
|
|
return this._icon;
|
2009-07-04 17:28:34 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
getWordWidth: function() {
|
|
|
|
return this._wordWidth;
|
|
|
|
},
|
|
|
|
|
|
|
|
setWidth: function(width) {
|
|
|
|
this._nameBox.width = width + GLOW_PADDING * 2;
|
2009-06-30 16:35:39 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Signals.addSignalMethods(WellDisplayItem.prototype);
|
|
|
|
|
|
|
|
function WellArea(width, isFavorite) {
|
|
|
|
this._init(width, isFavorite);
|
|
|
|
}
|
|
|
|
|
|
|
|
WellArea.prototype = {
|
|
|
|
_init : function(width, isFavorite) {
|
|
|
|
this.isFavorite = isFavorite;
|
|
|
|
|
2009-07-02 00:35:26 -04:00
|
|
|
this._grid = new Tidy.Grid({ width: width, row_gap: 4 });
|
|
|
|
this._grid._delegate = this;
|
|
|
|
|
|
|
|
this.actor = this._grid;
|
2009-06-30 16:35:39 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
redisplay: function (infos) {
|
|
|
|
let children;
|
|
|
|
|
2009-07-02 00:35:26 -04:00
|
|
|
children = this._grid.get_children();
|
2009-06-30 16:35:39 -04:00
|
|
|
children.forEach(Lang.bind(this, function (v) {
|
|
|
|
v.destroy();
|
|
|
|
}));
|
|
|
|
|
2009-07-04 17:28:34 -04:00
|
|
|
this._maxWordWidth = 0;
|
|
|
|
let displays = []
|
2009-06-30 16:35:39 -04:00
|
|
|
for (let i = 0; i < infos.length; i++) {
|
2009-07-07 16:08:41 -04:00
|
|
|
let app = infos[i];
|
|
|
|
let display = new WellDisplayItem(app, this.isFavorite);
|
2009-07-04 17:28:34 -04:00
|
|
|
displays.push(display);
|
|
|
|
let width = display.getWordWidth();
|
|
|
|
if (width > this._maxWordWidth)
|
|
|
|
this._maxWordWidth = width;
|
2009-06-30 16:35:39 -04:00
|
|
|
display.connect('activated', Lang.bind(this, function (display) {
|
|
|
|
this.emit('activated', display);
|
|
|
|
}));
|
|
|
|
this.actor.add_actor(display.actor);
|
2009-07-07 16:08:41 -04:00
|
|
|
}
|
2009-07-04 17:28:34 -04:00
|
|
|
this._displays = displays;
|
|
|
|
},
|
|
|
|
|
|
|
|
getWordWidth: function() {
|
|
|
|
return this._maxWordWidth;
|
|
|
|
},
|
|
|
|
|
|
|
|
setItemWidth: function(width) {
|
|
|
|
for (let i = 0; i < this._displays.length; i++) {
|
|
|
|
let display = this._displays[i];
|
|
|
|
display.setWidth(width);
|
|
|
|
}
|
2009-06-30 16:35:39 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// Draggable target interface
|
|
|
|
acceptDrop : function(source, actor, x, y, time) {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
2009-07-02 00:35:26 -04:00
|
|
|
let id = null;
|
|
|
|
if (source instanceof WellDisplayItem) {
|
2009-07-07 16:08:41 -04:00
|
|
|
id = source.appInfo.get_id();
|
2009-07-02 00:35:26 -04:00
|
|
|
} else if (source instanceof AppDisplayItem) {
|
|
|
|
id = source.getId();
|
2009-07-02 05:04:33 -04:00
|
|
|
} else if (source instanceof Workspaces.WindowClone) {
|
|
|
|
let appMonitor = Shell.AppMonitor.get_default();
|
2009-07-07 16:08:41 -04:00
|
|
|
let app = appMonitor.get_window_app(source.metaWindow);
|
|
|
|
id = app.get_id();
|
2009-07-02 05:04:33 -04:00
|
|
|
if (id === null)
|
|
|
|
return false;
|
2009-07-02 00:35:26 -04:00
|
|
|
} else {
|
2009-06-30 16:35:39 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let appSystem = Shell.AppSystem.get_default();
|
2009-07-02 00:35:26 -04:00
|
|
|
|
2009-06-30 16:35:39 -04:00
|
|
|
if (source.isFavorite && (!this.isFavorite)) {
|
|
|
|
Mainloop.idle_add(function () {
|
|
|
|
appSystem.remove_favorite(id);
|
|
|
|
});
|
|
|
|
} else if ((!source.isFavorite) && this.isFavorite) {
|
|
|
|
Mainloop.idle_add(function () {
|
|
|
|
appSystem.add_favorite(id);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Signals.addSignalMethods(WellArea.prototype);
|
|
|
|
|
|
|
|
function AppWell(width) {
|
|
|
|
this._init(width);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppWell.prototype = {
|
|
|
|
_init : function(width) {
|
|
|
|
this._menus = [];
|
|
|
|
this._menuDisplays = [];
|
|
|
|
|
|
|
|
this.actor = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
|
2009-07-02 00:35:26 -04:00
|
|
|
spacing: 4,
|
2009-06-30 16:35:39 -04:00
|
|
|
width: width });
|
|
|
|
|
|
|
|
this._appSystem = Shell.AppSystem.get_default();
|
|
|
|
this._appMonitor = Shell.AppMonitor.get_default();
|
|
|
|
|
|
|
|
this._appSystem.connect('installed-changed', Lang.bind(this, function(appSys) {
|
|
|
|
this._redisplay();
|
|
|
|
}));
|
|
|
|
this._appSystem.connect('favorites-changed', Lang.bind(this, function(appSys) {
|
|
|
|
this._redisplay();
|
|
|
|
}));
|
|
|
|
this._appMonitor.connect('changed', Lang.bind(this, function(monitor) {
|
|
|
|
this._redisplay();
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._favoritesArea = new WellArea(width, true);
|
|
|
|
this._favoritesArea.connect('activated', Lang.bind(this, function (a, display) {
|
|
|
|
this.emit('activated');
|
|
|
|
}));
|
|
|
|
this.actor.append(this._favoritesArea.actor, Big.BoxPackFlags.NONE);
|
|
|
|
|
|
|
|
this._runningBox = new Big.Box({ border_color: GenericDisplay.ITEM_DISPLAY_NAME_COLOR,
|
2009-07-02 00:35:26 -04:00
|
|
|
border_top: 1,
|
2009-06-30 16:35:39 -04:00
|
|
|
corner_radius: 3,
|
2009-07-27 17:47:28 -04:00
|
|
|
padding_top: GenericDisplay.PREVIEW_BOX_PADDING });
|
2009-06-30 16:35:39 -04:00
|
|
|
this._runningArea = new WellArea(width, false);
|
|
|
|
this._runningArea.connect('activated', Lang.bind(this, function (a, display) {
|
|
|
|
this.emit('activated');
|
|
|
|
}));
|
|
|
|
this._runningBox.append(this._runningArea.actor, Big.BoxPackFlags.EXPAND);
|
|
|
|
this.actor.append(this._runningBox, Big.BoxPackFlags.NONE);
|
|
|
|
|
|
|
|
this._redisplay();
|
|
|
|
},
|
|
|
|
|
2009-07-08 11:54:15 -04:00
|
|
|
_lookupApps: function(appIds) {
|
|
|
|
let result = [];
|
|
|
|
for (let i = 0; i < appIds.length; i++) {
|
|
|
|
let id = appIds[i];
|
|
|
|
let app = this._appSystem.lookup_app(id);
|
|
|
|
if (!app)
|
|
|
|
continue;
|
|
|
|
result.push(app);
|
|
|
|
}
|
|
|
|
return result;
|
2009-07-07 16:08:41 -04:00
|
|
|
},
|
|
|
|
|
2009-06-30 16:35:39 -04:00
|
|
|
_redisplay: function() {
|
|
|
|
let arrayToObject = function(a) {
|
|
|
|
let o = {};
|
|
|
|
for (let i = 0; i < a.length; i++)
|
|
|
|
o[a[i]] = 1;
|
|
|
|
return o;
|
|
|
|
};
|
2009-07-07 16:08:41 -04:00
|
|
|
let favoriteIds = this._appSystem.get_favorites();
|
|
|
|
let favoriteIdsObject = arrayToObject(favoriteIds);
|
|
|
|
let runningIds = this._appMonitor.get_running_app_ids().filter(function (e) {
|
|
|
|
return !(e in favoriteIdsObject);
|
2009-06-30 16:35:39 -04:00
|
|
|
});
|
2009-07-08 11:54:15 -04:00
|
|
|
let favorites = this._lookupApps(favoriteIds);
|
|
|
|
let running = this._lookupApps(runningIds);
|
2009-06-30 16:35:39 -04:00
|
|
|
this._favoritesArea.redisplay(favorites);
|
|
|
|
this._runningArea.redisplay(running);
|
2009-07-04 17:28:34 -04:00
|
|
|
let maxWidth = this._favoritesArea.getWordWidth();
|
|
|
|
if (this._runningArea.getWordWidth() > maxWidth)
|
|
|
|
maxWidth = this._runningArea.getWordWidth();
|
|
|
|
this._favoritesArea.setItemWidth(maxWidth);
|
|
|
|
this._runningArea.setItemWidth(maxWidth);
|
2009-07-04 09:14:44 -04:00
|
|
|
// If it's empty, we hide it so the top border doesn't show up
|
2009-07-03 22:32:23 -04:00
|
|
|
if (running.length == 0)
|
2009-07-04 09:14:44 -04:00
|
|
|
this._runningBox.hide();
|
2009-07-03 22:32:23 -04:00
|
|
|
else
|
2009-07-04 09:14:44 -04:00
|
|
|
this._runningBox.show();
|
2009-06-30 16:35:39 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Signals.addSignalMethods(AppWell.prototype);
|