From 34e02a8dd7797e6f7d43bbd51983b3dcf7928ec4 Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Wed, 11 Jun 2025 12:51:32 +0200 Subject: [PATCH] Refactoring --- BeWo/Core/Commands/CommandFactory.cs | 12 ++++++++++-- .../ListViewModel/AiConversationListVM.cs | 14 +++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/BeWo/Core/Commands/CommandFactory.cs b/BeWo/Core/Commands/CommandFactory.cs index c9db00e74..eb2090f52 100644 --- a/BeWo/Core/Commands/CommandFactory.cs +++ b/BeWo/Core/Commands/CommandFactory.cs @@ -14,12 +14,20 @@ namespace BeWo.Core.Commands public static DelegateCommand GetAiViewCommand(Action openView, UserRightType userRightType, Func additionalCheckup = null) { bool canExecute() => - CheckupTestVersion() && BeWoApp.AppSettings.ModuleAiEnabled && BeWoApp.HasLoggedOnUserRight(userRightType) && (additionalCheckup is null || additionalCheckup()); - return new DelegateCommand(openView, canExecute, false); + return GetTestClientCommand(openView, canExecute, false); + } + + public static DelegateCommand GetTestClientCommand(Action action, Func canExecute = null, bool? useCommandManager = null) + { + bool canExecute2() => + CheckupTestVersion() && + (canExecute is null || canExecute()); + + return new DelegateCommand(action, canExecute2, useCommandManager); } private static bool CheckupTestVersion() diff --git a/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs b/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs index 564e0d5ed..55b8ab7fc 100644 --- a/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs +++ b/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs @@ -1,4 +1,5 @@ using BeWo.Core; +using BeWo.Core.Commands; using BeWo.ServiceProxy; using BS.Shared; using BS.Shared.DataContracts; @@ -47,15 +48,18 @@ namespace BeWo.ViewModel.ListViewModel { Models = new ObservableSortCollection(); - SendNewMessageCommand = new DelegateCommand(SendNewMessage, () => SelectedVM is object && !string.IsNullOrWhiteSpace(MessageInput) && !IsSending); + bool sendCanExecute() => SelectedVM is object && !string.IsNullOrWhiteSpace(MessageInput) && !IsSending; + SendNewMessageCommand = new DelegateCommand(SendNewMessage, sendCanExecute); OpenNewConversationCommand = new DelegateCommand(OpenNewConversation, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleChatAdd)); - StartConversationWithMessageCommand = new DelegateCommand(StartConversationWithMessage, () => !string.IsNullOrWhiteSpace(MessageInput) && !IsSending); + bool startconvCanExecute() => !string.IsNullOrWhiteSpace(MessageInput) && !IsSending; + StartConversationWithMessageCommand = new DelegateCommand(StartConversationWithMessage, startconvCanExecute); ReloadConfigCommand = new DelegateCommand(ReloadConfig); ReloadConversationsCommand = new DelegateCommand(ReloadConversations); ReloadModelsCommand = new DelegateCommand(ReloadModels); - OpenSettingCommand = new DelegateCommand(OpenSetting, () => (BeWoApp.AppSettings?.ModuleAiSettingsEnabled ?? true) && BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleViewSetting)); + bool openCanExecute() => (BeWoApp.AppSettings?.ModuleAiSettingsEnabled ?? true) && BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleViewSetting); + OpenSettingCommand = new DelegateCommand(OpenSetting, openCanExecute, false); OpenCloneCommand = new DelegateCommand(OpenClone, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleChatClone) && SelectedVM is object); CloneCommand = new DelegateCommand(Clone); @@ -69,8 +73,8 @@ namespace BeWo.ViewModel.ListViewModel public DelegateCommand SendNewMessageCommand { get; set; } public DelegateCommand OpenNewConversationCommand { get; set; } public DelegateCommand StartConversationWithMessageCommand { get; set; } - public DelegateCommand RequestNewConversationCommand { get; set; } - public DelegateCommand TestCommand { get; set; } + //public DelegateCommand RequestNewConversationCommand { get; set; } + //public DelegateCommand TestCommand { get; set; } public DelegateCommand AskDeleteCommand { get; set; } public DelegateCommand ReloadConfigCommand { get; set; } public DelegateCommand ReloadConversationsCommand { get; set; }