window_manager.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include <memory>
  3. #include <vector>
  4. #include <list> // For std::list
  5. #include "lumacs/window.hpp" // For Window and LayoutNode
  6. #include "lumacs/buffer.hpp" // For shared_ptr<Buffer>
  7. #include "lumacs/i_window_manager.hpp"
  8. namespace lumacs {
  9. class EditorCore; // Forward declaration
  10. class BufferManager; // Forward declaration
  11. class IEditorNotifier;
  12. /// @brief Manages the layout and interaction of editor windows.
  13. class WindowManager : public IWindowManager {
  14. public:
  15. WindowManager(IEditorNotifier& notifier, BufferManager& buffer_manager);
  16. /// @brief Get the currently active window.
  17. /// @return A shared pointer to the active window.
  18. [[nodiscard]] std::shared_ptr<Window> active_window() const override;
  19. /// @brief Set the currently active window.
  20. /// @param window A shared pointer to the window to make active.
  21. /// @return True if the window was set as active, false otherwise.
  22. bool set_active_window(std::shared_ptr<Window> window);
  23. /// @brief Splits the active window horizontally, creating a new window below it.
  24. void split_horizontally();
  25. /// @brief Splits the active window vertically, creating a new window to its right.
  26. void split_vertically();
  27. /// @brief Closes the active window. If it's the last window, it's not closed.
  28. void close_active_window();
  29. /// @brief Cycles focus to the next window in the layout.
  30. void next_window();
  31. /// @brief Get the root node of the window layout tree.
  32. [[nodiscard]] std::shared_ptr<LayoutNode> root_layout() const override { return root_node_; }
  33. /// @brief Helper to collect all windows in traversal order.
  34. /// @param node The current node to traverse.
  35. /// @param windows The vector to populate with windows.
  36. void collect_windows(LayoutNode* node, std::vector<std::shared_ptr<Window>>& windows) override;
  37. private:
  38. IEditorNotifier& notifier_;
  39. BufferManager& buffer_manager_;
  40. std::shared_ptr<LayoutNode> root_node_;
  41. std::shared_ptr<Window> active_window_;
  42. // Helper functions for tree manipulation
  43. LayoutNode* find_parent_of_node(LayoutNode* current, LayoutNode* child_target);
  44. LayoutNode* find_node_with_window(LayoutNode* current, std::shared_ptr<Window> target);
  45. bool replace_window_node(std::shared_ptr<LayoutNode> node,
  46. std::shared_ptr<Window> target,
  47. std::shared_ptr<LayoutNode> replacement);
  48. };
  49. } // namespace lumacs