~voluntatefaber/granite/contractorview-custom-items

« back to all changes in this revision

Viewing changes to lib/Widgets/StaticNotebook.vala

Merge Victor's branch, StaticNotebook enhancements (and some cosmetics on this file).

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
namespace Granite.Widgets {
22
 
    public class StaticNotebook : Gtk.VBox
23
 
    {   
24
 
        Gtk.Notebook notebook;
25
 
        ModeButton switcher;
26
 
        
27
 
        public int page { 
 
22
 
 
23
    public class StaticNotebook : Gtk.Box {
 
24
 
 
25
        private Gtk.Notebook notebook;
 
26
        private ModeButton switcher;
 
27
        private Gtk.Box switcher_box;
 
28
 
 
29
        /* The page switcher will NEVER be shown if this property is set to true */
 
30
        private bool switcher_hidden;
 
31
 
 
32
        public int page {
28
33
            set { switcher.selected = value; notebook.page = value; }
29
34
            get { return notebook.page; }
30
35
        }
31
 
        
32
 
        public signal void page_changed (int index); 
33
 
        
34
 
        public StaticNotebook()
35
 
        {
 
36
 
 
37
        public signal void page_changed (int index);
 
38
 
 
39
        public StaticNotebook () {
 
40
 
 
41
            orientation = Gtk.Orientation.VERTICAL;
 
42
            switcher_hidden = false;
 
43
 
36
44
            notebook = new Gtk.Notebook();
37
45
            notebook.show_tabs = false;
 
46
 
38
47
            switcher = new ModeButton();
39
 
            var hbox = new Gtk.HBox(false, 0);
40
 
            hbox.pack_start(new Gtk.HSeparator(), true, true);
41
 
            hbox.pack_start(switcher, false, false);
 
48
 
 
49
            switcher_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
 
50
            var left_separator = new Gtk.Separator(Gtk.Orientation.HORIZONTAL);
 
51
            var right_separator = new Gtk.Separator(Gtk.Orientation.HORIZONTAL);
 
52
 
 
53
            switcher_box.pack_start(left_separator, true, true);
 
54
            switcher_box.pack_start(switcher, false, false);
 
55
            switcher_box.pack_end(right_separator, true, true);
 
56
 
42
57
            switcher.set_margin_top(5);
43
58
            switcher.set_margin_bottom(5);
44
 
            hbox.pack_start(new Gtk.HSeparator(), true, true);
45
 
            pack_start(hbox, false, false);
 
59
 
 
60
            pack_start(switcher_box, false, false);
46
61
            pack_start(notebook);
47
 
            
 
62
 
48
63
            switcher.mode_changed.connect(on_mode_changed);
49
64
        }
50
 
        
51
 
        public void append_page(Gtk.Widget widget, Gtk.Label label)
52
 
        {
 
65
 
 
66
        public void set_switcher_visible (bool val) {
 
67
            switcher_box.set_no_show_all(!val);
 
68
            switcher_hidden = !val;
 
69
            update_switcher_visibility();
 
70
        }
 
71
 
 
72
        public void append_page (Gtk.Widget widget, Gtk.Label label) {
53
73
            notebook.append_page(widget, null);
54
74
            label.set_margin_right(5);
55
75
            label.set_margin_left(5);
56
76
            switcher.append(label);
 
77
 
57
78
            if(switcher.selected == -1)
58
79
                switcher.selected = 0;
 
80
 
 
81
            update_switcher_visibility();
59
82
        }
60
 
        
61
 
        void on_mode_changed(Gtk.Widget widget)
62
 
        {
 
83
 
 
84
        void on_mode_changed (Gtk.Widget widget) {
63
85
            notebook.page = switcher.selected;
64
86
            page_changed(notebook.page);
65
87
        }
66
 
        
67
 
        public void remove_page(int number)
68
 
        {
 
88
 
 
89
        public void remove_page (int number) {
69
90
            notebook.remove_page(number);
70
91
            switcher.remove(number);
 
92
            update_switcher_visibility();
 
93
        }
 
94
 
 
95
        void update_switcher_visibility () {
 
96
            if (switcher_hidden) {
 
97
                switcher_box.hide();
 
98
                return;
 
99
            }
 
100
 
 
101
            // Don't show tabs if there's only one page
 
102
            bool switcher_visible = notebook.get_n_pages() > 1;
 
103
            switcher_box.set_no_show_all (!switcher_visible);
 
104
 
 
105
            if (switcher_visible)
 
106
                switcher_box.show_all();
 
107
            else
 
108
                switcher_box.hide();
71
109
        }
72
110
    }
73
111
}
 
112