Refactoring

This commit is contained in:
2025-06-11 12:51:32 +02:00
parent 8fce814084
commit 34e02a8dd7
2 changed files with 19 additions and 7 deletions

View File

@@ -14,12 +14,20 @@ namespace BeWo.Core.Commands
public static DelegateCommand GetAiViewCommand(Action openView, UserRightType userRightType, Func<bool> 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<bool> canExecute = null, bool? useCommandManager = null)
{
bool canExecute2() =>
CheckupTestVersion() &&
(canExecute is null || canExecute());
return new DelegateCommand(action, canExecute2, useCommandManager);
}
private static bool CheckupTestVersion()

View File

@@ -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<AiModelDC>();
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; }