mode_activator.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include "lumacs/ui_interface.hpp"
  3. #include <functional>
  4. namespace lumacs {
  5. // Forward declarations
  6. class EditorCore;
  7. /// @brief Handles the common mode activation logic for editor events.
  8. ///
  9. /// This class centralizes the minibuffer activation code that was previously
  10. /// duplicated between TUI and GTK frontends. It provides default callbacks
  11. /// for each mode while allowing frontends to customize quit behavior.
  12. class ModeActivator {
  13. public:
  14. /// @brief Callback invoked when the user confirms quitting.
  15. using QuitCallback = std::function<void()>;
  16. explicit ModeActivator(EditorCore& core);
  17. /// @brief Handle a mode-related editor event.
  18. /// @param event The editor event to handle.
  19. /// @param quit_callback Callback to invoke for quit commands (nullptr to ignore quit).
  20. /// @return true if the event was handled, false otherwise.
  21. bool handle_mode_event(EditorEvent event, QuitCallback quit_callback = nullptr);
  22. private:
  23. EditorCore& core_;
  24. void activate_command_mode(QuitCallback quit_callback);
  25. void activate_buffer_switch_mode();
  26. void activate_kill_buffer_mode();
  27. void activate_find_file_mode();
  28. void activate_theme_selection_mode();
  29. void activate_isearch_mode(bool forward);
  30. };
  31. } // namespace lumacs