mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 22:05:06 +00:00
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:
parent
4d2e18fb07
commit
ded5ba1f87
9 changed files with 35 additions and 34 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue