From 31bef80530edbf622a6678947dc832bc179b52fb Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 20 Dec 2020 22:10:45 -0500 Subject: add mention/emoji/channel completion --- components/completer.hpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 components/completer.hpp (limited to 'components/completer.hpp') diff --git a/components/completer.hpp b/components/completer.hpp new file mode 100644 index 0000000..259fcdc --- /dev/null +++ b/components/completer.hpp @@ -0,0 +1,61 @@ +#pragma once +#include +#include +#include "../discord/snowflake.hpp" + +class CompleterEntry : public Gtk::ListBoxRow { +public: + CompleterEntry(const Glib::ustring &completion, int index); + void SetTextColor(int color); // SetText will reset + void SetText(const Glib::ustring &text); + void SetImage(const Glib::RefPtr &pb); + + int GetIndex() const; + Glib::ustring GetCompletion() const; + +private: + Glib::ustring m_completion; + int m_index; + Gtk::Box m_box; + Gtk::Label *m_text = nullptr; + Gtk::Image *m_img = nullptr; +}; + +class Completer : public Gtk::Revealer { +public: + Completer(); + Completer(const Glib::RefPtr &buf); + + void SetBuffer(const Glib::RefPtr &buf); + bool ProcessKeyPress(GdkEventKey *e); + + using get_recent_authors_cb = std::function()>; + void SetGetRecentAuthors(get_recent_authors_cb cb); // maybe a better way idk + using get_channel_id_cb = std::function; + void SetGetChannelID(get_channel_id_cb cb); + + bool IsShown() const; + +private: + CompleterEntry *CreateEntry(const Glib::ustring &completion); + void CompleteMentions(const Glib::ustring &term); + void CompleteEmojis(const Glib::ustring &term); + void CompleteChannels(const Glib::ustring &term); + void DoCompletion(Gtk::ListBoxRow *row); + + std::vector m_entries; + + void OnRowActivate(Gtk::ListBoxRow *row); + void OnTextBufferChanged(); + Glib::ustring GetTerm(); + + Gtk::TextBuffer::iterator m_start; + Gtk::TextBuffer::iterator m_end; + + Gtk::ScrolledWindow m_scroll; + Gtk::ListBox m_list; + Glib::RefPtr m_buf; + + get_recent_authors_cb m_recent_authors_cb; + get_channel_id_cb m_channel_id_cb; +}; -- cgit v1.2.3