summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-08-26 19:14:12 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-26 23:41:38 +0200
commitc8c58626e9eb09136ea7a558e681ce6e98510690 (patch)
treedd1b1855b2d0fc9472795fcecf85b97f1a3e4c8c
parentedf784340999b6e8f44241e04e6d6f8afc27be29 (diff)
downloadserenity-c8c58626e9eb09136ea7a558e681ce6e98510690.zip
FileManager: Move "View as ViewType" actions into DirectoryView
Let DirectoryView manage these actions itself. This matches what we already do for a bunch of other actions, and prepares for the next patch which will add Config::Listener to the mix.
-rw-r--r--Userland/Applications/FileManager/DirectoryView.cpp41
-rw-r--r--Userland/Applications/FileManager/DirectoryView.h9
-rw-r--r--Userland/Applications/FileManager/main.cpp62
3 files changed, 62 insertions, 50 deletions
diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp
index 35bf4a5f07..45dc8cf635 100644
--- a/Userland/Applications/FileManager/DirectoryView.cpp
+++ b/Userland/Applications/FileManager/DirectoryView.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
@@ -10,6 +10,7 @@
#include <AK/LexicalPath.h>
#include <AK/NumberFormat.h>
#include <AK/StringBuilder.h>
+#include <LibConfig/Client.h>
#include <LibCore/File.h>
#include <LibCore/MimeData.h>
#include <LibCore/StandardPaths.h>
@@ -322,6 +323,23 @@ void DirectoryView::model_did_update(unsigned flags)
update_statusbar();
}
+void DirectoryView::set_view_mode_from_string(String const& mode)
+{
+ if (m_mode == Mode::Desktop)
+ return;
+
+ if (mode.contains("Table")) {
+ set_view_mode(DirectoryView::ViewMode::Table);
+ m_view_as_table_action->set_checked(true);
+ } else if (mode.contains("Columns")) {
+ set_view_mode(DirectoryView::ViewMode::Columns);
+ m_view_as_columns_action->set_checked(true);
+ } else {
+ set_view_mode(DirectoryView::ViewMode::Icon);
+ m_view_as_icons_action->set_checked(true);
+ }
+}
+
void DirectoryView::set_view_mode(ViewMode mode)
{
if (m_view_mode == mode)
@@ -552,6 +570,27 @@ void DirectoryView::setup_actions()
"Delete Without Confirmation", { Mod_Shift, Key_Delete },
[this](auto&) { do_delete(false); },
window());
+
+ m_view_as_icons_action = GUI::Action::create_checkable(
+ "View as &Icons", { Mod_Ctrl, KeyCode::Key_1 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/icon-view.png"), [&](GUI::Action const&) {
+ set_view_mode(DirectoryView::ViewMode::Icon);
+ Config::write_string("FileManager", "DirectoryView", "ViewMode", "Icon");
+ },
+ window());
+
+ m_view_as_table_action = GUI::Action::create_checkable(
+ "View as &Table", { Mod_Ctrl, KeyCode::Key_2 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/table-view.png"), [&](GUI::Action const&) {
+ set_view_mode(DirectoryView::ViewMode::Table);
+ Config::write_string("FileManager", "DirectoryView", "ViewMode", "Table");
+ },
+ window());
+
+ m_view_as_columns_action = GUI::Action::create_checkable(
+ "View as &Columns", { Mod_Ctrl, KeyCode::Key_3 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/columns-view.png"), [&](GUI::Action const&) {
+ set_view_mode(DirectoryView::ViewMode::Columns);
+ Config::write_string("FileManager", "DirectoryView", "ViewMode", "Columns");
+ },
+ window());
}
void DirectoryView::handle_drop(GUI::ModelIndex const& index, GUI::DropEvent const& event)
diff --git a/Userland/Applications/FileManager/DirectoryView.h b/Userland/Applications/FileManager/DirectoryView.h
index 5410dec6a5..e652bfe9d6 100644
--- a/Userland/Applications/FileManager/DirectoryView.h
+++ b/Userland/Applications/FileManager/DirectoryView.h
@@ -80,6 +80,8 @@ public:
void set_view_mode(ViewMode);
ViewMode view_mode() const { return m_view_mode; }
+ void set_view_mode_from_string(String const&);
+
GUI::AbstractView& current_view()
{
switch (m_view_mode) {
@@ -124,6 +126,9 @@ public:
GUI::Action& delete_action() { return *m_delete_action; }
GUI::Action& force_delete_action() { return *m_force_delete_action; }
GUI::Action& rename_action() { return *m_rename_action; }
+ GUI::Action& view_as_icons_action() { return *m_view_as_icons_action; }
+ GUI::Action& view_as_table_action() { return *m_view_as_table_action; }
+ GUI::Action& view_as_columns_action() { return *m_view_as_columns_action; }
private:
explicit DirectoryView(Mode);
@@ -170,6 +175,10 @@ private:
RefPtr<GUI::Action> m_delete_action;
RefPtr<GUI::Action> m_force_delete_action;
RefPtr<GUI::Action> m_rename_action;
+
+ RefPtr<GUI::Action> m_view_as_table_action;
+ RefPtr<GUI::Action> m_view_as_icons_action;
+ RefPtr<GUI::Action> m_view_as_columns_action;
};
}
diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp
index e5fb98c96d..0de4992110 100644
--- a/Userland/Applications/FileManager/main.cpp
+++ b/Userland/Applications/FileManager/main.cpp
@@ -601,36 +601,11 @@ int run_in_windowed_mode(String initial_location, String entry_focused_on_init)
location_toolbar.set_visible(false);
};
- RefPtr<GUI::Action> view_as_table_action;
- RefPtr<GUI::Action> view_as_icons_action;
- RefPtr<GUI::Action> view_as_columns_action;
-
- view_as_icons_action = GUI::Action::create_checkable(
- "View as &Icons", { Mod_Ctrl, KeyCode::Key_1 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/icon-view.png"), [&](GUI::Action const&) {
- directory_view.set_view_mode(DirectoryView::ViewMode::Icon);
- Config::write_string("FileManager", "DirectoryView", "ViewMode", "Icon");
- },
- window);
-
- view_as_table_action = GUI::Action::create_checkable(
- "View as &Table", { Mod_Ctrl, KeyCode::Key_2 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/table-view.png"), [&](GUI::Action const&) {
- directory_view.set_view_mode(DirectoryView::ViewMode::Table);
- Config::write_string("FileManager", "DirectoryView", "ViewMode", "Table");
- },
- window);
-
- view_as_columns_action = GUI::Action::create_checkable(
- "View as &Columns", { Mod_Ctrl, KeyCode::Key_3 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/columns-view.png"), [&](GUI::Action const&) {
- directory_view.set_view_mode(DirectoryView::ViewMode::Columns);
- Config::write_string("FileManager", "DirectoryView", "ViewMode", "Columns");
- },
- window);
-
auto view_type_action_group = make<GUI::ActionGroup>();
view_type_action_group->set_exclusive(true);
- view_type_action_group->add_action(*view_as_icons_action);
- view_type_action_group->add_action(*view_as_table_action);
- view_type_action_group->add_action(*view_as_columns_action);
+ view_type_action_group->add_action(directory_view.view_as_icons_action());
+ view_type_action_group->add_action(directory_view.view_as_table_action());
+ view_type_action_group->add_action(directory_view.view_as_columns_action());
auto tree_view_selected_file_paths = [&] {
Vector<String> paths;
@@ -876,9 +851,9 @@ int run_in_windowed_mode(String initial_location, String entry_focused_on_init)
view_menu.add_separator();
- view_menu.add_action(*view_as_icons_action);
- view_menu.add_action(*view_as_table_action);
- view_menu.add_action(*view_as_columns_action);
+ view_menu.add_action(directory_view.view_as_icons_action());
+ view_menu.add_action(directory_view.view_as_table_action());
+ view_menu.add_action(directory_view.view_as_columns_action());
view_menu.add_separator();
view_menu.add_action(action_show_dotfiles);
@@ -924,9 +899,9 @@ int run_in_windowed_mode(String initial_location, String entry_focused_on_init)
main_toolbar.add_action(paste_action);
main_toolbar.add_separator();
- main_toolbar.add_action(*view_as_icons_action);
- main_toolbar.add_action(*view_as_table_action);
- main_toolbar.add_action(*view_as_columns_action);
+ main_toolbar.add_action(directory_view.view_as_icons_action());
+ main_toolbar.add_action(directory_view.view_as_table_action());
+ main_toolbar.add_action(directory_view.view_as_columns_action());
directory_view.on_path_change = [&](String const& new_path, bool can_read_in_path, bool can_write_in_path) {
auto icon = GUI::FileIconProvider::icon_for_path(new_path);
@@ -1002,9 +977,9 @@ int run_in_windowed_mode(String initial_location, String entry_focused_on_init)
go_forward_action->set_enabled(directory_view.path_history_position() < directory_view.path_history_size() - 1);
go_back_action->set_enabled(directory_view.path_history_position() > 0);
open_parent_directory_action->set_enabled(new_path != "/");
- view_as_table_action->set_enabled(can_read_in_path);
- view_as_icons_action->set_enabled(can_read_in_path);
- view_as_columns_action->set_enabled(can_read_in_path);
+ directory_view.view_as_table_action().set_enabled(can_read_in_path);
+ directory_view.view_as_icons_action().set_enabled(can_read_in_path);
+ directory_view.view_as_columns_action().set_enabled(can_read_in_path);
};
directory_view.on_accepted_drop = [&] {
@@ -1199,18 +1174,7 @@ int run_in_windowed_mode(String initial_location, String entry_focused_on_init)
window->show();
- auto dir_view_mode = Config::read_string("FileManager", "DirectoryView", "ViewMode", "Icon");
-
- if (dir_view_mode.contains("Table")) {
- directory_view.set_view_mode(DirectoryView::ViewMode::Table);
- view_as_table_action->set_checked(true);
- } else if (dir_view_mode.contains("Columns")) {
- directory_view.set_view_mode(DirectoryView::ViewMode::Columns);
- view_as_columns_action->set_checked(true);
- } else {
- directory_view.set_view_mode(DirectoryView::ViewMode::Icon);
- view_as_icons_action->set_checked(true);
- }
+ directory_view.set_view_mode_from_string(Config::read_string("FileManager", "DirectoryView", "ViewMode", "Icon"));
if (!entry_focused_on_init.is_empty()) {
auto matches = directory_view.current_view().model()->matches(entry_focused_on_init, GUI::Model::MatchesFlag::MatchFull | GUI::Model::MatchesFlag::FirstMatchOnly);