LibGUI+Applications: Give SettingsWindow tabs a string ID

This gives us a convenient way to refer to them, which will be used in
the following commit.
This commit is contained in:
Sam Atkins 2022-04-21 15:12:09 +01:00 committed by Linus Groh
parent 4d2e18fb07
commit ded5ba1f87
Notes: sideshowbarker 2024-07-17 11:36:45 +09:00
9 changed files with 35 additions and 34 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -28,8 +28,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto window = TRY(GUI::SettingsWindow::create("Browser Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
window->set_icon(app_icon.bitmap_for_size(16));
(void)TRY(window->add_tab<BrowserSettingsWidget>("Browser"));
(void)TRY(window->add_tab<ContentFilterSettingsWidget>("Content Filtering"));
(void)TRY(window->add_tab<BrowserSettingsWidget>("Browser", "browser"));
(void)TRY(window->add_tab<ContentFilterSettingsWidget>("Content Filtering", "content-filtering"));
window->show();
return app->exec();

View file

@ -29,8 +29,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app_icon = GUI::Icon::default_icon("app-analog-clock"); // FIXME: Create a ClockSettings icon.
auto window = TRY(GUI::SettingsWindow::create("Clock Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
(void)TRY(window->add_tab<ClockSettingsWidget>("Clock"));
(void)TRY(window->add_tab<TimeZoneSettingsWidget>("Time Zone"));
(void)TRY(window->add_tab<ClockSettingsWidget>("Clock", "clock"));
(void)TRY(window->add_tab<TimeZoneSettingsWidget>("Time Zone", "time-zone"));
window->set_icon(app_icon.bitmap_for_size(16));
window->resize(540, 570);

View file

@ -1,7 +1,7 @@
/*
* Copyright (c) 2019-2020, Jesse Buhagiar <jooster669@gmail.com>
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -30,11 +30,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
bool background_settings_changed = false;
auto window = TRY(GUI::SettingsWindow::create("Display Settings"));
(void)TRY(window->add_tab<DisplaySettings::BackgroundSettingsWidget>("Background", background_settings_changed));
(void)TRY(window->add_tab<DisplaySettings::ThemesSettingsWidget>("Themes", background_settings_changed));
(void)TRY(window->add_tab<DisplaySettings::FontSettingsWidget>("Fonts"));
(void)TRY(window->add_tab<DisplaySettings::MonitorSettingsWidget>("Monitor"));
(void)TRY(window->add_tab<DisplaySettings::DesktopSettingsWidget>("Workspaces"));
(void)TRY(window->add_tab<DisplaySettings::BackgroundSettingsWidget>("Background", "background", background_settings_changed));
(void)TRY(window->add_tab<DisplaySettings::ThemesSettingsWidget>("Themes", "themes", background_settings_changed));
(void)TRY(window->add_tab<DisplaySettings::FontSettingsWidget>("Fonts", "fonts"));
(void)TRY(window->add_tab<DisplaySettings::MonitorSettingsWidget>("Monitor", "monitor"));
(void)TRY(window->add_tab<DisplaySettings::DesktopSettingsWidget>("Workspaces", "workspaces"));
window->set_icon(app_icon.bitmap_for_size(16));

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -31,7 +31,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto window = TRY(GUI::SettingsWindow::create("Keyboard Settings"));
window->set_icon(app_icon.bitmap_for_size(16));
auto keyboard_settings_widget = TRY(window->add_tab<KeyboardSettingsWidget>("Keyboard"));
auto keyboard_settings_widget = TRY(window->add_tab<KeyboardSettingsWidget>("Keyboard", "keyboard"));
window->on_active_window_change = [&](bool is_active_window) {
keyboard_settings_widget->window_activated(is_active_window);

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -28,7 +28,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app_icon = GUI::Icon::default_icon("app-mail");
auto window = TRY(GUI::SettingsWindow::create("Mail Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
(void)TRY(window->add_tab<MailSettingsWidget>("Mail"));
(void)TRY(window->add_tab<MailSettingsWidget>("Mail", "mail"));
window->set_icon(app_icon.bitmap_for_size(16));
window->show();

View file

@ -2,7 +2,7 @@
* Copyright (c) 2020, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -26,8 +26,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app_icon = GUI::Icon::default_icon("app-mouse");
auto window = TRY(GUI::SettingsWindow::create("Mouse Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
(void)TRY(window->add_tab<MouseWidget>("Mouse"));
(void)TRY(window->add_tab<ThemeWidget>("Cursor Theme"));
(void)TRY(window->add_tab<MouseWidget>("Mouse", "mouse"));
(void)TRY(window->add_tab<ThemeWidget>("Cursor Theme", "cursor-theme"));
window->set_icon(app_icon.bitmap_for_size(16));
window->show();

View file

@ -28,8 +28,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto window = TRY(GUI::SettingsWindow::create("Terminal Settings"));
window->set_icon(app_icon.bitmap_for_size(16));
(void)TRY(window->add_tab<TerminalSettingsMainWidget>("Terminal"));
(void)TRY(window->add_tab<TerminalSettingsViewWidget>("View"));
(void)TRY(window->add_tab<TerminalSettingsMainWidget>("Terminal", "terminal"));
(void)TRY(window->add_tab<TerminalSettingsViewWidget>("View", "view"));
window->show();
return app->exec();

View file

@ -2,7 +2,7 @@
* Copyright (c) 2020, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021-2022, the SerenityOS developers.
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -41,9 +41,9 @@ ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(String title, Show
window->m_reset_button = TRY(button_container->try_add<GUI::Button>("Defaults"));
window->m_reset_button->set_fixed_width(75);
window->m_reset_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) mutable {
for (auto& tab : window->m_tabs) {
tab.reset_default_values();
tab.apply_settings();
for (auto& [id, tab] : window->m_tabs) {
tab->reset_default_values();
tab->apply_settings();
}
};
}
@ -53,24 +53,24 @@ ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(String title, Show
window->m_ok_button = TRY(button_container->try_add<GUI::Button>("OK"));
window->m_ok_button->set_fixed_width(75);
window->m_ok_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) mutable {
for (auto& tab : window->m_tabs)
tab.apply_settings();
for (auto& [id, tab] : window->m_tabs)
tab->apply_settings();
GUI::Application::the()->quit();
};
window->m_cancel_button = TRY(button_container->try_add<GUI::Button>("Cancel"));
window->m_cancel_button->set_fixed_width(75);
window->m_cancel_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) mutable {
for (auto& tab : window->m_tabs)
tab.cancel_settings();
for (auto& [id, tab] : window->m_tabs)
tab->cancel_settings();
GUI::Application::the()->quit();
};
window->m_apply_button = TRY(button_container->try_add<GUI::Button>("Apply"));
window->m_apply_button->set_fixed_width(75);
window->m_apply_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) mutable {
for (auto& tab : window->m_tabs)
tab.apply_settings();
for (auto& [id, tab] : window->m_tabs)
tab->apply_settings();
};
return window;

View file

@ -1,13 +1,14 @@
/*
* Copyright (c) 2020, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021-2022, the SerenityOS developers.
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <LibGUI/Button.h>
#include <LibGUI/TabWidget.h>
#include <LibGUI/Window.h>
@ -34,10 +35,10 @@ public:
virtual ~SettingsWindow() override = default;
template<class T, class... Args>
ErrorOr<NonnullRefPtr<T>> add_tab(String title, Args&&... args)
ErrorOr<NonnullRefPtr<T>> add_tab(String title, StringView id, Args&&... args)
{
auto tab = TRY(m_tab_widget->try_add_tab<T>(move(title), forward<Args>(args)...));
TRY(m_tabs.try_append(tab));
TRY(m_tabs.try_set(id, tab));
return tab;
}
@ -45,7 +46,7 @@ private:
SettingsWindow() = default;
RefPtr<GUI::TabWidget> m_tab_widget;
NonnullRefPtrVector<Tab> m_tabs;
HashMap<StringView, NonnullRefPtr<Tab>> m_tabs;
RefPtr<GUI::Button> m_ok_button;
RefPtr<GUI::Button> m_cancel_button;