Skip to content

Commit 30e7bf9

Browse files
committed
Forked from original repository
0 parents  commit 30e7bf9

35 files changed

+2834
-0
lines changed

Diff for: CombinedTable.cs

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NSFW.TimingEditor
7+
{
8+
public enum Operation
9+
{
10+
Undefined = 0,
11+
Sum = 1,
12+
Difference = 2,
13+
}
14+
15+
public class CombinedTable : ITable
16+
{
17+
private ITable a;
18+
private ITable b;
19+
private Operation operation;
20+
21+
public bool IsReadOnly { get { return this.a.IsReadOnly || this.b.IsReadOnly || this.operation != Operation.Sum; } set { throw new InvalidOperationException(); } }
22+
public IList<double> RowHeaders { get { return this.a.RowHeaders; } }
23+
public IList<double> ColumnHeaders { get { return this.a.ColumnHeaders; } }
24+
25+
public CombinedTable(ITable a, ITable b, Operation operation)
26+
{
27+
this.a = a;
28+
this.b = b;
29+
this.operation = operation;
30+
}
31+
32+
public ITable Clone()
33+
{
34+
throw new InvalidOperationException();
35+
/*CombinedTable result = new CombinedTable();
36+
result.a = this.a.Clone();
37+
result.b = this.b.Clone();
38+
result.operation = this.operation;
39+
return result;*/
40+
}
41+
42+
public void CopyTo(ITable other)
43+
{
44+
throw new InvalidOperationException();
45+
}
46+
47+
public bool IsPopulated
48+
{
49+
get
50+
{
51+
return this.a.IsPopulated && this.b.IsPopulated;
52+
}
53+
}
54+
55+
public void Reset()
56+
{
57+
}
58+
59+
public void Populated()
60+
{
61+
throw new InvalidOperationException();
62+
}
63+
64+
public double GetCell(int x, int y)
65+
{
66+
if (this.operation == Operation.Sum)
67+
{
68+
return this.a.GetCell(x, y) + this.b.GetCell(x, y);
69+
}
70+
else if (this.operation == Operation.Difference)
71+
{
72+
return this.b.GetCell(x, y) - this.a.GetCell(x, y);
73+
}
74+
else
75+
{
76+
throw new InvalidOperationException("Undefined CombinedTable Operation: " + this.operation.ToString());
77+
}
78+
}
79+
80+
public void SetCell(int x, int y, double value)
81+
{
82+
double oldTotalValue = this.GetCell(x, y);
83+
double delta = value - oldTotalValue;
84+
85+
if (this.operation == Operation.Sum)
86+
{
87+
double oldValue = this.a.GetCell(x, y);
88+
double newValue = oldValue + delta;
89+
this.a.SetCell(x, y, newValue);
90+
return;
91+
}
92+
93+
throw new InvalidOperationException("Cannot set the value of a difference table.");
94+
}
95+
}
96+
}

Diff for: CommandHistory.cs

