diff options
-rw-r--r-- | Applications/IRCClient/IRCAppWindow.cpp | 22 | ||||
-rw-r--r-- | Applications/IRCClient/IRCAppWindow.h | 4 | ||||
-rw-r--r-- | Applications/IRCClient/IRCClient.cpp | 7 | ||||
-rw-r--r-- | Applications/IRCClient/IRCClient.h | 9 | ||||
-rw-r--r-- | 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 3cbc7d6f7e..c28fd00095 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -15,8 +15,18 @@ #include <stdio.h> #include <stdlib.h> +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<IRCWindow*>(m_container->active_widget()); diff --git a/Applications/IRCClient/IRCAppWindow.h b/Applications/IRCClient/IRCAppWindow.h index 128371c42d..a9787850c4 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 01821615b4..d9a6833731 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 e08220f8fa..a9a9c12efb 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>, 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 2828722840..f17ffe78dd 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<void(IRCWindow&)> on_activation; - private: explicit IRCWindowListModel(IRCClient&); |