-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathterminalwidgettabbed.cpp
More file actions
121 lines (95 loc) · 2.72 KB
/
Copy pathterminalwidgettabbed.cpp
File metadata and controls
121 lines (95 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "terminalwidgettabbed.h"
#include "application.h"
#include "terminalwidget.h"
#include "text_renderer.h"
TerminalWidgetTabbed::TerminalWidgetTabbed(Widget* parent) : Widget(parent) {
id = icu::UnicodeString::fromUTF8("Terminal Tabbed");
tab_bar = new Tabs(this);
tab_bar->tab_clicked_callback = [&](TabInfo info) {
tabinfoclicked(info);
};
tab_bar->all_tabs_closed_callback = [&]() {
createNew();
};
tab_bar->add_new_tab_callback = [&]() {
createNew();
};
tab_bar->erasing_tab = [&](TabInfo info) {
std::lock_guard<std::mutex> lock(App::canMakeChanges);
auto it = terminals.find(info.id);
if (it != terminals.end()) {
auto todel = it->second;
terminals.erase(info.id);
App::deleteWidget(todel);
}
};
tabid = 0;
createNew();
}
Widget* TerminalWidgetTabbed::findTerminal() {
return terminals[tab_bar->selected_id];
}
void TerminalWidgetTabbed::position(int x, int y, int w, int h) {
t_x = x;
t_y = y;
t_w = w;
t_h = h;
tab_bar->position(x, y, w, h);
terminals[tab_bar->selected_id]->position(x, y+tab_bar->t_h, w, h-tab_bar->t_h);
}
void TerminalWidgetTabbed::render() {
App::DrawRect(t_x, t_y, t_w, tab_bar->t_h, App::theme.darker_background_color);
App::runWithSKIZ(tab_bar->t_x, tab_bar->t_y, tab_bar->t_w, tab_bar->t_h, [&](){
tab_bar->render();
});
auto t = terminals[tab_bar->selected_id];
App::runWithSKIZ(t->t_x, t->t_y, t->t_w, t->t_h, [&](){
t->render();
});
}
void TerminalWidgetTabbed::createNew() {
auto ti = TabInfo();
#ifdef _WIN32
ti.title = icu::UnicodeString::fromUTF8(App::settings->getValue("terminal_cmd", (std::string)"cmd.exe"));
#else
ti.title = icu::UnicodeString::fromUTF8(App::settings->getValue("terminal_cmd", (std::string)"/bin/bash"));
#endif
ti.id = tabid;
tab_bar->addTab(ti);
tabid ++;
TerminalWidget* term = new TerminalWidget(this);
terminals[ti.id] = term;
for (auto it : terminals) {
if (it.first == ti.id) {
it.second->show();
}else{
it.second->hide();
}
}
tab_bar->selected_id = ti.id;
App::setActiveLeafNode(term);
for (auto it : terminals) {
if (it.first == ti.id && it.second->parent != this){
App::MoveWidget(it.second, this);
}else if (it.first != ti.id && it.second->parent == this) {
App::RemoveWidgetFromParent(it.second);
}
}
}
void TerminalWidgetTabbed::tabinfoclicked(TabInfo info) {
for (auto it : terminals) {
if (it.first == info.id && it.second->parent != this){
App::MoveWidget(it.second, this);
}else if (it.first != info.id && it.second->parent == this) {
App::RemoveWidgetFromParent(it.second);
}
}
App::setActiveLeafNode(terminals[info.id]);
for (auto it : terminals) {
if (it.first == info.id) {
it.second->show();
}else {
it.second->hide();
}
}
}