Add GConf schemas for sidebar prefs, and use those prefs from sidebar.js

This commit is contained in:
Dan Winship 2009-06-29 12:13:23 -04:00
parent 203ec385c5
commit 9890887126
2 changed files with 101 additions and 28 deletions

View File

@ -30,6 +30,49 @@
</locale> </locale>
</schema> </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> </schemalist>
</gconfschemafile> </gconfschemafile>

View File

@ -28,13 +28,6 @@ const SIDEBAR_EXPANDED_WIDTH = Widget.EXPANDED_WIDTH + 3 * WidgetBox.WIDGETBOX_P
const HARDCODED_TASKBAR_HEIGHT = 24; const HARDCODED_TASKBAR_HEIGHT = 24;
const MAXIMUM_SIDEBAR_HEIGHT = Shell.Global.get().screen_height - Panel.PANEL_HEIGHT - HARDCODED_TASKBAR_HEIGHT; 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() { function Sidebar() {
this._init(); this._init();
} }
@ -50,7 +43,6 @@ Sidebar.prototype = {
this.actor = new Clutter.Group({ x: -WidgetBox.WIDGETBOX_PADDING, this.actor = new Clutter.Group({ x: -WidgetBox.WIDGETBOX_PADDING,
y: Panel.PANEL_HEIGHT, y: Panel.PANEL_HEIGHT,
width: SIDEBAR_EXPANDED_WIDTH }); width: SIDEBAR_EXPANDED_WIDTH });
Main.chrome.addActor(this.actor);
// The actual widgets go into a Big.Box inside this.actor. The // The actual widgets go into a Big.Box inside this.actor. The
// box's width will vary during the expand/collapse animations, // box's width will vary during the expand/collapse animations,
@ -65,18 +57,33 @@ Sidebar.prototype = {
spacing: SIDEBAR_SPACING }); spacing: SIDEBAR_SPACING });
this.actor.add_actor(this.box); 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._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++) for (let i = 0; i < default_widgets.length; i++)
this.addWidget(default_widgets[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) { addWidget: function(widget) {
let widgetBox; let widgetBox;
try { try {
widgetBox = new WidgetBox.WidgetBox(widget, this.expanded); widgetBox = new WidgetBox.WidgetBox(widget, this._expanded);
} catch(e) { } catch(e) {
logError(e, "Failed to add widget '" + widget + "'"); logError(e, "Failed to add widget '" + widget + "'");
return; return;
@ -86,18 +93,32 @@ Sidebar.prototype = {
this._widgets.push(widgetBox); this._widgets.push(widgetBox);
}, },
show: function() { _visibleChanged: function() {
this._visible = true; let visible = this._gconf.get_boolean("sidebar/visible");
this.actor.show(); if (visible == this._visible)
return;
this._visible = visible;
if (visible)
Main.chrome.addActor(this.actor);
else
Main.chrome.removeActor(this.actor);
}, },
hide: function() { _expandedChanged: function() {
this._visible = false; let expanded = this._gconf.get_boolean("sidebar/expanded");
this.actor.hide(); if (expanded == this._expanded)
return;
this._expanded = expanded;
if (expanded)
this._expand();
else
this._collapse();
}, },
expand: function() { _expand: function() {
this.expanded = true; this._expanded = true;
for (let i = 0; i < this._widgets.length; i++) for (let i = 0; i < this._widgets.length; i++)
this._widgets[i].expand(); this._widgets[i].expand();
@ -108,8 +129,8 @@ Sidebar.prototype = {
} }); } });
}, },
collapse: function() { _collapse: function() {
this.expanded = false; this._expanded = false;
for (let i = 0; i < this._widgets.length; i++) for (let i = 0; i < this._widgets.length; i++)
this._widgets[i].collapse(); this._widgets[i].collapse();
@ -132,24 +153,33 @@ Sidebar.prototype = {
const LEFT_DOUBLE_ARROW = "\u00AB"; const LEFT_DOUBLE_ARROW = "\u00AB";
const RIGHT_DOUBLE_ARROW = "\u00BB"; const RIGHT_DOUBLE_ARROW = "\u00BB";
function ToggleWidget(sidebar) { function ToggleWidget() {
this._init(sidebar); this._init();
} }
ToggleWidget.prototype = { ToggleWidget.prototype = {
__proto__ : Widget.Widget.prototype, __proto__ : Widget.Widget.prototype,
_init : function(sidebar) { _init : function() {
this._sidebar = sidebar; this._gconf = Shell.GConf.get_default();
this.actor = new Clutter.Text({ font_name: "Sans Bold 16px", this.actor = new Clutter.Text({ font_name: "Sans Bold 16px",
text: LEFT_DOUBLE_ARROW, text: LEFT_DOUBLE_ARROW,
reactive: true }); reactive: true });
this.actor.connect('button-release-event', 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", this.collapsedActor = new Clutter.Text({ font_name: "Sans Bold 16px",
text: RIGHT_DOUBLE_ARROW, text: RIGHT_DOUBLE_ARROW,
reactive: true }); reactive: true });
this.collapsedActor.connect('button-release-event', 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);
} }
}; };