From d6282885e3dc44cebe09be827156b4272b3208f2 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 26 Feb 2026 17:04:18 +0100 Subject: [PATCH] refactor: move search dialog handling to AppOrchestrator --- src/EchoHub.Client/AppOrchestrator.cs | 33 ++++++++++++++++++++ src/EchoHub.Client/UI/MainWindow.cs | 44 ++++++--------------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/EchoHub.Client/AppOrchestrator.cs b/src/EchoHub.Client/AppOrchestrator.cs index 5c1f52d..fc47c3c 100644 --- a/src/EchoHub.Client/AppOrchestrator.cs +++ b/src/EchoHub.Client/AppOrchestrator.cs @@ -91,6 +91,7 @@ public sealed class AppOrchestrator : IDisposable _mainWindow.OnRollbackRequested += HandleRollbackRequested; _mainWindow.OnUserProfileRequested += HandleViewProfile; _mainWindow.OnChannelJoinRequested += HandleChannelJoinFromMessage; + _mainWindow.OnSearchRequested += HandleSearchRequested; } // ── Command Handler Wiring ───────────────────────────────────────────── @@ -733,6 +734,38 @@ public sealed class AppOrchestrator : IDisposable HandleChannelSelected(channelName); } + + private void HandleSearchRequested() + { + var result = SearchDialog.Show(_app, _mainWindow.GetChannelNames()); + if (result is null) return; + + switch (result.Type) + { + case SearchResultType.Channel: + _mainWindow.SwitchToChannel(result.Key); + HandleChannelSelected(result.Key); + break; + + case SearchResultType.Action: + switch (result.Key) + { + case "connect": HandleConnect(); break; + case "disconnect": HandleDisconnect(); break; + case "logout": HandleLogout(); break; + case "profile": HandleProfileRequested(); break; + case "status": HandleStatusRequested(); break; + case "create-channel": HandleCreateChannelRequested(); break; + case "delete-channel": HandleDeleteChannelRequested(); break; + case "servers": HandleSavedServersRequested(); break; + case "toggle-users": _mainWindow.ToggleUsersPanel(); break; + case "updates": HandleCheckForUpdatesRequested(); break; + case "quit": _app.RequestStop(); break; + } + break; + } + } + private void HandleProfileRequested() { HandleViewProfile(null); diff --git a/src/EchoHub.Client/UI/MainWindow.cs b/src/EchoHub.Client/UI/MainWindow.cs index 17ed1e0..a30230b 100644 --- a/src/EchoHub.Client/UI/MainWindow.cs +++ b/src/EchoHub.Client/UI/MainWindow.cs @@ -152,6 +152,11 @@ public sealed partial class MainWindow : Runnable /// public event Action? OnChannelJoinRequested; + /// + /// Fired when the user requests to open the search dialog (via menu or Ctrl+K). + /// + public event Action? OnSearchRequested; + public MainWindow(IApplication app, ChatMessageManager messageManager) { _app = app; @@ -613,6 +618,11 @@ public sealed partial class MainWindow : Runnable } } + private void ShowSearchDialog() + { + OnSearchRequested?.Invoke(); + } + private void OnMessagesChanged(string channelName) { if (channelName == _messageManager.CurrentChannel) @@ -910,40 +920,6 @@ public sealed partial class MainWindow : Runnable SetNeedsDraw(); } - /// - /// Open the command-palette search dialog (Ctrl+K) and dispatch the selected result. - /// - private void ShowSearchDialog() - { - var result = Dialogs.SearchDialog.Show(_app, _channelNames.AsReadOnly()); - if (result is null) return; - - switch (result.Type) - { - case Dialogs.SearchResultType.Channel: - SwitchToChannel(result.Key); - OnChannelSelected?.Invoke(result.Key); - break; - - case Dialogs.SearchResultType.Action: - switch (result.Key) - { - case "connect": OnConnectRequested?.Invoke(); break; - case "disconnect": OnDisconnectRequested?.Invoke(); break; - case "logout": OnLogoutRequested?.Invoke(); break; - case "profile": OnProfileRequested?.Invoke(); break; - case "status": OnStatusRequested?.Invoke(); break; - case "create-channel": OnCreateChannelRequested?.Invoke(); break; - case "delete-channel": OnDeleteChannelRequested?.Invoke(); break; - case "servers": OnSavedServersRequested?.Invoke(); break; - case "toggle-users": ToggleUsersPanel(); break; - case "updates": OnCheckForUpdatesRequested?.Invoke(); break; - case "quit": _app.RequestStop(); break; - } - break; - } - } - /// /// Toggle the online users panel visibility (F2). ///