WizardDialog.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #pragma once
  8. #include <AK/NonnullRefPtrVector.h>
  9. #include <LibGUI/Dialog.h>
  10. #include <LibGUI/Wizards/AbstractWizardPage.h>
  11. namespace GUI {
  12. class WizardDialog : public Dialog {
  13. C_OBJECT(WizardDialog)
  14. public:
  15. virtual ~WizardDialog() override = default;
  16. static void show(AbstractWizardPage& first_page, Window* parent_window = nullptr)
  17. {
  18. auto dialog = WizardDialog::construct(parent_window);
  19. dialog->push_page(first_page);
  20. dialog->exec();
  21. }
  22. Function<void()> on_cancel;
  23. /// Push a page onto the page stack and display it, preserving the previous page on the stack.
  24. void push_page(AbstractWizardPage& page);
  25. /// Replace the current page on the stack with a new page, preventing the user from returning to the current page.
  26. void replace_page(AbstractWizardPage& page);
  27. void pop_page();
  28. AbstractWizardPage& current_page();
  29. inline bool has_pages() const { return !m_page_stack.is_empty(); }
  30. protected:
  31. WizardDialog(Window* parent_window);
  32. virtual void handle_cancel();
  33. private:
  34. void update_navigation();
  35. RefPtr<Widget> m_page_container_widget;
  36. RefPtr<Button> m_back_button;
  37. RefPtr<Button> m_next_button;
  38. RefPtr<Button> m_cancel_button;
  39. NonnullRefPtrVector<AbstractWizardPage> m_page_stack;
  40. };
  41. }