mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
HackStudio: added new directory action
Added the possibility to create a new directory in the current project.
This commit is contained in:
parent
b48d8d1d6d
commit
40da077f6c
Notes:
sideshowbarker
2024-07-18 22:41:18 +09:00
Author: https://github.com/masozzi Commit: https://github.com/SerenityOS/serenity/commit/40da077f6c7 Pull-request: https://github.com/SerenityOS/serenity/pull/5207
2 changed files with 29 additions and 7 deletions
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue