-
Notifications
You must be signed in to change notification settings - Fork 1
/
frm_editsetastext.pas
238 lines (209 loc) · 6.14 KB
/
frm_editsetastext.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
unit frm_editsetastext;
interface
uses
Windows, Messages, SysUtils, StrUtils, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls, bi_db, ImportFileForm;
type
TEditSetAsTextForm = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Panel2: TPanel;
Panel3: TPanel;
txtPart: TEdit;
boxColor: TComboBox;
txtNum: TEdit;
btnAdd: TButton;
btnModify: TButton;
Label3: TLabel;
CheckBox1: TCheckBox;
Button3: TButton;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
grpSimilars: TGroupBox;
pnlSimilars: TPanel;
lstSimilars: TListBox;
procedure btnAddClick(Sender: TObject);
procedure btnModifyClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure txtNumKeyPress(Sender: TObject; var Key: Char);
procedure FormDestroy(Sender: TObject);
procedure Panel3Enter(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure txtPartKeyPress(Sender: TObject; var Key: Char);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
LineIndex: Integer;
partData: TStringList;
procedure listColors(const colors: colorinfoarray_t);
function InLineData: String;
public
{ Public declarations }
end;
function EditSetAsTextForm(const setid: string; const colors: colorinfoarray_t;
var data: string; var setinfo: TSetExtraInfo): boolean;
implementation
{$R *.dfm}
uses bi_delphi, bi_utils, timing, searchset, bi_globals;
function EditSetAsTextForm(const setid: string; const colors: colorinfoarray_t;
var data: string; var setinfo: TSetExtraInfo): boolean;
var
f: TEditSetAsTextForm;
i: integer;
s: string;
begin
result := false;
f := TEditSetAsTextForm.Create(nil);
try
f.Caption := f.Caption + ' - ' + setid;
f.LineIndex := -1;
f.Memo1.Text := data;
f.CheckBox1.Checked:= setinfo.moc;
f.Edit1.Text := setinfo.text;
f.Edit2.Text := itoa(setinfo.year);
ExtractStrings([FormatSettings.ListSeparator],[],PChar(setinfo.similars),f.lstSimilars.Items);
f.listColors(colors);
f.ShowModal;
if f.ModalResult = mrOK then
begin
s:= '';
for i:=0 to f.Memo1.Lines.Count-1 do begin
s:= s + ReplaceWhiteSpace(f.Memo1.Lines[i],'_',false)+sLineBreak;
end;
s:= StringReplace(s, '_', '', [rfReplaceAll]);
data := s;
setinfo.moc := f.CheckBox1.Checked;
setinfo.text := Trim(f.Edit1.Text);
setinfo.year := atoi(Trim(f.Edit2.Text));
s:= Trim(ReplaceWhiteSpace(f.lstSimilars.Items.Text ,' ' ,false));
s:= StringReplace(s, ' ', FormatSettings.ListSeparator, [rfReplaceAll]);
setinfo.similars:= s;
result := true;
end;
finally
f.Free;
end;
end;
function TEditSetAsTextForm.InLineData: String;
var
F,C: String;
begin
C:= Trim(Copy(boxColor.Text,0,Pos(':',boxColor.Text)-1));
F:= Trim(txtPart.Text) +', '+C+','+Trim(txtNum.Text);
result:= F;
end;
procedure TEditSetAsTextForm.listColors(const colors: colorinfoarray_t);
var
n,m: integer;
color: colorinfo_t;
begin
boxColor.AddItem(' 0 : Black', TObject(0));
for n:=0 to Length(colors) -1 do begin
color:= colors[n];
if (color.id > 0) and (Length(Trim(color.name))>0) then
boxColor.AddItem(LeftPad(IntToStr(color.id),4,' ')+' : '+color.name, TObject(color.id));
end;
end;
procedure TEditSetAsTextForm.btnAddClick(Sender: TObject);
begin
LineIndex:= 1;
Memo1.Lines.Insert(1,InLineData());
end;
procedure TEditSetAsTextForm.btnModifyClick(Sender: TObject);
begin
If LineIndex > 0 then
begin
Memo1.Lines.BeginUpdate();
try
Memo1.Lines[LineIndex]:= InLineData();
finally
Memo1.Lines.EndUpdate();
end;
end;
end;
procedure TEditSetAsTextForm.FormCreate(Sender: TObject);
var
i,j,n,prev,index : integer;
full,name : string;
begin
SendMessage(GetWindow(boxColor.Handle,GW_CHILD), EM_SETREADONLY, 1, 0);
partData:= TStringList.Create();
end;
procedure TEditSetAsTextForm.txtNumKeyPress(Sender: TObject;
var Key: Char);
begin
if not (Key in [#8, '0'..'9', FormatSettings.DecimalSeparator]) then Key := #0;
end;
procedure TEditSetAsTextForm.FormDestroy(Sender: TObject);
begin
partData.Free;
end;
procedure TEditSetAsTextForm.Panel3Enter(Sender: TObject);
var
i,j: integer;
begin
LineIndex:= Memo1.CaretPos.Y;
If LineIndex > 0 then
try
partData.Clear;
ExtractStrings([','], [], PChar(Memo1.Lines[LineIndex]), partData);
finally
If partData.Count = 3 then begin
txtPart.Text:= partData[0];
i:= StrToIntDef(RemoveChars(partData[1] ,true),-1);
if (Pos(BLDATATYPE+' ',partData[1])<>0) then
i:= db.BrickLinkColorToRebrickableColor(i);
j:= boxColor.Items.IndexOfObject(TObject(i));
boxColor.ItemIndex:= j;
txtNum.Text:= RemoveChars(partData[2] ,true);
end;
end;
end;
procedure TEditSetAsTextForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
TimingForm.CrawlerTimer.Enabled := true;
end;
procedure TEditSetAsTextForm.FormShow(Sender: TObject);
begin
TimingForm.CrawlerTimer.Enabled := false;
end;
procedure TEditSetAsTextForm.txtPartKeyPress(Sender: TObject;
var Key: Char);
begin
if (Key in SPECIALCHARS) then Key:= #0;
end;
procedure TEditSetAsTextForm.Button3Click(Sender: TObject);
var
data: TStringList;
ordValue: integer;
source: sourcetype_t;
begin
if OpenDialog1.Execute then
begin
data:= TStringList.Create;
try
ordValue:= OpenDialog1.FilterIndex;
if (ordValue >= Ord(Low(sourcetype_t))) and (ordValue <= Ord(High(sourcetype_t)))
then source:= sourcetype_t(ordValue)
else source:= stBrickLink;
if source = stLDraw
then Memo1.Lines.Add(LDrawToCSV(OpenDialog1.FileName))
else if source = stLDCad then Memo1.Lines.Add(LDCadToCSV(OpenDialog1.FileName))
else if GetDataFromFile(OpenDialog1.FileName, source, data) then
Memo1.Lines.AddStrings(data);
finally
data.Free;
end;
end;
end;
end.