1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:47:36 +00:00

IRCClient: Open query window immediately when created by the user.

When handling "/query nick", we now immediately switch to the new query.
This commit is contained in:
Andreas Kling 2019-07-13 11:54:01 +02:00
parent 85674aa498
commit 5e6c1c6912
5 changed files with 37 additions and 7 deletions

View file

@ -15,8 +15,18 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
static IRCAppWindow* s_the;
IRCAppWindow& IRCAppWindow::the()
{
return *s_the;
}
IRCAppWindow::IRCAppWindow() IRCAppWindow::IRCAppWindow()
{ {
ASSERT(!s_the);
s_the = this;
update_title(); update_title();
set_rect(200, 200, 600, 400); set_rect(200, 200, 600, 400);
setup_actions(); setup_actions();
@ -166,9 +176,7 @@ void IRCAppWindow::setup_widgets()
m_window_list->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); m_window_list->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
m_window_list->set_preferred_size({ 100, 0 }); m_window_list->set_preferred_size({ 100, 0 });
m_window_list->on_activation = [this](auto& index) { m_window_list->on_activation = [this](auto& index) {
auto& window = m_client.window_at(index.row()); set_active_window(m_client.window_at(index.row()));
m_container->set_active_widget(&window);
window.clear_unread_count();
}; };
m_container = new GStackWidget(horizontal_container); m_container = new GStackWidget(horizontal_container);
@ -179,6 +187,14 @@ void IRCAppWindow::setup_widgets()
create_window(&m_client, IRCWindow::Server, "Server"); create_window(&m_client, IRCWindow::Server, "Server");
} }
void IRCAppWindow::set_active_window(IRCWindow& window)
{
m_container->set_active_widget(&window);
window.clear_unread_count();
auto index = m_window_list->model()->index(m_client.window_index(window));
m_window_list->model()->set_selected_index(index);
}
void IRCAppWindow::update_part_action() void IRCAppWindow::update_part_action()
{ {
auto* window = static_cast<IRCWindow*>(m_container->active_widget()); auto* window = static_cast<IRCWindow*>(m_container->active_widget());

View file

@ -13,6 +13,10 @@ public:
IRCAppWindow(); IRCAppWindow();
virtual ~IRCAppWindow() override; virtual ~IRCAppWindow() override;
static IRCAppWindow& the();
void set_active_window(IRCWindow&);
private: private:
void setup_client(); void setup_client();
void setup_actions(); void setup_actions();

View file

@ -1,3 +1,4 @@
#include "IRCAppWindow.h"
#include "IRCClient.h" #include "IRCClient.h"
#include "IRCChannel.h" #include "IRCChannel.h"
#include "IRCLogBuffer.h" #include "IRCLogBuffer.h"
@ -607,8 +608,10 @@ void IRCClient::handle_user_command(const String& input)
return; return;
} }
if (command == "/QUERY") { if (command == "/QUERY") {
if (parts.size() >= 2) if (parts.size() >= 2) {
ensure_query(parts[1]); auto& query = ensure_query(parts[1]);
IRCAppWindow::the().set_active_window(query.window());
}
return; return;
} }
if (command == "/WHOIS") { if (command == "/WHOIS") {

View file

@ -60,6 +60,15 @@ public:
const IRCWindow& window_at(int index) const { return *m_windows.at(index); } const IRCWindow& window_at(int index) const { return *m_windows.at(index); }
IRCWindow& window_at(int index) { return *m_windows.at(index); } IRCWindow& window_at(int index) { return *m_windows.at(index); }
int window_index(const IRCWindow& window) const
{
for (int i = 0; i < m_windows.size(); ++i) {
if (m_windows[i] == &window)
return i;
}
return -1;
}
void did_part_from_channel(Badge<IRCChannel>, IRCChannel&); void did_part_from_channel(Badge<IRCChannel>, IRCChannel&);
void handle_user_input_in_channel(const String& channel_name, const String&); void handle_user_input_in_channel(const String& channel_name, const String&);

View file

@ -22,8 +22,6 @@ public:
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
virtual void update() override; virtual void update() override;
Function<void(IRCWindow&)> on_activation;
private: private:
explicit IRCWindowListModel(IRCClient&); explicit IRCWindowListModel(IRCClient&);