window_manager.hpp 2.2 KB

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