summaryrefslogtreecommitdiff
path: root/Applications/IRCClient
diff options
context:
space:
mode:
authorBrendan Coles <bcoles@gmail.com>2020-04-07 17:14:28 +0000
committerAndreas Kling <kling@serenityos.org>2020-04-07 21:27:06 +0200
commit0f91045008973f4e6dcae69da3c687e27056a4aa (patch)
tree38be4d14e77629ecd6e8f510a19790cc3e6cdd24 /Applications/IRCClient
parent6476f690febe067eb190a648fdc7797d7c68c54d (diff)
downloadserenity-0f91045008973f4e6dcae69da3c687e27056a4aa.zip
IRCClient: Add right-click context menu to IRCWindow member list
Diffstat (limited to 'Applications/IRCClient')
-rw-r--r--Applications/IRCClient/IRCWindow.cpp88
-rw-r--r--Applications/IRCClient/IRCWindow.h1
2 files changed, 89 insertions, 0 deletions
diff --git a/Applications/IRCClient/IRCWindow.cpp b/Applications/IRCClient/IRCWindow.cpp
index 8fbca5a57e..c3dc4e2e4e 100644
--- a/Applications/IRCClient/IRCWindow.cpp
+++ b/Applications/IRCClient/IRCWindow.cpp
@@ -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>();
diff --git a/Applications/IRCClient/IRCWindow.h b/Applications/IRCClient/IRCWindow.h
index ca8369b8bb..137ea90991 100644
--- a/Applications/IRCClient/IRCWindow.h
+++ b/Applications/IRCClient/IRCWindow.h
@@ -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 };
};