summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOriko <oriko1010@protonmail.com>2020-04-06 01:03:15 +0300
committerAndreas Kling <kling@serenityos.org>2020-04-06 09:01:42 +0200
commit795067e08c92e4be2565bc22f2980e25fb412d12 (patch)
treee18db385f8e2577af309215a237771debc1a193a
parent12c7375cdd40f6bed39ffaa6516f7ae85ea5f058 (diff)
downloadserenity-795067e08c92e4be2565bc22f2980e25fb412d12.zip
HackStudio: Add new Terminals
-rw-r--r--DevTools/HackStudio/TerminalWrapper.cpp6
-rw-r--r--DevTools/HackStudio/TerminalWrapper.h6
-rw-r--r--DevTools/HackStudio/main.cpp48
3 files changed, 55 insertions, 5 deletions
diff --git a/DevTools/HackStudio/TerminalWrapper.cpp b/DevTools/HackStudio/TerminalWrapper.cpp
index 7f7a904010..58b39506bf 100644
--- a/DevTools/HackStudio/TerminalWrapper.cpp
+++ b/DevTools/HackStudio/TerminalWrapper.cpp
@@ -167,13 +167,17 @@ void TerminalWrapper::kill_running_command()
(void)killpg(m_pid, SIGTERM);
}
-TerminalWrapper::TerminalWrapper()
+TerminalWrapper::TerminalWrapper(bool user_spawned)
+ : m_user_spawned(user_spawned)
{
set_layout<GUI::VerticalBoxLayout>();
RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("Terminal");
m_terminal_widget = add<TerminalWidget>(-1, false, config);
m_process_state_widget = add<ProcessStateWidget>();
+
+ if (user_spawned)
+ run_command("Shell");
}
TerminalWrapper::~TerminalWrapper()
diff --git a/DevTools/HackStudio/TerminalWrapper.h b/DevTools/HackStudio/TerminalWrapper.h
index 85ac9e1402..781f8150b0 100644
--- a/DevTools/HackStudio/TerminalWrapper.h
+++ b/DevTools/HackStudio/TerminalWrapper.h
@@ -39,12 +39,16 @@ public:
void run_command(const String&);
void kill_running_command();
+ bool user_spawned() const { return m_user_spawned; }
+ TerminalWidget* terminal() { return m_terminal_widget; }
+
Function<void()> on_command_exit;
private:
- explicit TerminalWrapper();
+ explicit TerminalWrapper(bool user_spawned = true);
RefPtr<ProcessStateWidget> m_process_state_widget;
RefPtr<TerminalWidget> m_terminal_widget;
pid_t m_pid { -1 };
+ bool m_user_spawned { true };
};
diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp
index 6c6743da0b..92bbef59ae 100644
--- a/DevTools/HackStudio/main.cpp
+++ b/DevTools/HackStudio/main.cpp
@@ -61,6 +61,7 @@
#include <LibGUI/TreeView.h>
#include <LibGUI/Widget.h>
#include <LibGUI/Window.h>
+#include <LibVT/TerminalWidget.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -435,6 +436,8 @@ int main(int argc, char** argv)
s_action_tab_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
s_action_tab_widget->set_preferred_size(0, 24);
+ s_action_tab_widget->on_change = [&](auto&) { update_actions(); };
+
auto reveal_action_tab = [&](auto& widget) {
if (s_action_tab_widget->preferred_size().height() < 200)
s_action_tab_widget->set_preferred_size(0, 200);
@@ -449,13 +452,38 @@ int main(int argc, char** argv)
hide_action_tabs();
});
- auto add_editor_action = GUI::Action::create("Add new editor", { Mod_Ctrl | Mod_Alt, Key_E }, [&](auto&) {
- add_new_editor(*g_text_inner_splitter);
+ auto add_editor_action = GUI::Action::create("Add new editor", { Mod_Ctrl | Mod_Alt, Key_E },
+ Gfx::Bitmap::load_from_file("/res/icons/TextEditor16.png"),
+ [&](auto&) {
+ add_new_editor(*g_text_inner_splitter);
+ update_actions();
+ });
+
+ auto add_terminal_action = GUI::Action::create("Add new Terminal", { Mod_Ctrl | Mod_Alt, Key_T },
+ Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"),
+ [&](auto&) {
+ auto& terminal = s_action_tab_widget->add_tab<TerminalWrapper>("Terminal");
+ reveal_action_tab(terminal);
+ update_actions();
+ terminal.terminal()->set_focus(true);
+ });
+
+ auto remove_current_terminal_action = GUI::Action::create("Remove current Terminal", { Mod_Alt | Mod_Shift, Key_T }, [&](auto&) {
+ auto widget = s_action_tab_widget->active_widget();
+ if (!widget)
+ return;
+ if (strcmp(widget->class_name(), "TerminalWrapper") != 0)
+ return;
+ auto terminal = reinterpret_cast<TerminalWrapper*>(widget);
+ if (!terminal->user_spawned())
+ return;
+
+ s_action_tab_widget->remove_tab(*terminal);
update_actions();
});
auto& find_in_files_widget = s_action_tab_widget->add_tab<FindInFilesWidget>("Find in files");
- auto& terminal_wrapper = s_action_tab_widget->add_tab<TerminalWrapper>("Console");
+ auto& terminal_wrapper = s_action_tab_widget->add_tab<TerminalWrapper>("Build", false);
auto& locator = widget.add<Locator>();
@@ -517,6 +545,8 @@ int main(int argc, char** argv)
view_menu.add_separator();
view_menu.add_action(add_editor_action);
view_menu.add_action(remove_current_editor_action);
+ view_menu.add_action(add_terminal_action);
+ view_menu.add_action(remove_current_terminal_action);
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::Action::create("About", [&](auto&) {
@@ -530,7 +560,19 @@ int main(int argc, char** argv)
g_window->show();
update_actions = [&]() {
+ auto is_remove_terminal_enabled = []() {
+ auto widget = s_action_tab_widget->active_widget();
+ if (!widget)
+ return false;
+ if (strcmp(widget->class_name(), "TerminalWrapper") != 0)
+ return false;
+ if (!reinterpret_cast<TerminalWrapper*>(widget)->user_spawned())
+ return false;
+ return true;
+ };
+
remove_current_editor_action->set_enabled(g_all_editor_wrappers.size() > 1);
+ remove_current_terminal_action->set_enabled(is_remove_terminal_enabled());
};
g_open_file = open_file;