-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.js
More file actions
121 lines (83 loc) · 2.3 KB
/
Copy pathcommand.js
File metadata and controls
121 lines (83 loc) · 2.3 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// *********************************************************
//
// Copyright (c) 2005-2008, Southpaw Technology
// All Rights Reserved
//
// PROPRIETARY INFORMATION. This software is proprietary to
// Southpaw Technolog, and is not to be reproduced, transmitted,
// or disclosed in any way without written permission.
//
//
// DEPRECATED: moved to dg_table.js
//
// BUT: keep around because this may be used for reference if we put
// a real command system in the interface
Command = new Class({
initialize: function(){
return;
},
execute: function() {
spt.js_log.debug("execute");
},
get_description: function() { return ''; },
undo: function() {
spt.js_log.debug("undo");
},
redo: function() {
spt.js_log.debug("redo");
}
});
// store a list of commands that have been executed
Command.commands = [];
Command.command_index = -1;
Command.execute_cmd = function(cmd) {
cmd.execute();
try {
var description = cmd.get_description();
spt.js_log.debug( "CMD: " + description);
} catch(e) {
spt.js_log.debug( "No description" );
}
// FIXME: do not add to undo just yet
//this.add_to_undo(cmd);
}
Command.add_to_undo = function(cmd) {
// remove old commands
for (var i=Command.commands.length;i>Command.command_index+1;i--) {
Command.commands.pop();
}
Command.commands.push(cmd);
Command.command_index += 1;
}
Command.undo_last = function() {
if (Command.command_index == -1) {
alert("Nothing to undo");
return;
}
var cmd = Command.commands[Command.command_index];
cmd.undo();
Command.command_index -= 1;
}
Command.redo_last = function() {
if (Command.command_index == Command.commands.length-1) {
alert("Nothing to redo");
return;
}
var cmd = Command.commands[Command.command_index+1];
cmd.redo();
Command.command_index += 1;
}
Command.undo_all = function() {
for (var i = Command.commands.length-1; i >= 0; i--) {
var cmd = Command.commands[i];
cmd.undo();
}
}
Command.test = function() {
for (var i=0; i < 5; i++) {
var cmd = new Command();
Command.execute_cmd(cmd);
}
// undo all of the commands
Command.undo_all()
}