[gnome-shell] Add GConf schemas for sidebar prefs, and use those prefs from sidebar.js
- From: Dan Winship <danw src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-shell] Add GConf schemas for sidebar prefs, and use those prefs from sidebar.js
- Date: Mon, 6 Jul 2009 16:06:27 +0000 (UTC)
commit 98908871266b1bc3a723de050ca141968f6ed0b6
Author: Dan Winship <danw gnome org>
Date: Mon Jun 29 12:13:23 2009 -0400
Add GConf schemas for sidebar prefs, and use those prefs from sidebar.js
data/gnome-shell.schemas | 45 ++++++++++++++++++++++++-
js/ui/sidebar.js | 84 +++++++++++++++++++++++++++++++---------------
2 files changed, 101 insertions(+), 28 deletions(-)
---
diff --git a/data/gnome-shell.schemas b/data/gnome-shell.schemas
index 3ab8817..f183cb6 100644
--- a/data/gnome-shell.schemas
+++ b/data/gnome-shell.schemas
@@ -30,6 +30,49 @@
</locale>
</schema>
+ <schema>
+ <key>/schemas/desktop/gnome/shell/sidebar/visible</key>
+ <applyto>/desktop/gnome/shell/sidebar/visible</applyto>
+ <owner>gnome-shell</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Whether or not to display the sidebar</short>
+ <long>
+ Determines whether or not the sidebar is visible.
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
+ <key>/schemas/desktop/gnome/shell/sidebar/expanded</key>
+ <applyto>/desktop/gnome/shell/sidebar/expanded</applyto>
+ <owner>gnome-shell</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Whether the sidebar should be in the expanded (wide) mode</short>
+ <long>
+ Controls the expanded/collapsed state of the sidebar.
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
+ <key>/schemas/desktop/gnome/shell/sidebar/widgets</key>
+ <applyto>/desktop/gnome/shell/sidebar/widgets</applyto>
+ <owner>gnome-shell</owner>
+ <type>list</type>
+ <list_type>string</list_type>
+ <default>[imports.ui.widget.ClockWidget,imports.ui.widget.AppsWidget,imports.ui.widget.DocsWidget]</default>
+ <locale name="C">
+ <short>The widgets to display in the sidebar</short>
+ <long>
+ The widgets to display in the sidebar, in order from top to bottom. Each widget "name" is actually a JavaScript expression referring to a widget constructor object.
+ </long>
+ </locale>
+ </schema>
+
</schemalist>
-</gconfschemafile>
\ No newline at end of file
+</gconfschemafile>
diff --git a/js/ui/sidebar.js b/js/ui/sidebar.js
index 6ec5276..0c5c455 100644
--- a/js/ui/sidebar.js
+++ b/js/ui/sidebar.js
@@ -28,13 +28,6 @@ const SIDEBAR_EXPANDED_WIDTH = Widget.EXPANDED_WIDTH + 3 * WidgetBox.WIDGETBOX_P
const HARDCODED_TASKBAR_HEIGHT = 24;
const MAXIMUM_SIDEBAR_HEIGHT = Shell.Global.get().screen_height - Panel.PANEL_HEIGHT - HARDCODED_TASKBAR_HEIGHT;
-// FIXME, needs to be configurable, obviously
-const default_widgets = [
- "imports.ui.widget.ClockWidget",
- "imports.ui.widget.AppsWidget",
- "imports.ui.widget.DocsWidget"
-];
-
function Sidebar() {
this._init();
}
@@ -50,7 +43,6 @@ Sidebar.prototype = {
this.actor = new Clutter.Group({ x: -WidgetBox.WIDGETBOX_PADDING,
y: Panel.PANEL_HEIGHT,
width: SIDEBAR_EXPANDED_WIDTH });
- Main.chrome.addActor(this.actor);
// The actual widgets go into a Big.Box inside this.actor. The
// box's width will vary during the expand/collapse animations,
@@ -65,18 +57,33 @@ Sidebar.prototype = {
spacing: SIDEBAR_SPACING });
this.actor.add_actor(this.box);
- this._visible = this.expanded = true;
+ this._gconf = Shell.GConf.get_default();
+
+ this._expanded = this._gconf.get_boolean ("sidebar/expanded");
+ if (!this._expanded)
+ this.actor.width = SIDEBAR_COLLAPSED_WIDTH;
+
+ this._visible = this._gconf.get_boolean ("sidebar/visible");
+ if (this._visible)
+ Main.chrome.addActor(this.actor);
this._widgets = [];
- this.addWidget(new ToggleWidget(this));
+ this.addWidget(new ToggleWidget());
+
+ let default_widgets = this._gconf.get_string_list("sidebar/widgets");
for (let i = 0; i < default_widgets.length; i++)
this.addWidget(default_widgets[i]);
+
+ this._gconf.connect('changed::sidebar/expanded',
+ Lang.bind(this, this._expandedChanged));
+ this._gconf.connect('changed::sidebar/visible',
+ Lang.bind(this, this._visibleChanged));
},
addWidget: function(widget) {
let widgetBox;
try {
- widgetBox = new WidgetBox.WidgetBox(widget, this.expanded);
+ widgetBox = new WidgetBox.WidgetBox(widget, this._expanded);
} catch(e) {
logError(e, "Failed to add widget '" + widget + "'");
return;
@@ -86,18 +93,32 @@ Sidebar.prototype = {
this._widgets.push(widgetBox);
},
- show: function() {
- this._visible = true;
- this.actor.show();
+ _visibleChanged: function() {
+ let visible = this._gconf.get_boolean("sidebar/visible");
+ if (visible == this._visible)
+ return;
+
+ this._visible = visible;
+ if (visible)
+ Main.chrome.addActor(this.actor);
+ else
+ Main.chrome.removeActor(this.actor);
},
- hide: function() {
- this._visible = false;
- this.actor.hide();
+ _expandedChanged: function() {
+ let expanded = this._gconf.get_boolean("sidebar/expanded");
+ if (expanded == this._expanded)
+ return;
+
+ this._expanded = expanded;
+ if (expanded)
+ this._expand();
+ else
+ this._collapse();
},
- expand: function() {
- this.expanded = true;
+ _expand: function() {
+ this._expanded = true;
for (let i = 0; i < this._widgets.length; i++)
this._widgets[i].expand();
@@ -108,8 +129,8 @@ Sidebar.prototype = {
} });
},
- collapse: function() {
- this.expanded = false;
+ _collapse: function() {
+ this._expanded = false;
for (let i = 0; i < this._widgets.length; i++)
this._widgets[i].collapse();
@@ -132,24 +153,33 @@ Sidebar.prototype = {
const LEFT_DOUBLE_ARROW = "\u00AB";
const RIGHT_DOUBLE_ARROW = "\u00BB";
-function ToggleWidget(sidebar) {
- this._init(sidebar);
+function ToggleWidget() {
+ this._init();
}
ToggleWidget.prototype = {
__proto__ : Widget.Widget.prototype,
- _init : function(sidebar) {
- this._sidebar = sidebar;
+ _init : function() {
+ this._gconf = Shell.GConf.get_default();
+
this.actor = new Clutter.Text({ font_name: "Sans Bold 16px",
text: LEFT_DOUBLE_ARROW,
reactive: true });
this.actor.connect('button-release-event',
- Lang.bind(this._sidebar, this._sidebar.collapse));
+ Lang.bind(this, this._collapse));
this.collapsedActor = new Clutter.Text({ font_name: "Sans Bold 16px",
text: RIGHT_DOUBLE_ARROW,
reactive: true });
this.collapsedActor.connect('button-release-event',
- Lang.bind(this._sidebar, this._sidebar.expand));
+ Lang.bind(this, this._expand));
+ },
+
+ _collapse : function () {
+ this._gconf.set_boolean ("sidebar/expanded", false);
+ },
+
+ _expand : function () {
+ this._gconf.set_boolean ("sidebar/expanded", true);
}
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]