diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-09 15:51:57 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-09 15:51:57 +0200 |
commit | e569ef6412549b1e6eb1394d75a7d55a93c6f55d (patch) | |
tree | 3dc19260d8c33a749de651bfb39e1a37cc89de4c /LibGUI | |
parent | fa232ac1801e398bdd3d254e62c26a783de6a225 (diff) | |
download | serenity-e569ef6412549b1e6eb1394d75a7d55a93c6f55d.zip |
GFilePicker: Add a button for moving up to parent directory.
Diffstat (limited to 'LibGUI')
-rw-r--r-- | LibGUI/GFilePicker.cpp | 25 | ||||
-rw-r--r-- | LibGUI/GSortingProxyModel.cpp | 5 |
2 files changed, 25 insertions, 5 deletions
diff --git a/LibGUI/GFilePicker.cpp b/LibGUI/GFilePicker.cpp index bc54d99601..c93eebb563 100644 --- a/LibGUI/GFilePicker.cpp +++ b/LibGUI/GFilePicker.cpp @@ -5,6 +5,8 @@ #include <LibGUI/GLabel.h> #include <LibGUI/GButton.h> #include <LibGUI/GSortingProxyModel.h> +#include <LibGUI/GAction.h> +#include <LibGUI/GToolBar.h> #include <AK/FileSystemPath.h> GFilePicker::GFilePicker(const String& path, CObject* parent) @@ -19,10 +21,22 @@ GFilePicker::GFilePicker(const String& path, CObject* parent) main_widget()->layout()->set_spacing(4); main_widget()->set_fill_with_background_color(true); main_widget()->set_background_color(Color::LightGray); - m_view = new GTableView(main_widget()); + + auto* upper_container = new GWidget(main_widget()); + upper_container->set_layout(make<GBoxLayout>(Orientation::Vertical)); + upper_container->layout()->set_spacing(4); + + auto* toolbar = new GToolBar(upper_container); + + m_view = new GTableView(upper_container); m_view->set_model(GSortingProxyModel::create(*m_model)); m_model->open(path); + auto open_parent_directory_action = GAction::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [this] (const GAction&) { + m_model->open(String::format("%s/..", m_model->path().characters())); + }); + toolbar->add_action(*open_parent_directory_action); + auto* lower_container = new GWidget(main_widget()); lower_container->set_layout(make<GBoxLayout>(Orientation::Vertical)); lower_container->layout()->set_spacing(4); @@ -39,16 +53,19 @@ GFilePicker::GFilePicker(const String& path, CObject* parent) filename_label->set_preferred_size({ 60, 0 }); auto* filename_textbox = new GTextBox(filename_container); - m_view->on_activation = [&] (auto& index) { + m_view->on_activation = [this, filename_textbox] (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()) + if (entry.is_directory()) { m_model->open(path.string()); - filename_textbox->set_text(entry.name); + // NOTE: 'entry' is invalid from here on + } else { + filename_textbox->set_text(entry.name); + } }; auto* button_container = new GWidget(lower_container); diff --git a/LibGUI/GSortingProxyModel.cpp b/LibGUI/GSortingProxyModel.cpp index 380748fc49..edc3189f89 100644 --- a/LibGUI/GSortingProxyModel.cpp +++ b/LibGUI/GSortingProxyModel.cpp @@ -78,8 +78,10 @@ void GSortingProxyModel::resort() m_row_mappings.resize(row_count); for (int i = 0; i < row_count; ++i) m_row_mappings[i] = i; - if (m_key_column == -1) + if (m_key_column == -1) { + did_update(); return; + } quick_sort(m_row_mappings.begin(), m_row_mappings.end(), [&] (auto row1, auto row2) -> bool { auto data1 = target().data(target().index(row1, m_key_column), GModel::Role::Sort); auto data2 = target().data(target().index(row2, m_key_column), GModel::Role::Sort); @@ -90,6 +92,7 @@ void GSortingProxyModel::resort() }); if (previously_selected_target_row != -1) { // Preserve selection. + ASSERT(m_row_mappings.size() == row_count); for (int i = 0; i < row_count; ++i) { if (m_row_mappings[i] == previously_selected_target_row) { set_selected_index(index(i, 0)); |