[latexila] Move the bottom panel into its own class



commit b8ec5e2f77271325f5ab970a84ea1d05618f031f
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Tue Jul 10 06:30:48 2012 +0200

    Move the bottom panel into its own class
    
    The best classes are the shortest ones, after all.
    
    The toolbar parameter for the build view was only there for widget's
    packing.

 src/bottom_panel.vala |   57 +++++++++++++++++++++++++++++++++++++++++
 src/build_view.vala   |   67 ++++++++++++------------------------------------
 src/main_window.vala  |   18 ++++++++-----
 3 files changed, 85 insertions(+), 57 deletions(-)
---
diff --git a/src/bottom_panel.vala b/src/bottom_panel.vala
new file mode 100644
index 0000000..c6776c1
--- /dev/null
+++ b/src/bottom_panel.vala
@@ -0,0 +1,57 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright  2012 SÃbastien Wilmet
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: SÃbastien Wilmet
+ */
+
+using Gtk;
+
+public class BottomPanel : Grid
+{
+    public BottomPanel (BuildView build_view, Toolbar toolbar)
+    {
+        set_orientation (Orientation.HORIZONTAL);
+
+        Widget scrolled_window = Utils.add_scrollbar (build_view);
+        scrolled_window.expand = true;
+        scrolled_window.show_all ();
+        add (scrolled_window);
+
+        Grid grid = new Grid ();
+        grid.orientation = Orientation.VERTICAL;
+        grid.add (get_close_button ());
+
+        toolbar.vexpand = true;
+        grid.add (toolbar);
+
+        grid.show_all ();
+        add (grid);
+    }
+
+    private Button get_close_button ()
+    {
+        Button close_button = new Button ();
+        close_button.relief = ReliefStyle.NONE;
+        close_button.focus_on_click = false;
+        close_button.tooltip_text = _("Hide panel");
+        close_button.add (new Image.from_stock (Stock.CLOSE, IconSize.MENU));
+        close_button.clicked.connect (() => this.hide ());
+
+        return close_button;
+    }
+}
diff --git a/src/build_view.vala b/src/build_view.vala
index e0eb15f..3da5044 100644
--- a/src/build_view.vala
+++ b/src/build_view.vala
@@ -56,7 +56,7 @@ public struct BuildMsg
     public bool expand;
 }
 
