[gnome-documents] sidebar: move the source model to Sources
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] sidebar: move the source model to Sources
- Date: Thu, 25 Aug 2011 17:18:38 +0000 (UTC)
commit bddac88964d361fd3115e424d1fc3b165799c941
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Thu Aug 25 13:17:26 2011 -0400
sidebar: move the source model to Sources
And turn the sidebar into a more manageable GtkNotebook widget while
we're at it.
src/sidebar.js | 163 +++++++++++--------------------------------------------
src/sources.js | 123 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 156 insertions(+), 130 deletions(-)
---
diff --git a/src/sidebar.js b/src/sidebar.js
index 105196d..a7d1183 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -22,127 +22,46 @@
const Gd = imports.gi.Gd;
const Goa = imports.gi.Goa;
const Gtk = imports.gi.Gtk;
-const Pango = imports.gi.Pango;
const _ = imports.gettext.gettext;
const Lang = imports.lang;
const Signals = imports.signals;
const Global = imports.global;
+const Sources = imports.sources;
const _SIDEBAR_WIDTH_REQUEST = 240;
-const SidebarModelColumns = {
- ID: 0,
- NAME: 1,
- HEADING: 2
-};
-
-function SidebarModel() {
- this._init();
-}
-
-SidebarModel.prototype = {
- _init: function() {
- this.model = Gd.create_sidebar_store();
-
- this._sourceManager = Global.sourceManager;
- this.model.clear();
-
- let iter = this.model.append();
- Gd.sidebar_store_set(this.model, iter,
- '', _("Sources"), true);
-
- let sources = this._sourceManager.sources;
- sources.forEach(Lang.bind(this,
- function(source) {
- iter = this.model.append();
- Gd.sidebar_store_set(this.model, iter,
- source.id, source.name, false);
- }));
- }
-};
-
function SidebarView() {
this._init();
-}
+};
SidebarView.prototype = {
_init: function() {
- this._model = new SidebarModel();
- this._sourceManager = Global.sourceManager;
+ this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
+ border_width: 6,
+ width_request: _SIDEBAR_WIDTH_REQUEST,
+ column_homogeneous: true });
- this._treeView = new Gtk.TreeView({ headers_visible: false,
- no_show_all: true });
- Gd.gtk_tree_view_set_activate_on_single_click(this._treeView, true);
- this.widget = this._treeView;
- this._treeView.set_model(this._model.model);
-
- let selection = this._treeView.get_selection();
- selection.set_mode(Gtk.SelectionMode.SINGLE);
-
- this._treeView.connect('row-activated', Lang.bind(this,
- function(view, path) {
- let iter = this._model.model.get_iter(path)[1];
- let id = this._model.model.get_value(iter, SidebarModelColumns.ID);
- let name = this._model.model.get_value(iter, SidebarModelColumns.NAME);
-
- this._sourceManager.setActiveSourceId(id);
- }));
-
- let col = new Gtk.TreeViewColumn();
- this._treeView.append_column(col);
-
- // headings
- this._rendererHeading = new Gtk.CellRendererText({ weight: Pango.Weight.BOLD,
- weight_set: true });
- col.pack_start(this._rendererHeading, false);
- col.add_attribute(this._rendererHeading,
- 'text', SidebarModelColumns.NAME);
- col.set_cell_data_func(this._rendererHeading,
- Lang.bind(this, this._visibilityForHeading, true));
-
- // radio selection
- this._rendererRadio = new Gtk.CellRendererToggle({ radio: true,
- mode: Gtk.CellRendererMode.INERT });
- col.pack_start(this._rendererRadio, false);
- col.set_cell_data_func(this._rendererRadio,
- Lang.bind(this, this._visibilityForHeading, false,
- Lang.bind(this,
- function(col, cell, model, iter) {
- let id = model.get_value(iter, SidebarModelColumns.ID);
- if (id == this._sourceManager.getActiveSourceId())
- cell.active = true;
- else
- cell.active = false;
- })));
-
- // source name
- this._rendererText = new Gtk.CellRendererText();
- col.pack_start(this._rendererText, true);
- col.add_attribute(this._rendererText,
- 'text', SidebarModelColumns.NAME);
- col.set_cell_data_func(this._rendererText,
- Lang.bind(this, this._visibilityForHeading, false));
-
- // arrow
- this._rendererArrow = new Gtk.CellRendererPixbuf({ icon_name: 'go-next-symbolic',
- follow_state: true });
- col.pack_start(this._rendererArrow, false);
- col.set_cell_data_func(this._rendererArrow,
- Lang.bind(this, this._visibilityForHeading, false));
- },
+ let buttonContent = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
+ row_spacing: 6 });
+ // FIXME: setting yalign here seems wrong, but why are those not aligned
+ // otherwise?
+ buttonContent.add(new Gtk.Image({ icon_size: Gtk.IconSize.MENU,
+ icon_name: 'go-previous-symbolic',
+ yalign: 0.75 }));
+ this._buttonLabel = new Gtk.Label({ label: _("Sources") });
+ buttonContent.add(this._buttonLabel);
- _visibilityForHeading: function(col, cell, model, iter, visible, additionalFunc) {
- let heading = model.get_value(iter, SidebarModelColumns.HEADING);
+ this._sourcesButton = new Gtk.Button({ child: buttonContent });
+ this.widget.add(this._sourcesButton);
+ this._sourcesButton.connect('clicked', Lang.bind(this, this._onSourcesButtonClicked));
- if ((visible && heading) || (!visible && !heading))
- cell.visible = true;
- else
- cell.visible = false;
+ this.widget.show_all();
+ },
- if (additionalFunc)
- additionalFunc(col, cell, model, iter);
+ _onSourcesButtonClicked: function() {
+ this.emit('sources-button-clicked');
}
};
Signals.addSignalMethods(SidebarView.prototype);
@@ -157,42 +76,26 @@ Sidebar.prototype = {
this._sourceManager.connect('active-source-changed',
Lang.bind(this, this._onSourceFilterChanged));
- this.widget = new Gtk.ScrolledWindow({ hscrollbar_policy: Gtk.PolicyType.NEVER });
+ this.widget = new Gtk.Notebook({ show_tabs: false });
this.widget.get_style_context().add_class(Gtk.STYLE_CLASS_SIDEBAR);
- this._grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
- border_width: 6,
- width_request: _SIDEBAR_WIDTH_REQUEST,
- column_homogeneous: true });
- this.widget.add_with_viewport(this._grid);
-
- let buttonContent = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
- row_spacing: 6 });
- // FIXME: setting yalign here seems wrong, but why are those not aligned
- // otherwise?
- buttonContent.add(new Gtk.Image({ icon_size: Gtk.IconSize.MENU,
- icon_name: 'go-previous-symbolic',
- yalign: 0.75 }));
- this._buttonLabel = new Gtk.Label({ label: _("Sources") });
- buttonContent.add(this._buttonLabel);
-
- this._sourcesButton = new Gtk.Button({ child: buttonContent });
- this._grid.add(this._sourcesButton);
- this._sourcesButton.connect('clicked', Lang.bind(this, this._onSourcesButtonClicked));
+ this._sourceView = new Sources.SourceView();
+ this.widget.insert_page(this._sourceView.widget, null, 0);
this._sidebarView = new SidebarView();
- this._grid.add(this._sidebarView.widget);
+ this.widget.insert_page(this._sidebarView.widget, null, 1);
+ this._sidebarView.connect('sources-button-clicked',
+ Lang.bind(this, this._onSourcesButtonClicked));
+ this.widget.set_current_page(1);
this.widget.show_all();
},
- _onSourcesButtonClicked: function() {
- this._sourcesButton.hide();
- this._sidebarView.widget.show();
+ _onSourceFilterChanged: function(sourcePage, id, name) {
+ this.widget.set_current_page(1);
},
- _onSourceFilterChanged: function(sourcePage, id, name) {
- this._sidebarView.widget.hide();
- this._sourcesButton.show();
+ _onSourcesButtonClicked: function() {
+ this.widget.set_current_page(0);
}
};
diff --git a/src/sources.js b/src/sources.js
index 8e29e39..552cccd 100644
--- a/src/sources.js
+++ b/src/sources.js
@@ -23,7 +23,10 @@ const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Signals = imports.signals;
+const Gd = imports.gi.Gd;
const Goa = imports.gi.Goa;
+const Gtk = imports.gi.Gtk;
+const Pango = imports.gi.Pango;
const _ = imports.gettext.gettext;
const Global = imports.global;
@@ -140,3 +143,123 @@ SourceManager.prototype = {
}
};
Signals.addSignalMethods(SourceManager.prototype);
+
+// GTK+ implementations
+
+const SourceModelColumns = {
+ ID: 0,
+ NAME: 1,
+ HEADING: 2
+};
+
+function SourceModel() {
+ this._init();
+}
+
+SourceModel.prototype = {
+ _init: function() {
+ this.model = Gd.create_sidebar_store();
+
+ this._sourceManager = Global.sourceManager;
+ this.model.clear();
+
+ let iter = this.model.append();
+ Gd.sidebar_store_set(this.model, iter,
+ '', _("Sources"), true);
+
+ let sources = this._sourceManager.sources;
+ sources.forEach(Lang.bind(this,
+ function(source) {
+ iter = this.model.append();
+ Gd.sidebar_store_set(this.model, iter,
+ source.id, source.name, false);
+ }));
+ }
+};
+
+function SourceView() {
+ this._init();
+}
+
+SourceView.prototype = {
+ _init: function() {
+ this._model = new SourceModel();
+ this._sourceManager = Global.sourceManager;
+
+ this._treeView = new Gtk.TreeView({ headers_visible: false });
+ Gd.gtk_tree_view_set_activate_on_single_click(this._treeView, true);
+ this._treeView.set_model(this._model.model);
+
+ this.widget = new Gtk.ScrolledWindow({ hscrollbar_policy: Gtk.PolicyType.NEVER });
+ this.widget.add(this._treeView);
+
+ let selection = this._treeView.get_selection();
+ selection.set_mode(Gtk.SelectionMode.SINGLE);
+
+ this._treeView.connect('row-activated', Lang.bind(this,
+ function(view, path) {
+ let iter = this._model.model.get_iter(path)[1];
+ let id = this._model.model.get_value(iter, SourceModelColumns.ID);
+ let name = this._model.model.get_value(iter, SourceModelColumns.NAME);
+
+ this._sourceManager.setActiveSourceId(id);
+ }));
+
+ let col = new Gtk.TreeViewColumn();
+ this._treeView.append_column(col);
+
+ // headings
+ this._rendererHeading = new Gtk.CellRendererText({ weight: Pango.Weight.BOLD,
+ weight_set: true });
+ col.pack_start(this._rendererHeading, false);
+ col.add_attribute(this._rendererHeading,
+ 'text', SourceModelColumns.NAME);
+ col.set_cell_data_func(this._rendererHeading,
+ Lang.bind(this, this._visibilityForHeading, true));
+
+ // radio selection
+ this._rendererRadio = new Gtk.CellRendererToggle({ radio: true,
+ mode: Gtk.CellRendererMode.INERT });
+ col.pack_start(this._rendererRadio, false);
+ col.set_cell_data_func(this._rendererRadio,
+ Lang.bind(this, this._visibilityForHeading, false,
+ Lang.bind(this,
+ function(col, cell, model, iter) {
+ let id = model.get_value(iter, SourceModelColumns.ID);
+ if (id == this._sourceManager.getActiveSourceId())
+ cell.active = true;
+ else
+ cell.active = false;
+ })));
+
+ // source name
+ this._rendererText = new Gtk.CellRendererText();
+ col.pack_start(this._rendererText, true);
+ col.add_attribute(this._rendererText,
+ 'text', SourceModelColumns.NAME);
+ col.set_cell_data_func(this._rendererText,
+ Lang.bind(this, this._visibilityForHeading, false));
+
+ // arrow
+ this._rendererArrow = new Gtk.CellRendererPixbuf({ icon_name: 'go-next-symbolic',
+ follow_state: true });
+ col.pack_start(this._rendererArrow, false);
+ col.set_cell_data_func(this._rendererArrow,
+ Lang.bind(this, this._visibilityForHeading, false));
+
+ this.widget.show_all();
+ },
+
+ _visibilityForHeading: function(col, cell, model, iter, visible, additionalFunc) {
+ let heading = model.get_value(iter, SourceModelColumns.HEADING);
+
+ if ((visible && heading) || (!visible && !heading))
+ cell.visible = true;
+ else
+ cell.visible = false;
+
+ if (additionalFunc)
+ additionalFunc(col, cell, model, iter);
+ }
+};
+Signals.addSignalMethods(SourceView.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]