diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-04-29 17:00:24 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-05-12 13:10:49 +0200 |
commit | 4f9f948b6db5531f3e56f5f8cb277ad005580350 (patch) | |
tree | 0c9070aa95ab6555f1882b8c9c6517f813fb6787 /Userland/Libraries/LibGUI/SettingsWindow.h | |
parent | ebbbca98fab810587787683dce66e8cb8168eabb (diff) | |
download | serenity-4f9f948b6db5531f3e56f5f8cb277ad005580350.zip |
LibGUI: Support "modified" window state in SettingsWindow
SettingsWindow now notices if the window is marked as modified, and
shows a confirmation pop-up to check if the user wants to apply or
discard their changes. It automatically marks the window as unmodified
after restoring defaults or applying the changes, but each Tab subclass
needs to call `set_modified(true)` when the user modifies things.
The "Apply" button is automatically disabled when there are no unsaved
changes to be applied.
Diffstat (limited to 'Userland/Libraries/LibGUI/SettingsWindow.h')
-rw-r--r-- | Userland/Libraries/LibGUI/SettingsWindow.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/SettingsWindow.h b/Userland/Libraries/LibGUI/SettingsWindow.h index 05b9a4748d..1d2471ae85 100644 --- a/Userland/Libraries/LibGUI/SettingsWindow.h +++ b/Userland/Libraries/LibGUI/SettingsWindow.h @@ -23,6 +23,18 @@ public: virtual void apply_settings() = 0; virtual void cancel_settings() { } virtual void reset_default_values() { } + + SettingsWindow& settings_window() { return *m_window; } + void set_settings_window(SettingsWindow& settings_window) { m_window = settings_window; } + + void set_modified(bool modified) + { + if (m_window) + m_window->set_modified(modified); + } + + private: + WeakPtr<SettingsWindow> m_window; }; enum class ShowDefaultsButton { @@ -39,12 +51,19 @@ public: { auto tab = TRY(m_tab_widget->try_add_tab<T>(move(title), forward<Args>(args)...)); TRY(m_tabs.try_set(id, tab)); + tab->set_settings_window(*this); return tab; } Optional<NonnullRefPtr<Tab>> get_tab(StringView id) const; void set_active_tab(StringView id); + void apply_settings(); + void cancel_settings(); + void reset_default_values(); + + void set_modified(bool); + private: SettingsWindow() = default; |