-public class BuildView : Grid
+public class BuildView : TreeView
 {
     private enum BuildMsgColumn
     {
@@ -78,19 +78,16 @@ public class BuildView : Grid
 
     private unowned MainWindow _main_window;
     private TreeStore _store;
-    private TreeView _view;
 
     // Used to show/hide warnings and badboxes.
     private TreeModelFilter _filtered_model;
 
-    public BuildView (MainWindow main_window, Toolbar toolbar)
+    public BuildView (MainWindow main_window)
     {
-        orientation = Orientation.HORIZONTAL;
         _main_window = main_window;
 
         init_tree_models ();
         init_tree_view ();
-        packing_widgets (toolbar);
     }
 
     private void init_tree_models ()
@@ -133,8 +130,8 @@ public class BuildView : Grid
 
     private void init_tree_view ()
     {
-        _view = new TreeView.with_model (_filtered_model);
-        _view.headers_visible = false;
+        this.set_model (_filtered_model);
+        this.headers_visible = false;
 
         /* Columns, cell renderers */
         TreeViewColumn column_job = new TreeViewColumn ();
@@ -151,17 +148,17 @@ public class BuildView : Grid
         column_job.add_attribute (renderer_text, "text", BuildMsgColumn.MESSAGE);
         column_job.add_attribute (renderer_text, "weight", BuildMsgColumn.WEIGHT);
 
-        _view.append_column (column_job);
+        this.append_column (column_job);
 
-        _view.insert_column_with_attributes (-1, null, new CellRendererText (),
+        this.insert_column_with_attributes (-1, null, new CellRendererText (),
             "text", BuildMsgColumn.BASENAME);
-        _view.insert_column_with_attributes (-1, null, new CellRendererText (),
+        this.insert_column_with_attributes (-1, null, new CellRendererText (),
             "text", BuildMsgColumn.LINE_STR);
 
-        _view.set_tooltip_column (BuildMsgColumn.PATH);
+        this.set_tooltip_column (BuildMsgColumn.PATH);
 
         /* Selection */
-        TreeSelection select = _view.get_selection ();
+        TreeSelection select = this.get_selection ();
         select.set_mode (SelectionMode.SINGLE);
         select.set_select_function ((select, model, path, path_currently_selected) =>
         {
@@ -173,37 +170,7 @@ public class BuildView : Grid
         });
 
         /* Double-click */
-        _view.row_activated.connect ((path) => select_row (_filtered_model, path));
-    }
-
-    private Button get_close_button ()
-    {
-        Button close_button = new Button ();
-        close_button.relief = ReliefStyle.NONE;
-        close_button.focus_on_click = false;
-        close_button.tooltip_text = _("Hide panel");
-        close_button.add (new Image.from_stock (Stock.CLOSE, IconSize.MENU));
-        close_button.clicked.connect (() => this.hide ());
-
-        return close_button;
-    }
-
-    private void packing_widgets (Toolbar toolbar)
-    {
-        Widget sw = Utils.add_scrollbar (_view);
-        sw.expand = true;
-        add (sw);
-        sw.show_all ();
-
-        Grid grid = new Grid ();
-        grid.orientation = Orientation.VERTICAL;
-        grid.add (get_close_button ());
-
-        toolbar.set_vexpand (true);
-        grid.add (toolbar);
-
-        add (grid);
-        grid.show_all ();
+        this.row_activated.connect ((path) => select_row (_filtered_model, path));
     }
 
     private bool select_row (TreeModel model, TreePath path)
@@ -215,10 +182,10 @@ public class BuildView : Grid
 
         if (model.iter_has_child (iter))
         {
-            if (_view.is_row_expanded (path))
-                _view.collapse_row (path);
+            if (this.is_row_expanded (path))
+                this.collapse_row (path);
             else
-                _view.expand_to_path (path);
+                this.expand_to_path (path);
 
             // the row is not selected
             return false;
@@ -260,7 +227,7 @@ public class BuildView : Grid
     public void clear ()
     {
         _store.clear ();
-        _view.columns_autosize ();
+        this.columns_autosize ();
     }
 
     public TreeIter add_partition (string msg, PartitionState state, TreeIter? parent,
@@ -277,7 +244,7 @@ public class BuildView : Grid
             BuildMsgColumn.WEIGHT,       bold ? 800 : 400
         );
 
-        _view.expand_to_path (_store.get_path (iter));
+        this.expand_to_path (_store.get_path (iter));
 
         return iter;
     }
@@ -301,7 +268,7 @@ public class BuildView : Grid
                 append_messages (child, cur_node, false);
 
                 if (cur_node.data.expand)
-                    _view.expand_to_path (_store.get_path (child));
+                    this.expand_to_path (_store.get_path (child));
             }
 
             cur_node = cur_node.next_sibling ();
@@ -310,7 +277,7 @@ public class BuildView : Grid
         // All partitions are expanded, but we must do that when the partition have
         // children.
         if (parent_is_partition)
-            _view.expand_row (_store.get_path (parent), false);
+            this.expand_row (_store.get_path (parent), false);
     }
 
     public TreeIter append_single_message (TreeIter parent, BuildMsg message)
diff --git a/src/main_window.vala b/src/main_window.vala
index d3cb320..5ac397e 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -297,11 +297,19 @@ public class MainWindow : Window
         goto_line = new GotoLine (this);
         search_and_replace = new SearchAndReplace (this);
 
-        // build view
+        // bottom panel
         action_stop_exec = action_group.get_action ("BuildStopExecution");
         action_stop_exec.set_sensitive (false);
 
-        _build_view = new BuildView (this, build_toolbar);
+        _build_view = new BuildView (this);
+
+        BottomPanel bottom_panel = new BottomPanel (_build_view, build_toolbar);
+
+        ToggleAction action_bottom_panel =
+            action_group.get_action ("ViewBottomPanel") as ToggleAction;
+
+        bottom_panel.bind_property ("visible", action_bottom_panel, "active",
+            BindingFlags.BIDIRECTIONAL);
 
         // side panel
         _side_panel = new SidePanel ();
@@ -491,7 +499,7 @@ public class MainWindow : Window
 
         // when we resize the window, the bottom panel keeps the same height
         vpaned.pack1 (vgrid_source_view, true, true);
-        vpaned.pack2 (_build_view, false, true);
+        vpaned.pack2 (bottom_panel, false, true);
 
         main_hpaned.add1 (_side_panel);
         main_hpaned.add2 (vpaned);
@@ -660,10 +668,6 @@ public class MainWindow : Window
 
         /* bottom panel */
         action = action_group.get_action ("ViewBottomPanel") as ToggleAction;
-
-        _build_view.bind_property ("visible", action, "active",
-            BindingFlags.BIDIRECTIONAL);
-
         action.active = settings.get_boolean ("bottom-panel-visible");
     }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]