diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-10-11 00:32:14 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-10-11 00:32:14 -0400 |
commit | 059146b060e9cdd57f6ddbb9d6e6a17a2d6529f9 (patch) | |
tree | f4607207ab979156965476f5b1f9e03ad09286ab /components | |
parent | ea6650884c91740ccb25c7e9e3e15700ffdf2c82 (diff) | |
download | abaddon-portaudio-059146b060e9cdd57f6ddbb9d6e6a17a2d6529f9.tar.gz abaddon-portaudio-059146b060e9cdd57f6ddbb9d6e6a17a2d6529f9.zip |
add category/channel menu and update some other menu stuff
Diffstat (limited to 'components')
-rw-r--r-- | components/channels.cpp | 56 | ||||
-rw-r--r-- | components/channels.hpp | 18 | ||||
-rw-r--r-- | components/chatmessage.cpp | 12 | ||||
-rw-r--r-- | components/chatmessage.hpp | 2 |
4 files changed, 58 insertions, 30 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index 9b95f1d..76519bf 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -161,23 +161,29 @@ ChannelList::ChannelList() { m_list->get_style_context()->add_class("channel-list"); m_guild_menu_up = Gtk::manage(new Gtk::MenuItem("Move _Up", true)); - m_guild_menu_up->signal_activate().connect(sigc::mem_fun(*this, &ChannelList::on_menu_move_up)); + m_guild_menu_up->signal_activate().connect(sigc::mem_fun(*this, &ChannelList::on_guild_menu_move_up)); m_guild_menu.append(*m_guild_menu_up); m_guild_menu_down = Gtk::manage(new Gtk::MenuItem("Move _Down", true)); - m_guild_menu_down->signal_activate().connect(sigc::mem_fun(*this, &ChannelList::on_menu_move_down)); + m_guild_menu_down->signal_activate().connect(sigc::mem_fun(*this, &ChannelList::on_guild_menu_move_down)); m_guild_menu.append(*m_guild_menu_down); m_guild_menu_copyid = Gtk::manage(new Gtk::MenuItem("_Copy ID", true)); - m_guild_menu_copyid->signal_activate().connect(sigc::mem_fun(*this, &ChannelList::on_menu_copyid)); + m_guild_menu_copyid->signal_activate().connect(sigc::mem_fun(*this, &ChannelList::on_guild_menu_copyid)); m_guild_menu.append(*m_guild_menu_copyid); m_guild_menu_leave = Gtk::manage(new Gtk::MenuItem("_Leave Guild", true)); - m_guild_menu_leave->signal_activate().connect(sigc::mem_fun(*this, &ChannelList::on_menu_leave)); + m_guild_menu_leave->signal_activate().connect(sigc::mem_fun(*this, &ChannelList::on_guild_menu_leave)); m_guild_menu.append(*m_guild_menu_leave); m_guild_menu.show_all(); + m_channel_menu_copyid = Gtk::manage(new Gtk::MenuItem("_Copy ID", true)); + m_channel_menu_copyid->signal_activate().connect(sigc::mem_fun(*this, &ChannelList::on_channel_menu_copyid)); + m_channel_menu.append(*m_channel_menu_copyid); + + m_channel_menu.show_all(); + m_list->set_activate_on_single_click(true); m_list->signal_row_activated().connect(sigc::mem_fun(*this, &ChannelList::on_row_activated)); @@ -298,7 +304,7 @@ void ChannelList::UpdateListingInternal() { guild_row->IsHidden = false; guild_row->GuildIndex = m_guild_count++; m_list->add(*guild_row); - AttachMenuHandler(guild_row); + AttachGuildMenuHandler(guild_row); // add channels with no parent category if (orphan_channels.find(gid) != orphan_channels.end()) { @@ -323,6 +329,7 @@ void ChannelList::UpdateListingInternal() { auto *cat_row = Gtk::manage(new ChannelListRowCategory(cat)); cat_row->IsUserCollapsed = false; cat_row->IsHidden = true; + AttachChannelMenuHandler(cat_row); m_list->add(*cat_row); guild_row->Children.insert(cat_row); @@ -337,6 +344,7 @@ void ChannelList::UpdateListingInternal() { auto *chan_row = Gtk::manage(new ChannelListRowChannel(channel)); chan_row->IsHidden = false; chan_row->IsUserCollapsed = false; + AttachChannelMenuHandler(chan_row); m_list->add(*chan_row); cat_row->Children.insert(chan_row); } @@ -345,34 +353,34 @@ void ChannelList::UpdateListingInternal() { } } -void ChannelList::on_menu_move_up() { +void ChannelList::on_guild_menu_move_up() { auto tmp = m_list->get_selected_row(); auto row = dynamic_cast<ChannelListRow *>(tmp); if (row != nullptr) m_signal_action_guild_move_up.emit(row->ID); } -void ChannelList::on_menu_move_down() { +void ChannelList::on_guild_menu_move_down() { auto tmp = m_list->get_selected_row(); auto row = dynamic_cast<ChannelListRow *>(tmp); if (row != nullptr) m_signal_action_guild_move_down.emit(row->ID); } -void ChannelList::on_menu_copyid() { +void ChannelList::on_guild_menu_copyid() { auto tmp = m_list->get_selected_row(); auto row = dynamic_cast<ChannelListRow *>(tmp); if (row != nullptr) - m_signal_action_guild_copy_id.emit(row->ID); + Gtk::Clipboard::get()->set_text(std::to_string(row->ID)); } -void ChannelList::on_menu_leave() { +void ChannelList::on_guild_menu_leave() { auto row = dynamic_cast<ChannelListRow *>(m_list->get_selected_row()); if (row != nullptr) m_signal_action_guild_leave.emit(row->ID); } -void ChannelList::AttachMenuHandler(Gtk::ListBoxRow *row) { +void ChannelList::AttachGuildMenuHandler(Gtk::ListBoxRow *row) { row->signal_button_press_event().connect([&, row](GdkEventButton *e) -> bool { if (e->type == GDK_BUTTON_PRESS && e->button == GDK_BUTTON_SECONDARY) { auto grow = dynamic_cast<ChannelListRowGuild *>(row); @@ -389,6 +397,28 @@ void ChannelList::AttachMenuHandler(Gtk::ListBoxRow *row) { }); } +void ChannelList::on_channel_menu_copyid() { + auto tmp = m_list->get_selected_row(); + auto row = dynamic_cast<ChannelListRow *>(tmp); + if (row != nullptr) + Gtk::Clipboard::get()->set_text(std::to_string(row->ID)); +} + +void ChannelList::AttachChannelMenuHandler(Gtk::ListBoxRow *row) { + row->signal_button_press_event().connect([&, row](GdkEventButton *e) -> bool { + if (e->type == GDK_BUTTON_PRESS && e->button == GDK_BUTTON_SECONDARY) { + auto grow = dynamic_cast<ChannelListRow *>(row); + if (grow != nullptr) { + m_list->select_row(*row); + m_channel_menu.popup_at_pointer(reinterpret_cast<const GdkEvent *>(e)); + } + return true; + } + + return false; + }); +} + ChannelList::type_signal_action_channel_item_select ChannelList::signal_action_channel_item_select() { return m_signal_action_channel_item_select; } @@ -401,10 +431,6 @@ ChannelList::type_signal_action_guild_move_down ChannelList::signal_action_guild return m_signal_action_guild_move_down; } -ChannelList::type_signal_action_guild_copy_id ChannelList::signal_action_guild_copy_id() { - return m_signal_action_guild_copy_id; -} - ChannelList::type_signal_action_guild_leave ChannelList::signal_action_guild_leave() { return m_signal_action_guild_leave; } diff --git a/components/channels.hpp b/components/channels.hpp index b1c1262..8215133 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -103,35 +103,37 @@ protected: Gtk::MenuItem *m_guild_menu_down; Gtk::MenuItem *m_guild_menu_copyid; Gtk::MenuItem *m_guild_menu_leave; - void on_menu_move_up(); - void on_menu_move_down(); - void on_menu_copyid(); - void on_menu_leave(); + void on_guild_menu_move_up(); + void on_guild_menu_move_down(); + void on_guild_menu_copyid(); + void on_guild_menu_leave(); + + Gtk::Menu m_channel_menu; + Gtk::MenuItem *m_channel_menu_copyid; + void on_channel_menu_copyid(); Glib::Dispatcher m_update_dispatcher; //mutable std::mutex m_update_mutex; //std::queue<std::unordered_set<Snowflake>> m_update_queue; void AddPrivateChannels(); // retard moment void UpdateListingInternal(); - void AttachMenuHandler(Gtk::ListBoxRow *row); + void AttachGuildMenuHandler(Gtk::ListBoxRow *row); + void AttachChannelMenuHandler(Gtk::ListBoxRow *row); public: typedef sigc::signal<void, Snowflake> type_signal_action_channel_item_select; typedef sigc::signal<void, Snowflake> type_signal_action_guild_move_up; typedef sigc::signal<void, Snowflake> type_signal_action_guild_move_down; - typedef sigc::signal<void, Snowflake> type_signal_action_guild_copy_id; typedef sigc::signal<void, Snowflake> type_signal_action_guild_leave; type_signal_action_channel_item_select signal_action_channel_item_select(); type_signal_action_guild_move_up signal_action_guild_move_up(); type_signal_action_guild_move_down signal_action_guild_move_down(); - type_signal_action_guild_copy_id signal_action_guild_copy_id(); type_signal_action_guild_leave signal_action_guild_leave(); protected: type_signal_action_channel_item_select m_signal_action_channel_item_select; type_signal_action_guild_move_up m_signal_action_guild_move_up; type_signal_action_guild_move_down m_signal_action_guild_move_down; - type_signal_action_guild_copy_id m_signal_action_guild_copy_id; type_signal_action_guild_leave m_signal_action_guild_leave; }; diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index b945d8e..39b6626 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -31,14 +31,14 @@ ChatMessageItemContainer *ChatMessageItemContainer::FromMessage(Snowflake id) { if (data->Content.size() > 0 || data->Type != MessageType::DEFAULT) { container->m_text_component = container->CreateTextComponent(data); - container->AttachMenuHandler(container->m_text_component); + container->AttachGuildMenuHandler(container->m_text_component); container->m_main->add(*container->m_text_component); } // there should only ever be 1 embed (i think?) if (data->Embeds.size() == 1) { container->m_embed_component = container->CreateEmbedComponent(data); - container->AttachMenuHandler(container->m_embed_component); + container->AttachGuildMenuHandler(container->m_embed_component); container->m_main->add(*container->m_embed_component); } @@ -50,13 +50,13 @@ ChatMessageItemContainer *ChatMessageItemContainer::FromMessage(Snowflake id) { auto *widget = container->CreateImageComponent(a); auto *ev = Gtk::manage(new Gtk::EventBox); ev->add(*widget); - container->AttachMenuHandler(ev); + container->AttachGuildMenuHandler(ev); container->AddClickHandler(ev, a.URL); container->m_main->add(*ev); container->HandleImage(a, widget, a.ProxyURL); } else { auto *widget = container->CreateAttachmentComponent(a); - container->AttachMenuHandler(widget); + container->AttachGuildMenuHandler(widget); container->AddClickHandler(widget, a.URL); container->m_main->add(*widget); } @@ -81,7 +81,7 @@ void ChatMessageItemContainer::UpdateContent() { if (m_embed_imgurl.size() > 0) { m_signal_image_load.emit(m_embed_imgurl); } - AttachMenuHandler(m_embed_component); + AttachGuildMenuHandler(m_embed_component); m_main->add(*m_embed_component); } } @@ -567,7 +567,7 @@ ChatMessageItemContainer::type_signal_image_load ChatMessageItemContainer::signa } // clang-format off -void ChatMessageItemContainer::AttachMenuHandler(Gtk::Widget *widget) { +void ChatMessageItemContainer::AttachGuildMenuHandler(Gtk::Widget *widget) { widget->signal_button_press_event().connect([this](GdkEventButton *event) -> bool { if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_SECONDARY) { ShowMenu(reinterpret_cast<GdkEvent*>(event)); diff --git a/components/chatmessage.hpp b/components/chatmessage.hpp index bf8edf2..5fe60f3 100644 --- a/components/chatmessage.hpp +++ b/components/chatmessage.hpp @@ -40,7 +40,7 @@ protected: std::unordered_map<std::string, std::pair<Gtk::Image *, AttachmentData>> m_img_loadmap; - void AttachMenuHandler(Gtk::Widget *widget); + void AttachGuildMenuHandler(Gtk::Widget *widget); void ShowMenu(GdkEvent *event); Gtk::Menu m_menu; |