1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 18:25:08 +00:00

GFilePicker: Make double-clicking actually choose/pick the file

..unless it's a directory, in which case we navigate into the directory
instead, as you would expect.
This commit is contained in:
Andreas Kling 2019-08-09 23:45:04 +02:00
parent d31ddf9aaa
commit db6ed8eebd

View file

@ -142,7 +142,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
on_file_return();
};
m_view->on_activation = [this](auto& index) {
m_view->on_selection = [this](auto& index) {
auto& filter_model = (GSortingProxyModel&)*m_view->model();
auto local_index = filter_model.map_to_target(index);
const GDirectoryModel::Entry& entry = m_model->entry(local_index.row());
@ -150,13 +150,9 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
clear_preview();
if (entry.is_directory()) {
m_model->open(path.string());
// NOTE: 'entry' is invalid from here on
} else {
if (!entry.is_directory())
m_filename_textbox->set_text(entry.name);
set_preview(path);
}
set_preview(path);
};
auto* button_container = new GWidget(lower_container);
@ -182,6 +178,20 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
on_file_return();
};
m_view->on_activation = [this](auto& index) {
auto& filter_model = (GSortingProxyModel&)*m_view->model();
auto local_index = filter_model.map_to_target(index);
const GDirectoryModel::Entry& entry = m_model->entry(local_index.row());
FileSystemPath path(String::format("%s/%s", m_model->path().characters(), entry.name.characters()));
if (entry.is_directory()) {
m_model->open(path.string());
// NOTE: 'entry' is invalid from here on
} else {
on_file_return();
}
};
auto* preview_container = new GFrame(horizontal_container);
preview_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
preview_container->set_preferred_size(180, 0);