gpanthera.cc
C++ source, ASCII text
1
#include "gpanthera.hh"
2
#include <iostream>
3
4
namespace gPanthera {
5
DockablePane::DockablePane(Gtk::Widget &child, const Glib::ustring &name, const Glib::ustring &label, Gtk::Image *icon, DockStack *stack, Gtk::Widget *custom_header)
6
: Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0), name(name) {
7
if(icon) {
8
this->icon = icon;
9
}
10
if(stack) {
11
this->stack = stack;
12
}
13
this->label.set_text(label);
14
auto header = Gtk::make_managed<Gtk::HeaderBar>();
15
header->set_show_close_button(false);
16
if(custom_header) {
17
header->set_custom_title(*custom_header);
18
} else {
19
header->set_custom_title(this->label);
20
}
21
auto header_menu_button = Gtk::make_managed<Gtk::MenuButton>();
22
auto header_menu = Gtk::make_managed<Gtk::Menu>();
23
header_menu_button->set_direction(Gtk::ARROW_NONE);
24
header_menu_button->set_popup(*header_menu);
25
auto close_menu_item = Gtk::make_managed<Gtk::MenuItem>("Close");
26
close_menu_item->signal_activate().connect([this]() {
27
if(this->stack) {
28
this->stack->set_visible_child("empty");
29
}
30
});
31
header_menu->append(*close_menu_item);
32
header_menu->show_all();
33
header->pack_end(*header_menu_button);
34
this->pack_start(*header, Gtk::PACK_SHRINK);
35
this->pack_end(child, Gtk::PACK_EXPAND_WIDGET);
36
show_all_children();
37
}
38
39
void DockablePane::redock(DockStack *stack) {
40
this->stack = stack;
41
}
42
43
Glib::ustring DockablePane::get_identifier() const {
44
return name;
45
}
46
47
Gtk::Image *DockablePane::get_icon() const {
48
return icon;
49
}
50
51
Gtk::Label *DockablePane::get_label() {
52
return &label;
53
}
54
55
LayoutManager::LayoutManager() : Glib::ObjectBase("LayoutManager") {
56
}
57
58
void LayoutManager::add_pane(std::shared_ptr<DockablePane> pane) {
59
panes.push_back(std::move(pane));
60
}
61
62
DockStack::DockStack(std::shared_ptr<LayoutManager> layout) : Gtk::Stack(), layout(std::move(layout)) {
63
auto *empty_child = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_VERTICAL, 0);
64
add(*empty_child, "empty");
65
}
66
67
DockStackSwitcher::DockStackSwitcher(DockStack *stack) : Gtk::ButtonBox(Gtk::ORIENTATION_HORIZONTAL), stack(std::move(stack)) {}
68
69
void DockStackSwitcher::update_buttons() {
70
for(auto const &child : get_children()) {
71
remove(*child);
72
}
73
for(auto const &widget : stack->get_children()) {
74
if(auto pane = dynamic_cast<DockablePane*>(widget)) {
75
auto *button = Gtk::make_managed<Gtk::Button>();
76
if(pane->get_icon()) {
77
button->set_image(*pane->get_icon());
78
}
79
button->signal_clicked().connect([this, pane]() {
80
if(stack->get_visible_child_name() == pane->get_identifier()) {
81
stack->set_visible_child("empty");
82
} else {
83
stack->set_visible_child(pane->get_identifier());
84
}
85
});
86
if(pane->get_identifier() != Glib::ustring("empty")) {
87
pack_start(*button);
88
}
89
}
90
}
91
}
92
93
void DockStack::add(Gtk::Widget &child, const Glib::ustring &name) {
94
if(auto pane = dynamic_cast<DockablePane*>(&child)) {
95
pane->redock(this);
96
}
97
Gtk::Stack::add(child, name);
98
}
99
} // namespace gPanthera
100