summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-19 21:42:00 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-19 21:42:00 +0200
commit76523a3d2d5c3f5af019017b1a089d65da7e6c97 (patch)
treed64b9b56fbd971345fe9941748d52450fc8837af
parentf286eb7fcdf8fab0ff1f5859d1cf609b40e396c2 (diff)
downloadserenity-76523a3d2d5c3f5af019017b1a089d65da7e6c97.zip
LibGUI: Show the special home directory icon in GUI::FilePicker
-rw-r--r--Libraries/LibGUI/FilePicker.cpp41
-rw-r--r--Libraries/LibGUI/FilePicker.h2
2 files changed, 28 insertions, 15 deletions
diff --git a/Libraries/LibGUI/FilePicker.cpp b/Libraries/LibGUI/FilePicker.cpp
index 7ec373e2a1..d8c7c3b5a2 100644
--- a/Libraries/LibGUI/FilePicker.cpp
+++ b/Libraries/LibGUI/FilePicker.cpp
@@ -26,6 +26,7 @@
#include <AK/Function.h>
#include <AK/LexicalPath.h>
+#include <LibCore/StandardPaths.h>
#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
@@ -81,15 +82,15 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const
, m_mode(mode)
{
switch (m_mode) {
- case Mode::Open:
- set_title("Open File");
- break;
- case Mode::OpenMultiple:
- set_title("Open Files");
- break;
- case Mode::Save:
- set_title("Save File");
- break;
+ case Mode::Open:
+ set_title("Open File");
+ break;
+ case Mode::OpenMultiple:
+ set_title("Open Files");
+ break;
+ case Mode::Save:
+ set_title("Save File");
+ break;
}
set_title(m_mode == Mode::Open ? "Open File" : "Save File");
set_rect(200, 200, 700, 400);
@@ -121,7 +122,6 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const
m_location_textbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_location_textbox->set_preferred_size(0, 22);
m_location_textbox->set_text(path);
- m_location_textbox->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-folder.png"));
m_view = vertical_container.add<MultiView>();
m_view->set_multi_select(m_mode == Mode::OpenMultiple);
@@ -133,20 +133,22 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const
m_view->set_column_hidden(FileSystemModel::Column::Permissions, true);
m_view->set_column_hidden(FileSystemModel::Column::Inode, true);
m_view->set_column_hidden(FileSystemModel::Column::SymlinkTarget, true);
- m_model->set_root_path(path);
+
+ set_path(path);
+
m_model->register_client(*this);
m_location_textbox->on_return_pressed = [this] {
- m_model->set_root_path(m_location_textbox->text());
+ set_path(m_location_textbox->text());
};
auto open_parent_directory_action = Action::create("Open parent directory", { Mod_Alt, Key_Up }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [this](const Action&) {
- m_model->set_root_path(String::format("%s/..", m_model->root_path().characters()));
+ set_path(String::format("%s/..", m_model->root_path().characters()));
});
toolbar.add_action(*open_parent_directory_action);
auto go_home_action = CommonActions::make_go_home_action([this](auto&) {
- m_model->set_root_path(Core::StandardPaths::home_directory());
+ set_path(Core::StandardPaths::home_directory());
});
toolbar.add_action(go_home_action);
toolbar.add_separator();
@@ -249,7 +251,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const
auto path = node.full_path(m_model);
if (node.is_directory()) {
- m_model->set_root_path(path);
+ set_path(path);
// NOTE: 'node' is invalid from here on
} else {
on_file_return();
@@ -345,4 +347,13 @@ bool FilePicker::file_exists(const StringView& path)
return false;
}
+void FilePicker::set_path(const String& path)
+{
+ if (path == Core::StandardPaths::home_directory())
+ m_location_textbox->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/home-directory.png"));
+ else
+ m_location_textbox->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-folder.png"));
+ m_model->set_root_path(path);
+}
+
}
diff --git a/Libraries/LibGUI/FilePicker.h b/Libraries/LibGUI/FilePicker.h
index a681ef3c83..11956bf7eb 100644
--- a/Libraries/LibGUI/FilePicker.h
+++ b/Libraries/LibGUI/FilePicker.h
@@ -67,6 +67,8 @@ private:
void clear_preview();
void on_file_return();
+ void set_path(const String&);
+
virtual void on_model_update(unsigned) override;
FilePicker(Window* parent_window, Mode type = Mode::Open, Options = Options::None, const StringView& file_name = "Untitled", const StringView& path = Core::StandardPaths::home_directory());