Ansatz 1. Wenn das nix wird, esse ich einen Besen
This commit is contained in:
110
BeWo/ViewModel/Controls/AI/AiChatButtonWithHistoryViewModel.cs
Normal file
110
BeWo/ViewModel/Controls/AI/AiChatButtonWithHistoryViewModel.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeWo.ViewModel.Controls.AI
|
||||
{
|
||||
public class AiChatButtonWithHistoryViewModel : AiChatButtonViewModel
|
||||
{
|
||||
private string currentValue;
|
||||
|
||||
public int CurrentIndex { get; set; }
|
||||
public List<string> History { get; set; }
|
||||
|
||||
public string CurrentValue
|
||||
{
|
||||
get => currentValue;
|
||||
set => SetProperty(ref currentValue, value, nameof(CurrentValue));
|
||||
}
|
||||
|
||||
public bool IsUndoButtonVisible => CurrentIndex > 0;
|
||||
public bool IsRedoButtonVisible => CurrentIndex < History.Count - 1;
|
||||
|
||||
public override bool IsHistoryEnabled => true;
|
||||
|
||||
public AiChatButtonWithHistoryViewModel() : base()
|
||||
{
|
||||
History = new List<string>();
|
||||
CurrentIndex = 0;
|
||||
AssistentCommands = new List<AiMenuItemTemplate>()
|
||||
{
|
||||
new AiMenuItemTemplate()
|
||||
{
|
||||
Command = new DevExpress.Mvvm.DelegateCommand<AiConversationMessageVM>(x => Accept1(x.Message)),
|
||||
Icon = null,
|
||||
Name = "Akzeptieren"
|
||||
},
|
||||
new AiMenuItemTemplate()
|
||||
{
|
||||
Command = new DevExpress.Mvvm.DelegateCommand<AiConversationMessageVM>(x => Accept2(x.Message)),
|
||||
Icon = null,
|
||||
Name = "Ersetzen"
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public void ClearHistory()
|
||||
{
|
||||
History.Clear();
|
||||
History.Add(CurrentValue);
|
||||
CurrentIndex = 0;
|
||||
|
||||
FirePropertyChanged(nameof(IsRedoButtonVisible));
|
||||
FirePropertyChanged(nameof(IsUndoButtonVisible));
|
||||
}
|
||||
|
||||
public void Accept(string str)
|
||||
{
|
||||
var idx = CurrentIndex;
|
||||
var count = History.Count;
|
||||
|
||||
var last_idx = count - 1;
|
||||
|
||||
if (last_idx > idx)
|
||||
{
|
||||
History.RemoveRange(idx + 1, last_idx - idx);
|
||||
}
|
||||
|
||||
if (CurrentValue != History[CurrentIndex])
|
||||
{
|
||||
History.Add(CurrentValue);
|
||||
CurrentIndex++;
|
||||
}
|
||||
|
||||
History.Add(str);
|
||||
CurrentIndex++;
|
||||
|
||||
CurrentValue = str;
|
||||
}
|
||||
|
||||
public void UndoAiAction()
|
||||
{
|
||||
if (CurrentIndex <= 0)
|
||||
return;
|
||||
|
||||
CurrentIndex--;
|
||||
CurrentValue = History[CurrentIndex];
|
||||
}
|
||||
|
||||
public void RedoAiAction()
|
||||
{
|
||||
if (CurrentIndex >= History.Count - 1)
|
||||
return;
|
||||
|
||||
CurrentIndex++;
|
||||
CurrentValue = History[CurrentIndex];
|
||||
}
|
||||
|
||||
public void Accept1(string s)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Accept2(string s)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user