#pragma once #include "dispatcher.h" #include "tooltips.h" #include #include class Autocomplete { Gtk::TextView *view; bool &interactive_completion; /// Some libraries/utilities, like libclang, require that autocomplete is started at the beginning of a word bool strip_word; Dispatcher dispatcher; public: enum class State { IDLE, STARTING, RESTARTING, CANCELED }; std::string prefix; std::mutex prefix_mutex; std::vector rows; Tooltips tooltips; std::atomic state; std::thread thread; std::function is_processing = [] { return true; }; std::function reparse = [] {}; std::function cancel_reparse = [] {}; std::function>()> get_parse_lock = [] { return nullptr; }; std::function stop_parse = [] {}; std::function is_continue_key = [](guint) { return false; }; std::function is_restart_key = [](guint) { return false; }; std::function run_check = [] { return false; }; std::function before_add_rows = [] {}; std::function after_add_rows = [] {}; std::function on_add_rows_error = [] {}; /// The handler is not run in the main loop. std::function add_rows = [](std::string &, int, int) {}; std::function on_show = [] {}; std::function on_hide = [] {}; std::function on_changed = [](unsigned int index, const std::string &text) {}; std::function on_select = [](unsigned int index, const std::string &text, bool hide_window) {}; std::function get_tooltip = [](unsigned int index) { return std::string(); }; Autocomplete(Gtk::TextView *view, bool &interactive_completion, guint &last_keyval, bool strip_word); void run(); void stop(); private: void setup_dialog(); };