mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 02:55:07 +00:00
FileManager: Add ability to create new directories.
This commit is contained in:
parent
1030e6b848
commit
be4533717a
7 changed files with 32 additions and 8 deletions
|
@ -42,3 +42,8 @@ void DirectoryTableView::open_parent_directory()
|
||||||
{
|
{
|
||||||
model().open(String::format("%s/..", model().path().characters()));
|
model().open(String::format("%s/..", model().path().characters()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DirectoryTableView::refresh()
|
||||||
|
{
|
||||||
|
model().update();
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ public:
|
||||||
String path() const { return model().path(); }
|
String path() const { return model().path(); }
|
||||||
void open_parent_directory();
|
void open_parent_directory();
|
||||||
|
|
||||||
|
void refresh();
|
||||||
|
|
||||||
Function<void(const String&)> on_path_change;
|
Function<void(const String&)> on_path_change;
|
||||||
Function<void(String)> on_status_message;
|
Function<void(String)> on_status_message;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ STANDARD_FLAGS = -std=c++17
|
||||||
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough
|
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough
|
||||||
FLAVOR_FLAGS = -fno-exceptions -fno-rtti
|
FLAVOR_FLAGS = -fno-exceptions -fno-rtti
|
||||||
OPTIMIZATION_FLAGS = -Os
|
OPTIMIZATION_FLAGS = -Os
|
||||||
INCLUDE_FLAGS = -I../.. -I. -I../../LibC
|
INCLUDE_FLAGS = -I../.. -I../../Servers -I. -I../../LibC
|
||||||
|
|
||||||
DEFINES = -DSERENITY -DSANITIZE_PTRS -DUSERLAND
|
DEFINES = -DSERENITY -DSANITIZE_PTRS -DUSERLAND
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include <LibGUI/GMenuBar.h>
|
#include <LibGUI/GMenuBar.h>
|
||||||
#include <LibGUI/GAction.h>
|
#include <LibGUI/GAction.h>
|
||||||
#include <LibGUI/GLabel.h>
|
#include <LibGUI/GLabel.h>
|
||||||
|
#include <LibGUI/GInputBox.h>
|
||||||
|
#include <LibGUI/GMessageBox.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -56,8 +58,21 @@ int main(int argc, char** argv)
|
||||||
directory_table_view->open_parent_directory();
|
directory_table_view->open_parent_directory();
|
||||||
});
|
});
|
||||||
|
|
||||||
auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/mkdir.rgb", { 16, 16 }), [] (const GAction&) {
|
auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/mkdir.rgb", { 16, 16 }), [&] (const GAction&) {
|
||||||
dbgprintf("'New directory' action activated!\n");
|
GInputBox input_box("Enter name:", "New directory", window);
|
||||||
|
if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) {
|
||||||
|
auto new_dir_path = String::format("%s/%s",
|
||||||
|
directory_table_view->path().characters(),
|
||||||
|
input_box.text_value().characters()
|
||||||
|
);
|
||||||
|
int rc = mkdir(new_dir_path.characters(), 0777);
|
||||||
|
if (rc < 0) {
|
||||||
|
GMessageBox message_box(String::format("mkdir() failed: %s", strerror(errno)), "Error", window);
|
||||||
|
message_box.exec();
|
||||||
|
} else {
|
||||||
|
directory_table_view->refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
auto copy_action = GAction::create("Copy", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/copyfile16.rgb", { 16, 16 }), [] (const GAction&) {
|
auto copy_action = GAction::create("Copy", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/copyfile16.rgb", { 16, 16 }), [] (const GAction&) {
|
||||||
|
|
|
@ -25,14 +25,15 @@ int GDialog::exec()
|
||||||
show();
|
show();
|
||||||
auto result = m_event_loop->exec();
|
auto result = m_event_loop->exec();
|
||||||
m_event_loop = nullptr;
|
m_event_loop = nullptr;
|
||||||
dbgprintf("event loop returned with result %d\n", result);
|
dbgprintf("%s: event loop returned with result %d\n", class_name(), result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDialog::done(int result)
|
void GDialog::done(int result)
|
||||||
{
|
{
|
||||||
ASSERT(m_event_loop);
|
if (!m_event_loop)
|
||||||
|
return;
|
||||||
m_result = result;
|
m_result = result;
|
||||||
dbgprintf("quit event loop with result %d\n", result);
|
dbgprintf("%s: quit event loop with result %d\n", class_name(), result);
|
||||||
m_event_loop->quit(result);
|
m_event_loop->quit(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ void GMessageBox::build()
|
||||||
button->set_preferred_size({ 100, 16 });
|
button->set_preferred_size({ 100, 16 });
|
||||||
button->set_caption("OK");
|
button->set_caption("OK");
|
||||||
button->on_click = [this] (auto&) {
|
button->on_click = [this] (auto&) {
|
||||||
dbgprintf("OK button clicked\n");
|
dbgprintf("GMessageBox: OK button clicked\n");
|
||||||
done(0);
|
done(0);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,8 +80,9 @@ public:
|
||||||
Size base_size() const { return m_base_size; }
|
Size base_size() const { return m_base_size; }
|
||||||
void set_base_size(const Size& size) { m_base_size = size; }
|
void set_base_size(const Size& size) { m_base_size = size; }
|
||||||
|
|
||||||
private:
|
|
||||||
virtual const char* class_name() const override { return "GWindow"; }
|
virtual const char* class_name() const override { return "GWindow"; }
|
||||||
|
|
||||||
|
private:
|
||||||
virtual bool is_window() const override final { return true; }
|
virtual bool is_window() const override final { return true; }
|
||||||
|
|
||||||
Retained<GraphicsBitmap> create_backing_bitmap(const Size&);
|
Retained<GraphicsBitmap> create_backing_bitmap(const Size&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue