2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-10-15 23:28:29 +00:00
|
|
|
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
|
2010-02-08 22:50:50 +00:00
|
|
|
const Main = imports.ui.main;
|
2009-10-15 23:28:29 +00:00
|
|
|
|
2014-07-22 12:16:48 +00:00
|
|
|
const RENAMED_DESKTOP_IDS = {
|
|
|
|
'baobab.desktop': 'org.gnome.baobab.desktop',
|
|
|
|
'cheese.desktop': 'org.gnome.Cheese.desktop',
|
|
|
|
'dconf-editor.desktop': 'ca.desrt.dconf-editor.desktop',
|
2016-12-09 18:39:12 +00:00
|
|
|
'epiphany.desktop': 'org.gnome.Epiphany.desktop',
|
2014-07-22 12:16:48 +00:00
|
|
|
'file-roller.desktop': 'org.gnome.FileRoller.desktop',
|
2016-12-13 00:47:27 +00:00
|
|
|
'gcalctool.desktop': 'org.gnome.Calculator.desktop',
|
2016-12-02 09:52:22 +00:00
|
|
|
'geary.desktop': 'org.gnome.Geary.desktop',
|
2014-07-22 12:16:48 +00:00
|
|
|
'gedit.desktop': 'org.gnome.gedit.desktop',
|
|
|
|
'glchess.desktop': 'gnome-chess.desktop',
|
2014-09-15 22:03:27 +00:00
|
|
|
'glines.desktop': 'five-or-more.desktop',
|
|
|
|
'gnect.desktop': 'four-in-a-row.desktop',
|
2016-02-13 02:02:57 +00:00
|
|
|
'gnibbles.desktop': 'org.gnome.Nibbles.desktop',
|
2014-09-15 22:03:27 +00:00
|
|
|
'gnobots2.desktop': 'gnome-robots.desktop',
|
2014-09-16 14:51:03 +00:00
|
|
|
'gnome-boxes.desktop': 'org.gnome.Boxes.desktop',
|
2016-12-13 00:47:27 +00:00
|
|
|
'gnome-calculator.desktop': 'org.gnome.Calculator.desktop',
|
2017-02-06 07:40:43 +00:00
|
|
|
'gnome-clocks.desktop': 'org.gnome.clocks.desktop',
|
2014-08-29 11:21:58 +00:00
|
|
|
'gnome-contacts.desktop': 'org.gnome.Contacts.desktop',
|
2014-07-22 12:16:48 +00:00
|
|
|
'gnome-documents.desktop': 'org.gnome.Documents.desktop',
|
|
|
|
'gnome-font-viewer.desktop': 'org.gnome.font-viewer.desktop',
|
2016-02-13 02:02:57 +00:00
|
|
|
'gnome-nibbles.desktop': 'org.gnome.Nibbles.desktop',
|
2014-07-22 12:16:48 +00:00
|
|
|
'gnome-photos.desktop': 'org.gnome.Photos.desktop',
|
|
|
|
'gnome-screenshot.desktop': 'org.gnome.Screenshot.desktop',
|
|
|
|
'gnome-software.desktop': 'org.gnome.Software.desktop',
|
2015-03-04 17:31:05 +00:00
|
|
|
'gnome-terminal.desktop': 'org.gnome.Terminal.desktop',
|
2014-07-22 12:16:48 +00:00
|
|
|
'gnome-weather.desktop': 'org.gnome.Weather.Application.desktop',
|
|
|
|
'gnomine.desktop': 'gnome-mines.desktop',
|
2014-09-15 22:03:27 +00:00
|
|
|
'gnotravex.desktop': 'gnome-tetravex.desktop',
|
|
|
|
'gnotski.desktop': 'gnome-klotski.desktop',
|
|
|
|
'gtali.desktop': 'tali.desktop',
|
2014-07-22 12:16:48 +00:00
|
|
|
'nautilus.desktop': 'org.gnome.Nautilus.desktop',
|
|
|
|
'polari.desktop': 'org.gnome.Polari.desktop',
|
2014-08-29 11:21:58 +00:00
|
|
|
'totem.desktop': 'org.gnome.Totem.desktop',
|
2014-07-22 12:16:48 +00:00
|
|
|
};
|
|
|
|
|
2011-11-20 17:56:27 +00:00
|
|
|
const AppFavorites = new Lang.Class({
|
|
|
|
Name: 'AppFavorites',
|
2009-10-15 23:28:29 +00:00
|
|
|
|
2010-05-05 21:05:42 +00:00
|
|
|
FAVORITE_APPS_KEY: 'favorite-apps',
|
2009-10-15 23:28:29 +00:00
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this._favorites = {};
|
2010-05-05 21:05:42 +00:00
|
|
|
global.settings.connect('changed::' + this.FAVORITE_APPS_KEY, Lang.bind(this, this._onFavsChanged));
|
2013-08-27 12:00:26 +00:00
|
|
|
this.reload();
|
2009-10-15 23:28:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onFavsChanged: function() {
|
2013-08-27 12:00:26 +00:00
|
|
|
this.reload();
|
2009-10-15 23:28:29 +00:00
|
|
|
this.emit('changed');
|
|
|
|
},
|
|
|
|
|
2013-08-27 12:00:26 +00:00
|
|
|
reload: function() {
|
2010-05-05 21:05:42 +00:00
|
|
|
let ids = global.settings.get_strv(this.FAVORITE_APPS_KEY);
|
2014-07-22 12:16:48 +00:00
|
|
|
|
|
|
|
// Map old desktop file names to the current ones
|
|
|
|
let updated = false;
|
|
|
|
ids = ids.map(function (id) {
|
|
|
|
let newId = RENAMED_DESKTOP_IDS[id];
|
|
|
|
if (newId !== undefined) {
|
|
|
|
updated = true;
|
|
|
|
return newId;
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
});
|
|
|
|
// ... and write back the updated desktop file names
|
|
|
|
if (updated)
|
|
|
|
global.settings.set_strv(this.FAVORITE_APPS_KEY, ids);
|
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
let appSys = Shell.AppSystem.get_default();
|
|
|
|
let apps = ids.map(function (id) {
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
return appSys.lookup_app(id);
|
2009-10-15 23:28:29 +00:00
|
|
|
}).filter(function (app) {
|
|
|
|
return app != null;
|
|
|
|
});
|
|
|
|
this._favorites = {};
|
|
|
|
for (let i = 0; i < apps.length; i++) {
|
|
|
|
let app = apps[i];
|
|
|
|
this._favorites[app.get_id()] = app;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_getIds: function() {
|
|
|
|
let ret = [];
|
|
|
|
for (let id in this._favorites)
|
|
|
|
ret.push(id);
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFavoriteMap: function() {
|
|
|
|
return this._favorites;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFavorites: function() {
|
|
|
|
let ret = [];
|
|
|
|
for (let id in this._favorites)
|
|
|
|
ret.push(this._favorites[id]);
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
isFavorite: function(appId) {
|
|
|
|
return appId in this._favorites;
|
|
|
|
},
|
|
|
|
|
2010-11-08 01:51:02 +00:00
|
|
|
_addFavorite: function(appId, pos) {
|
2009-10-15 23:28:29 +00:00
|
|
|
if (appId in this._favorites)
|
2010-02-08 22:50:50 +00:00
|
|
|
return false;
|
|
|
|
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
let app = Shell.AppSystem.get_default().lookup_app(appId);
|
2010-02-08 22:50:50 +00:00
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
if (!app)
|
2010-02-08 22:50:50 +00:00
|
|
|
return false;
|
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
let ids = this._getIds();
|
2010-11-08 01:51:02 +00:00
|
|
|
if (pos == -1)
|
|
|
|
ids.push(appId);
|
|
|
|
else
|
|
|
|
ids.splice(pos, 0, appId);
|
2010-05-05 21:05:42 +00:00
|
|
|
global.settings.set_strv(this.FAVORITE_APPS_KEY, ids);
|
2009-10-15 23:28:29 +00:00
|
|
|
this._favorites[appId] = app;
|
2010-02-08 22:50:50 +00:00
|
|
|
return true;
|
2009-10-15 23:28:29 +00:00
|
|
|
},
|
|
|
|
|
2010-11-08 01:51:02 +00:00
|
|
|
addFavoriteAtPos: function(appId, pos) {
|
|
|
|
if (!this._addFavorite(appId, pos))
|
2009-10-15 23:28:29 +00:00
|
|
|
return;
|
2010-02-08 22:50:50 +00:00
|
|
|
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
let app = Shell.AppSystem.get_default().lookup_app(appId);
|
2010-02-08 22:50:50 +00:00
|
|
|
|
2012-11-02 17:06:40 +00:00
|
|
|
Main.overview.setMessage(_("%s has been added to your favorites.").format(app.get_name()),
|
|
|
|
{ forFeedback: true,
|
|
|
|
undoCallback: Lang.bind(this, function () {
|
|
|
|
this._removeFavorite(appId);
|
|
|
|
})
|
|
|
|
});
|
2010-02-08 22:50:50 +00:00
|
|
|
},
|
|
|
|
|
2010-11-08 01:51:02 +00:00
|
|
|
addFavorite: function(appId) {
|
|
|
|
this.addFavoriteAtPos(appId, -1);
|
|
|
|
},
|
|
|
|
|
|
|
|
moveFavoriteToPos: function(appId, pos) {
|
|
|
|
this._removeFavorite(appId);
|
|
|
|
this._addFavorite(appId, pos);
|
|
|
|
},
|
|
|
|
|
2010-02-08 22:50:50 +00:00
|
|
|
_removeFavorite: function(appId) {
|
|
|
|
if (!appId in this._favorites)
|
|
|
|
return false;
|
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
let ids = this._getIds().filter(function (id) { return id != appId; });
|
2010-05-05 21:05:42 +00:00
|
|
|
global.settings.set_strv(this.FAVORITE_APPS_KEY, ids);
|
2010-02-08 22:50:50 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeFavorite: function(appId) {
|
2010-11-08 01:51:02 +00:00
|
|
|
let ids = this._getIds();
|
|
|
|
let pos = ids.indexOf(appId);
|
|
|
|
|
2010-07-14 01:32:41 +00:00
|
|
|
let app = this._favorites[appId];
|
2010-02-08 22:50:50 +00:00
|
|
|
if (!this._removeFavorite(appId))
|
|
|
|
return;
|
|
|
|
|
2011-08-28 14:07:44 +00:00
|
|
|
Main.overview.setMessage(_("%s has been removed from your favorites.").format(app.get_name()),
|
2012-11-02 17:06:40 +00:00
|
|
|
{ forFeedback: true,
|
|
|
|
undoCallback: Lang.bind(this, function () {
|
|
|
|
this._addFavorite(appId, pos);
|
|
|
|
})
|
|
|
|
});
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2009-10-15 23:28:29 +00:00
|
|
|
Signals.addSignalMethods(AppFavorites.prototype);
|
|
|
|
|
|
|
|
var appFavoritesInstance = null;
|
|
|
|
function getAppFavorites() {
|
|
|
|
if (appFavoritesInstance == null)
|
|
|
|
appFavoritesInstance = new AppFavorites();
|
|
|
|
return appFavoritesInstance;
|
|
|
|
}
|