This repository was archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathundo_base.pas
85 lines (60 loc) · 2.43 KB
/
undo_base.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{ This file is a part of Map editor for VCMI project
Copyright (C) 2013-2017 Alexander Shishkin [email protected]
This source is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
version.
This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
A copy of the GNU General Public License is available on the World Wide Web at
<http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
unit undo_base;
{$I compilersetup.inc}
interface
uses
Classes, SysUtils;
type
TUndoItemState = (Idle, UnDone, ReDone);
{ TAbstractUndoItem }
TAbstractUndoItem = class abstract
private
FState: TUndoItemState;
protected
function GetDescription: string; virtual; abstract;
public
property State:TUndoItemState read FState write FState;
procedure Undo; virtual; abstract;
procedure Redo; virtual; abstract;
//return true if action was actually executed
function Execute: boolean; virtual; abstract;
property Description: string read GetDescription;
end;
{ TAbstractUndoManager }
TAbstractUndoManager = class abstract
protected
class procedure SetItemState(AItem: TAbstractUndoItem; AState: TUndoItemState); static;
public
//Last executed item. Will be undone first
function PeekCurrent: TAbstractUndoItem; virtual; abstract;
//Last undone item. Will be redone next if any
function PeekNext: TAbstractUndoItem; virtual; abstract;
//current present
function CanUndo: boolean; virtual; abstract;
//next present
function CanRedo: boolean; virtual; abstract;
procedure Undo; virtual; abstract;
procedure Redo; virtual; abstract;
//redo action (= first execute), push to stack, acquire ownership
function ExecuteItem(AItem: TAbstractUndoItem): boolean; virtual; abstract;
procedure Clear; virtual; abstract;
end;
implementation
{ TAbstractUndoManager }
class procedure TAbstractUndoManager.SetItemState(AItem: TAbstractUndoItem;
AState: TUndoItemState);
begin
AItem.State:=AState;
end;
end.