Serenity Operating System
1/*
2 * Copyright (c) 2021, Nick Vella <nick@nxk.io>
3 * Copyright (c) 2022, the SerenityOS developers.
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#pragma once
9
10#include <LibGUI/Dialog.h>
11#include <LibGUI/Wizards/AbstractWizardPage.h>
12
13namespace GUI {
14
15class WizardDialog : public Dialog {
16 C_OBJECT(WizardDialog)
17public:
18 virtual ~WizardDialog() override = default;
19
20 static void show(AbstractWizardPage& first_page, Window* parent_window = nullptr)
21 {
22 auto dialog = WizardDialog::construct(parent_window);
23 dialog->push_page(first_page);
24 dialog->exec();
25 }
26
27 Function<void()> on_cancel;
28
29 /// Push a page onto the page stack and display it, preserving the previous page on the stack.
30 void push_page(AbstractWizardPage& page);
31 /// Replace the current page on the stack with a new page, preventing the user from returning to the current page.
32 void replace_page(AbstractWizardPage& page);
33 void pop_page();
34 AbstractWizardPage& current_page();
35
36 inline bool has_pages() const { return !m_page_stack.is_empty(); }
37
38protected:
39 WizardDialog(Window* parent_window);
40
41 virtual void handle_cancel();
42
43private:
44 void update_navigation();
45
46 RefPtr<Widget> m_page_container_widget;
47 RefPtr<Button> m_back_button;
48 RefPtr<Button> m_next_button;
49 RefPtr<Button> m_cancel_button;
50
51 Vector<NonnullRefPtr<AbstractWizardPage>> m_page_stack;
52};
53}