FileManager: Make DirectoryView listen for configuration changes

DirectoryView now inherits from Config::Listener and will update its
view mode immediately if changed from elsewhere.

This is pretty neat. :^)
This commit is contained in:
Andreas Kling 2021-08-26 19:15:55 +02:00
parent c8c58626e9
commit 696dbc889f
Notes: sideshowbarker 2024-07-18 05:15:01 +09:00
3 changed files with 18 additions and 1 deletions

View File

@ -340,6 +340,17 @@ void DirectoryView::set_view_mode_from_string(String const& mode)
}
}
void DirectoryView::config_string_did_change(String const& domain, String const& group, String const& key, String const& value)
{
if (domain != "FileManager" || group != "DirectoryView")
return;
if (key == "ViewMode") {
set_view_mode_from_string(value);
return;
}
}
void DirectoryView::set_view_mode(ViewMode mode)
{
if (m_view_mode == mode)

View File

@ -8,6 +8,7 @@
#include <AK/URL.h>
#include <AK/Vector.h>
#include <LibConfig/Listener.h>
#include <LibDesktop/Launcher.h>
#include <LibGUI/Action.h>
#include <LibGUI/ColumnsView.h>
@ -38,7 +39,8 @@ private:
class DirectoryView final
: public GUI::StackWidget
, private GUI::ModelClient {
, private GUI::ModelClient
, public Config::Listener {
C_OBJECT(DirectoryView);
public:
@ -130,6 +132,9 @@ public:
GUI::Action& view_as_table_action() { return *m_view_as_table_action; }
GUI::Action& view_as_columns_action() { return *m_view_as_columns_action; }
// ^Config::Listener
virtual void config_string_did_change(String const& domain, String const& group, String const& key, String const& value) override;
private:
explicit DirectoryView(Mode);

View File

@ -92,6 +92,7 @@ int main(int argc, char** argv)
}
Config::pledge_domains({ "FileManager", "WindowManager" });
Config::monitor_domain("FileManager");
if (is_desktop_mode)
return run_in_desktop_mode();