diff --git a/BeWo/View/Controls/AI/AiChatButton.xaml b/BeWo/View/Controls/AI/AiChatButton.xaml index 06fa3f743..ad8192e0b 100644 --- a/BeWo/View/Controls/AI/AiChatButton.xaml +++ b/BeWo/View/Controls/AI/AiChatButton.xaml @@ -19,7 +19,7 @@ - + BeWoApp.AppSettings.ShowAI && BeWoApp.HasLoggedOnUserRight(GetUserRightType()); + public bool IsVisible + { + get => isVisible; + set => SetProperty(ref isVisible, value, nameof(IsVisible)); + } public bool CanExecute { get => canExecute; set => SetProperty(ref canExecute, value, nameof(CanExecute)); } + public AiChatButtonState ButtonState { get => buttonState; @@ -47,6 +55,10 @@ namespace BeWo.ViewModel.Controls.AI return; FirePropertyChanged(nameof(IsContextSizeTooBig)); + FirePropertyChanged(nameof(CanSendNewMessage)); + FirePropertyChanged(nameof(CanOpenConversation)); + + CommandManager.InvalidateRequerySuggested(); } } @@ -59,6 +71,8 @@ namespace BeWo.ViewModel.Controls.AI public DelegateCommand OpenFavoritePromptsPopupCommand { get; protected set; } public bool IsContextSizeTooBig => ButtonState == AiChatButtonState.Warning; + public virtual bool CanSendNewMessage => ButtonState == AiChatButtonState.Normal; + public bool CanOpenConversation => ButtonState == AiChatButtonState.Normal || ButtonState == AiChatButtonState.Warning; public AiChatButtonViewModel(AiActionType aiActionType) { @@ -67,11 +81,12 @@ namespace BeWo.ViewModel.Controls.AI if (!IsEnabled) return; - canExecute = true; + canExecute = false; + isVisible = false; - OpenConversationPopupCommand = new DelegateCommand(OpenConversationPopup); - OpenAllPromptsPopupCommand = new DelegateCommand(OpenAllPromptsPopup); - OpenFavoritePromptsPopupCommand = new DelegateCommand(OpenFavoritePromptsPopup); + OpenConversationPopupCommand = new DelegateCommand(OpenConversationPopup, () => CanOpenConversation); + OpenAllPromptsPopupCommand = new DelegateCommand(OpenAllPromptsPopup, () => CanSendNewMessage); + OpenFavoritePromptsPopupCommand = new DelegateCommand(OpenFavoritePromptsPopup, () => CanSendNewMessage); } public void CheckContextSize() @@ -85,6 +100,15 @@ namespace BeWo.ViewModel.Controls.AI var context = GetAiVisualContext(); if (context != null) { + if(context.Primary is null) + { + IsVisible = false; + ButtonState = AiChatButtonState.Disabled; + return; + } + + IsVisible = true; + var context2 = context.References.ToDictionary(kv => kv.Key, kv => kv.Value.ToList()); ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.CheckContextSize(ActionType, context2, null), @@ -99,13 +123,18 @@ namespace BeWo.ViewModel.Controls.AI } } - private protected void OpenConversationPopup() + private protected AiConversationChatViewModel GetConversationViewModel() { var context = GetAiVisualContext(); - var chat_viewmodel = VMFactory.CreateAiConversationChatViewModel(ActionType, context.References, (long)context.Primary, true); + var chat_viewmodel = VMFactory.CreateAiConversationChatViewModel(ActionType, context.References, (long)context.Primary, CanSendNewMessage); - BeWoApp.MainControl.WindowService.Show(chat_viewmodel); + return chat_viewmodel; + } + + private protected void OpenConversationPopup() + { + BeWoApp.MainControl.WindowService.Show(GetConversationViewModel()); } private protected void OpenAllPromptsPopup() @@ -135,6 +164,23 @@ namespace BeWo.ViewModel.Controls.AI throw new InvalidOperationException($"UserRightType '{ActionType}' not implemented"); } + + public void ItemAccepted(AbstractBaseVM e) + { + if(e is AiPromptbausteinPromptVM prompt) + { + var vm = GetConversationViewModel(); + vm.SendAfterLoaded = true; + vm.MessageInput = prompt.Prompt; + BeWoApp.MainControl.WindowService.Show(vm); + } + else if(e is AiPromptbausteinRoutineVM routine) + { + + } + + throw new NotImplementedException(); + } } public class AiMenuItemTemplate diff --git a/BeWo/ViewModel/Controls/AI/AiChatButtonWithHistoryViewModel.cs b/BeWo/ViewModel/Controls/AI/AiChatButtonWithHistoryViewModel.cs index 6f8dc2223..ae4ed44b7 100644 --- a/BeWo/ViewModel/Controls/AI/AiChatButtonWithHistoryViewModel.cs +++ b/BeWo/ViewModel/Controls/AI/AiChatButtonWithHistoryViewModel.cs @@ -51,13 +51,10 @@ namespace BeWo.ViewModel.Controls.AI }; UndoAiActionCommand= new DelegateCommand(UndoAiAction); RedoAiActionCommand= new DelegateCommand(RedoAiAction); - - Func canExecute = () => !string.IsNullOrEmpty(CurrentValue); - OpenAllPromptsPopupCommand = new DelegateCommand(OpenAllPromptsPopup, canExecute); - OpenConversationPopupCommand = new DelegateCommand(OpenConversationPopup, canExecute); - OpenFavoritePromptsPopupCommand = new DelegateCommand(OpenFavoritePromptsPopup, canExecute); } + public override bool CanSendNewMessage => base.CanSendNewMessage && !string.IsNullOrEmpty(CurrentValue); + public void ClearHistory() { History.Clear();