-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pas
executable file
·356 lines (318 loc) · 7.97 KB
/
main.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
unit main;
{$MODE Delphi}
interface
uses
LCLIntf, LCLType, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls,
Menus, Inifiles, Spin, ComCtrls, Edit, Subrec;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Panel1: TPanel;
ListBox1: TListBox;
SaveDialog1: TSaveDialog;
MainMenu1: TMainMenu;
File1: TMenuItem;
N1: TMenuItem;
About1: TMenuItem;
Exit1: TMenuItem;
Renumber1: TMenuItem;
N2: TMenuItem;
Panel3: TPanel;
Panel2: TPanel;
Label1: TLabel;
GroupBox2: TGroupBox;
Label3: TLabel;
Label4: TLabel;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
GroupBox1: TGroupBox;
Label2: TLabel;
TowardEnd: TRadioButton;
TowardTop: TRadioButton;
Edit2: TEdit;
SpinH: TSpinEdit;
SpinM: TSpinEdit;
SpinS: TSpinEdit;
StatusBar1: TStatusBar;
Append1: TMenuItem;
SpinMs: TSpinEdit;
ProgressBar1: TProgressBar;
Edit3: TMenuItem;
Delete1: TMenuItem;
Modify1: TMenuItem;
Open1: TMenuItem;
Save1: TMenuItem;
Save2: TMenuItem;
N3: TMenuItem;
ApplyBtn: TButton;
procedure ApplyBtnClick(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
procedure Renumber1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure SpinChange(Sender: TObject);
procedure OnHint(sender : Tobject);
procedure Append1Click(Sender: TObject);
procedure Delete1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure Save2Click(Sender: TObject);
procedure Panel3Resize(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
ini : Tinifile;
Sub : TsubFile;
{ Private declarations }
procedure LoadFile(fname : string);
function GoToNumber(n : integer):integer;
procedure LoadInterface;
procedure Changed;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure Tform1.Changed;
begin
Save1.Enabled := true;
Save2.Enabled := true;
end;
procedure TForm1.Save1Click(Sender: TObject);
begin
SaveDialog1.FileName := label1.caption;
if SaveDialog1.Execute then
begin
Label1.Caption := SaveDialog1.FileName;
Save2Click(self);
end;
end;
procedure TForm1.Save2Click(Sender: TObject);
begin
if length(label1.Caption)>0 then
Sub.SaveToFile(label1.Caption)
else
Save1Click(self);
end;
function TForm1.GoToNumber(n : integer):integer;
var
i : integer;
begin
result := -1;
for i:=0 to listbox1.count-1 do
begin
if (Sub.Objects[i].index=n) then
begin
result:=i;
exit;
end;
end;
end;
procedure Tform1.LoadInterface;
var
j : integer;
begin
Listbox1.clear;
ComboBox1.Clear;
ComboBox2.Clear;
for j:=0 to Sub.Count-1 do
begin
ComboBox1.Items.Add(inttostr(Sub.Objects[j].index));
ComboBox2.Items.Add(inttostr(Sub.Objects[j].index));
// fill the listbox
Listbox1.Items.Add(Sub.Objects[j].ToString);
end;
if(ComboBox1.Items.Count > 1) then
begin
ComboBox1.ItemIndex := 0;
ComboBox2.ItemIndex := ComboBox2.Items.Count - 1;
end;
end;
procedure TForm1.LoadFile(fname : string);
begin
Sub.loadfromfile(fname);
LoadInterface;
label1.Caption := fname;
end;
procedure TForm1.Append1Click(Sender: TObject);
var
tm : string;
begin
if (opendialog1.Execute) then
begin
tm := sub.Rec[sub.lastindex].endTimeToString;
tm := inputbox('Merge at (time:length of first part of movie) ?','Choose time :', tm);
if tm<>'00:00:00,000' then
begin
sub.Merge(opendialog1.FileName, tm);
LoadInterface;
Changed;
end;
end;
end;
procedure TForm1.ApplyBtnClick(Sender: TObject);
var
r : Trec;
i,j : integer;
s : string;
begin
ProgressBar1.Visible := true;
ProgressBar1.Min := 1;
ProgressBar1.Max := strtoint(combobox2.Text)-strtoint(combobox1.Text);
ProgressBar1.Position := 1;
for i:=strtoint(combobox1.Text) to strtoint(combobox2.Text) do
begin
r := Sub.Rec[i];
if (assigned(r)) then
begin
if TowardEnd.Checked then
r.IncreaseTime(Edit2.Text)
else
r.DecreaseTime(Edit2.Text);
//
j:=GotoNumber(i);
s := r.ToString;
ListBox1.Items[j] := s;
end;
ProgressBar1.StepIt;
Application.ProcessMessages;
end;
ProgressBar1.Visible := false;
Changed;
end;
procedure TForm1.Delete1Click(Sender: TObject);
var
i, ind : integer;
begin
i := Listbox1.ItemIndex;
ind := Sub.Objects[i].index;
Sub.Delete(ind);
LoadInterface;
Changed;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.ListBox1DblClick(Sender: TObject);
var
i : integer;
begin
i := ListBox1.ItemIndex;
if(i<0) then exit;
with TeditFrm.Create(Application) do
try
Memo1.Lines.Assign(Sub.Objects[i].subs);
if ShowModal=MrOk then
begin
Sub.Objects[i].subs.assign(Memo1.Lines);
ListBox1.Items[i] := Sub.Objects[i].Tostring;
end;
finally
Free;
end;
end;
procedure TForm1.Renumber1Click(Sender: TObject);
var
num : integer;
begin
num := strtoint(inputbox('Renumber from ?','Choose number to renumber from :', '1'));
if num>0 then
begin
Sub.Renumber(num);
LoadInterface;
Changed;
end;
end;
procedure TForm1.About1Click(Sender: TObject);
begin
MessageDlg('Simple subwork (c) Ollivier Civiol 2006', MTINFORMATION, [MBOK], 0);
end;
procedure TForm1.OnHint(sender : Tobject);
begin
StatusBar1.SimpleText := Application.Hint;
end;
procedure TForm1.Open1Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
ComboBox1.Clear;
ComboBox2.Clear;
//
Listbox1.Clear;
LoadFile(OpenDialog1.FileName);
ApplyBtn.Enabled := ListBox1.Items.count>0;
Save1.Enabled := false;
Save2.Enabled := false;
//
label1.Caption := OpenDialog1.Filename;
end;
end;
procedure TForm1.Panel3Resize(Sender: TObject);
begin
if Panel3.Width>Panel2.Width then
panel2.Left := (panel3.Width-panel2.width) div 2
else
panel2.Left := 0;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
s : string;
begin
Sub := TsubFile.Create;
Application.OnHint := OnHint;
//
s := copy(application.exename , 1, length(application.exename)-3);
ini := Tinifile.Create(s+'ini');
//
left := ini.ReadInteger('Size', 'left' , left);
top := ini.ReadInteger('Size', 'top' , top);
width := ini.ReadInteger('Size', 'width' , width);
height:= ini.ReadInteger('Size', 'height' , height);
//
OpenDialog1.InitialDir := ini.ReadString('Open/Save', 'Initialdir', '');
if ParamCount>0 then
begin
s := ParamStr(1);
LoadFile(s);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ini.writeInteger('Size', 'left' , left);
ini.writeInteger('Size', 'top' , top);
ini.writeInteger('Size', 'width' , width);
ini.writeInteger('Size', 'height' , height);
//
OpenDialog1.InitialDir := ExtractFilePath(Opendialog1.FileName);
ini.WriteString('Open/Save', 'Initialdir', OpenDialog1.InitialDir);
//
ini.Free;
sub.Free;
end;
procedure TForm1.SpinChange(Sender: TObject);
var
h,m,s,ms : string;
begin
h := SpinH.Text;
m := SpinM.Text;
s := SpinS.Text;
ms := SpinMs.Text;
//
if(length(h)<2) then h := '0'+h;
if(length(m)<2) then m := '0'+m;
if(length(s)<2) then s := '0'+s;
while(length(ms)<3) do ms := '0'+ms;
//
edit2.Text := h+':'+m+':'+s+','+ms;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
if listbox1.ItemIndex >= 0 then
combobox1.ItemIndex := listbox1.ItemIndex;
end;
end.