mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +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:
parent
85674aa498
commit
5e6c1c6912
Notes:
sideshowbarker
2024-07-19 13:18:19 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5e6c1c69128
5 changed files with 37 additions and 7 deletions
|
@ -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());
|
||||
|
|
|
@ -13,6 +13,10 @@ public:
|
|||
IRCAppWindow();
|
||||
virtual ~IRCAppWindow() override;
|
||||
|
||||
static IRCAppWindow& the();
|
||||
|
||||
void set_active_window(IRCWindow&);
|
||||
|
||||
private:
|
||||
void setup_client();
|
||||
void setup_actions();
|
||||
|
|
|
@ -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") {
|
||||
|
|
|
@ -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&);
|
||||
|
|
|
@ -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&);
|
||||
|
||||
|
|
Loading…
Reference in a new issue