[gnome-latex/wip/side-panel] 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/wip/side-panel] SidePanel: use GtkStack, GtkStackSwitcher and tepl_stack_*() functions
- Date: Mon, 20 Apr 2020 16:59:38 +0000 (UTC)
commit 6366ccb524eb842b99c8d86b66c4fda443e3c019
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Apr 20 16:03:23 2020 +0200
SidePanel: use GtkStack, GtkStackSwitcher and tepl_stack_*() functions
data/org.gnome.gnome-latex.gschema.xml.in | 6 +--
src/side_panel.vala | 87 +++++--------------------------
2 files changed, 16 insertions(+), 77 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/side_panel.vala b/src/side_panel.vala
index a0b7687..b20725e 100644
--- a/src/side_panel.vala
+++ b/src/side_panel.vala
@@ -21,67 +21,33 @@ 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?> ();
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;
+ _stack = new Gtk.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.StackSwitcher stack_switcher = new Gtk.StackSwitcher ();
+ stack_switcher.set_stack (_stack);
- 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);
+ Gtk.ActionBar action_bar = new Gtk.ActionBar ();
+ action_bar.set_center_widget (stack_switcher);
+ action_bar.pack_end (get_close_button ());
- /* 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 ());
@@ -90,39 +56,12 @@ public class SidePanel : Grid
public void add_component (string name, string icon_name, Grid component)
{
- 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, icon_name, name, 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 ();
+ Tepl.stack_bind_setting (_stack, _settings, "side-panel-component");
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]