-
Notifications
You must be signed in to change notification settings - Fork 0
/
palettehandingui.pas
464 lines (415 loc) · 17.6 KB
/
palettehandingui.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
UNIT paletteHandingUi;
{$mode objfpc}{$H+}
INTERFACE
USES
Classes, sysutils, Forms, Controls, Graphics, Dialogs, Grids, ExtCtrls,
StdCtrls, Menus, paletteHandling,workspaces,visualGates;
TYPE
{ TPaletteHandlingDialog }
TPaletteHandlingDialog = class(TForm)
EditBoardLabel: TLabel;
EditBoardShape: TShape;
entriesGrid: TStringGrid;
MainMenu1: TMainMenu;
MarkNoneShape: TShape;
MarkAllLabel: TLabel;
MarkAllShape: TShape;
ExportLabel: TLabel;
ImportLabel: TLabel;
ExportShape: TShape;
DeleteLabel: TLabel;
ImportShape: TShape;
DeleteShape: TShape;
MarkNoneLabel: TLabel;
DetailsMemo: TMemo;
MenuItem1: TMenuItem;
miCleanupManually: TMenuItem;
miRemoveDuplicatesExact: TMenuItem;
miRemoveDuplicatesBehavior: TMenuItem;
MoveTaskDownLabel: TLabel;
MoveTaskDownShape: TShape;
MoveTaskUpLabel: TLabel;
MoveTaskUpShape: TShape;
OpenDialog1: TOpenDialog;
Splitter1: TSplitter;
SubPaletteStringGrid: TStringGrid;
SubPalettePanel: TPanel;
SaveDialog1: TSaveDialog;
StartTaskLabel: TLabel;
PROCEDURE EditBoardShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE entriesGridGetCheckboxState(Sender: TObject; aCol, aRow: integer; VAR value: TCheckboxState);
PROCEDURE entriesGridHeaderClick(Sender: TObject; IsColumn: boolean; index: integer);
PROCEDURE entriesGridSelectEditor(Sender: TObject; aCol, aRow: integer; VAR editor: TWinControl);
PROCEDURE entriesGridSelection(Sender: TObject; aCol, aRow: integer);
PROCEDURE DeleteShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE entriesGridSetCheckboxState(Sender: TObject; aCol, aRow: integer; CONST value: TCheckboxState);
PROCEDURE entriesGridValidateEntry(Sender: TObject; aCol, aRow: integer; CONST oldValue: string; VAR newValue: string);
PROCEDURE ExportShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE FormCreate(Sender: TObject);
PROCEDURE FormShow(Sender: TObject);
PROCEDURE ImportShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE MarkAllShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE MarkNoneShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE miCleanupManuallyClick(Sender: TObject);
PROCEDURE miRemoveDuplicatesBehaviorClick(Sender: TObject);
PROCEDURE miRemoveDuplicatesExactClick(Sender: TObject);
PROCEDURE MoveTaskDownShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE MoveTaskUpShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE SubPaletteStringGridSelection(Sender: TObject; aCol, aRow: integer);
PROCEDURE SubPaletteStringGridValidateEntry(Sender: TObject; aCol, aRow: integer; CONST oldValue: string; VAR newValue: string);
private
palette:P_workspacePalette;
lastClicked:longint;
lastClickedSubPalette:longint;
sorting:record
byColumn:byte;
ascending:boolean;
index:array of longint;
end;
backupCreated:boolean;
PROCEDURE createBackupOnce(CONST reason: T_workspaceHistorizationTriggerEnum);
PROCEDURE fillTable(CONST initial:boolean=false);
PROCEDURE updateButtons;
public
PROCEDURE showFor(CONST palette_:P_workspacePalette);
end;
VAR uiAdapter:P_uiAdapter;
FUNCTION PaletteHandlingDialog: TPaletteHandlingDialog;
IMPLEMENTATION
USES visuals,logicalGates,paletteImportUi,duplicateRemovalUi;
VAR
myPaletteForm: TPaletteHandlingDialog=nil;
{$R *.lfm}
FUNCTION PaletteHandlingDialog: TPaletteHandlingDialog;
begin
if myPaletteForm=nil then myPaletteForm:=TPaletteHandlingDialog.create(nil);
result:=myPaletteForm;
end;
PROCEDURE TPaletteHandlingDialog.entriesGridSelection(Sender: TObject; aCol, aRow: integer);
begin
lastClicked:=aRow-1;
if (lastClicked>=0) and (lastClicked<length(sorting.index))
then DetailsMemo.text:=palette^.describeEntry(sorting.index[lastClicked]);
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.entriesGridSelectEditor(Sender: TObject; aCol, aRow: integer; VAR editor: TWinControl);
begin
if (editor is TPickListCellEditor) then begin
TPickListCellEditor(editor).color:=colorScheme.editorBackgroundColor;
TPickListCellEditor(editor).Font.color:=colorScheme.ENABLED_TEXT_COLOR;
TPickListCellEditor(editor).style:=csOwnerDrawEditableFixed;
TPickListCellEditor(editor).AutoComplete:=true;
TPickListCellEditor(editor).AutoCompleteText:=[cbactEnabled,cbactEndOfLineComplete,cbactSearchAscending];
end;
end;
PROCEDURE TPaletteHandlingDialog.entriesGridHeaderClick(Sender: TObject; IsColumn: boolean; index: integer);
begin
if not(IsColumn) then exit;
if sorting.byColumn=index then sorting.ascending:=not(sorting.ascending)
else begin
sorting.byColumn:=index;
sorting.ascending:=true;
end;
fillTable(false);
end;
PROCEDURE TPaletteHandlingDialog.entriesGridGetCheckboxState(Sender: TObject; aCol, aRow: integer; VAR value: TCheckboxState);
begin
if (aCol<>3) then exit;
aRow-=1;
if (aRow<0) or (aRow>=length(sorting.index)) then exit;
if palette^.paletteEntries[sorting.index[aRow]].entryType=gt_compound
then begin
if palette^.paletteEntries[sorting.index[aRow]].markedForExport
then value:=cbChecked
else value:=cbUnchecked;
end else value:=cbGrayed;
end;
PROCEDURE TPaletteHandlingDialog.EditBoardShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
VAR i:longint;
begin
i:=lastClicked;
if (i<0) or (i>length(sorting.index)) then exit else i:=sorting.index[i];
if palette^.paletteEntries[i].entryType=gt_compound
then begin
workspace.editPaletteEntry(palette^.paletteEntries[i].prototype,uiAdapter);
ModalResult:=mrYes;
end;
end;
PROCEDURE TPaletteHandlingDialog.DeleteShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
VAR i:longint;
selection:TGridRect;
begin
buttonClicked(DeleteShape);
i:=lastClicked;
if (i<0) or (i>length(sorting.index)) then exit;
createBackupOnce(wht_beforeDeletingEntry);
palette^.deleteEntry(sorting.index[i]);
fillTable(true);
lastClicked-=1;
selection.Bottom:=lastClicked+1;
selection.top:=lastClicked+1;
selection.Left:=0;
selection.Right:=0;
entriesGrid.selection:=selection;
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.entriesGridSetCheckboxState(Sender: TObject; aCol, aRow: integer; CONST value: TCheckboxState);
begin
if (aCol<>3) then exit;
aRow-=1;
if (aRow<0) or (aRow>=length(sorting.index)) then exit;
if palette^.paletteEntries[sorting.index[aRow]].entryType=gt_compound
then begin
palette^.markEntryForExport(sorting.index[aRow],value=cbChecked);
fillTable;
updateButtons;
end;
end;
PROCEDURE TPaletteHandlingDialog.entriesGridValidateEntry(Sender: TObject; aCol, aRow: integer; CONST oldValue: string; VAR newValue: string);
VAR editedIdx: longint;
begin
dec(aRow);
if (aRow<0) or (aRow>=length(sorting.index)) then exit;
editedIdx:=sorting.index[aRow];
if aCol=0 then begin
//Edit caption
if not(palette^.setPaletteEntryCaption(editedIdx,StringReplace(newValue,'\n',LineEnding,[rfReplaceAll]))) then newValue:=oldValue
end else if aCol=1 then begin
//Edit description
if not(palette^.setPaletteEntryDescription(editedIdx,StringReplace(newValue,'\n',LineEnding,[rfReplaceAll]))) then newValue:=oldValue
end else if aCol=2 then begin
//Edit palette
palette^.setPaletteEntrySubPalette(editedIdx,newValue);
end;
end;
PROCEDURE TPaletteHandlingDialog.ExportShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
buttonClicked(ExportShape);
if SaveDialog1.execute then palette^.exportSelected(SaveDialog1.fileName);
end;
PROCEDURE TPaletteHandlingDialog.FormCreate(Sender: TObject);
begin
palette:=nil;
entriesGrid.rowCount:=1;
SubPaletteStringGrid.editor .color:=SubPaletteStringGrid .color;
SubPaletteStringGrid.editor.Font.color:=SubPaletteStringGrid.Font.color;
entriesGrid.editor .color:=entriesGrid .color;
entriesGrid.editor.Font.color:=entriesGrid.Font.color;
addButton(MoveTaskUpShape,MoveTaskUpLabel);
addButton(MoveTaskDownShape,MoveTaskDownLabel);
addButton(MarkAllShape,MarkAllLabel);
addButton(MarkNoneShape,MarkNoneLabel);
addButton(ExportShape,ExportLabel);
addButton(ImportShape,ImportLabel);
addButton(DeleteShape,DeleteLabel);
end;
PROCEDURE TPaletteHandlingDialog.FormShow(Sender: TObject);
begin
applyColorScheme(self);
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.ImportShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
buttonClicked(ImportShape);
createBackupOnce(wht_beforePaletteImport);
if OpenDialog1.execute then begin
if PaletteImportForm.ShowModal=mrOk
then palette^.importPalette(OpenDialog1.fileName,PaletteImportForm.importOptions)
else exit;
end else exit;
fillTable(true);
end;
PROCEDURE TPaletteHandlingDialog.MarkAllShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
buttonClicked(MarkAllShape);
palette^.markAllEntriesForExport(true);
fillTable;
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.MarkNoneShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
buttonClicked(MarkNoneShape);
palette^.markAllEntriesForExport(false);
fillTable;
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.miCleanupManuallyClick(Sender: TObject);
begin
if (lastClicked>=0) and (lastClicked<length(sorting.index))
then begin
DuplicateRemovalDialog.showFor(sorting.index[lastClicked]);
fillTable(true);
end;
end;
PROCEDURE TPaletteHandlingDialog.miRemoveDuplicatesBehaviorClick(Sender: TObject);
begin
createBackupOnce(wht_beforeDuplicateRemoval);
palette^.removeDuplicates(true);
fillTable;
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.miRemoveDuplicatesExactClick(Sender: TObject);
begin
createBackupOnce(wht_beforeDuplicateRemoval);
palette^.removeDuplicates(false);
fillTable;
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.MoveTaskDownShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
VAR selection:TGridRect;
begin
buttonClicked(MoveTaskDownShape);
palette^.swapPaletteName(lastClickedSubPalette,false);
inc(lastClickedSubPalette);
fillTable;
selection.Bottom:=lastClickedSubPalette+1;
selection.top:=lastClickedSubPalette+1;
selection.Left:=0;
selection.Right:=0;
SubPaletteStringGrid.selection:=selection;
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.MoveTaskUpShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
VAR selection:TGridRect;
begin
buttonClicked(MoveTaskUpShape);
palette^.swapPaletteName(lastClickedSubPalette,true);
dec(lastClickedSubPalette);
fillTable;
selection.Bottom:=lastClickedSubPalette+1;
selection.top:=lastClickedSubPalette+1;
selection.Left:=0;
selection.Right:=0;
SubPaletteStringGrid.selection:=selection;
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.SubPaletteStringGridSelection(Sender: TObject; aCol, aRow: integer);
begin
lastClickedSubPalette:=aRow-1;
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.SubPaletteStringGridValidateEntry(Sender: TObject; aCol, aRow: integer; CONST oldValue: string; VAR newValue: string);
begin
lastClickedSubPalette:=aRow-1;
if (lastClickedSubPalette<0) or (lastClickedSubPalette>=length(palette^.paletteNames))
then newValue:=oldValue
else palette^.paletteNames[lastClickedSubPalette]:=newValue;
fillTable;
end;
PROCEDURE TPaletteHandlingDialog.createBackupOnce(CONST reason: T_workspaceHistorizationTriggerEnum);
begin
if backupCreated then exit;
addBackup(@workspace,reason);
backupCreated:=true;
end;
PROCEDURE TPaletteHandlingDialog.fillTable(CONST initial: boolean);
PROCEDURE updateSorting;
FUNCTION comesBefore(CONST i,j:longint):boolean;
begin
case sorting.byColumn of
0: if sorting.ascending
then result:=uppercase(titleOf(palette^.paletteEntries[i]))<uppercase(titleOf(palette^.paletteEntries[j]))
else result:=uppercase(titleOf(palette^.paletteEntries[i]))>uppercase(titleOf(palette^.paletteEntries[j]));
1: if sorting.ascending
then result:=uppercase(descriptionOf(palette^.paletteEntries[i]))<uppercase(descriptionOf(palette^.paletteEntries[j]))
else result:=uppercase(descriptionOf(palette^.paletteEntries[i]))>uppercase(descriptionOf(palette^.paletteEntries[j]));
2: if sorting.ascending
then result:=palette^.paletteEntries[i].subPaletteIndex<palette^.paletteEntries[j].subPaletteIndex
else result:=palette^.paletteEntries[i].subPaletteIndex>palette^.paletteEntries[j].subPaletteIndex;
3: if sorting.ascending
then result:=palette^.paletteEntries[i].markedForExport<palette^.paletteEntries[j].markedForExport
else result:=palette^.paletteEntries[i].markedForExport>palette^.paletteEntries[j].markedForExport;
else exit(false);
end;
end;
VAR i,j,k:longint;
begin
with sorting do begin
if length(index)<>length(palette^.paletteEntries) then begin
setLength(index,length(palette^.paletteEntries));
for k:=0 to length(index)-1 do index[k]:=k;
end;
if sorting.byColumn in [0..3] then begin
for i:=1 to length(index)-1 do for j:=0 to i-1 do
if comesBefore(index[i],index[j]) then begin
k:=index[i]; index[i]:=index[j]; index[j]:=k;
end;
end else for k:=0 to length(index)-1 do index[k]:=k;
end;
end;
PROCEDURE fillRow(CONST i: longint);
begin
with palette^.paletteEntries[sorting.index[i]] do begin
entriesGrid.Cells[0,i+1]:=StringReplace(titleOf (palette^.paletteEntries[sorting.index[i]]),LineEnding,'\n',[rfReplaceAll]);
entriesGrid.Cells[1,i+1]:=StringReplace(descriptionOf(palette^.paletteEntries[sorting.index[i]]),LineEnding,'\n',[rfReplaceAll]);
entriesGrid.Cells[2,i+1]:=palette^.subPaletteNames[subPaletteIndex];
entriesGrid.Cells[3,i+1]:=BoolToStr(markedForExport,'x',' ');
end;
end;
VAR i:longint;
begin
entriesGrid.rowCount:=1+length(palette^.paletteEntries);
entriesGrid.Columns[3].ValueChecked:='x';
entriesGrid.Columns[3].ValueUnchecked:=' ';
updateSorting;
for i:=0 to length(palette^.paletteEntries)-1 do fillRow(i);
SubPaletteStringGrid.rowCount:=1+length(palette^.paletteNames);
entriesGrid.Columns[2].PickList.clear;
for i:=0 to length(palette^.paletteNames)-1 do begin
SubPaletteStringGrid.Cells[0,i+1]:=palette^.paletteNames[i];
entriesGrid.Columns[2].PickList.add(palette^.paletteNames[i]);
end;
entriesGrid.Columns[3].visible:=not(workspace.simplisticUi);
ImportShape .visible:=not(workspace.simplisticUi);
ImportLabel .visible:=not(workspace.simplisticUi);
ExportShape .visible:=not(workspace.simplisticUi);
ExportLabel .visible:=not(workspace.simplisticUi);
DeleteShape .visible:=not(workspace.simplisticUi);
DeleteLabel .visible:=not(workspace.simplisticUi);
MarkAllShape .visible:=not(workspace.simplisticUi);
MarkAllLabel .visible:=not(workspace.simplisticUi);
MarkNoneShape .visible:=not(workspace.simplisticUi);
MarkNoneLabel .visible:=not(workspace.simplisticUi);
MoveTaskDownShape.visible:=not(workspace.simplisticUi);
MoveTaskDownLabel.visible:=not(workspace.simplisticUi);
MoveTaskUpShape .visible:=not(workspace.simplisticUi);
MoveTaskUpLabel .visible:=not(workspace.simplisticUi);
if not(initial) then exit;
entriesGrid.AutoSizeColumn(0);
entriesGrid.AutoSizeColumn(2);
entriesGrid.AutoSizeColumn(3);
lastClicked:=-1;
lastClickedSubPalette:=-1;
updateButtons;
end;
PROCEDURE TPaletteHandlingDialog.updateButtons;
VAR anyMarked:boolean=false;
i:longint;
begin
for i:=0 to length(palette^.paletteEntries)-1 do with palette^.paletteEntries[i] do anyMarked:=anyMarked or (entryType=gt_compound) and markedForExport;
setEnableButton(DeleteShape,DeleteLabel,
(lastClicked>=0) and
(palette^.paletteEntries[sorting.index[lastClicked]].entryType=gt_compound) and
palette^.allowDeletion(sorting.index[lastClicked]));
setEnableButton(EditBoardShape,EditBoardLabel,
(lastClicked>=0) and
(palette^.paletteEntries[sorting.index[lastClicked]].entryType=gt_compound));
setEnableButton(ExportShape,ExportLabel,anyMarked);
setEnableButton(MoveTaskUpShape,MoveTaskUpLabel,lastClickedSubPalette>0);
setEnableButton(MoveTaskDownShape,MoveTaskDownLabel,(lastClickedSubPalette>=0) and (lastClickedSubPalette<length(palette^.paletteNames)-1));
end;
PROCEDURE TPaletteHandlingDialog.showFor(CONST palette_: P_workspacePalette);
begin
lastClicked:=-1;
lastClickedSubPalette:=-1;
backupCreated:=false;
palette:=palette_;
sorting.byColumn:=255;
setLength(sorting.index,0);
fillTable(true);
updateButtons;
ShowModal;
end;
FINALIZATION
if myPaletteForm<>nil then FreeAndNil(myPaletteForm);
end.