21
21
namespace Granite.Widgets {
22
public class StaticNotebook : Gtk.VBox
24
Gtk.Notebook notebook;
23
public class StaticNotebook : Gtk.Box {
25
private Gtk.Notebook notebook;
26
private ModeButton switcher;
27
private Gtk.Box switcher_box;
29
/* The page switcher will NEVER be shown if this property is set to true */
30
private bool switcher_hidden;
28
33
set { switcher.selected = value; notebook.page = value; }
29
34
get { return notebook.page; }
32
public signal void page_changed (int index);
34
public StaticNotebook()
37
public signal void page_changed (int index);
39
public StaticNotebook () {
41
orientation = Gtk.Orientation.VERTICAL;
42
switcher_hidden = false;
36
44
notebook = new Gtk.Notebook();
37
45
notebook.show_tabs = false;
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);
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);
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);
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);
60
pack_start(switcher_box, false, false);
46
61
pack_start(notebook);
48
63
switcher.mode_changed.connect(on_mode_changed);
51
public void append_page(Gtk.Widget widget, Gtk.Label label)
66
public void set_switcher_visible (bool val) {
67
switcher_box.set_no_show_all(!val);
68
switcher_hidden = !val;
69
update_switcher_visibility();
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);
57
78
if(switcher.selected == -1)
58
79
switcher.selected = 0;
81
update_switcher_visibility();
61
void on_mode_changed(Gtk.Widget widget)
84
void on_mode_changed (Gtk.Widget widget) {
63
85
notebook.page = switcher.selected;
64
86
page_changed(notebook.page);
67
public void remove_page(int number)
89
public void remove_page (int number) {
69
90
notebook.remove_page(number);
70
91
switcher.remove(number);
92
update_switcher_visibility();
95
void update_switcher_visibility () {
96
if (switcher_hidden) {
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);
105
if (switcher_visible)
106
switcher_box.show_all();