[gnome-shell] Add Places
- From: Colin Walters <walters src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-shell] Add Places
- Date: Sun, 9 Aug 2009 13:53:52 +0000 (UTC)
commit e323593f4a4d8278c744ddc8153021cbf50f553a
Author: Colin Walters <walters verbum org>
Date: Thu Aug 6 09:06:33 2009 -0400
Add Places
Implement the Places mockup. This commit adds a link to Home,
Network, Connect to server, and the GTK+ bookmarks.
js/ui/dash.js | 13 +++++
js/ui/places.js | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 160 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/dash.js b/js/ui/dash.js
index 9e01eab..2e2fce3 100644
--- a/js/ui/dash.js
+++ b/js/ui/dash.js
@@ -11,6 +11,7 @@ const Lang = imports.lang;
const AppDisplay = imports.ui.appDisplay;
const DocDisplay = imports.ui.docDisplay;
+const Places = imports.ui.places;
const GenericDisplay = imports.ui.genericDisplay;
const Button = imports.ui.button;
const Main = imports.ui.main;
@@ -443,6 +444,18 @@ Dash.prototype = {
this.dashContainer.append(this._appsSection, Big.BoxPackFlags.NONE);
+ /***** Places *****/
+
+ let placesSection = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
+ spacing: DEFAULT_PADDING });
+ let placesHeader = new SectionHeader("PLACES");
+ placesSection.append(placesHeader.actor, Big.BoxPackFlags.NONE);
+
+ let placesDisplay = new Places.Places();
+ placesSection.append(placesDisplay.actor, Big.BoxPackFlags.EXPAND);
+
+ this.dashContainer.append(placesSection, Big.BoxPackFlags.NONE);
+
/***** Documents *****/
this._docsSection = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
diff --git a/js/ui/places.js b/js/ui/places.js
new file mode 100644
index 0000000..8dcaf72
--- /dev/null
+++ b/js/ui/places.js
@@ -0,0 +1,147 @@
+/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+const Big = imports.gi.Big;
+const Clutter = imports.gi.Clutter;
+const Pango = imports.gi.Pango;
+const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+const Shell = imports.gi.Shell;
+const Lang = imports.lang;
+const Mainloop = imports.mainloop;
+const Signals = imports.signals;
+
+const Main = imports.ui.main;
+const GenericDisplay = imports.ui.genericDisplay;
+
+const PLACES_VSPACING = 8;
+const PLACES_ICON_SIZE = 16;
+
+function PlaceDisplay(name, icon, onActivate) {
+ this._init(name, icon, onActivate);
+}
+
+PlaceDisplay.prototype = {
+ _init : function(name, iconTexture, onActivate) {
+ this.actor = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
+ reactive: true,
+ spacing: 4 });
+ this.actor.connect('button-press-event', Lang.bind(this, function (b, e) {
+ onActivate(this);
+ }));
+ let text = new Clutter.Text({ font_name: "Sans 14px",
+ ellipsize: Pango.EllipsizeMode.END,
+ color: GenericDisplay.ITEM_DISPLAY_NAME_COLOR,
+ text: name });
+ this.actor.append(iconTexture, Big.BoxPackFlags.NONE);
+ this.actor.append(text, Big.BoxPackFlags.EXPAND);
+ }
+};
+Signals.addSignalMethods(PlaceDisplay.prototype);
+
+function Places() {
+ this._init();
+}
+
+Places.prototype = {
+ _init : function() {
+ this.actor = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
+ spacing: 4 });
+ this._menuBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
+ spacing: PLACES_VSPACING });
+ this.actor.append(this._menuBox, Big.BoxPackFlags.EXPAND);
+ this._dirsBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
+ spacing: PLACES_VSPACING });
+ this.actor.append(this._dirsBox, Big.BoxPackFlags.EXPAND);
+
+ let homeFile = Gio.file_new_for_path (GLib.get_home_dir());
+ let homeUri = homeFile.get_uri();
+ let homeLabel = Shell.util_get_label_for_uri (homeUri);
+ let homeIcon = Shell.util_get_icon_for_uri (homeUri);
+ let homeTexture = Shell.TextureCache.get_default().load_gicon(homeIcon, PLACES_ICON_SIZE);
+ let home = new PlaceDisplay(homeLabel, homeTexture, Lang.bind(this, function() {
+ Main.overlay.hide();
+ Gio.app_info_launch_default_for_uri(homeUri, Main.createAppLaunchContext());
+ }));
+
+ this._menuBox.append(home.actor, Big.BoxPackFlags.NONE);
+
+ let networkApp = Shell.AppSystem.get_default().load_from_desktop_file('gnome-network-scheme.desktop');
+ let networkIcon = networkApp.create_icon_texture(PLACES_ICON_SIZE);
+ let network = new PlaceDisplay(networkApp.get_name(), networkIcon, Lang.bind(this, function () {
+ Main.overlay.hide();
+ networkApp.launch();
+ }));
+ this._menuBox.append(network.actor, Big.BoxPackFlags.NONE);
+
+ let connectIcon = Shell.TextureCache.get_default().load_icon_name("applications-internet", PLACES_ICON_SIZE);
+ let connect = new PlaceDisplay('Connect to...', connectIcon, Lang.bind(this, function () {
+ Main.overlay.hide();
+ new Shell.Process({ args: ['nautilus-connect-server'] }).run();
+ }));
+ this._menuBox.append(connect.actor, Big.BoxPackFlags.NONE);
+
+ this._bookmarksPath = GLib.build_filenamev([GLib.get_home_dir(), ".gtk-bookmarks"]);
+ this._bookmarksFile = Gio.file_new_for_path(this._bookmarksPath);
+ let monitor = this._bookmarksFile.monitor_file(Gio.FileMonitorFlags.NONE, null);
+ let timeoutId = 0;
+ monitor.connect('changed', Lang.bind(this, function () {
+ if (timeoutId > 0)
+ return;
+ /* Defensive event compression */
+ timeoutId = Mainloop.timeout_add(100, Lang.bind(this, function () {
+ this._timeoutId = 0;
+ this._reloadBookmarks();
+ return false;
+ }));
+ }));
+
+ this._reloadBookmarks();
+ },
+
+ _reloadBookmarks: function() {
+
+ this._dirsBox.remove_all();
+
+ let [success, bookmarksContent, len] = GLib.file_get_contents(this._bookmarksPath);
+
+ if (!success)
+ return;
+
+ let bookmarks = bookmarksContent.split('\n');
+
+ let bookmarksToLabel = {};
+ let bookmarksOrder = [];
+ for (let i = 0; i < bookmarks.length; i++) {
+ let bookmarkLine = bookmarks[i];
+ let components = bookmarkLine.split(' ');
+ let bookmark = components[0];
+ if (bookmark in bookmarksToLabel)
+ continue;
+ let label = null;
+ if (components.length > 1)
+ label = components[1];
+ bookmarksToLabel[bookmark] = label;
+ bookmarksOrder.push(bookmark);
+ }
+
+ for (let i = 0; i < bookmarksOrder.length; i++) {
+ let bookmark = bookmarksOrder[i];
+ let label = bookmarksToLabel[bookmark];
+ let file = Gio.file_new_for_uri(bookmark);
+ if (!file.query_exists(null))
+ continue;
+ if (label == null)
+ label = Shell.util_get_label_for_uri(bookmark);
+ if (label == null)
+ continue;
+ let icon = Shell.util_get_icon_for_uri(bookmark);
+ let iconTexture = Shell.TextureCache.get_default().load_gicon(icon, PLACES_ICON_SIZE);
+ let item = new PlaceDisplay(label, iconTexture, Lang.bind(this, function() {
+ Main.overlay.hide();
+ Gio.app_info_launch_default_for_uri(bookmark, Main.createAppLaunchContext());
+ }));
+ this._dirsBox.append(item.actor, Big.BoxPackFlags.NONE);
+ }
+ }
+};
+Signals.addSignalMethods(Places.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]