[gnome-latex] SidePanel: use GtkStack, GtkStackSwitcher and tepl_stack_*() functions
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex] SidePanel: use GtkStack, GtkStackSwitcher and tepl_stack_*() functions
- Date: Mon, 20 Apr 2020 17:28:15 +0000 (UTC)
commit ec4d3a8058f8fe10efa3b8dfd7c9108c5a8a6f45
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Apr 20 16:03:23 2020 +0200
SidePanel: use GtkStack, GtkStackSwitcher and tepl_stack_*() functions
And GtkActionBar. Good combination.
data/org.gnome.gnome-latex.gschema.xml.in | 6 +-
src/main_window.vala | 7 ++-
src/side_panel.vala | 93 +++++--------------------------
3 files changed, 22 insertions(+), 84 deletions(-)
---
diff --git a/data/org.gnome.gnome-latex.gschema.xml.in b/data/org.gnome.gnome-latex.gschema.xml.in
index 15cee4c..ddfbe0c 100644
--- a/data/org.gnome.gnome-latex.gschema.xml.in
+++ b/data/org.gnome.gnome-latex.gschema.xml.in
@@ -121,10 +121,10 @@
<summary>Bottom panel is Visible</summary>
<description>Whether the bottom panel containing the build view should be visible.</description>
</key>
- <key name="side-panel-component" type="i">
- <default>0</default>
+ <key name="side-panel-component" type="s">
+ <default>''</default>
<summary>Side panel component</summary>
- <description>Side panel’s active component. 0: Symbols. 1: File browser. 2: Structure.</description>
+ <description>Side panel’s active component.</description>
</key>
<key name="show-build-warnings" type="b">
<default>true</default>
diff --git a/src/main_window.vala b/src/main_window.vala
index e0e31ac..e46526e 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -443,16 +443,17 @@ public class MainWindow : ApplicationWindow
// Symbols
SymbolsView symbols = new SymbolsView (this);
- side_panel.add_component (_("Symbols"), "symbol_greek", symbols);
+ side_panel.add_component (symbols, "symbols", _("Symbols"), "symbol_greek");
// File browser
FileBrowser file_browser = new FileBrowser (this);
- side_panel.add_component (_("File Browser"), "document-open", file_browser);
+ side_panel.add_component (file_browser, "file-browser", _("File Browser"),
+ "document-open");
// Structure
Structure structure = new Structure (this);
_main_window_structure.set_structure (structure);
- side_panel.add_component (_("Structure"), Stock.INDEX, structure); // FIXME don't use Stock
+ side_panel.add_component (structure, "structure", _("Structure"), Stock.INDEX); // FIXME don't use
Stock
side_panel.restore_state ();
diff --git a/src/side_panel.vala b/src/side_panel.vala
index a0b7687..632c500 100644
--- a/src/side_panel.vala
+++ b/src/side_panel.vala
@@ -21,108 +21,45 @@ using Gtk;
public class SidePanel : Grid
{
- private enum SidePanelColumn
- {
- PIXBUF,
- NAME,
- N_COLUMNS
- }
-
- private GLib.Settings _settings;
- private Gee.ArrayList<Grid?> _components;
- private ComboBox _combo_box;
- private Gtk.ListStore _list_store;
- private int _current_component = -1;
+ private Gtk.Stack _stack;
public SidePanel ()
{
- _settings = new GLib.Settings ("org.gnome.gnome-latex.preferences.ui");
- _components = new Gee.ArrayList<Grid?> ();
+ _stack = new Gtk.Stack ();
margin_start = 6;
- margin_top = 3;
- column_spacing = 3;
- row_spacing = 3;
-
- init_combo_box ();
- Button close_button = get_close_button ();
-
- attach (_combo_box, 0, 0, 1, 1);
- attach (close_button, 1, 0, 1, 1);
- show_all ();
- }
-
- private void init_combo_box ()
- {
- _list_store = new Gtk.ListStore (SidePanelColumn.N_COLUMNS,
- typeof (string), // pixbuf (icon-name)
- typeof (string) // name
- );
- _combo_box = new ComboBox.with_model (_list_store);
- _combo_box.hexpand = true;
+ Gtk.StackSwitcher stack_switcher = new Gtk.StackSwitcher ();
+ stack_switcher.set_stack (_stack);
- CellRendererPixbuf pixbuf_renderer = new CellRendererPixbuf ();
- _combo_box.pack_start (pixbuf_renderer, false);
- _combo_box.set_attributes (pixbuf_renderer,
- "icon-name", SidePanelColumn.PIXBUF, null);
+ Gtk.ActionBar action_bar = new Gtk.ActionBar ();
+ action_bar.set_center_widget (stack_switcher);
+ action_bar.pack_end (get_close_button ());
- CellRendererText text_renderer = new CellRendererText ();
- text_renderer.ellipsize_set = true;
- text_renderer.ellipsize = Pango.EllipsizeMode.END;
- _combo_box.pack_start (text_renderer, true);
- _combo_box.set_attributes (text_renderer, "text", SidePanelColumn.NAME, null);
-
- /* signals */
- _combo_box.changed.connect (show_active_component);
+ attach (action_bar, 0, 0, 1, 1);
+ attach (_stack, 0, 1, 1, 1);
+ show_all ();
}
private Button get_close_button ()
{
Button close_button = Tepl.utils_create_close_button () as Button;
close_button.tooltip_text = _("Hide panel");
- close_button.margin_end = 3;
close_button.clicked.connect (() => this.hide ());
return close_button;
}
- public void add_component (string name, string icon_name, Grid component)
+ public void add_component (Grid component, string name, string title, string icon_name)
{
- TreeIter iter;
- _list_store.append (out iter);
- _list_store.set (iter,
- SidePanelColumn.PIXBUF, icon_name,
- SidePanelColumn.NAME, name);
-
- _components.add (component);
- attach (component, 0, _components.size, 2, 1);
+ component.show ();
+ Tepl.stack_add_component (_stack, component, name, title, icon_name);
}
public void restore_state ()
{
- foreach (Grid component in _components)
- component.hide ();
-
- int num = _settings.get_int ("side-panel-component");
- num = num.clamp (0, _components.size - 1);
- _combo_box.set_active (num);
-
- // Save which component is displayed. Since the component can be different
- // on each window, we make only a SET (not a GET).
- // The setting is bind only after getting the old value, otherwise the old value
- // is overwritten.
- _settings.bind ("side-panel-component", _combo_box, "active",
- SettingsBindFlags.SET);
- }
-
- private void show_active_component ()
- {
- if (0 <= _current_component && _current_component < _components.size)
- _components[_current_component].hide ();
-
- _current_component = _combo_box.active;
- _components[_current_component].show ();
+ GLib.Settings settings = new GLib.Settings ("org.gnome.gnome-latex.preferences.ui");
+ Tepl.stack_bind_setting (_stack, settings, "side-panel-component");
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]