From 9710c9742ca55986abc4cb7e9f21c95bc3ad4db0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 18 Jul 2020 18:46:37 +0200 Subject: [PATCH] LibGUI+FileManager: Add setting for showing/hiding dotfiles GUI::FileSystemModel can now be told to display (or not display) files whose name start with a dot (other than . and ..) --- Applications/FileManager/main.cpp | 4 ++++ Libraries/LibGUI/FileSystemModel.cpp | 10 +++++++++- Libraries/LibGUI/FileSystemModel.h | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 4f3a7e3088..474d7bf9db 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -655,6 +655,10 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio 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_separator(); + view_menu.add_action(GUI::Action::create_checkable("Show dotfiles", { Mod_Ctrl, Key_H }, [&](auto& action) { + directory_view.model().set_should_show_dotfiles(action.is_checked()); + })); auto& go_menu = menubar->add_menu("Go"); go_menu.add_action(go_back_action); diff --git a/Libraries/LibGUI/FileSystemModel.cpp b/Libraries/LibGUI/FileSystemModel.cpp index 2fc0913a60..bff0f5857e 100644 --- a/Libraries/LibGUI/FileSystemModel.cpp +++ b/Libraries/LibGUI/FileSystemModel.cpp @@ -91,7 +91,7 @@ void FileSystemModel::Node::traverse_if_needed(const FileSystemModel& model) total_size = 0; auto full_path = this->full_path(model); - Core::DirIterator di(full_path, Core::DirIterator::SkipDots); + Core::DirIterator di(full_path, model.should_show_dotfiles() ? Core::DirIterator::SkipParentAndBaseDir : Core::DirIterator::SkipDots); if (di.has_error()) { m_error = di.error(); fprintf(stderr, "DirIterator: %s\n", di.error_string()); @@ -600,4 +600,12 @@ bool FileSystemModel::accepts_drag(const ModelIndex& index, const StringView& da return node.is_directory(); } +void FileSystemModel::set_should_show_dotfiles(bool show) +{ + if (m_should_show_dotfiles == show) + return; + m_should_show_dotfiles = show; + update(); +} + } diff --git a/Libraries/LibGUI/FileSystemModel.h b/Libraries/LibGUI/FileSystemModel.h index 1ebbb8e39d..2dd020de29 100644 --- a/Libraries/LibGUI/FileSystemModel.h +++ b/Libraries/LibGUI/FileSystemModel.h @@ -162,6 +162,9 @@ public: return Core::DateTime::from_timestamp(timestamp).to_string(); } + bool should_show_dotfiles() const { return m_should_show_dotfiles; } + void set_should_show_dotfiles(bool); + private: FileSystemModel(const StringView& root_path, Mode); @@ -192,6 +195,8 @@ private: unsigned m_thumbnail_progress { 0 }; unsigned m_thumbnail_progress_total { 0 }; + + bool m_should_show_dotfiles { false }; }; }