| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #pragma once
- #ifdef LUMACS_WITH_GTK
- #include <gtkmm.h>
- #include <vector>
- #include <string>
- #include "lumacs/completion_common.hpp" // For CompletionCandidate
- namespace lumacs {
- /// @brief A GTK widget that displays a list of completion candidates in a popup.
- class GtkCompletionPopup : public Gtk::Window {
- public:
- GtkCompletionPopup();
- ~GtkCompletionPopup() override;
- /// @brief Displays the completion popup with the given candidates.
- /// @param candidates The list of completion candidates to display.
- /// @param active_index The index of the currently active candidate.
- /// @param attach_widget The widget to attach the popup to (e.g., the minibuffer).
- /// @param x_pos The x-coordinate relative to the attach_widget for positioning.
- /// @param y_pos The y-coordinate relative to the attach_widget for positioning.
- void show_popup(const std::vector<CompletionCandidate>& candidates, size_t active_index, Gtk::Widget& attach_widget, int x_pos, int y_pos);
- /// @brief Hides the completion popup.
- void hide_popup();
- /// @brief Navigates to the next candidate in the list.
- void select_next();
- /// @brief Navigates to the previous candidate in the list.
- void select_previous();
- /// @brief Returns the currently selected candidate, if any.
- std::optional<CompletionCandidate> get_selected_candidate() const;
- /// Signals
- using type_signal_candidate_selected = sigc::signal<void, CompletionCandidate>;
- type_signal_candidate_selected signal_candidate_selected();
- using type_signal_cancelled = sigc::signal<void>;
- type_signal_cancelled signal_cancelled();
- protected:
- // Signal handlers
- void on_row_activated(Gtk::ListBoxRow* row);
- private:
- Gtk::ScrolledWindow list_scrolled_window_;
- Gtk::ListBox list_box_;
- std::vector<CompletionCandidate> candidates_;
- size_t active_index_;
- type_signal_candidate_selected signal_candidate_selected_;
- type_signal_cancelled signal_cancelled_;
- // Helper to update the displayed list and selection
- void update_list();
- void set_active_row(size_t index);
- };
- } // namespace lumacs
- #endif // LUMACS_WITH_GTK
|