mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 13:35:12 +00:00
IRCClient: Add right-click context menu to IRCWindow member list
This commit is contained in:
parent
6476f690fe
commit
0f91045008
Notes:
sideshowbarker
2024-07-19 07:49:38 +09:00
Author: https://github.com/bcoles Commit: https://github.com/SerenityOS/serenity/commit/0f910450089 Pull-request: https://github.com/SerenityOS/serenity/pull/1686
2 changed files with 89 additions and 0 deletions
|
@ -29,7 +29,10 @@
|
|||
#include "IRCChannelMemberListModel.h"
|
||||
#include "IRCClient.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/InputBox.h>
|
||||
#include <LibGUI/Notification.h>
|
||||
#include <LibGUI/Splitter.h>
|
||||
#include <LibGUI/TableView.h>
|
||||
|
@ -59,6 +62,91 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na
|
|||
member_view.set_alternating_row_colors(false);
|
||||
member_view.set_model(channel().member_model());
|
||||
member_view.set_activates_on_selection(true);
|
||||
member_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
|
||||
if (!index.is_valid())
|
||||
return;
|
||||
|
||||
m_context_menu = GUI::Menu::construct();
|
||||
|
||||
m_context_menu->add_action(GUI::Action::create("Open query", Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-open-query.png"), [&](const GUI::Action&) {
|
||||
GUI::ModelIndex new_index = member_view.selection().first();
|
||||
auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
|
||||
if (nick.is_empty())
|
||||
return;
|
||||
if (IRCClient::is_nick_prefix(nick[0]))
|
||||
nick = nick.substring(1, nick.length() - 1);
|
||||
m_client.handle_open_query_action(nick.characters());
|
||||
}));
|
||||
|
||||
m_context_menu->add_action(GUI::Action::create("Whois", Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-whois.png"), [&](const GUI::Action&) {
|
||||
GUI::ModelIndex new_index = member_view.selection().first();
|
||||
auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
|
||||
if (nick.is_empty())
|
||||
return;
|
||||
if (IRCClient::is_nick_prefix(nick[0]))
|
||||
nick = nick.substring(1, nick.length() - 1);
|
||||
m_client.handle_whois_action(nick.characters());
|
||||
}));
|
||||
|
||||
m_context_menu->add_separator();
|
||||
|
||||
m_context_menu->add_action(GUI::Action::create("Voice", [&](const GUI::Action&) {
|
||||
GUI::ModelIndex new_index = member_view.selection().first();
|
||||
auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
|
||||
if (nick.is_empty())
|
||||
return;
|
||||
if (IRCClient::is_nick_prefix(nick[0]))
|
||||
nick = nick.substring(1, nick.length() - 1);
|
||||
auto input_box = GUI::InputBox::construct("Enter reason:", "Reason");
|
||||
m_client.handle_voice_user_action(m_name.characters(), nick.characters());
|
||||
}));
|
||||
|
||||
m_context_menu->add_action(GUI::Action::create("DeVoice", [&](const GUI::Action&) {
|
||||
GUI::ModelIndex new_index = member_view.selection().first();
|
||||
auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
|
||||
if (nick.is_empty())
|
||||
return;
|
||||
if (IRCClient::is_nick_prefix(nick[0]))
|
||||
nick = nick.substring(1, nick.length() - 1);
|
||||
m_client.handle_devoice_user_action(m_name.characters(), nick.characters());
|
||||
}));
|
||||
|
||||
m_context_menu->add_action(GUI::Action::create("Op", [&](const GUI::Action&) {
|
||||
GUI::ModelIndex new_index = member_view.selection().first();
|
||||
auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
|
||||
if (nick.is_empty())
|
||||
return;
|
||||
if (IRCClient::is_nick_prefix(nick[0]))
|
||||
nick = nick.substring(1, nick.length() - 1);
|
||||
m_client.handle_op_user_action(m_name.characters(), nick.characters());
|
||||
}));
|
||||
|
||||
m_context_menu->add_action(GUI::Action::create("DeOp", [&](const GUI::Action&) {
|
||||
GUI::ModelIndex new_index = member_view.selection().first();
|
||||
auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
|
||||
if (nick.is_empty())
|
||||
return;
|
||||
if (IRCClient::is_nick_prefix(nick[0]))
|
||||
nick = nick.substring(1, nick.length() - 1);
|
||||
m_client.handle_deop_user_action(m_name.characters(), nick.characters());
|
||||
}));
|
||||
|
||||
m_context_menu->add_separator();
|
||||
|
||||
m_context_menu->add_action(GUI::Action::create("Kick", [&](const GUI::Action&) {
|
||||
GUI::ModelIndex new_index = member_view.selection().first();
|
||||
auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
|
||||
if (nick.is_empty())
|
||||
return;
|
||||
if (IRCClient::is_nick_prefix(nick[0]))
|
||||
nick = nick.substring(1, nick.length() - 1);
|
||||
auto input_box = GUI::InputBox::construct("Enter reason:", "Reason");
|
||||
if (input_box->exec() == GUI::InputBox::ExecOK)
|
||||
m_client.handle_kick_user_action(m_name.characters(), nick.characters(), input_box->text_value());
|
||||
}));
|
||||
|
||||
m_context_menu->popup(event.screen_position());
|
||||
};
|
||||
}
|
||||
|
||||
m_text_editor = add<GUI::TextBox>();
|
||||
|
|
|
@ -77,5 +77,6 @@ private:
|
|||
RefPtr<Web::HtmlView> m_html_view;
|
||||
RefPtr<GUI::TextEditor> m_text_editor;
|
||||
RefPtr<IRCLogBuffer> m_log_buffer;
|
||||
RefPtr<GUI::Menu> m_context_menu;
|
||||
int m_unread_count { 0 };
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue