111 lines
2.1 KiB
C#
111 lines
2.1 KiB
C#
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)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|