-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunit3.pas
More file actions
509 lines (458 loc) · 13.4 KB
/
unit3.pas
File metadata and controls
509 lines (458 loc) · 13.4 KB
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
// **********************************************************************
// ***********************************************************************
// mxMarkEdit 1.x
// Author and copyright: Massimo Nardello, Modena (Italy) 2024 - 2025.
// Free software released under GPL licence version 3 or later.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. You can read the version 3
// of the Licence in http://www.gnu.org/licenses/gpl-3.0.txt
// or in the file Licence.txt included in the files of the
// source code of this software.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// ***********************************************************************
// ***********************************************************************
unit Unit3;
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
ExtCtrls, Menus, LazUTF8, CocoaAll, CocoaUtils, translate, LazFileUtils;
type
{ TfmOptions }
TfmOptions = class(TForm)
bnClose: TButton;
bnSetColors: TButton;
bnRemoveColors: TButton;
bnStFontCodeColorMod: TButton;
bnStFontFootColor: TButton;
bnStFontLinkColor: TButton;
bnStFontTextColorMod: TButton;
bnStFontTitle3ColorMod: TButton;
bnStFontTitle1ColorMod: TButton;
bnStFontTitle2ColorMod: TButton;
bnStFontTodoColor: TButton;
cbAuthSmallCaps: TCheckBox;
cbStFontsMono: TComboBox;
cbDelay: TComboBox;
cbLineSpacing: TComboBox;
cbShowMarkers: TCheckBox;
edAuthSeparator: TEdit;
edTitleSeparator: TEdit;
edPanOptions: TEdit;
edPanTemplate: TEdit;
edPanOutput: TEdit;
edPanPath: TEdit;
cbStFonts: TComboBox;
cdColorDialog: TColorDialog;
edStMaxSize: TEdit;
edStSize: TEdit;
edStSizeLess: TButton;
edStMaxSizeLess: TButton;
edStMaxSizePlus: TButton;
edStSizePlus: TButton;
edStSizeMono: TEdit;
edStSizeMonoLess: TButton;
edStSizeMonoPlus: TButton;
lbExistModel: TLabel;
lbExistExe: TLabel;
lbPanOptions: TLabel;
lbPanTemplate: TLabel;
lbPanOutput: TLabel;
lbPanPath: TLabel;
lbStMaxSize: TLabel;
lbStSize: TLabel;
lbStSizeMono: TLabel;
lbShowMarkers: TLabel;
lbStLineSpace: TLabel;
lnStFonts: TLabel;
lbStDelay: TLabel;
lnStFontsMono: TLabel;
lbAuthSeparator: TLabel;
lbTitleSeparator: TLabel;
lbAuthSmallCaps: TLabel;
procedure bnSetColorsClick(Sender: TObject);
procedure bnRemoveColorsClick(Sender: TObject);
procedure bnCloseClick(Sender: TObject);
procedure bnStFontCodeColorModClick(Sender: TObject);
procedure bnStFontFootColorClick(Sender: TObject);
procedure bnStFontLinkColorClick(Sender: TObject);
procedure bnStFontTextColorModClick(Sender: TObject);
procedure bnStFontTitle3ColorModClick(Sender: TObject);
procedure bnStFontTitle2ColorModClick(Sender: TObject);
procedure bnStFontTitle1ColorModClick(Sender: TObject);
procedure bnStFontTodoColorClick(Sender: TObject);
procedure cbAuthSmallCapsChange(Sender: TObject);
procedure cbDelayChange(Sender: TObject);
procedure cbLineSpacingChange(Sender: TObject);
procedure cbShowMarkersChange(Sender: TObject);
procedure cbStFontsChange(Sender: TObject);
procedure cbStFontsMonoChange(Sender: TObject);
procedure edAuthSeparatorChange(Sender: TObject);
procedure edPanPathChange(Sender: TObject);
procedure edPanTemplateChange(Sender: TObject);
procedure edStMaxSizeLessClick(Sender: TObject);
procedure edStMaxSizePlusClick(Sender: TObject);
procedure edStSizeLessClick(Sender: TObject);
procedure edStSizeMonoLessClick(Sender: TObject);
procedure edStSizeMonoPlusClick(Sender: TObject);
procedure edStSizePlusClick(Sender: TObject);
procedure edTitleSeparatorChange(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure FormShow(Sender: TObject);
private
public
end;
var
fmOptions: TfmOptions;
implementation
uses Unit1;
{$R *.lfm}
{ TfmOptions }
procedure TfmOptions.FormCreate(Sender: TObject);
var
fm: NSFontManager;
fd: NSFontDescriptor;
FontFamilies: NSArray;
i: integer;
begin
if LowerCase(UTF8Copy(NSStringToString(
NSLocale.preferredLanguages.objectAtIndex(0)), 1, 2)) = 'it' then
begin
translate.TranslateTo('mxmarkedit.it');
end;
fm := NSFontManager.sharedFontManager;
FontFamilies := fm.availableFontFamilies;
for i := 0 to FontFamilies.Count - 1 do
begin
fd := fmMain.FindFont(NSStringToString(
FontFamilies.objectAtIndex(i).description), 0);
if NSStringToString(fd.fontAttributes.description) <> '' then
begin
cbStFonts.Items.Add(NSStringToString(FontFamilies.objectAtIndex(
i).description));
end;
end;
cbStFontsMono.Items := cbStFonts.Items;
cbStFonts.ItemIndex := 0;
cbStFontsMono.ItemIndex := 0;
cbDelay.ItemIndex := iDelay;
end;
procedure TfmOptions.FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
begin
if key = 27 then
begin
key := 0;
Close;
end;
end;
procedure TfmOptions.FormShow(Sender: TObject);
var
stLineSpacing: String;
begin
cbStFonts.ItemIndex := cbStFonts.Items.IndexOf(fmMain.dbText.Font.Name);
cbStFontsMono.ItemIndex := cbStFontsMono.Items.IndexOf(stFontMono);
edStSize.Text := IntToStr(fmMain.dbText.Font.Size);
edStSizeMono.text := IntToStr(iFontMonoSize);
edStMaxSize.Text := IntToStr(iMaxSize);
cbShowMarkers.Checked := blShowMarkers;
stLineSpacing := FormatFloat('0.0', iLineSpacing);
stLineSpacing := stLineSpacing[1] + '.' + stLineSpacing[3];
cbLineSpacing.ItemIndex := cbLineSpacing.Items.
IndexOf(stLineSpacing);
edAuthSeparator.Text := stAuthSeparator;
edTitleSeparator.Text := stTitleSeparator;
cbAuthSmallCaps.Checked := blAuthSmallCaps;
edPanOptions.Text := pandocOptions;
edPanTemplate.Text := pandocTemplate;
edPanOutput.Text := pandocOutput;
edPanPath.Text := pandocPath;
if FileExistsUTF8(edPanPath.Text + 'pandoc') then
begin
lbExistExe.Font.Color := clGreen;
end
else
begin
lbExistExe.Font.Color := clRed;
end;
if FileExistsUTF8(edPanTemplate.Text) then
begin
lbExistModel.Font.Color := clGreen;
end
else
begin
lbExistModel.Font.Color := clRed;
end;
end;
procedure TfmOptions.FormActivate(Sender: TObject);
begin
bnClose.SetFocus;
end;
procedure TfmOptions.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
pandocOptions := edPanOptions.Text;
pandocTemplate := edPanTemplate.Text;
pandocOutput := edPanOutput.Text;
pandocPath := edPanPath.Text;
end;
procedure TfmOptions.cbStFontsChange(Sender: TObject);
begin
fmMain.dbText.Font.Name := cbStFonts.Text;
fmMain.FormatListTitleTodo;
end;
procedure TfmOptions.cbStFontsMonoChange(Sender: TObject);
begin
stFontMono := cbStFontsMono.Text;
fmMain.FormatListTitleTodo;
end;
procedure TfmOptions.edAuthSeparatorChange(Sender: TObject);
begin
stAuthSeparator := edAuthSeparator.Text;
end;
procedure TfmOptions.edPanPathChange(Sender: TObject);
begin
if FileExistsUTF8(edPanPath.Text + 'pandoc') then
begin
lbExistExe.Font.Color := clGreen;
end
else
begin
lbExistExe.Font.Color := clRed;
end;
end;
procedure TfmOptions.edPanTemplateChange(Sender: TObject);
begin
if FileExistsUTF8(edPanTemplate.Text) then
begin
lbExistModel.Font.Color := clGreen;
end
else
begin
lbExistModel.Font.Color := clRed;
end;
end;
procedure TfmOptions.edStSizePlusClick(Sender: TObject);
begin
if fmMain.dbText.Font.Size < 128 then
begin
edStSize.Text := IntToStr(StrToInt(edStSize.Text) + 1);
fmMain.dbText.Font.Size := StrToInt(edStSize.Text);
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.edTitleSeparatorChange(Sender: TObject);
begin
stTitleSeparator := edTitleSeparator.Text;
end;
procedure TfmOptions.edStSizeLessClick(Sender: TObject);
begin
if fmMain.dbText.Font.Size > 6 then
begin
edStSize.Text := IntToStr(StrToInt(edStSize.Text) - 1);
fmMain.dbText.Font.Size := StrToInt(edStSize.Text);
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.edStSizeMonoPlusClick(Sender: TObject);
begin
if iFontMonoSize < 128 then
begin
edStSizeMono.Text := IntToStr(StrToInt(edStSizeMono.Text) + 1);
iFontMonoSize := StrToInt(edStSizeMono.Text);
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.edStSizeMonoLessClick(Sender: TObject);
begin
if iFontMonoSize > 6 then
begin
edStSizeMono.Text := IntToStr(StrToInt(edStSizeMono.Text) - 1);
iFontMonoSize := StrToInt(edStSizeMono.Text);
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.edStMaxSizePlusClick(Sender: TObject);
begin
if iMaxSize < 4000000 then
begin
edStMaxSize.Text := IntToStr(StrToInt(edStMaxSize.Text) + 50000);
iMaxSize := StrToInt(edStMaxSize.Text);
end;
end;
procedure TfmOptions.edStMaxSizeLessClick(Sender: TObject);
begin
if iMaxSize > 100000 then
begin
edStMaxSize.Text := IntToStr(StrToInt(edStMaxSize.Text) - 50000);
iMaxSize := StrToInt(edStMaxSize.Text);
end;
end;
procedure TfmOptions.bnStFontLinkColorClick(Sender: TObject);
begin
cdColorDialog.Color := clLink;
if cdColorDialog.Execute then
begin
clLink := cdColorDialog.Color;
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.bnStFontFootColorClick(Sender: TObject);
begin
cdColorDialog.Color := clFootnote;
if cdColorDialog.Execute then
begin
clFootnote := cdColorDialog.Color;
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.bnStFontTextColorModClick(Sender: TObject);
begin
cdColorDialog.Color := fmMain.dbText.Font.Color;
if cdColorDialog.Execute then
begin
fmMain.dbText.Font.Color := cdColorDialog.Color;
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.bnStFontCodeColorModClick(Sender: TObject);
begin
cdColorDialog.Color := clCode;
if cdColorDialog.Execute then
begin
clCode := cdColorDialog.Color;
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.bnStFontTitle1ColorModClick(Sender: TObject);
begin
cdColorDialog.Color := clTitle1;
if cdColorDialog.Execute then
begin
clTitle1 := cdColorDialog.Color;
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.bnStFontTodoColorClick(Sender: TObject);
begin
cdColorDialog.Color := clTodo;
if cdColorDialog.Execute then
begin
clTodo := cdColorDialog.Color;
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.cbAuthSmallCapsChange(Sender: TObject);
begin
blAuthSmallCaps := cbAuthSmallCaps.Checked;
end;
procedure TfmOptions.cbDelayChange(Sender: TObject);
begin
iDelay := cbDelay.ItemIndex;
end;
procedure TfmOptions.cbLineSpacingChange(Sender: TObject);
begin
case cbLineSpacing.ItemIndex of
0: iLineSpacing := 0.8;
1: iLineSpacing := 0.9;
2: iLineSpacing := 1.0;
3: iLineSpacing := 1.1;
4: iLineSpacing := 1.2;
5: iLineSpacing := 1.3;
6: iLineSpacing := 1.4;
7: iLineSpacing := 1.5;
8: iLineSpacing := 1.6;
9: iLineSpacing := 1.7;
10: iLineSpacing := 1.8;
11: iLineSpacing := 1.9;
12: iLineSpacing := 2.0;
end;
fmMain.FormatListTitleTodo;
end;
procedure TfmOptions.cbShowMarkersChange(Sender: TObject);
begin
blShowMarkers := cbShowMarkers.Checked;
fmMain.FormatListTitleTodo;
end;
procedure TfmOptions.bnStFontTitle2ColorModClick(Sender: TObject);
begin
cdColorDialog.Color := clTitle2;
if cdColorDialog.Execute then
begin
clTitle2 := cdColorDialog.Color;
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.bnStFontTitle3ColorModClick(Sender: TObject);
begin
cdColorDialog.Color := clTitle3;
if cdColorDialog.Execute then
begin
clTitle3 := cdColorDialog.Color;
fmMain.FormatListTitleTodo;
end;
end;
procedure TfmOptions.bnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfmOptions.bnSetColorsClick(Sender: TObject);
begin
if IsAppDark = True then
begin
fmMain.dbText.Font.Color := $00D6D6D6;
clLink := $00F89442;
clFootnote := $00FDA69E;
clCode := $00D6AC77;
clTodo := $00D88AFF;
clTitle1 := $005EB2FB;
clTitle2 := $0099F692;
clTitle3 := $005EF3FF;
end
else
begin
fmMain.dbText.Font.Color := $00424242;
clLink := $00DA6800;
clFootnote := $00FF3794;
clCode := $00932194;
clTodo := $00E539E3;
clTitle1 := $00511794;
clTitle2 := $00519000;
clTitle3 := $00009092
end;
fmMain.FormatListTitleTodo;
end;
procedure TfmOptions.bnRemoveColorsClick(Sender: TObject);
begin
if IsAppDark = True then
begin
fmMain.dbText.Font.Color := clWhite;
clLink := clSilver;
clFootnote := clSilver;
clCode := clSilver;
clTodo := clWhite;
clTitle1 := clWhite;
clTitle2 := clWhite;
clTitle3 := clWhite;
end
else
begin
fmMain.dbText.Font.Color := clBlack;
clLink := clDkGray;
clFootnote := clDkGray;
clCode := clDkGray;
clTodo := clBlack;
clTitle1 := clBlack;
clTitle2 := clBlack;
clTitle3 := clBlack;
end;
fmMain.FormatListTitleTodo;
end;
end.