-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunit1.pas
359 lines (314 loc) · 9.32 KB
/
unit1.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
{
/***************************************************************************
unit1.pas
------------
***************************************************************************/
*****************************************************************************
This file is part of the Lazarus packages by Andreas Jakobsche
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs,
Menus, ComCtrls, StdCtrls{, PathView};
type
{ TForm1 }
TForm1 = class(TForm)
FindDialog: TFindDialog;
FontDialog: TFontDialog;
Flags: TImageList;
MainMenu: TMainMenu;
TextEdit: TMemo;
MenuItem1: TMenuItem;
MenuItem10: TMenuItem;
MenuItem11: TMenuItem;
MenuItem12: TMenuItem;
MenuItem13: TMenuItem;
MenuItem14: TMenuItem;
MenuItem15: TMenuItem;
MenuItem16: TMenuItem;
MenuItem17: TMenuItem;
MenuItem18: TMenuItem;
MenuItem19: TMenuItem;
MenuItem2: TMenuItem;
MenuItem20: TMenuItem;
MenuItem21: TMenuItem;
MenuItem22: TMenuItem;
MenuItem23: TMenuItem;
MenuItem24: TMenuItem;
MenuItem25: TMenuItem;
LangMenu: TMenuItem;
MenuItem26: TMenuItem;
MenuItem27: TMenuItem;
MenuItem28: TMenuItem;
MenuItem29: TMenuItem;
MenuItem30: TMenuItem;
MenuItem31: TMenuItem;
MenuItem32: TMenuItem;
WordWrapItem: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
MenuItem5: TMenuItem;
MenuItem6: TMenuItem;
MenuItem7: TMenuItem;
MenuItemSave: TMenuItem;
MenuItemSaveAs: TMenuItem;
MenuItem8: TMenuItem;
MenuItem9: TMenuItem;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
StatusBar1: TStatusBar;
procedure FindDialogFind(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure TextEditChange(Sender: TObject);
procedure MenuItem10Click(Sender: TObject);
procedure MenuItem17Click(Sender: TObject);
procedure MenuItem20Click(Sender: TObject);
procedure MenuItem21Click(Sender: TObject);
procedure MenuItem23Click(Sender: TObject);
procedure MenuItem25Click(Sender: TObject);
procedure MenuItem27Click(Sender: TObject);
procedure MenuItem28Click(Sender: TObject);
procedure MenuItem29Click(Sender: TObject);
procedure MenuItem30Click(Sender: TObject);
procedure MenuItem31Click(Sender: TObject);
procedure MenuItem32Click(Sender: TObject);
procedure WordWrapItemClick(Sender: TObject);
procedure MenuItem2Click(Sender: TObject);
procedure MenuItem4Click(Sender: TObject);
procedure MenuItem8Click(Sender: TObject);
procedure MenuItemSaveClick(Sender: TObject);
procedure MenuItemSaveAsClick(Sender: TObject);
private
{ private declarations }
procedure Translate(Language: string; MenuItem: TMenuItem);
public
{ public declarations }
Start: Integer;
FileName: string;
HasChanged: Boolean;
procedure LoadFile;
end;
var
Form1: TForm1;
implementation
uses About, FormEx, Config;
{$R *.lfm}
{ TForm1 }
procedure TForm1.MenuItem4Click(Sender: TObject);
begin
if HasChanged then
case MessageDlg('Der Text wurde geändert. Soll er gespeichert werden?',
mtConfirmation, [mbYes, mbNo, mbCancel], 0) of
mrYes: MenuItemSave.Click;
mrNo:;
else Exit;
end;
if OpenDialog.Execute then begin
FileName := OpenDialog.FileName;
TextEdit.Lines.LoadFromFile(FileName);
Caption := Format('%s - Karina', [FileName]);
HasChanged := False
end;
end;
procedure TForm1.MenuItem8Click(Sender: TObject);
begin
Close
end;
procedure TForm1.MenuItem2Click(Sender: TObject);
begin
if HasChanged then
case MessageDlg('Der Text wurde geändert. Soll er gespeichert werden?',
mtConfirmation, [mbYes, mbNo, mbCancel], 0) of
mrYes: MenuItemSave.Click;
mrNo:;
else Exit;
end;
TextEdit.Lines.Clear;
FileName := '';
Caption := 'Karina';
end;
procedure TForm1.TextEditChange(Sender: TObject);
begin
HasChanged := True
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
if HasChanged then
case MessageDlg('Der Text wurde geändert. Soll er gespeichert werden?',
mtConfirmation, [mbYes, mbNo, mbCancel], 0) of
mrYes: begin
MenuItemSave.Click;
CanClose := True
end;
mrNo: CanClose := True
else CanClose := False;
end;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
end;
procedure TForm1.FindDialogFind(Sender: TObject);
var
P: Integer;
begin
if Start = 0 then begin
P := Pos(FindDialog.FindText, TextEdit.Text) - 1;
if P = -1 then begin
ShowMessage('Kein Fund');
end
else begin
TextEdit.SelStart := P;
TextEdit.SelLength := Length(FindDialog.FindText);
Start := P + Length(FindDialog.FindText) + 1;
end;
end
else begin
P := Start + Pos(FindDialog.FindText, Copy(TextEdit.Text, Start + 1, Length(TextEdit.Text))) - 2;
if P <= Start then begin
ShowMessage('Kein weiterer Fund');
Start := 0
end
else begin
TextEdit.SelStart := P;
TextEdit.SelLength := Length(FindDialog.FindText);
Start := Start + P + Length(FindDialog.FindText);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i, j: Integer;
begin
FormAdjust(Self);
LoadFile;
WordWrapItem.Checked := TextEdit.WordWrap;
with KarinaConfig do begin
if (Language = '') or (Language = 'de') then LangMenu.ImageIndex:=0
else if Language = 'en' then LangMenu.ImageIndex := 1
else if Language = 'fr' then LangMenu.ImageIndex := 2
else if Language = 'es' then LangMenu.ImageIndex := 3
else if Language = 'ru' then LangMenu.ImageIndex := 4;
end;
{ Nicht verwendete Menübefehle deaktivieren }
with MainMenu.Items do
for i := 0 to Count - 1 do
for j := 0 to Items[i].Count - 1 do
Items[i].Items[j].Enabled := (Items[i].Items[j].Caption = '-') or (Items[i].Items[j].OnClick <> nil);
end;
procedure TForm1.MenuItem10Click(Sender: TObject);
begin
Close
end;
procedure TForm1.MenuItem17Click(Sender: TObject);
begin
FindDialog.Execute;
end;
procedure TForm1.MenuItem20Click(Sender: TObject);
begin
end;
procedure TForm1.MenuItem21Click(Sender: TObject);
begin
end;
procedure TForm1.MenuItem23Click(Sender: TObject);
begin
AboutBox.Show;
AboutBox.BringToFront
end;
procedure TForm1.MenuItem25Click(Sender: TObject);
begin
if FontDialog.Execute then TextEdit.Font := FontDialog.Font;
end;
procedure TForm1.MenuItem27Click(Sender: TObject);
begin
Translate('', Sender as TMenuItem);
end;
procedure TForm1.MenuItem28Click(Sender: TObject);
begin
Translate('en', Sender as TMenuItem);
end;
procedure TForm1.MenuItem29Click(Sender: TObject);
begin
if HasChanged then
case MessageDlg('Der Text wurde geändert. Soll er gespeichert werden?',
mtConfirmation, [mbYes, mbNo, mbCancel], 0) of
mrYes: MenuItemSave.Click;
mrNo:;
else Exit;
end;
FileName := KarinaConfig.ConfigFileName;
TextEdit.Lines.LoadFromFile(FileName);
Caption := Format('%s - Karina', [FileName]);
HasChanged := False
end;
procedure TForm1.MenuItem30Click(Sender: TObject);
begin
Translate('fr', Sender as TMenuItem);
end;
procedure TForm1.MenuItem31Click(Sender: TObject);
begin
Translate('es', Sender as TMenuItem);
end;
procedure TForm1.MenuItem32Click(Sender: TObject);
begin
Translate('ru', Sender as TMenuItem);
end;
procedure TForm1.WordWrapItemClick(Sender: TObject);
begin
TextEdit.WordWrap := not TextEdit.WordWrap;
(Sender as TMenuItem).Checked := TextEdit.WordWrap;
end;
procedure TForm1.MenuItemSaveClick(Sender: TObject);
begin
if FileName <> '' then begin
TextEdit.Lines.SaveToFile(FileName);
HasChanged := False
end
else MenuItemSaveAs.Click
end;
procedure TForm1.MenuItemSaveAsClick(Sender: TObject);
begin
if SaveDialog.Execute then begin
FileName := SaveDialog.FileName;
TextEdit.Lines.SaveToFile(FileName);
HasChanged := False;
Caption := Format('%s - Karina', [FileName])
end;
end;
procedure TForm1.Translate(Language: string; MenuItem: TMenuItem);
begin
KarinaConfig.Language := Language;
LangMenu.ImageIndex := MenuItem.ImageIndex
end;
procedure TForm1.LoadFile;
var
i: Integer;
begin
ShowMessage(Format('%d Parameter', [ParamCount]));
if Application.ParamCount > 0 then begin
i := 1;
with Application do
while (i <= ParamCount) do begin
ShowMessage(Format('1. Parameter: %s', [Application.Params[1]]));
{ Optionen mit je 1 Parameter überspringen }
if (Params[i] = '-l') or (Params[i] = '--lang') then begin
Inc(i, 2) {wird von Unit LCLTranslator ausgewertet}
end
{ Optionen ohne Parameter überspringen }
else if Params[i][1] = '-' then Inc(i)
else Break {Dateiname als Parameter an Position i vermutet}
end;
if Application.Params[i] <> '' then begin
TextEdit.Lines.LoadFromFile(Application.Params[i]);
Caption := Format('%s - Karina', [Application.Params[i]]);
FileName := Application.Params[i]
end
end;
end;
end.