From 5e6c1c6912801e201fd55902002dc82d4895428f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 13 Jul 2019 11:54:01 +0200 Subject: [PATCH] IRCClient: Open query window immediately when created by the user. When handling "/query nick", we now immediately switch to the new query. --- Applications/IRCClient/IRCAppWindow.cpp | 22 ++++++++++++++++++--- Applications/IRCClient/IRCAppWindow.h | 4 ++++ Applications/IRCClient/IRCClient.cpp | 7 +++++-- Applications/IRCClient/IRCClient.h | 9 +++++++++ Applications/IRCClient/IRCWindowListModel.h | 2 -- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index 3cbc7d6f7e6..c28fd00095f 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -15,8 +15,18 @@ #include #include +static IRCAppWindow* s_the; + +IRCAppWindow& IRCAppWindow::the() +{ + return *s_the; +} + IRCAppWindow::IRCAppWindow() { + ASSERT(!s_the); + s_the = this; + update_title(); set_rect(200, 200, 600, 400); setup_actions(); @@ -166,9 +176,7 @@ void IRCAppWindow::setup_widgets() m_window_list->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); m_window_list->set_preferred_size({ 100, 0 }); m_window_list->on_activation = [this](auto& index) { - auto& window = m_client.window_at(index.row()); - m_container->set_active_widget(&window); - window.clear_unread_count(); + set_active_window(m_client.window_at(index.row())); }; m_container = new GStackWidget(horizontal_container); @@ -179,6 +187,14 @@ void IRCAppWindow::setup_widgets() 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() { auto* window = static_cast(m_container->active_widget()); diff --git a/Applications/IRCClient/IRCAppWindow.h b/Applications/IRCClient/IRCAppWindow.h index 128371c42d5..a9787850c4e 100644 --- a/Applications/IRCClient/IRCAppWindow.h +++ b/Applications/IRCClient/IRCAppWindow.h @@ -13,6 +13,10 @@ public: IRCAppWindow(); virtual ~IRCAppWindow() override; + static IRCAppWindow& the(); + + void set_active_window(IRCWindow&); + private: void setup_client(); void setup_actions(); diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index 01821615b4c..d9a6833731b 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -1,3 +1,4 @@ +#include "IRCAppWindow.h" #include "IRCClient.h" #include "IRCChannel.h" #include "IRCLogBuffer.h" @@ -607,8 +608,10 @@ void IRCClient::handle_user_command(const String& input) return; } if (command == "/QUERY") { - if (parts.size() >= 2) - ensure_query(parts[1]); + if (parts.size() >= 2) { + auto& query = ensure_query(parts[1]); + IRCAppWindow::the().set_active_window(query.window()); + } return; } if (command == "/WHOIS") { diff --git a/Applications/IRCClient/IRCClient.h b/Applications/IRCClient/IRCClient.h index e08220f8fa3..a9a9c12efb3 100644 --- a/Applications/IRCClient/IRCClient.h +++ b/Applications/IRCClient/IRCClient.h @@ -60,6 +60,15 @@ public: const IRCWindow& window_at(int index) const { 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&); void handle_user_input_in_channel(const String& channel_name, const String&); diff --git a/Applications/IRCClient/IRCWindowListModel.h b/Applications/IRCClient/IRCWindowListModel.h index 28287228400..f17ffe78dd9 100644 --- a/Applications/IRCClient/IRCWindowListModel.h +++ b/Applications/IRCClient/IRCWindowListModel.h @@ -22,8 +22,6 @@ public: virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; virtual void update() override; - Function on_activation; - private: explicit IRCWindowListModel(IRCClient&);