WizardDialog.h 1.4 KB

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