← Back to team overview

elementaryart team mailing list archive

[Merge] lp:~victored/granite/static-notebook-fixes into lp:granite

 

Victor Eduardo has proposed merging lp:~victored/granite/static-notebook-fixes into lp:granite.

Requested reviews:
  xapantu (xapantu)

For more details, see:
https://code.launchpad.net/~victored/granite/static-notebook-fixes/+merge/89565

[Granite.Widgets.StaticNotebook]
lp:889376
lp:889551
-- 
https://code.launchpad.net/~victored/granite/static-notebook-fixes/+merge/89565
Your team elementaryart (old) is subscribed to branch lp:granite.
=== modified file 'lib/Widgets/StaticNotebook.vala'
--- lib/Widgets/StaticNotebook.vala	2011-09-06 16:22:53 +0000
+++ lib/Widgets/StaticNotebook.vala	2012-01-22 03:05:26 +0000
@@ -19,55 +19,94 @@
  */
 
 namespace Granite.Widgets {
-    public class StaticNotebook : Gtk.VBox
-    {   
-        Gtk.Notebook notebook;
-        ModeButton switcher;
-        
-        public int page { 
+
+    public class StaticNotebook : Gtk.Box {
+
+        private Gtk.Notebook notebook;
+        private ModeButton switcher;
+        private Gtk.Box switcher_box;
+
+        /* The page switcher will NEVER be shown if this property is set to true */
+        private bool switcher_hidden;
+
+        public int page {
             set { switcher.selected = value; notebook.page = value; }
             get { return notebook.page; }
         }
-        
-        public signal void page_changed (int index); 
-        
-        public StaticNotebook()
-        {
+
+        public signal void page_changed(int index);
+
+        public StaticNotebook() {
+
+            orientation = Gtk.Orientation.VERTICAL;
+            switcher_hidden = false;
+
             notebook = new Gtk.Notebook();
             notebook.show_tabs = false;
+
             switcher = new ModeButton();
-            var hbox = new Gtk.HBox(false, 0);
-            hbox.pack_start(new Gtk.HSeparator(), true, true);
-            hbox.pack_start(switcher, false, false);
+
+            switcher_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
+            var left_separator = new Gtk.Separator(Gtk.Orientation.HORIZONTAL);
+            var right_separator = new Gtk.Separator(Gtk.Orientation.HORIZONTAL);
+
+            switcher_box.pack_start(left_separator, true, true);
+            switcher_box.pack_start(switcher, false, false);
+            switcher_box.pack_end(right_separator, true, true);
+
             switcher.set_margin_top(5);
             switcher.set_margin_bottom(5);
-            hbox.pack_start(new Gtk.HSeparator(), true, true);
-            pack_start(hbox, false, false);
+
+            pack_start(switcher_box, false, false);
             pack_start(notebook);
-            
+
             switcher.mode_changed.connect(on_mode_changed);
         }
-        
-        public void append_page(Gtk.Widget widget, Gtk.Label label)
-        {
+
+        public void set_switcher_visible(bool val) {
+            switcher_box.set_no_show_all(!val);
+            switcher_hidden = !val;
+            update_switcher_visibility();
+        }
+
+        public void append_page(Gtk.Widget widget, Gtk.Label label) {
             notebook.append_page(widget, null);
             label.set_margin_right(5);
             label.set_margin_left(5);
             switcher.append(label);
+
             if(switcher.selected == -1)
                 switcher.selected = 0;
+
+            update_switcher_visibility();
         }
-        
-        void on_mode_changed(Gtk.Widget widget)
-        {
+
+        void on_mode_changed(Gtk.Widget widget) {
             notebook.page = switcher.selected;
             page_changed(notebook.page);
         }
-        
-        public void remove_page(int number)
-        {
+
+        public void remove_page(int number) {
             notebook.remove_page(number);
             switcher.remove(number);
+            update_switcher_visibility();
+        }
+
+        private void update_switcher_visibility() {
+            if (switcher_hidden) {
+                switcher_box.hide();
+                return;
+            }
+
+            // Don't show tabs if there's only one page
+            bool switcher_visible = notebook.get_n_pages() > 1;
+            switcher_box.set_no_show_all (!switcher_visible);
+
+            if (switcher_visible)
+                switcher_box.show_all();
+            else
+                switcher_box.hide();
         }
     }
 }
+


Follow ups