ladybird/Userland/Libraries/LibGUI/SettingsWindow.h
Ali Mohammad Pur 5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30

88 lines
2.3 KiB
C++

/*
* Copyright (c) 2020, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021-2022, the SerenityOS developers.
* 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>
namespace GUI {
class SettingsWindow : public GUI::Window {
C_OBJECT(SettingsWindow)
public:
class Tab : public GUI::Widget {
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 {
Yes,
No,
};
static ErrorOr<NonnullRefPtr<SettingsWindow>> create(ByteString title, ShowDefaultsButton = ShowDefaultsButton::No);
virtual ~SettingsWindow() override = default;
template<class T, class... Args>
ErrorOr<NonnullRefPtr<T>> add_tab(String title, StringView id, Args&&... args)
{
auto tab = TRY(T::try_create(forward<Args>(args)...));
TRY(add_tab(tab, title, id));
return tab;
}
ErrorOr<void> add_tab(NonnullRefPtr<Tab> const& tab, String title, StringView id)
{
tab->set_title(move(title));
TRY(m_tab_widget->try_add_widget(*tab));
TRY(m_tabs.try_set(id, tab));
tab->set_settings_window(*this);
return {};
}
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;
RefPtr<GUI::TabWidget> m_tab_widget;
HashMap<StringView, NonnullRefPtr<Tab>> m_tabs;
RefPtr<GUI::Button> m_ok_button;
RefPtr<GUI::Button> m_cancel_button;
RefPtr<GUI::Button> m_apply_button;
RefPtr<GUI::Button> m_reset_button;
};
}