137 lines
3.8 KiB
C#
137 lines
3.8 KiB
C#
using BeWo.Core;
|
|
using BeWo.ViewModel.ListViewModel;
|
|
using BS.Shared.Core;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static BeWo.View.Detail.MassnahmenHistoryRecord;
|
|
|
|
namespace BeWo.View.Detail
|
|
{
|
|
//public class MassnahmenTreeViewHistoryManager
|
|
//{
|
|
// public MassnahmenTreeViewHistoryManager()
|
|
// {
|
|
// History = new Stack<MassnahmenActionParameters>();
|
|
// }
|
|
|
|
// public Stack<MassnahmenActionParameters> History { get; set; }
|
|
|
|
// internal void RecordAction(MassnahmenActionParameters param)
|
|
// {
|
|
// History.Push(param);
|
|
// }
|
|
|
|
// internal void UndoAction()
|
|
// {
|
|
|
|
// }
|
|
|
|
// internal void UndoAddAction()
|
|
// {
|
|
|
|
// }
|
|
|
|
// internal void UndoDeleteAction()
|
|
// {
|
|
|
|
// }
|
|
|
|
// internal void UndoMoveAction()
|
|
// {
|
|
|
|
// }
|
|
|
|
// internal void UndoCopyAction()
|
|
// {
|
|
|
|
// }
|
|
//}
|
|
|
|
public class MassnahmenHistory
|
|
{
|
|
public Action RefreshTree { get; set; }
|
|
public Action RefreshButton { get; set; }
|
|
|
|
public MassnahmenHistoryRecordOrigin Origin { get; set; }
|
|
public LinkedList<MassnahmenHistoryRecord> History { get; set; }
|
|
public LinkedListNode<MassnahmenHistoryRecord> LastChange { get; set; }
|
|
|
|
public MassnahmenTreeTrimmer TreeTrimmer { get; set; }
|
|
|
|
public MassnahmenHistory(MassnahmenTreeTrimmer trimmer, Action refresh, Action button)
|
|
{
|
|
Origin = new MassnahmenHistoryRecordOrigin();
|
|
History = new LinkedList<MassnahmenHistoryRecord>();
|
|
History.AddLast(Origin);
|
|
|
|
LastChange = History.Last;
|
|
|
|
TreeTrimmer = trimmer;
|
|
RefreshTree = refresh;
|
|
RefreshButton = button;
|
|
}
|
|
|
|
public bool GotPrevAction => LastChange is object && LastChange.Value != Origin;
|
|
public bool GotNextAction => LastChange is object && LastChange.Next is object;
|
|
public bool GotChanges => LastChange is object && (GotNextAction || GotPrevAction);
|
|
|
|
public void RecordAdd(NodeRelation param) => RecordAction(new MassnahmenHistoryRecordAdd(param));
|
|
public void RecordMove(MassnahmenHistoryRecordMove move) => RecordAction(move);
|
|
public void RecordImport(List<NodeRelation> param) => RecordAction(new MassnahmenHistoryRecordImport(param));
|
|
public void RecordDelete(MassnahmenHistoryRecordDelete del) => RecordAction(del);
|
|
public void RecordCopy(NodeRelation root, List<NodeRelation> param) => RecordAction(new MassnahmenHistoryRecordCopy(root, param));
|
|
public void RecordEdit(MassnahmenHistoryRecordEdit edit) => RecordAction(edit);
|
|
|
|
private void RecordAction(MassnahmenHistoryRecord val)
|
|
{
|
|
while (LastChange != History.Last)
|
|
{
|
|
History.RemoveLast();
|
|
}
|
|
|
|
History.AddLast(val);
|
|
|
|
LastChange = History.Last;
|
|
|
|
RefreshTree();
|
|
RefreshButton();
|
|
}
|
|
|
|
public void ClearHistory()
|
|
{
|
|
while(History.Last != History.First)
|
|
{
|
|
History.RemoveLast();
|
|
}
|
|
|
|
LastChange = History.Last;
|
|
|
|
RefreshButton();
|
|
}
|
|
|
|
public void UndoPrevAction()
|
|
{
|
|
var action = LastChange.Value;
|
|
|
|
TreeTrimmer.UndoAction(action);
|
|
|
|
LastChange = LastChange.Previous;
|
|
RefreshButton();
|
|
RefreshTree();
|
|
}
|
|
public void RedoNextAction()
|
|
{
|
|
var action = LastChange.Next.Value;
|
|
|
|
TreeTrimmer.RedoAction(action);
|
|
|
|
LastChange = LastChange.Next;
|
|
RefreshButton();
|
|
RefreshTree();
|
|
}
|
|
}
|
|
}
|