mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 22:15:08 +00:00
GFilePicker: Add a "new directory" button.
This commit is contained in:
parent
7c6784f50c
commit
e6443649cb
2 changed files with 21 additions and 2 deletions
|
@ -7,6 +7,8 @@
|
||||||
#include <LibGUI/GSortingProxyModel.h>
|
#include <LibGUI/GSortingProxyModel.h>
|
||||||
#include <LibGUI/GAction.h>
|
#include <LibGUI/GAction.h>
|
||||||
#include <LibGUI/GToolBar.h>
|
#include <LibGUI/GToolBar.h>
|
||||||
|
#include <LibGUI/GInputBox.h>
|
||||||
|
#include <LibGUI/GMessageBox.h>
|
||||||
#include <AK/FileSystemPath.h>
|
#include <AK/FileSystemPath.h>
|
||||||
|
|
||||||
GFilePicker::GFilePicker(const String& path, CObject* parent)
|
GFilePicker::GFilePicker(const String& path, CObject* parent)
|
||||||
|
@ -30,7 +32,7 @@ GFilePicker::GFilePicker(const String& path, CObject* parent)
|
||||||
|
|
||||||
auto* toolbar = new GToolBar(upper_container);
|
auto* toolbar = new GToolBar(upper_container);
|
||||||
toolbar->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
toolbar->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||||
toolbar->set_preferred_size({ 32, 0 });
|
toolbar->set_preferred_size({ 60, 0 });
|
||||||
|
|
||||||
auto* location_textbox = new GTextBox(upper_container);
|
auto* location_textbox = new GTextBox(upper_container);
|
||||||
location_textbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
location_textbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||||
|
@ -53,6 +55,23 @@ GFilePicker::GFilePicker(const String& path, CObject* parent)
|
||||||
});
|
});
|
||||||
toolbar->add_action(*open_parent_directory_action);
|
toolbar->add_action(*open_parent_directory_action);
|
||||||
|
|
||||||
|
auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this] (const GAction&) {
|
||||||
|
GInputBox input_box("Enter name:", "New directory", this);
|
||||||
|
if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) {
|
||||||
|
auto new_dir_path = FileSystemPath(String::format("%s/%s",
|
||||||
|
m_model->path().characters(),
|
||||||
|
input_box.text_value().characters()
|
||||||
|
)).string();
|
||||||
|
int rc = mkdir(new_dir_path.characters(), 0777);
|
||||||
|
if (rc < 0) {
|
||||||
|
GMessageBox::show(String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", GMessageBox::Type::Error, this);
|
||||||
|
} else {
|
||||||
|
m_model->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
toolbar->add_action(*mkdir_action);
|
||||||
|
|
||||||
auto* lower_container = new GWidget(main_widget());
|
auto* lower_container = new GWidget(main_widget());
|
||||||
lower_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
lower_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||||
lower_container->layout()->set_spacing(4);
|
lower_container->layout()->set_spacing(4);
|
||||||
|
|
|
@ -30,7 +30,7 @@ GModelIndex GSortingProxyModel::map_to_target(const GModelIndex& index) const
|
||||||
{
|
{
|
||||||
if (!index.is_valid())
|
if (!index.is_valid())
|
||||||
return { };
|
return { };
|
||||||
if (index.row() >= row_count() || index.column() >= column_count())
|
if (index.row() >= m_row_mappings.size() || index.column() >= column_count())
|
||||||
return { };
|
return { };
|
||||||
return target().index(m_row_mappings[index.row()], index.column());
|
return target().index(m_row_mappings[index.row()], index.column());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue