mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
GFilePicker: Quality of life improvements (#370)
Added: - Default to home directory on open. - Save button focus. - Correct title for the mode were in. - Home directory shortcut.
This commit is contained in:
parent
608fee9bff
commit
731f91f1ab
2 changed files with 12 additions and 3 deletions
|
@ -48,7 +48,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
|
||||||
, m_model(GDirectoryModel::create())
|
, m_model(GDirectoryModel::create())
|
||||||
, m_mode(mode)
|
, m_mode(mode)
|
||||||
{
|
{
|
||||||
set_title("GFilePicker");
|
set_title(m_mode == Mode::Open ? "Open File" : "Save File");
|
||||||
set_rect(200, 200, 700, 400);
|
set_rect(200, 200, 700, 400);
|
||||||
auto* horizontal_container = new GWidget;
|
auto* horizontal_container = new GWidget;
|
||||||
set_main_widget(horizontal_container);
|
set_main_widget(horizontal_container);
|
||||||
|
@ -69,7 +69,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& 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(60, 0);
|
toolbar->set_preferred_size(85, 0);
|
||||||
toolbar->set_has_frame(false);
|
toolbar->set_has_frame(false);
|
||||||
|
|
||||||
auto* location_textbox = new GTextBox(upper_container);
|
auto* location_textbox = new GTextBox(upper_container);
|
||||||
|
@ -95,6 +95,12 @@ GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
|
||||||
});
|
});
|
||||||
toolbar->add_action(*open_parent_directory_action);
|
toolbar->add_action(*open_parent_directory_action);
|
||||||
|
|
||||||
|
auto go_home_action = GAction::create("Go to Home Directory", GraphicsBitmap::load_from_file("/res/icons/16x16/go-home.png"), [this](auto&) {
|
||||||
|
m_model->open(get_current_user_home_path());
|
||||||
|
});
|
||||||
|
toolbar->add_action(go_home_action);
|
||||||
|
toolbar->add_separator();
|
||||||
|
|
||||||
auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const GAction&) {
|
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);
|
GInputBox input_box("Enter name:", "New directory", this);
|
||||||
if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) {
|
if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) {
|
||||||
|
@ -169,6 +175,8 @@ GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
|
||||||
ok_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
ok_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||||
ok_button->set_preferred_size(80, 0);
|
ok_button->set_preferred_size(80, 0);
|
||||||
ok_button->set_text(ok_button_name(m_mode));
|
ok_button->set_text(ok_button_name(m_mode));
|
||||||
|
if (m_mode == Mode::Save)
|
||||||
|
ok_button->set_focus(true);
|
||||||
ok_button->on_click = [this, filename_textbox](auto&) {
|
ok_button->on_click = [this, filename_textbox](auto&) {
|
||||||
FileSystemPath path(String::format("%s/%s", m_model->path().characters(), filename_textbox->text().characters()));
|
FileSystemPath path(String::format("%s/%s", m_model->path().characters(), filename_textbox->text().characters()));
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <AK/FileSystemPath.h>
|
#include <AK/FileSystemPath.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
|
#include <LibCore/CUserInfo.h>
|
||||||
#include <LibGUI/GDialog.h>
|
#include <LibGUI/GDialog.h>
|
||||||
#include <LibGUI/GTableView.h>
|
#include <LibGUI/GTableView.h>
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ public:
|
||||||
static Optional<String> get_save_filepath();
|
static Optional<String> get_save_filepath();
|
||||||
static bool file_exists(const StringView& path);
|
static bool file_exists(const StringView& path);
|
||||||
|
|
||||||
GFilePicker(Mode type = Mode::Open, const StringView& path = "/", CObject* parent = nullptr);
|
GFilePicker(Mode type = Mode::Open, const StringView& path = String(get_current_user_home_path()), CObject* parent = nullptr);
|
||||||
virtual ~GFilePicker() override;
|
virtual ~GFilePicker() override;
|
||||||
|
|
||||||
FileSystemPath selected_file() const { return m_selected_file; }
|
FileSystemPath selected_file() const { return m_selected_file; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue