1919using CommunityToolkit . Mvvm . Input ;
2020using Microsoft . Extensions . Logging ;
2121using McpServer . Client ;
22+ using McpServer . Cqrs . Mvvm ;
2223using McpServerManager . Core . Converters ;
2324using McpServerManager . Core . Models ;
2425using McpServerManager . Core . Models . Json ;
@@ -81,6 +82,13 @@ public partial class MainWindowViewModel : ViewModelBase, Commands.ICommandTarge
8182 /// <summary>Raised when the active workspace path changes. Child VMs subscribe to refresh reactively.</summary>
8283 public event Action < string > ? WorkspacePathChanged ;
8384
85+ // ── CqrsRelayCommand properties (parameterless CQRS dispatches) ──
86+ public CqrsRelayCommand < bool > CloseRequestDetailsCommand { get ; private set ; } = null ! ;
87+ public CqrsRelayCommand < bool > OpenPreviewInBrowserCommand { get ; private set ; } = null ! ;
88+ public CqrsRelayCommand < bool > ToggleShowRawMarkdownCommand { get ; private set ; } = null ! ;
89+ public CqrsRelayCommand < bool > OpenAgentConfigCommand { get ; private set ; } = null ! ;
90+ public CqrsRelayCommand < bool > OpenPromptTemplatesCommand { get ; private set ; } = null ! ;
91+
8492 /// <summary>ViewModel for the Todo tab. Created lazily on first access.</summary>
8593 public TodoListViewModel TodoViewModel => _todoViewModel ??= CreateTodoViewModel ( ) ;
8694 private TodoListViewModel ? _todoViewModel ;
@@ -442,6 +450,7 @@ private void InitializeMcpEndpoint(string mcpBaseUrl, string? initialApiKey = nu
442450 ActiveWorkspacePath = _mcpClient . WorkspacePath ?? string . Empty
443451 } ) ;
444452 _dispatcher = _uiCoreRuntime . GetRequiredService < McpServer . Cqrs . Dispatcher > ( ) ;
453+ InitializeCqrsCommands ( ) ;
445454
446455 // Pre-populate the workspace picker with a placeholder.
447456 // No switch is triggered here — the real switch happens in LoadWorkspaceConnectionsAsync
@@ -471,6 +480,15 @@ private static string NormalizeMcpBaseUrl(string mcpBaseUrl)
471480 return uri . ToString ( ) . TrimEnd ( '/' ) ;
472481 }
473482
483+ private void InitializeCqrsCommands ( )
484+ {
485+ CloseRequestDetailsCommand = new CqrsRelayCommand < bool > ( _dispatcher , ( ) => new Commands . CloseRequestDetailsCommand ( ) ) ;
486+ OpenPreviewInBrowserCommand = new CqrsRelayCommand < bool > ( _dispatcher , ( ) => new Commands . OpenPreviewInBrowserCommand ( ) ) ;
487+ ToggleShowRawMarkdownCommand = new CqrsRelayCommand < bool > ( _dispatcher , ( ) => new Commands . ToggleShowRawMarkdownCommand ( ) ) ;
488+ OpenAgentConfigCommand = new CqrsRelayCommand < bool > ( _dispatcher , ( ) => new Commands . OpenAgentConfigCommand ( ) ) ;
489+ OpenPromptTemplatesCommand = new CqrsRelayCommand < bool > ( _dispatcher , ( ) => new Commands . OpenPromptTemplatesCommand ( ) ) ;
490+ }
491+
474492 private void ApplyActiveMcpBaseUrl ( string mcpBaseUrl , string ? mcpApiKey = null , string ? workspaceRootPath = null )
475493 {
476494 _activeMcpBaseUrl = NormalizeMcpBaseUrl ( mcpBaseUrl ) ;
@@ -1905,8 +1923,6 @@ public void SelectSearchEntryInternal(SearchableEntry entry)
19051923 SelectedSearchEntry = entry ;
19061924 }
19071925
1908- [ RelayCommand ]
1909- private void CloseRequestDetails ( ) => _ = _dispatcher . SendAsync ( new Commands . CloseRequestDetailsCommand ( ) ) ;
19101926
19111927 public void CloseRequestDetailsInternal ( )
19121928 {
@@ -2683,8 +2699,6 @@ private void OpenHtmlInDefaultBrowser(string htmlFilePath)
26832699 }
26842700 }
26852701
2686- [ RelayCommand ]
2687- private void OpenPreviewInBrowser ( ) => _ = _dispatcher . SendAsync ( new Commands . OpenPreviewInBrowserCommand ( ) ) ;
26882702
26892703 public void OpenPreviewInBrowserInternal ( )
26902704 {
@@ -2696,25 +2710,19 @@ public void OpenPreviewInBrowserInternal()
26962710 SetStatus ( "HTML preview is disabled." ) ;
26972711 }
26982712
2699- [ RelayCommand ]
2700- private void ToggleShowRawMarkdown ( ) => _ = _dispatcher . SendAsync ( new Commands . ToggleShowRawMarkdownCommand ( ) ) ;
27012713
27022714 public void ToggleShowRawMarkdownInternal ( )
27032715 {
27042716 ShowMarkdownAsRawText = ! ShowMarkdownAsRawText ;
27052717 }
27062718
2707- [ RelayCommand ]
2708- private void OpenAgentConfig ( ) => _ = _dispatcher . SendAsync ( new Commands . OpenAgentConfigCommand ( ) ) ;
27092719
27102720 public void OpenAgentConfigInternal ( )
27112721 {
27122722 AgentConfigIo . EnsureExists ( ) ;
27132723 OpenFileInDefaultEditor ( AgentConfigIo . GetFilePath ( ) , "config" ) ;
27142724 }
27152725
2716- [ RelayCommand ]
2717- private void OpenPromptTemplates ( ) => _ = _dispatcher . SendAsync ( new Commands . OpenPromptTemplatesCommand ( ) ) ;
27182726
27192727 public void OpenPromptTemplatesInternal ( )
27202728 {
0 commit comments