summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorMatteo Sozzi <sozziteo@googlemail.com>2021-01-31 19:06:41 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-01 09:52:13 +0100
commit40da077f6c702fe39d4494cf421856635c023980 (patch)
tree2b1fb16c1f8304bb7d24324b282af279e83cafa1 /Userland
parentb48d8d1d6de5bcb0d2dc02590f5af3c0855dad9d (diff)
downloadserenity-40da077f6c702fe39d4494cf421856635c023980.zip
HackStudio: added new directory action
Added the possibility to create a new directory in the current project.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.cpp30
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.h6
2 files changed, 29 insertions, 7 deletions
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
index 227e5feef5..2bcbdfe0d0 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
@@ -45,6 +45,7 @@
#include "TerminalWrapper.h"
#include "WidgetTool.h"
#include "WidgetTreeModel.h"
+#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Event.h>
@@ -286,18 +287,20 @@ void HackStudioWidget::set_edit_mode(EditMode mode)
NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu()
{
m_open_selected_action = create_open_selected_action();
- m_new_action = create_new_action();
+ m_new_file_action = create_new_file_action();
+ m_new_directory_action = create_new_directory_action();
m_delete_action = create_delete_action();
auto project_tree_view_context_menu = GUI::Menu::construct("Project Files");
project_tree_view_context_menu->add_action(*m_open_selected_action);
// TODO: Rename, cut, copy, duplicate with new name, show containing folder ...
project_tree_view_context_menu->add_separator();
- project_tree_view_context_menu->add_action(*m_new_action);
+ project_tree_view_context_menu->add_action(*m_new_file_action);
+ project_tree_view_context_menu->add_action(*m_new_directory_action);
project_tree_view_context_menu->add_action(*m_delete_action);
return project_tree_view_context_menu;
}
-NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_action()
+NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_file_action()
{
return GUI::Action::create("Add new file to project...", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) {
String filename;
@@ -312,6 +315,21 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_action()
});
}
+NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_directory_action()
+{
+ return GUI::Action::create("Add new directory to project...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const GUI::Action&) {
+ String directory_name;
+ if (GUI::InputBox::show(directory_name, window(), "Enter name of new directory:", "Add new folder to project") != GUI::InputBox::ExecOK)
+ return;
+ auto formatted_dir_name = LexicalPath::canonicalized_path(String::formatted("{}/{}", m_project->model().root_path(), directory_name));
+ int rc = mkdir(formatted_dir_name.characters(), 0755);
+ if (rc < 0) {
+ GUI::MessageBox::show(window(), "Failed to create new directory", "Error", GUI::MessageBox::Type::Error);
+ return;
+ }
+ });
+}
+
NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_selected_action()
{
@@ -758,7 +776,8 @@ void HackStudioWidget::create_form_editor(GUI::Widget& parent)
void HackStudioWidget::create_toolbar(GUI::Widget& parent)
{
auto& toolbar = parent.add<GUI::ToolBar>();
- toolbar.add_action(*m_new_action);
+ toolbar.add_action(*m_new_file_action);
+ toolbar.add_action(*m_new_directory_action);
toolbar.add_action(*m_save_action);
toolbar.add_action(*m_delete_action);
toolbar.add_separator();
@@ -838,7 +857,8 @@ void HackStudioWidget::create_app_menubar(GUI::MenuBar& menubar)
void HackStudioWidget::create_project_menubar(GUI::MenuBar& menubar)
{
auto& project_menu = menubar.add_menu("Project");
- project_menu.add_action(*m_new_action);
+ project_menu.add_action(*m_new_file_action);
+ project_menu.add_action(*m_new_directory_action);
project_menu.add_action(*create_set_autocomplete_mode_action());
}
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h
index d35ec85284..3723ba4874 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.h
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.h
@@ -79,7 +79,8 @@ private:
void set_edit_mode(EditMode);
NonnullRefPtr<GUI::Menu> create_project_tree_view_context_menu();
- NonnullRefPtr<GUI::Action> create_new_action();
+ NonnullRefPtr<GUI::Action> create_new_file_action();
+ NonnullRefPtr<GUI::Action> create_new_directory_action();
NonnullRefPtr<GUI::Action> create_open_selected_action();
NonnullRefPtr<GUI::Action> create_delete_action();
NonnullRefPtr<GUI::Action> create_switch_to_next_editor_action();
@@ -152,7 +153,8 @@ private:
RefPtr<LibThread::Thread> m_debugger_thread;
RefPtr<EditorWrapper> m_current_editor_in_execution;
- RefPtr<GUI::Action> m_new_action;
+ RefPtr<GUI::Action> m_new_file_action;
+ RefPtr<GUI::Action> m_new_directory_action;
RefPtr<GUI::Action> m_open_selected_action;
RefPtr<GUI::Action> m_delete_action;
RefPtr<GUI::Action> m_switch_to_next_editor;