mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-06 20:15:19 +03:00
member list gets a basic right click menu
This commit is contained in:
@@ -245,6 +245,10 @@ void Abaddon::ActionChatEditMessage(Snowflake channel_id, Snowflake id) {
|
||||
}
|
||||
}
|
||||
|
||||
void Abaddon::ActionInsertMention(Snowflake id) {
|
||||
m_main_window->InsertChatInput("<@" + std::to_string(id) + ">");
|
||||
}
|
||||
|
||||
void Abaddon::ActionReloadCSS() {
|
||||
try {
|
||||
Gtk::StyleContext::remove_provider_for_screen(Gdk::Screen::get_default(), m_css_provider);
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
void ActionChatLoadHistory(Snowflake id);
|
||||
void ActionChatDeleteMessage(Snowflake channel_id, Snowflake id);
|
||||
void ActionChatEditMessage(Snowflake channel_id, Snowflake id);
|
||||
void ActionInsertMention(Snowflake id);
|
||||
|
||||
void ActionReloadCSS();
|
||||
|
||||
|
||||
@@ -204,6 +204,12 @@ void ChatWindow::ClearMessages() {
|
||||
m_message_set_dispatch.emit();
|
||||
}
|
||||
|
||||
void ChatWindow::InsertChatInput(std::string text) {
|
||||
auto buf = m_input->get_buffer();
|
||||
buf->insert_at_cursor(text);
|
||||
m_input->grab_focus();
|
||||
}
|
||||
|
||||
void ChatWindow::ScrollToBottom() {
|
||||
auto x = m_scroll->get_vadjustment();
|
||||
x->set_value(x->get_upper());
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
void DeleteMessage(Snowflake id);
|
||||
void UpdateMessageContent(Snowflake id);
|
||||
void ClearMessages();
|
||||
void InsertChatInput(std::string text);
|
||||
|
||||
protected:
|
||||
void ScrollToBottom();
|
||||
|
||||
@@ -10,6 +10,16 @@ MemberList::MemberList() {
|
||||
|
||||
m_listbox->set_selection_mode(Gtk::SELECTION_NONE);
|
||||
|
||||
m_menu_copy_id = Gtk::manage(new Gtk::MenuItem("_Copy ID", true));
|
||||
m_menu_copy_id->signal_activate().connect(sigc::mem_fun(*this, &MemberList::on_copy_id_activate));
|
||||
m_menu.append(*m_menu_copy_id);
|
||||
|
||||
m_menu_insert_mention = Gtk::manage(new Gtk::MenuItem("Insert _Mention", true));
|
||||
m_menu_insert_mention->signal_activate().connect(sigc::mem_fun(*this, &MemberList::on_insert_mention_activate));
|
||||
m_menu.append(*m_menu_insert_mention);
|
||||
|
||||
m_menu.show_all();
|
||||
|
||||
m_main->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
|
||||
m_main->add(*m_listbox);
|
||||
m_main->show_all();
|
||||
@@ -84,7 +94,9 @@ void MemberList::UpdateMemberListInternal() {
|
||||
}
|
||||
|
||||
auto add_user = [this, &user_to_color](const UserData *data) {
|
||||
auto *user_row = Gtk::manage(new Gtk::ListBoxRow);
|
||||
auto *user_row = Gtk::manage(new MemberListUserRow);
|
||||
user_row->ID = data->ID;
|
||||
auto *user_ev = Gtk::manage(new Gtk::EventBox);
|
||||
auto *user_lbl = Gtk::manage(new Gtk::Label);
|
||||
user_lbl->set_single_line_mode(true);
|
||||
user_lbl->set_ellipsize(Pango::ELLIPSIZE_END);
|
||||
@@ -103,9 +115,11 @@ void MemberList::UpdateMemberListInternal() {
|
||||
user_lbl->set_markup("<i>[unknown user]</i>");
|
||||
}
|
||||
user_lbl->set_halign(Gtk::ALIGN_START);
|
||||
user_row->add(*user_lbl);
|
||||
user_ev->add(*user_lbl);
|
||||
user_row->add(*user_ev);
|
||||
user_row->show_all();
|
||||
m_listbox->add(*user_row);
|
||||
AttachUserMenuHandler(user_row, data->ID);
|
||||
};
|
||||
|
||||
auto add_role = [this](std::string name) {
|
||||
@@ -142,6 +156,30 @@ void MemberList::UpdateMemberListInternal() {
|
||||
}
|
||||
}
|
||||
|
||||
void MemberList::on_copy_id_activate() {
|
||||
auto *row = dynamic_cast<MemberListUserRow *>(m_row_menu_target);
|
||||
if (row == nullptr) return;
|
||||
Gtk::Clipboard::get()->set_text(std::to_string(row->ID));
|
||||
}
|
||||
|
||||
void MemberList::on_insert_mention_activate() {
|
||||
auto *row = dynamic_cast<MemberListUserRow *>(m_row_menu_target);
|
||||
if (row == nullptr) return;
|
||||
m_abaddon->ActionInsertMention(row->ID);
|
||||
}
|
||||
|
||||
void MemberList::AttachUserMenuHandler(Gtk::ListBoxRow *row, Snowflake id) {
|
||||
row->signal_button_press_event().connect([&, row](GdkEventButton *e) -> bool {
|
||||
if (e->type == GDK_BUTTON_PRESS && e->button == GDK_BUTTON_SECONDARY) {
|
||||
m_row_menu_target = row;
|
||||
m_menu.popup_at_pointer(reinterpret_cast<const GdkEvent *>(e));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void MemberList::SetAbaddon(Abaddon *ptr) {
|
||||
m_abaddon = ptr;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
class Abaddon;
|
||||
class MemberList {
|
||||
public:
|
||||
class MemberListUserRow : public Gtk::ListBoxRow {
|
||||
public:
|
||||
Snowflake ID;
|
||||
};
|
||||
|
||||
MemberList();
|
||||
Gtk::Widget *GetRoot() const;
|
||||
|
||||
@@ -15,7 +20,16 @@ public:
|
||||
void SetAbaddon(Abaddon *ptr);
|
||||
|
||||
private:
|
||||
void on_copy_id_activate();
|
||||
void on_insert_mention_activate();
|
||||
|
||||
void UpdateMemberListInternal();
|
||||
void AttachUserMenuHandler(Gtk::ListBoxRow *row, Snowflake id);
|
||||
|
||||
Gtk::Menu m_menu;
|
||||
Gtk::MenuItem *m_menu_copy_id;
|
||||
Gtk::MenuItem *m_menu_insert_mention;
|
||||
Gtk::ListBoxRow *m_row_menu_target = nullptr; // maybe hacky
|
||||
|
||||
std::mutex m_mutex;
|
||||
Glib::Dispatcher m_update_member_list_dispatcher;
|
||||
|
||||
@@ -146,6 +146,10 @@ void MainWindow::UpdateChatPrependHistory(const std::vector<Snowflake> &msgs) {
|
||||
m_members.UpdateMemberList();
|
||||
}
|
||||
|
||||
void MainWindow::InsertChatInput(std::string text) {
|
||||
m_chat.InsertChatInput(text);
|
||||
}
|
||||
|
||||
void MainWindow::SetAbaddon(Abaddon *ptr) {
|
||||
m_abaddon = ptr;
|
||||
m_channel_list.SetAbaddon(ptr);
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
void UpdateChatMessageDeleted(Snowflake id, Snowflake channel_id);
|
||||
void UpdateChatMessageEditContent(Snowflake id, Snowflake channel_id);
|
||||
void UpdateChatPrependHistory(const std::vector<Snowflake> &msgs);
|
||||
void InsertChatInput(std::string text);
|
||||
|
||||
protected:
|
||||
Gtk::Box m_main_box;
|
||||
|
||||
Reference in New Issue
Block a user