1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 05:08:10 +00:00

FileManager: Use FileIconProvider in the properties dialog

This removes the need for the properties dialog to access the internal
data model used by the directory view.
This commit is contained in:
Andreas Kling 2020-08-12 19:29:02 +02:00
parent 3dd15da7b1
commit aae296ef08
3 changed files with 10 additions and 12 deletions

View file

@ -29,6 +29,7 @@
#include <AK/StringBuilder.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/FileIconProvider.h>
#include <LibGUI/FilePicker.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/TabWidget.h>
@ -39,9 +40,8 @@
#include <string.h>
#include <unistd.h>
PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, bool disable_rename, Window* parent_window)
PropertiesDialog::PropertiesDialog(const String& path, bool disable_rename, Window* parent_window)
: Dialog(parent_window)
, m_model(model)
{
auto lexical_path = LexicalPath(path);
ASSERT(lexical_path.is_valid());
@ -170,7 +170,7 @@ PropertiesDialog::~PropertiesDialog() { }
void PropertiesDialog::update()
{
auto bitmap = m_model.icon_for_file(m_mode, m_name).bitmap_for_size(32);
auto bitmap = GUI::FileIconProvider::icon_for_path(m_name, m_mode).bitmap_for_size(32);
m_icon->set_bitmap(bitmap);
set_title(String::format("%s - Properties", m_name.characters()));
}
@ -187,7 +187,7 @@ void PropertiesDialog::permission_changed(mode_t mask, bool set)
m_apply_button->set_enabled(m_name_dirty || m_permissions_dirty);
}
String PropertiesDialog::make_full_path(String name)
String PropertiesDialog::make_full_path(const String& name)
{
return String::format("%s/%s", m_parent_path.characters(), name.characters());
}

View file

@ -40,7 +40,7 @@ public:
virtual ~PropertiesDialog() override;
private:
PropertiesDialog(GUI::FileSystemModel&, String, bool disable_rename, Window* parent = nullptr);
PropertiesDialog(const String& path, bool disable_rename, Window* parent = nullptr);
struct PropertyValuePair {
String property;
@ -82,17 +82,16 @@ private:
void permission_changed(mode_t mask, bool set);
bool apply_changes();
void update();
String make_full_path(String name);
String make_full_path(const String& name);
GUI::FileSystemModel& m_model;
RefPtr<GUI::Button> m_apply_button;
RefPtr<GUI::TextBox> m_name_box;
RefPtr<GUI::ImageWidget> m_icon;
String m_name;
String m_parent_path;
String m_path;
mode_t m_mode;
mode_t m_old_mode;
mode_t m_mode { 0 };
mode_t m_old_mode { 0 };
bool m_permissions_dirty { false };
bool m_name_dirty { false };
};

View file

@ -480,7 +480,6 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
auto properties_action
= GUI::Action::create(
"Properties...", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"), [&](const GUI::Action& action) {
auto& model = directory_view.model();
String container_dir_path;
String path;
Vector<String> selected;
@ -496,9 +495,9 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
RefPtr<PropertiesDialog> properties;
if (selected.is_empty()) {
properties = window->add<PropertiesDialog>(model, path, true);
properties = window->add<PropertiesDialog>(path, true);
} else {
properties = window->add<PropertiesDialog>(model, selected.first(), access(container_dir_path.characters(), W_OK) != 0);
properties = window->add<PropertiesDialog>(selected.first(), access(container_dir_path.characters(), W_OK) != 0);
}
properties->exec();