gtk_completion_popup.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #ifdef LUMACS_WITH_GTK
  3. #include <gtkmm.h>
  4. #include <vector>
  5. #include <string>
  6. #include "lumacs/completion_common.hpp" // For CompletionCandidate
  7. namespace lumacs {
  8. /// @brief A GTK widget that displays a list of completion candidates in a popup.
  9. class GtkCompletionPopup : public Gtk::Window {
  10. public:
  11. GtkCompletionPopup();
  12. ~GtkCompletionPopup() override;
  13. /// @brief Displays the completion popup with the given candidates.
  14. /// @param candidates The list of completion candidates to display.
  15. /// @param active_index The index of the currently active candidate.
  16. /// @param attach_widget The widget to attach the popup to (e.g., the minibuffer).
  17. /// @param x_pos The x-coordinate relative to the attach_widget for positioning.
  18. /// @param y_pos The y-coordinate relative to the attach_widget for positioning.
  19. void show_popup(const std::vector<CompletionCandidate>& candidates, size_t active_index, Gtk::Widget& attach_widget, int x_pos, int y_pos);
  20. /// @brief Hides the completion popup.
  21. void hide_popup();
  22. /// @brief Navigates to the next candidate in the list.
  23. void select_next();
  24. /// @brief Navigates to the previous candidate in the list.
  25. void select_previous();
  26. /// @brief Returns the currently selected candidate, if any.
  27. std::optional<CompletionCandidate> get_selected_candidate() const;
  28. /// Signals
  29. using type_signal_candidate_selected = sigc::signal<void, CompletionCandidate>;
  30. type_signal_candidate_selected signal_candidate_selected();
  31. using type_signal_cancelled = sigc::signal<void>;
  32. type_signal_cancelled signal_cancelled();
  33. protected:
  34. // Signal handlers
  35. void on_row_activated(Gtk::ListBoxRow* row);
  36. private:
  37. Gtk::ScrolledWindow list_scrolled_window_;
  38. Gtk::ListBox list_box_;
  39. std::vector<CompletionCandidate> candidates_;
  40. size_t active_index_;
  41. type_signal_candidate_selected signal_candidate_selected_;
  42. type_signal_cancelled signal_cancelled_;
  43. // Helper to update the displayed list and selection
  44. void update_list();
  45. void set_active_row(size_t index);
  46. };
  47. } // namespace lumacs
  48. #endif // LUMACS_WITH_GTK