diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-10-11 01:56:30 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-10-11 01:56:30 -0400 |
commit | 1ff177ad5a11f084acca616084021664f8201514 (patch) | |
tree | 0ecf71075af0a66a62ef58c2a395cc3dc9a06dc3 /components | |
parent | 059146b060e9cdd57f6ddbb9d6e6a17a2d6529f9 (diff) | |
download | abaddon-portaudio-1ff177ad5a11f084acca616084021664f8201514.tar.gz abaddon-portaudio-1ff177ad5a11f084acca616084021664f8201514.zip |
shift click on message author to insert mention
Diffstat (limited to 'components')
-rw-r--r-- | components/chatmessage.cpp | 18 | ||||
-rw-r--r-- | components/chatmessage.hpp | 9 | ||||
-rw-r--r-- | components/chatwindow.cpp | 7 | ||||
-rw-r--r-- | components/chatwindow.hpp | 3 |
4 files changed, 36 insertions, 1 deletions
diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index 39b6626..f804572 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -586,6 +586,7 @@ ChatMessageHeader::ChatMessageHeader(const Message *data) { m_main_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL)); m_content_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL)); m_meta_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL)); + m_author_ev = Gtk::manage(new Gtk::EventBox); m_author = Gtk::manage(new Gtk::Label); m_timestamp = Gtk::manage(new Gtk::Label); @@ -609,6 +610,7 @@ ChatMessageHeader::ChatMessageHeader(const Message *data) { m_author->set_ellipsize(Pango::ELLIPSIZE_END); m_author->set_xalign(0.f); m_author->set_can_focus(false); + m_author_ev->signal_button_press_event().connect(sigc::mem_fun(*this, &ChatMessageHeader::on_author_button_press)); if (data->WebhookID.IsValid()) { m_extra = Gtk::manage(new Gtk::Label); @@ -642,7 +644,8 @@ ChatMessageHeader::ChatMessageHeader(const Message *data) { m_content_box->set_can_focus(false); - m_meta_box->add(*m_author); + m_author_ev->add(*m_author); + m_meta_box->add(*m_author_ev); if (m_extra != nullptr) m_meta_box->add(*m_extra); m_meta_box->add(*m_timestamp); @@ -675,6 +678,19 @@ void ChatMessageHeader::UpdateNameColor() { m_author->set_markup(md); } +bool ChatMessageHeader::on_author_button_press(GdkEventButton *ev) { + if (ev->button == GDK_BUTTON_PRIMARY && (ev->state & GDK_SHIFT_MASK)) { + m_signal_action_insert_mention.emit(UserID); + return true; + } + + return false; +} + +ChatMessageHeader::type_signal_action_insert_mention ChatMessageHeader::signal_action_insert_mention() { + return m_signal_action_insert_mention; +} + void ChatMessageHeader::AddContent(Gtk::Widget *widget, bool prepend) { m_content_box->add(*widget); if (prepend) diff --git a/components/chatmessage.hpp b/components/chatmessage.hpp index 5fe60f3..35d4fea 100644 --- a/components/chatmessage.hpp +++ b/components/chatmessage.hpp @@ -92,11 +92,20 @@ public: void UpdateNameColor(); protected: + bool on_author_button_press(GdkEventButton *ev); + Gtk::Box *m_main_box; Gtk::Box *m_content_box; Gtk::Box *m_meta_box; + Gtk::EventBox *m_author_ev; Gtk::Label *m_author; Gtk::Label *m_timestamp; Gtk::Label *m_extra = nullptr; Gtk::Image *m_avatar; + + typedef sigc::signal<void, Snowflake> type_signal_action_insert_mention; + type_signal_action_insert_mention m_signal_action_insert_mention; + +public: + type_signal_action_insert_mention signal_action_insert_mention(); }; diff --git a/components/chatwindow.cpp b/components/chatwindow.cpp index 43f61bb..3943bd5 100644 --- a/components/chatwindow.cpp +++ b/components/chatwindow.cpp @@ -182,6 +182,9 @@ void ChatWindow::ProcessNewMessage(Snowflake id, bool prepend) { if (user == nullptr) return; header = Gtk::manage(new ChatMessageHeader(data)); + header->signal_action_insert_mention().connect([this](const Snowflake &id) { + m_signal_action_insert_mention.emit(id); + }); m_num_rows++; Abaddon::Get().GetImageManager().LoadFromURL(user->GetAvatarURL("png", "32"), [this, user_id](Glib::RefPtr<Gdk::Pixbuf> buf) { Glib::signal_idle().connect([this, buf, user_id]() -> bool { @@ -334,3 +337,7 @@ ChatWindow::type_signal_action_chat_load_history ChatWindow::signal_action_chat_ ChatWindow::type_signal_action_channel_click ChatWindow::signal_action_channel_click() { return m_signal_action_channel_click; } + +ChatWindow::type_signal_action_insert_mention ChatWindow::signal_action_insert_mention() { + return m_signal_action_insert_mention; +} diff --git a/components/chatwindow.hpp b/components/chatwindow.hpp index 2372f3d..0b0c7e0 100644 --- a/components/chatwindow.hpp +++ b/components/chatwindow.hpp @@ -70,12 +70,14 @@ public: typedef sigc::signal<void, std::string, Snowflake> type_signal_action_chat_submit; typedef sigc::signal<void, Snowflake> type_signal_action_chat_load_history; typedef sigc::signal<void, Snowflake> type_signal_action_channel_click; + typedef sigc::signal<void, Snowflake> type_signal_action_insert_mention; type_signal_action_message_delete signal_action_message_delete(); type_signal_action_message_edit signal_action_message_edit(); type_signal_action_chat_submit signal_action_chat_submit(); type_signal_action_chat_load_history signal_action_chat_load_history(); type_signal_action_channel_click signal_action_channel_click(); + type_signal_action_insert_mention signal_action_insert_mention(); private: type_signal_action_message_delete m_signal_action_message_delete; @@ -83,4 +85,5 @@ private: type_signal_action_chat_submit m_signal_action_chat_submit; type_signal_action_chat_load_history m_signal_action_chat_load_history; type_signal_action_channel_click m_signal_action_channel_click; + type_signal_action_insert_mention m_signal_action_insert_mention; }; |