add category/channel menu and update some other menu stuff

This commit is contained in:
ouwou 2020-10-11 00:32:14 -04:00
parent ea6650884c
commit 059146b060
6 changed files with 58 additions and 36 deletions

View File

@ -60,7 +60,6 @@ int Abaddon::StartGTK() {
m_main_window->GetChannelList()->signal_action_channel_item_select().connect(sigc::mem_fun(*this, &Abaddon::ActionListChannelItemClick));
m_main_window->GetChannelList()->signal_action_guild_move_up().connect(sigc::mem_fun(*this, &Abaddon::ActionMoveGuildUp));
m_main_window->GetChannelList()->signal_action_guild_move_down().connect(sigc::mem_fun(*this, &Abaddon::ActionMoveGuildDown));
m_main_window->GetChannelList()->signal_action_guild_copy_id().connect(sigc::mem_fun(*this, &Abaddon::ActionCopyGuildID));
m_main_window->GetChannelList()->signal_action_guild_leave().connect(sigc::mem_fun(*this, &Abaddon::ActionLeaveGuild));
m_main_window->GetChatWindow()->signal_action_message_delete().connect(sigc::mem_fun(*this, &Abaddon::ActionChatDeleteMessage));
@ -226,10 +225,6 @@ void Abaddon::ActionMoveGuildDown(Snowflake id) {
m_discord.UpdateSettingsGuildPositions(order);
}
void Abaddon::ActionCopyGuildID(Snowflake id) {
Gtk::Clipboard::get()->set_text(std::to_string(id));
}
void Abaddon::ActionListChannelItemClick(Snowflake id) {
if (id == m_main_window->GetChatActiveChannel()) return;

View File

@ -34,7 +34,6 @@ public:
void ActionJoinGuildDialog();
void ActionMoveGuildUp(Snowflake id);
void ActionMoveGuildDown(Snowflake id);
void ActionCopyGuildID(Snowflake id);
void ActionListChannelItemClick(Snowflake id);
void ActionChatInputSubmit(std::string msg, Snowflake channel);
void ActionChatLoadHistory(Snowflake id);

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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));

View File

@ -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;