gtk_completion_popup.hpp 2.1 KB

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