1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:27:43 +00:00

LibGUI: Add GInputBox for getting a string from a modal dialog.

Use this to implement some of the toolbar actions in IRCClient. :^)
This commit is contained in:
Andreas Kling 2019-03-19 01:41:00 +01:00
parent b87c099535
commit a6538feed1
11 changed files with 158 additions and 17 deletions

View file

@ -9,7 +9,7 @@
#include <LibGUI/GAction.h>
#include <LibGUI/GMenu.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GMessageBox.h>
#include <LibGUI/GInputBox.h>
#include <stdio.h>
IRCAppWindow::IRCAppWindow()
@ -49,23 +49,26 @@ void IRCAppWindow::setup_client()
void IRCAppWindow::setup_actions()
{
m_join_action = GAction::create("Join channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-join.rgb", { 16, 16 }), [] (auto&) {
printf("FIXME: Implement join action\n");
m_join_action = GAction::create("Join channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-join.rgb", { 16, 16 }), [&] (auto&) {
GInputBox input_box("Enter nickname:", "Join channel");
if (input_box.exec() == GInputBox::ExecOK)
m_client.handle_join_action(input_box.text_value());
});
m_part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-part.rgb", { 16, 16 }), [] (auto&) {
printf("FIXME: Implement part action\n");
});
m_whois_action = GAction::create("Whois user", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-whois.rgb", { 16, 16 }), [] (auto&) {
printf("FIXME: Implement whois action\n");
GMessageBox box("Who would you like to WHOIS?", "Whois user");
int code = box.exec();
dbgprintf("GMessageBox::exec() returned %d\n", code);
m_whois_action = GAction::create("Whois user", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-whois.rgb", { 16, 16 }), [&] (auto&) {
GInputBox input_box("Enter nickname:", "IRC WHOIS lookup");
if (input_box.exec() == GInputBox::ExecOK)
m_client.handle_whois_action(input_box.text_value());
});
m_open_query_action = GAction::create("Open query", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-open-query.rgb", { 16, 16 }), [] (auto&) {
printf("FIXME: Implement open-query action\n");
m_open_query_action = GAction::create("Open query", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-open-query.rgb", { 16, 16 }), [&] (auto&) {
GInputBox input_box("Enter nickname:", "Open IRC query with...");
if (input_box.exec() == GInputBox::ExecOK)
m_client.handle_open_query_action(input_box.text_value());
});
m_close_query_action = GAction::create("Close query", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-close-query.rgb", { 16, 16 }), [] (auto&) {

View file

@ -554,3 +554,29 @@ void IRCClient::handle_user_command(const String& input)
return;
}
}
void IRCClient::handle_whois_action(const String& nick)
{
send_whois(nick);
}
void IRCClient::handle_open_query_action(const String& nick)
{
ensure_query(nick);
}
void IRCClient::handle_close_query_action(const String& nick)
{
m_queries.remove(nick);
m_client_window_list_model->update();
}
void IRCClient::handle_join_action(const String& channel)
{
join_channel(channel);
}
void IRCClient::handle_part_action(const String& channel)
{
part_channel(channel);
}

View file

@ -57,6 +57,12 @@ public:
void handle_user_input_in_query(const String& query_name, const String&);
void handle_user_input_in_server(const String&);
void handle_whois_action(const String&);
void handle_open_query_action(const String&);
void handle_close_query_action(const String&);
void handle_join_action(const String&);
void handle_part_action(const String&);
IRCQuery& ensure_query(const String& name);
IRCChannel& ensure_channel(const String& name);