#pragma once #include "gtkmm.h" #include class SelectionDialogBase { class ListViewText : public Gtk::TreeView { class ColumnRecord : public Gtk::TreeModel::ColumnRecord { public: ColumnRecord() { add(text); add(index); } Gtk::TreeModelColumn text; Gtk::TreeModelColumn index; }; public: bool use_markup; ColumnRecord column_record; ListViewText(bool use_markup); void append(const std::string& value); void clear(); private: Glib::RefPtr list_store; Gtk::CellRendererText cell_renderer; unsigned int size=0; }; class SearchEntry : public Gtk::Entry { public: SearchEntry() : Gtk::Entry() {} bool on_key_press_event(GdkEventKey *event) override { return Gtk::Entry::on_key_press_event(event); }; }; public: SelectionDialogBase(Gtk::TextView *text_view, Glib::RefPtr start_mark, bool show_search_entry, bool use_markup); virtual ~SelectionDialogBase(); void add_row(const std::string& row); void set_cursor_at_last_row(); void show(); void hide(); bool is_visible() {return window.is_visible();} void get_position(int &root_x, int &root_y) {window.get_position(root_x, root_y);} std::function on_show; std::function on_hide; std::function on_select; std::function on_changed; Glib::RefPtr start_mark; protected: void cursor_changed(); Gtk::TextView *text_view; Gtk::Window window; Gtk::Box vbox; Gtk::ScrolledWindow scrolled_window; ListViewText list_view_text; SearchEntry search_entry; bool show_search_entry; unsigned int last_index=static_cast(-1); }; class SelectionDialog : public SelectionDialogBase { SelectionDialog(Gtk::TextView *text_view, Glib::RefPtr start_mark, bool show_search_entry, bool use_markup); static std::unique_ptr instance; public: bool on_key_press(GdkEventKey* key); static void create(Gtk::TextView *text_view, Glib::RefPtr start_mark, bool show_search_entry=true, bool use_markup=false) { instance=std::unique_ptr(new SelectionDialog(text_view, start_mark, show_search_entry, use_markup)); } static void create(bool show_search_entry=true, bool use_markup=false) { instance=std::unique_ptr(new SelectionDialog(nullptr, Glib::RefPtr(), show_search_entry, use_markup)); } static std::unique_ptr &get() {return instance;} }; class CompletionDialog : public SelectionDialogBase { CompletionDialog(Gtk::TextView *text_view, Glib::RefPtr start_mark); static std::unique_ptr instance; public: bool on_key_release(GdkEventKey* key); bool on_key_press(GdkEventKey* key); static void create(Gtk::TextView *text_view, Glib::RefPtr start_mark) { instance=std::unique_ptr(new CompletionDialog(text_view, start_mark)); } static std::unique_ptr &get() {return instance;} private: void select(bool hide_window=true); int show_offset; bool row_in_entry=false; };