+203
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NSFW.TimingEditor
7+
{
8+
public abstract class Command
9+
{
10+
public abstract void Execute();
11+
public abstract void Undo();
12+
}
13+
14+
public class EditCell : Command
15+
{
16+
private ITable table;
17+
private double oldValue;
18+
private double newValue;
19+
private int x;
20+
private int y;
21+
22+
public ITable Table { get { return this.table; } }
23+
public int Y { get { return this.y; } }
24+
public int X { get { return this.x; } }
25+
public double OldValue { get { return this.oldValue; } }
26+
public double NewValue { get { return this.newValue; } }
27+
28+
public EditCell(ITable table, int x, int y, double newValue)
29+
{
30+
this.table = table;
31+
this.x = x;
32+
this.y = y;
33+
this.newValue = newValue;
34+
this.oldValue = this.table.GetCell(this.x, this.y);
35+
}
36+
37+
public override void Execute()
38+
{
39+
this.table.SetCell(this.x, this.y, this.newValue);
40+
}
41+
42+
public override void Undo()
43+
{
44+
this.table.SetCell(this.x, this.y, this.oldValue);
45+
}
46+
}
47+
48+
/* public class EditMultipleCells : Command
49+
{
50+
private IList<EditCell> cells;
51+
public EditMultipleCells(IList<EditCell> cells)
52+
{
53+
this.cells = cells;
54+
}
55+
56+
public override void Execute()
57+
{
58+
foreach (EditCell cell in this.cells)
59+
{
60+
cell.Execute();
61+
}
62+
}
63+
64+
public override void Undo()
65+
{
66+
foreach (EditCell cell in this.cells)
67+
{
68+
cell.Undo();
69+
}
70+
}
71+
}
72+
73+
public class Paste : Command
74+
{
75+
private ITable source;
76+
private ITable destination;
77+
private ITable backup;
78+
79+
public Paste(ITable source, ITable destination)
80+
{
81+
this.source = source;
82+
this.destination = destination;
83+
this.backup = destination.Clone();
84+
}
85+
86+
public override void Execute()
87+
{
88+
this.source.CopyTo(destination);
89+
}
90+
91+
public override void Undo()
92+
{
93+
this.backup.CopyTo(this.destination);
94+
}
95+
}
96+
97+
public class DoublePaste : Command
98+
{
99+
private Paste initial;
100+
private Paste modified;
101+
102+
public DoublePaste(Paste initial, Paste modified)
103+
{
104+
this.initial = initial;
105+
this.modified = modified;
106+
}
107+
108+
public override void Execute()
109+
{
110+
this.initial.Execute();
111+
this.modified.Execute();
112+
}
113+
114+
public override void Undo()
115+
{
116+
this.initial.Undo();
117+
this.modified.Undo();
118+
}
119+
}
120+
*/
121+
public delegate void UpdateCommandHistoryButtons(object sender, EventArgs args);
122+
123+
public class CommandHistory
124+
{
125+
private static CommandHistory instance = new CommandHistory();
126+
private List<Command> commands;
127+
private List<Command> undone;
128+
129+
public event UpdateCommandHistoryButtons UpdateCommandHistoryButtons;
130+
131+
private CommandHistory()
132+
{
133+
this.commands = new List<Command>();
134+
this.undone = new List<Command>();
135+
}
136+
137+
public static CommandHistory Instance
138+
{
139+
[System.Diagnostics.DebuggerStepThrough]
140+
get
141+
{
142+
return instance;
143+
}
144+
}
145+
146+
public bool CanUndo { get { return this.commands.Count > 0; } }
147+
public bool CanRedo { get { return this.undone.Count > 0; } }
148+
149+
public void Execute(Command command)
150+
{
151+
command.Execute();
152+
this.commands.Add(command);
153+
this.undone.Clear();
154+
this.UpdateButtons();
155+
}
156+
157+
public Command Undo()
158+
{
159+
if (this.commands.Count == 0)
160+
{
161+
return null;
162+
}
163+
164+
int lastIndex = this.commands.Count - 1;
165+
Command command = this.commands[lastIndex];
166+
this.commands.RemoveAt(lastIndex);
167+
168+
command.Undo();
169+
170+
this.undone.Add(command);
171+
this.UpdateButtons();
172+
173+
return command;
174+
}
175+
176+
public Command Redo()
177+
{
178+
if (this.undone.Count == 0)
179+
{
180+
return null;
181+
}
182+
183+
int lastIndex = this.undone.Count - 1;
184+
Command command = this.undone[lastIndex];
185+
this.undone.RemoveAt(lastIndex);
186+
187+
command.Execute();
188+
189+
this.commands.Add(command);
190+
this.UpdateButtons();
191+
192+
return command;
193+
}
194+
195+
private void UpdateButtons()
196+
{
197+
if (this.UpdateCommandHistoryButtons != null)
198+
{
199+
this.UpdateCommandHistoryButtons(this, new EventArgs());
200+
}
201+
}
202+
}
203+
}

Diff for: ITable.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NSFW.TimingEditor
7+
{
8+
public interface ITable
9+
{
10+
bool IsReadOnly { get; set; }
11+
bool IsPopulated { get; }
12+
IList<double> RowHeaders { get; }
13+
IList<double> ColumnHeaders { get; }
14+
ITable Clone();
15+
void CopyTo(ITable destination);
16+
double GetCell(int x, int y);
17+
void SetCell(int x, int y, double value);
18+
void Reset();
19+
void Populated();
20+
}
21+
}

0 commit comments

Comments
 (0)