-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYataGrid_editrow.cs
205 lines (165 loc) · 5.07 KB
/
YataGrid_editrow.cs
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using System;
using System.Drawing;
namespace yata
{
// Routines for row edits.
sealed partial class YataGrid
{
/// <summary>
/// Inserts a <c><see cref="Row"/></c> into this <c>YataGrid</c>.
/// </summary>
/// <param name="rowid">row-id to insert at</param>
/// <param name="fields">an array of fields</param>
/// <param name="brush">a <c>Brush</c> to use for Undo/Redo</param>
/// <param name="bypassCalibrate"><c>false</c> to re-layout the grid or
/// <c>true</c> if <c><see cref="Calibrate()">Calibrate()</see></c> will
/// be done by the caller</param>
/// <remarks>Ensure that <paramref name="fields"/> is valid.</remarks>
internal void Insert(int rowid,
string[] fields,
Brush brush,
bool bypassCalibrate = false)
{
// if (!bypassCalibrate)
// DrawRegulator.SuspendDrawing(this);
var row = new Row(rowid, ColCount, brush, this);
string field;
for (int c = 0; c != ColCount; ++c)
{
if (c < fields.Length)
field = fields[c];
else
field = gs.Stars;
row[c] = new Cell(rowid, c, field);
doTextwidth(row[c]);
}
Rows.Insert(rowid, row);
++RowCount;
for (int r = rowid + 1; r != RowCount; ++r) // straighten out row._id and cell.y ->
{
++(row = Rows[r])._id;
for (int c = 0; c != ColCount; ++c)
++row[c].y;
}
if (!bypassCalibrate)
{
Calibrate(rowid);
if (rowid < RowCount)
EnsureDisplayedRow(rowid);
// DrawRegulator.ResumeDrawing(this);
}
}
/// <summary>
/// Deletes a <c><see cref="Row"/></c> from this <c>YataGrid</c>.
/// </summary>
/// <param name="rowid">row-id to delete</param>
/// <param name="bypassCalibrate"><c>true</c> to re-layout the grid or
/// <c>false</c> if <c><see cref="Calibrate()">Calibrate()</see></c>
/// will be done by the caller</param>
/// <param name="bypassCreate"><c>true</c> to bypass the creation of a
/// blank row if all rows are deleted - passed by
/// <list type="bullet">
/// <item><c><see cref="UndoRedo"/>.DeleteRow()</c></item>
/// <item><c><see cref="UndoRedo"/>.DeleteArray()</c></item>
/// <item><c><see cref="Yata"/>.editrowsclick_PasteRangeReplace()</c></item>
/// </list></param>
/// <returns>a <c><see cref="Row"/></c> iff a default row has been
/// created</returns>
internal Row Delete(int rowid, bool bypassCalibrate = false, bool bypassCreate = false)
{
// if (!bypassCalibrate)
// DrawRegulator.SuspendDrawing(this);
Rows.Remove(Rows[rowid]);
--RowCount;
Row created;
for (int r = rowid; r != RowCount; ++r) // straighten out row._id and cell.y ->
{
--(created = Rows[r])._id;
for (int c = 0; c != ColCount; ++c)
--created[c].y;
}
if (RowCount == 0 && !bypassCreate) // add a row of stars so grid is not left blank ->
{
++RowCount;
created = new Row(0, ColCount, ColorOptions._rowcreated, this);
int c = 0;
if (Options._autorder)
{
created[0] = new Cell(0,0, "0");
doTextwidth(created[0]);
++c;
}
for (; c != ColCount; ++c)
{
created[c] = new Cell(0, c, gs.Stars);
doTextwidth(created[c]);
}
Rows.Add(created);
if (!bypassCalibrate)
{
Calibrate(0);
// DrawRegulator.ResumeDrawing(this);
return created; // <- that row needs to be added to UndoRedo after the delete operation
}
}
else
created = null;
if (!bypassCalibrate)
{
Calibrate();
if (rowid < RowCount)
EnsureDisplayedRow(rowid);
// DrawRegulator.ResumeDrawing(this);
}
return created;
}
/// <summary>
/// Deletes a single or multiple <c><see cref="Row">Rows</see></c>.
/// </summary>
/// <remarks>Called by
/// <list type="bullet">
/// <item><c><see cref="Yata"/>.editrowsclick_DeleteRange()</c></item>
/// <item><c><see cref="Yata"/>.editrowsclick_PasteRangeReplace()</c></item>
/// </list></remarks>
internal void DeleteRows(bool bypassCreate = false)
{
_f.Obfuscate();
// DrawRegulator.SuspendDrawing(this);
int selr = getSelectedRow();
int range = Math.Abs(RangeSelect);
Restorable rest = UndoRedo.createArray(range + 1, UndoRedo.UrType.rt_ArrayInsert);
Row created = null;
int rFirst, rLast;
if (RangeSelect > 0) { rFirst = selr; rLast = selr + RangeSelect; }
else { rFirst = selr + RangeSelect; rLast = selr; }
while (rLast >= rFirst) // reverse delete.
{
rest.array[range--] = Rows[rLast].Clone() as Row;
created = Delete(rLast, true, bypassCreate);
--rLast;
}
if (RowCount == 1 && rLast == -1) // ie. if grid was blanked -> ID #0 was auto-inserted.
rLast = 0;
else
rLast = -1; // calibrate all extant rows.
Calibrate(rLast); // delete key
if (selr < RowCount)
EnsureDisplayedRow(selr);
if (!Changed)
{
Changed = true;
rest.isSaved = UndoRedo.IsSavedType.is_Undo;
}
_ur.Push(rest);
if (created != null)
{
rest = UndoRedo.createArray(1, UndoRedo.UrType.rt_ArrayDelete);
rest.array[0] = created.Clone() as Row;
_ur.Push(rest);
_ur.SetChained(2);
}
// DrawRegulator.ResumeDrawing(this);
_f.Obfuscate(false);
}
}
}