Complex Visible Bindings

This commit is contained in:
2026-05-26 14:57:10 +02:00
parent b45b3c76fd
commit bd9d0b2f06
4 changed files with 57 additions and 14 deletions

View File

@@ -19,7 +19,7 @@
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid Visibility="{Binding IsVisible, Converter={StaticResource BoolVisibilityConverter}}">
<StackPanel
Margin="0"
VerticalAlignment="Center"

View File

@@ -71,7 +71,7 @@ namespace BeWo.View.Controls.AI
private void ItemAccepted(object sender, AbstractBaseVM e)
{
throw new NotImplementedException();
ViewModel.ItemAccepted(e);
}
private void btnOpenAi5_MouseRightButtonUp(object sender, MouseButtonEventArgs e)

View File

@@ -9,6 +9,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
namespace BeWo.ViewModel.Controls.AI
{
@@ -23,6 +24,7 @@ namespace BeWo.ViewModel.Controls.AI
public class AiChatButtonViewModel : AbstractBaseVM
{
private bool isVisible;
private bool canExecute;
private AiChatButtonState buttonState;
@@ -34,11 +36,17 @@ namespace BeWo.ViewModel.Controls.AI
public bool IsEnabled => 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

View File

@@ -51,13 +51,10 @@ namespace BeWo.ViewModel.Controls.AI
};
UndoAiActionCommand= new DelegateCommand(UndoAiAction);
RedoAiActionCommand= new DelegateCommand(RedoAiAction);
Func<bool> 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();