[gnome-shell/app-picker-refresh: 11/15] appDisplay: Add AlphabeticalView.addFolder() method
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/app-picker-refresh: 11/15] appDisplay: Add AlphabeticalView.addFolder() method
- Date: Tue, 19 Feb 2013 17:11:06 +0000 (UTC)
commit 29f1c14ae9b5388f3b3434ab5ea0cf8ce4971722
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Jan 31 15:32:02 2013 +0100
appDisplay: Add AlphabeticalView.addFolder() method
Adjust AlphabeticalView to be able to hold both apps and folders,
and add a addFolder() method to insert a folder.
js/ui/appDisplay.js | 54 +++++++++++++++++++++++++++++++++++---------------
1 files changed, 38 insertions(+), 16 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index ec273d7..d64b183 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -63,8 +63,8 @@ const AlphabeticalView = new Lang.Class({
columnLimit: MAX_COLUMNS });
this._appSystem = Shell.AppSystem.get_default();
- this._appIcons = {}; // desktop file id
- this._allApps = [];
+ this._items = {}; // desktop file id
+ this._allItems = [];
let box = new St.BoxLayout({ vertical: true });
this._stack = new St.Widget({ layout_manager: new Clutter.BinLayout() });
@@ -96,23 +96,43 @@ const AlphabeticalView = new Lang.Class({
removeAll: function() {
this._grid.removeAll();
- this._appIcons = {};
- this._allApps = [];
+ this._items = {};
+ this._allItems = [];
+ },
+
+ _compareItems: function(itemA, itemB) {
+ // bit of a hack: rely on both ShellApp and GMenuTreeDirectory
+ // having a get_name() method
+ let nameA = GLib.utf8_collate_key(itemA.get_name(), -1);
+ let nameB = GLib.utf8_collate_key(itemB.get_name(), -1);
+ return (nameA > nameB) ? 1 : (nameA < nameB ? -1 : 0);
},
addApp: function(app) {
var id = app.get_id();
- if (this._appIcons[id] !== undefined)
+ if (this._items[id] !== undefined)
return;
let appIcon = new AppIcon(app);
- let pos = Util.insertSorted(this._allApps, app, function(a, b) {
- return a.compare_by_name(b);
- });
+ let pos = Util.insertSorted(this._allItems, app, this._compareItems);
this._grid.addItem(appIcon.actor, pos);
appIcon.actor.connect('key-focus-in', Lang.bind(this, this._ensureIconVisible));
- this._appIcons[id] = appIcon;
+ this._items[id] = appIcon;
+ },
+
+ addFolder: function(dir) {
+ let id = dir.get_menu_id();
+ if (this._items[id] !== undefined)
+ return;
+
+ let folderIcon = new FolderIcon(dir, this);
+ let pos = Util.insertSorted(this._allItems, dir, this._compareItems);
+
+ this._grid.addItem(folderIcon.actor, pos);
+ folderIcon.actor.connect('key-focus-in', Lang.bind(this, this._ensureIconVisible));
+
+ this._items[id] = folderIcon;
},
addFolderPopup: function(popup) {
@@ -151,22 +171,24 @@ const AlphabeticalView = new Lang.Class({
},
createFolderIcon: function(size) {
- if (this._allApps.length == 0)
- return new St.Icon();
-
let icon = new St.Widget({ layout_manager: new Clutter.BinLayout(),
style_class: 'app-folder-icon',
width: size, height: size });
let subSize = Math.floor(FOLDER_SUBICON_FRACTION * size);
let aligns = [ Clutter.ActorAlign.START, Clutter.ActorAlign.END ];
- for (let i = 0; i < Math.min(this._allApps.length, 4); i++) {
- let texture = this._allApps[i].create_icon_texture(subSize);
+ let n = 0;
+ for (let i = 0; i < this._allItems.length; i++) {
+ if (!this._allItems[i] instanceof Shell.App)
+ continue;
+ let texture = this._allItems[i].create_icon_texture(subSize);
let bin = new St.Bin({ child: texture,
x_expand: true, y_expand: true });
- bin.set_x_align(aligns[i % 2]);
- bin.set_y_align(aligns[Math.floor(i / 2)]);
+ bin.set_x_align(aligns[n % 2]);
+ bin.set_y_align(aligns[Math.floor(n / 2)]);
icon.add_actor(bin);
+ if (++n == 4)
+ break;
}
return icon;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]