-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunit1.pas
More file actions
6775 lines (6656 loc) · 204 KB
/
unit1.pas
File metadata and controls
6775 lines (6656 loc) · 204 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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ***********************************************************************
// ***********************************************************************
// 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 Unit1;
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, CocoaAll,
CocoaTextEdits, CocoaUtils, Clipbrd, Menus, StdCtrls, Grids, ExtCtrls,
DefaultTranslator, translate, IniFiles, LazUTF8, FileUtil,
LazFileUtils, Unix, Types, DateUtils, LCLType, LCLIntf;
type
{ TfmMain }
TfmMain = class(TForm)
bnResetFilter: TButton;
cbFilter: TComboBox;
dbText: TMemo;
edFilterGrid: TEdit;
lbDateTime: TLabel;
lbChars: TLabel;
lbFindGrid: TLabel;
lbFilterGrid: TLabel;
miFileImpTables: TMenuItem;
miFileInsert: TMenuItem;
miToolsBiblio: TMenuItem;
miToolsManual: TMenuItem;
miToolsOptmize: TMenuItem;
miFilesSearch: TMenuItem;
miEditWords: TMenuItem;
miEditTasks: TMenuItem;
miEditShowCurrent: TMenuItem;
miEditFindDuplicate: TMenuItem;
miEditHideList: TMenuItem;
miEditLink: TMenuItem;
miEditDisableForm: TMenuItem;
miEditDisSpell: TMenuItem;
miSepLastFiles: TMenuItem;
miFileOpenLast1: TMenuItem;
miFileOpenLast2: TMenuItem;
miFileOpenLast3: TMenuItem;
miFileOpenLast4: TMenuItem;
miFileOpenLast5: TMenuItem;
miFileOpenLast6: TMenuItem;
miFileOpenLast7: TMenuItem;
miFileOpenLast8: TMenuItem;
miToolsOpenWin: TMenuItem;
odLink: TOpenDialog;
odTables: TOpenDialog;
pnBackground: TPanel;
pnFindGrid: TPanel;
pnGrid: TPanel;
pnTitTodo: TPanel;
Sep0a: TMenuItem;
Sep2a: TMenuItem;
Sep3: TMenuItem;
Sep5: TMenuItem;
Sep6: TMenuItem;
miToolsTrans3: TMenuItem;
miToolsTrans2: TMenuItem;
miToolsTrans1: TMenuItem;
miToolsTransparency: TMenuItem;
Sep4: TMenuItem;
miToolsOptions: TMenuItem;
miToolsPandoc: TMenuItem;
miCopyright: TMenuItem;
miHelp: TMenuItem;
miTools: TMenuItem;
miEditFind: TMenuItem;
odOpen: TOpenDialog;
sdSave: TSaveDialog;
Sep1: TMenuItem;
miEditCut: TMenuItem;
miEditCopy: TMenuItem;
miEditPaste: TMenuItem;
miEditSelectAll: TMenuItem;
miEdit: TMenuItem;
miFileNew: TMenuItem;
miFileOpen: TMenuItem;
miFileSave: TMenuItem;
miFileSaveAs: TMenuItem;
mmMenu: TMainMenu;
miFile: TMenuItem;
pnBottom: TPanel;
Sep2: TMenuItem;
Sep7: TMenuItem;
Sep8: TMenuItem;
Sep0b: TMenuItem;
sgTitles: TStringGrid;
sgTable: TStringGrid;
miToolsShortcuts: TMenuItem;
shFind: TShape;
spTable: TSplitter;
spTitles: TSplitter;
tmDateTime: TTimer;
edFindGrid: TEdit;
procedure cbFilterChange(Sender: TObject);
procedure dbTextChange(Sender: TObject);
procedure dbTextClick(Sender: TObject);
procedure dbTextKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure dbTextKeyPress(Sender: TObject; var Key: char);
procedure dbTextKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
procedure edFilterGridKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure edFindGridKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure miEditFindDuplicateClick(Sender: TObject);
procedure miEditHideListClick(Sender: TObject);
procedure miEditLinkClick(Sender: TObject);
procedure miEditDisableFormClick(Sender: TObject);
procedure miEditDisSpellClick(Sender: TObject);
procedure miCopyrightClick(Sender: TObject);
procedure miEditCopyClick(Sender: TObject);
procedure miEditCutClick(Sender: TObject);
procedure miEditFindClick(Sender: TObject);
procedure miEditPasteClick(Sender: TObject);
procedure miEditSelectAllClick(Sender: TObject);
procedure miEditShowCurrentClick(Sender: TObject);
procedure miEditTasksClick(Sender: TObject);
procedure miEditWordsClick(Sender: TObject);
procedure miFileImpTablesClick(Sender: TObject);
procedure miFileInsertClick(Sender: TObject);
procedure miFileNewClick(Sender: TObject);
procedure miFileOpenClick(Sender: TObject);
procedure miFileOpenLast1Click(Sender: TObject);
procedure miFileOpenLast2Click(Sender: TObject);
procedure miFileOpenLast3Click(Sender: TObject);
procedure miFileOpenLast4Click(Sender: TObject);
procedure miFileOpenLast5Click(Sender: TObject);
procedure miFileOpenLast6Click(Sender: TObject);
procedure miFileOpenLast7Click(Sender: TObject);
procedure miFileOpenLast8Click(Sender: TObject);
procedure miFileSaveAsClick(Sender: TObject);
procedure miFileSaveClick(Sender: TObject);
procedure miFilesSearchClick(Sender: TObject);
procedure miToolsBiblioClick(Sender: TObject);
procedure miToolsManualClick(Sender: TObject);
procedure miToolsOpenWinClick(Sender: TObject);
procedure miToolsOptionsClick(Sender: TObject);
procedure miToolsOptmizeClick(Sender: TObject);
procedure miToolsPandocClick(Sender: TObject);
procedure miToolsTrans1Click(Sender: TObject);
procedure miToolsTrans2Click(Sender: TObject);
procedure miToolsTrans3Click(Sender: TObject);
procedure sgTableEditingDone(Sender: TObject);
procedure sgTableKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure sgTableKeyPress(Sender: TObject; var Key: char);
procedure sgTableKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure sgTablePrepareCanvas(Sender: TObject; aCol, aRow: integer;
aState: TGridDrawState);
procedure sgTableSetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: string);
procedure sgTitlesClick(Sender: TObject);
procedure sgTitlesDrawCell(Sender: TObject; aCol, aRow: integer;
aRect: TRect; aState: TGridDrawState);
procedure sgTitlesGetCellHint(Sender: TObject; ACol, ARow: integer;
var HintText: string);
procedure sgTitlesPrepareCanvas(Sender: TObject; aCol, aRow: integer;
aState: TGridDrawState);
procedure miToolsShortcutsClick(Sender: TObject);
procedure tmDateTimeTimer(Sender: TObject);
private
procedure CalcAllColInGrid;
procedure CalcInGrid(iCol: Integer);
procedure CreateBackup;
procedure CreateYAML;
procedure DeactForm(stFileName: String);
procedure DisablePresenting;
procedure FilterInGrid;
procedure FindInGrid(blDown: Boolean);
function GetDict(txt: NSTextStorage; textOffset: integer): NSDictionary;
function GetPara(txt: NSTextStorage; textOffset: integer;
isReadOnly, useDefault: boolean): NSParagraphStyle;
function GetWritePara(txt: NSTextStorage;
textOffset: integer): NSMutableParagraphStyle;
procedure OpenLastFile(stLastFileName: String);
procedure RenumberFootnotes;
procedure RenumberList;
procedure ResetFilterGrid;
function SaveFile: boolean;
procedure SaveScreenShot;
procedure SelectInsertFootnote;
procedure CutZone;
procedure SetTable;
public
function GetHeaderLevel(stHeader: String): Integer;
procedure UpdateLastFile;
procedure LabelFileNameChars;
procedure MoveToPos;
procedure ShowCurrentTitleTodo;
procedure FormatListTitleTodo;
function UTF8CocoaPos(const SearchForText, SearchInText: string;
StartPos: SizeInt = 1): PtrInt;
function FindFont(FamilyName: string; iStyle: smallint): NSFontDescriptor;
end;
var
fmMain: TfmMain;
myHomeDir, myConfigFile: string;
iTitleTodoRowHeight: integer = 28;
clTitle1: TColor = clBlack;
clTitle2: TColor = clBlack;
clTitle3: TColor = clBlack;
clRepetition: TColor = $005766EA;
clFootnote: TColor = clSilver;
clLink: TColor = clSilver;
clCode: TColor = clSilver;
clHighlightList: TColor = clDkGray;
clQuote: TColor = clSilver;
clTodo: TColor = clBlack;
clInsertionPoint: TColor;
clFontContrast: TColor;
clFontFade: TColor;
clGridHeadings: TColor;
stFontMono: string = 'Menlo';
iFontMonoSize: smallint = 18;
stFileName: string = '';
iBookmarkPos: integer = 0;
iDelay: integer = 7;
iLineSpacing: double = 1.0;
blShowMarkers: Bool = False;
LastDatabase1, LastDatabase2, LastDatabase3, LastDatabase4: string;
LastDatabase5, LastDatabase6, LastDatabase7, LastDatabase8: string;
LastPosDatabase1, LastPosDatabase2, LastPosDatabase3, LastPosDatabase4: integer;
LastPosDatabase5, LastPosDatabase6, LastPosDatabase7, LastPosDatabase8: integer;
TopIndexDatabase1, TopIndexDatabase2, TopIndexDatabase3, TopIndexDatabase4: integer;
TopIndexDatabase5, TopIndexDatabase6, TopIndexDatabase7, TopIndexDatabase8: integer;
ColDatabase1, ColDatabase2, ColDatabase3, ColDatabase4: integer;
ColDatabase5, ColDatabase6, ColDatabase7, ColDatabase8: integer;
RowDatabase1, RowDatabase2, RowDatabase3, RowDatabase4: integer;
RowDatabase5, RowDatabase6, RowDatabase7, RowDatabase8: integer;
ColWidthDatabase1, ColWidthDatabase2, ColWidthDatabase3, ColWidthDatabase4: String;
ColWidthDatabase5, ColWidthDatabase6, ColWidthDatabase7, ColWidthDatabase8: String;
blFileSaved: boolean = True;
blFileMod: boolean = False;
blTableSaved: boolean = True;
blTableMod: boolean = False;
blHideTitleTodo: boolean = False;
blDisableFormatting: boolean = False;
blIsPresenting: boolean = False;
iMaxSize: Integer = 250000;
iNumScreenshot: Integer = 1;
stTableLoaded: String = ' && .csv ';
csTableRowCount: Integer = 10000;
blTextOnChange: boolean = False;
stGridLoaded: String = '';
stAuthSeparator: String = ', ';
stTitleSeparator: String = ', ';
blAuthSmallCaps: boolean = False;
pandocPath: string = '/usr/local/bin/';
pandocOptions: string = '+footnotes+inline_notes';
pandocTemplate: string = 'word-template.docx';
pandocOutput: string = '.docx';
resourcestring
msg001 = 'Characters:';
msg002 = 'Discard text changes?';
msg003 = 'It was not possible to save the current file.';
msg004 = 'It was not possible to load the selected file.';
msg005 = 'Create a new document?';
msg006 = 'It was not possible to load the last used file.';
msg007 = 'The file is not available.';
msg008 = 'The current document has no name.';
msg009 = 'It was not possible to create the backup file.';
msg010 = 'Delete the current column of the current table?';
msg011 = 'It''s not possible to create a footnote reference at the beginning of a paragraph.';
msg012 = 'It''s not possible to insert a new row since the last one contains some data.';
msg013 = 'Delete the current row?';
msg014 = 'Sort the content of current column of the current table?';
msg015 = 'Delete the content of the selected cells?';
msg016 = 'Insert a new column in the current table?';
msg017 = 'This functionality must be called within a heading and not at the end of the text.';
msg018 = 'Cut in the clipboard all the text under the current heading?';
msg019 = 'The table is not delimited at the bottom; add a fictional title ' +
'after its last row in the first left column.';
msg020 = 'Create in a new file a version of the current presentation ' +
'optimized for mxMarkEdit?';
msg021 = 'It was not possible to save the optimized file.';
msg022 = 'Save in the Downloads directory the screenshots of the presentation ' +
'(press ESC to stop)?';
msg023 = 'Create in a new file a version of the current document ' +
'with the bibliography?';
msg024 = 'It was not possible to save the file with bibliography.';
msg025 = 'Replace the content of the grid with the tables of the selected file?';
msg026 = 'The selected key has no match in the bibliographic table.';
dlg001 = 'Markdown files|*.md|All files|*';
dlg002 = 'Save Markdown file';
dlg003 = 'Open Markdown file';
dlg004 = 'All files|*';
dlg005 = 'Open file';
dlg006 = 'Tables|*.csv';
dlg007 = 'Open tables';
lb000 = 'with bibliography';
lb000b = '# Bibliography';
lb001 = 'All the headings';
lb002 = 'Headings 1 - 5';
lb003 = 'Headings 1 - 4';
lb004 = 'Headings 1 - 3';
lb005 = 'Headings 1 - 2';
lb006 = 'Headings 1';
lb007 = 'Tables names';
lb008 = 'Tables';
lb009 = 'Sum:';
lb010 = 'Maximum value:';
lb011 = 'Minimum value:';
lb012 = 'Average:';
lb013 = 'Count:';
dateformat = 'en';
implementation
uses copyright, unit2, unit3, unit4, unit5, unit6, unit7, unit8, unit9;
{$R *.lfm}
{ TfmMain }
// *****************************************************
// ************ Procedures of the main form ************
// *****************************************************
procedure TfmMain.FormCreate(Sender: TObject);
var
MyIni: TIniFile;
nsInset: NSSize;
begin
if LowerCase(UTF8Copy(NSStringToString(
NSLocale.preferredLanguages.objectAtIndex(0)), 1, 2)) = 'it' then
begin
translate.TranslateTo('mxmarkedit.it');
end;
if IsAppDark = True then
begin
dbText.Font.Color := clWhite;
sgTitles.Font.Color := clWhite;
sgTable.FixedGridLineColor := $005E5E5E;
sgTable.GridLineColor := $005E5E5E;
sgTable.Color := $00282A2B;
sgTable.FixedColor := $00282A2B;
sgTable.FocusColor := clSilver;
sgTable.Editor.Color := $00282A2B;
sgTable.SelectedColor := $00454545;
clGridHeadings := $00373737;
lbChars.Font.Color := clSilver;
lbFindGrid.Font.Color := clSilver;
edFindGrid.Font.Color := clSilver;
lbFilterGrid.Font.Color := clSilver;
edFilterGrid.Font.Color := clSilver;
lbDateTime.Font.Color := clSilver;
clTitle1 := clWhite;
clTitle2 := clWhite;
clTitle3 := clWhite;
clFootnote := clSilver;
clLink := clSilver;
clCode := clSilver;
clQuote := $00404040;
clHighlightList := $005E5E5E;
clRepetition := $005766EA;
clTodo := clWhite;
clFontContrast := clWhite;
clFontFade := $005E5E5E;
end
else
begin
dbText.Font.Color := clBlack;
sgTitles.Font.Color := clBlack;
dbText.Color := clWhite;
sgTitles.Color := clWhite;
sgTable.FixedGridLineColor := clSilver;
sgTable.GridLineColor := clSilver;
sgTable.Color := clWhite;
sgTable.Editor.Color := clWhite;
sgTable.FixedColor := clWhite;
sgTable.BorderStyle := bsNone;
sgTable.FocusColor := clGray;
pnFindGrid.Color := clWhite;
sgTable.SelectedColor := clSilver;
clGridHeadings := $00F0F0F0;
fmMain.Color := clWhite;
spTitles.Color := clForm;
pnBottom.Color := clForm;
lbChars.Font.Color := clDkGray;
lbFindGrid.Font.Color := clDkGray;
edFindGrid.Font.Color := clDkGray;
lbFilterGrid.Font.Color := clDkGray;
edFilterGrid.Font.Color := clDkGray;
lbDateTime.Font.Color := clDkGray;
clTitle1 := clBlack;
clTitle2 := clBlack;
clTitle3 := clBlack;
clFootnote := clDkGray;
clLink := clDkGray;
clCode := clDkGray;
clQuote := $00EFEFEF;
clHighlightList := $00EBEBEB;
clRepetition := clRed;
clTodo := clBlack;
clFontContrast := clBlack;
clFontFade := $00D6D6D6;
end;
clInsertionPoint := NSColorToColorRef(TCocoaTextView(NSScrollView(dbText.Handle).
documentView).insertionPointColor);
sgTitles.FocusRectVisible := False;
sgTable.FocusRectVisible := False;
sgTable.TitleFont.Style := [fsBold];
pnGrid.Height := 1;
SetTable;
lbChars.Caption := msg001 + ' 0';
sdSave.Filter := dlg001;
sdSave.Title := dlg002;
odOpen.Filter := dlg001;
odOpen.Title := dlg003;
odLink.Filter := dlg004;
odLink.Title := dlg005;
odTables.Filter := dlg006;
odTables.Title := dlg007;
cbFilter.Items.Clear;
cbFilter.Items.Add(lb006);
cbFilter.Items.Add(lb005);
cbFilter.Items.Add(lb004);
cbFilter.Items.Add(lb003);
cbFilter.Items.Add(lb002);
cbFilter.Items.Add(lb001);
cbFilter.ItemIndex := 5;
CreateYAML;
myHomeDir := GetUserDir + 'Library/Preferences/';
myConfigFile := 'mxmarkedit';
if DirectoryExists(myHomeDir) = False then
begin
CreateDirUTF8(myHomeDir);
end;
if FileExistsUTF8(myHomeDir + myConfigFile) then
begin
try
MyIni := TIniFile.Create(myHomeDir + myConfigFile);
if MyIni.ReadString('mxpanmark', 'maximize', '') = 'true' then
begin
fmMain.WindowState := wsMaximized;
end
else
begin
fmMain.Top := MyIni.ReadInteger('mxmarkedit', 'top', 0);
fmMain.Left := MyIni.ReadInteger('mxmarkedit', 'left', 0);
if MyIni.ReadInteger('mxmarkedit', 'width', 0) > 100 then
fmMain.Width := MyIni.ReadInteger('mxmarkedit', 'width', 0)
else
fmMain.Width := 1000;
if MyIni.ReadInteger('mxmarkedit', 'heigth', 0) > 100 then
fmMain.Height := MyIni.ReadInteger('mxmarkedit', 'heigth', 0)
else
fmMain.Height := 600;
end;
dbText.Font.Name := MyIni.ReadString('mxmarkedit', 'fontname', 'Avenir Next');
dbText.Font.Size := MyIni.ReadInteger('mxmarkedit', 'fontsize', 16);
dbText.Font.Color := StringToColor(MyIni.ReadString('mxmarkedit',
'fontcolor', ColorToString(dbText.Font.Color)));
stFontMono := MyIni.ReadString('mxmarkedit', 'fontmononame', 'Menlo');
iFontMonoSize := MyIni.ReadInteger('mxmarkedit', 'fontmonosize', 18);
clTitle1 := StringToColor(MyIni.ReadString('mxmarkedit', 'title1',
'clTitle1'));
clTitle2 := StringToColor(MyIni.ReadString('mxmarkedit', 'title2', 'clTitle2'));
clTitle3 := StringToColor(MyIni.ReadString('mxmarkedit', 'title3', 'clTitle3'));
clFootnote := StringToColor(MyIni.ReadString('mxmarkedit',
'footnote', 'clFootnote'));
clLink := StringToColor(MyIni.ReadString('mxmarkedit', 'link', 'clLink'));
clCode := StringToColor(MyIni.ReadString('mxmarkedit', 'code', 'clCode'));
clTodo := StringToColor(MyIni.ReadString('mxmarkedit', 'todo', 'clTodo'));
pnTitTodo.Width := MyIni.ReadInteger('mxmarkedit', 'titlewidth', 400);
stFileName := MyIni.ReadString('mxmarkedit', 'filename', '');
iDelay := MyIni.ReadInteger('mxmarkedit', 'delay', 7);
iLineSpacing := MyIni.ReadFloat('mxmarkedit', 'linespacing', 1.0);
blShowMarkers := MyIni.ReadBool('mxmarkedit', 'showmarkers', false);
stAuthSeparator := MyIni.ReadString('mxmarkedit', 'authseparator', ', $');
stAuthSeparator := UTF8Copy(stAuthSeparator, 1,
UTF8Length(stAuthSeparator) - 1);
stTitleSeparator := MyIni.ReadString('mxmarkedit', 'titleseparator', ', $');
stTitleSeparator := UTF8Copy(stTitleSeparator, 1,
UTF8Length(stTitleSeparator) - 1);
blAuthSmallCaps := MyIni.ReadBool('mxmarkedit', 'authsmallcaps', false);
pandocOptions := MyIni.ReadString('mxmarkedit', 'panoption',
'+footnotes+inline_notes');
pandocTemplate := MyIni.ReadString('mxmarkedit', 'pantemplate',
'word-template.docx');
pandocOutput := MyIni.ReadString('mxmarkedit', 'panoutputput', '.docx');
pandocPath := MyIni.ReadString('mxmarkedit', 'panpath', '/usr/local/bin/');
if MyIni.ReadString('mxmarkedit', 'lastfile1', '') <> '' then
begin
LastDatabase1 := MyIni.ReadString('mxmarkedit', 'lastfile1', '');
miFileOpenLast1.Caption := ExtractFileNameOnly(LastDatabase1);
miFileOpenLast1.Visible := True;
end
else
begin
miFileOpenLast1.Visible := False;
end;
if MyIni.ReadString('mxmarkedit', 'lastfile2', '') <> '' then
begin
LastDatabase2 := MyIni.ReadString('mxmarkedit', 'lastfile2', '');
miFileOpenLast2.Caption := ExtractFileNameOnly(LastDatabase2);
miFileOpenLast2.Visible := True;
end
else
begin
miFileOpenLast2.Visible := False;
end;
if MyIni.ReadString('mxmarkedit', 'lastfile3', '') <> '' then
begin
LastDatabase3 := MyIni.ReadString('mxmarkedit', 'lastfile3', '');
miFileOpenLast3.Caption := ExtractFileNameOnly(LastDatabase3);
miFileOpenLast3.Visible := True;
end
else
begin
miFileOpenLast3.Visible := False;
end;
if MyIni.ReadString('mxmarkedit', 'lastfile4', '') <> '' then
begin
LastDatabase4 := MyIni.ReadString('mxmarkedit', 'lastfile4', '');
miFileOpenLast4.Caption := ExtractFileNameOnly(LastDatabase4);
miFileOpenLast4.Visible := True;
end
else
begin
miFileOpenLast4.Visible := False;
end;
if MyIni.ReadString('mxmarkedit', 'lastfile5', '') <> '' then
begin
LastDatabase5 := MyIni.ReadString('mxmarkedit', 'lastfile5', '');
miFileOpenLast5.Caption := ExtractFileNameOnly(LastDatabase5);
miFileOpenLast5.Visible := True;
end
else
begin
miFileOpenLast5.Visible := False;
end;
if MyIni.ReadString('mxmarkedit', 'lastfile6', '') <> '' then
begin
LastDatabase6 := MyIni.ReadString('mxmarkedit', 'lastfile6', '');
miFileOpenLast6.Caption := ExtractFileNameOnly(LastDatabase6);
miFileOpenLast6.Visible := True;
end
else
begin
miFileOpenLast6.Visible := False;
end;
if MyIni.ReadString('mxmarkedit', 'lastfile7', '') <> '' then
begin
LastDatabase7 := MyIni.ReadString('mxmarkedit', 'lastfile7', '');
miFileOpenLast7.Caption := ExtractFileNameOnly(LastDatabase7);
miFileOpenLast7.Visible := True;
end
else
begin
miFileOpenLast7.Visible := False;
end;
if MyIni.ReadString('mxmarkedit', 'lastfile8', '') <> '' then
begin
LastDatabase8 := MyIni.ReadString('mxmarkedit', 'lastfile8', '');
miFileOpenLast8.Caption := ExtractFileNameOnly(LastDatabase8);
miFileOpenLast8.Visible := True;
end
else
begin
miFileOpenLast8.Visible := False;
end;
if ((miFileOpenLast1.Visible = False) and
(miFileOpenLast2.Visible = False) and
(miFileOpenLast3.Visible = False) and
(miFileOpenLast4.Visible = False) and
(miFileOpenLast5.Visible = False) and
(miFileOpenLast6.Visible = False) and
(miFileOpenLast7.Visible = False) and
(miFileOpenLast8.Visible = False)) then
begin
miSepLastFiles.Visible := False;
end
else
begin
miSepLastFiles.Visible := True;
end;
LastPosDatabase1 := MyIni.ReadInteger('mxmarkedit', 'lastposdatabase1', 0);
LastPosDatabase2 := MyIni.ReadInteger('mxmarkedit', 'lastposdatabase2', 0);
LastPosDatabase3 := MyIni.ReadInteger('mxmarkedit', 'lastposdatabase3', 0);
LastPosDatabase4 := MyIni.ReadInteger('mxmarkedit', 'lastposdatabase4', 0);
LastPosDatabase5 := MyIni.ReadInteger('mxmarkedit', 'lastposdatabase5', 0);
LastPosDatabase6 := MyIni.ReadInteger('mxmarkedit', 'lastposdatabase6', 0);
LastPosDatabase7 := MyIni.ReadInteger('mxmarkedit', 'lastposdatabase7', 0);
LastPosDatabase8 := MyIni.ReadInteger('mxmarkedit', 'lastposdatabase8', 0);
TopIndexDatabase1 := MyIni.ReadInteger('mxmarkedit', 'topindexdatabase1', 0);
TopIndexDatabase2 := MyIni.ReadInteger('mxmarkedit', 'topindexdatabase2', 0);
TopIndexDatabase3 := MyIni.ReadInteger('mxmarkedit', 'topindexdatabase3', 0);
TopIndexDatabase4 := MyIni.ReadInteger('mxmarkedit', 'topindexdatabase4', 0);
TopIndexDatabase5 := MyIni.ReadInteger('mxmarkedit', 'topindexdatabase5', 0);
TopIndexDatabase6 := MyIni.ReadInteger('mxmarkedit', 'topindexdatabase6', 0);
TopIndexDatabase7 := MyIni.ReadInteger('mxmarkedit', 'topindexdatabase7', 0);
TopIndexDatabase8 := MyIni.ReadInteger('mxmarkedit', 'topindexdatabase8', 0);
ColDatabase1 := MyIni.ReadInteger('mxmarkedit', 'coldatabase1', 1);
ColDatabase2 := MyIni.ReadInteger('mxmarkedit', 'coldatabase2', 1);
ColDatabase3 := MyIni.ReadInteger('mxmarkedit', 'coldatabase3', 1);
ColDatabase4 := MyIni.ReadInteger('mxmarkedit', 'coldatabase4', 1);
ColDatabase5 := MyIni.ReadInteger('mxmarkedit', 'coldatabase5', 1);
ColDatabase6 := MyIni.ReadInteger('mxmarkedit', 'coldatabase6', 1);
ColDatabase7 := MyIni.ReadInteger('mxmarkedit', 'coldatabase7', 1);
ColDatabase8 := MyIni.ReadInteger('mxmarkedit', 'coldatabase8', 1);
RowDatabase1 := MyIni.ReadInteger('mxmarkedit', 'rowdatabase1', 1);
RowDatabase2 := MyIni.ReadInteger('mxmarkedit', 'rowdatabase2', 1);
RowDatabase3 := MyIni.ReadInteger('mxmarkedit', 'rowdatabase3', 1);
RowDatabase4 := MyIni.ReadInteger('mxmarkedit', 'rowdatabase4', 1);
RowDatabase5 := MyIni.ReadInteger('mxmarkedit', 'rowdatabase5', 1);
RowDatabase6 := MyIni.ReadInteger('mxmarkedit', 'rowdatabase6', 1);
RowDatabase7 := MyIni.ReadInteger('mxmarkedit', 'rowdatabase7', 1);
RowDatabase8 := MyIni.ReadInteger('mxmarkedit', 'rowdatabase8', 1);
ColWidthDatabase1 := MyIni.ReadString('mxmarkedit', 'colwidthdatabase1', '');
ColWidthDatabase2 := MyIni.ReadString('mxmarkedit', 'colwidthdatabase2', '');
ColWidthDatabase3 := MyIni.ReadString('mxmarkedit', 'colwidthdatabase3', '');
ColWidthDatabase4 := MyIni.ReadString('mxmarkedit', 'colwidthdatabase4', '');
ColWidthDatabase5 := MyIni.ReadString('mxmarkedit', 'colwidthdatabase5', '');
ColWidthDatabase6 := MyIni.ReadString('mxmarkedit', 'colwidthdatabase6', '');
ColWidthDatabase7 := MyIni.ReadString('mxmarkedit', 'colwidthdatabase7', '');
ColWidthDatabase8 := MyIni.ReadString('mxmarkedit', 'colwidthdatabase8', '');
blHideTitleTodo := MyIni.ReadBool('mxmarkedit', 'blhidetodo', False);
iMaxSize := MyIni.ReadInteger('mxmarkedit', 'maxsize', 250000);
finally
MyIni.Free;
end;
end;
if blDisableFormatting = True then
begin
miEditDisableFormClick(nil);
end;
if blHideTitleTodo = True then
begin
miEditHideListClick(nil);
end;
sgTable.Font.Color := dbText.Font.Color;
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setContinuousSpellCheckingEnabled(True);
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setGrammarCheckingEnabled(False);
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setFocusRingType(1);
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setAutomaticQuoteSubstitutionEnabled(True);
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setSmartInsertDeleteEnabled(True);
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setAutomaticLinkDetectionEnabled(True);
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setImportsGraphics(False);
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setRichText(True);
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
textContainer.setLineFragmentPadding(50);
nsInset.height := 30;
nsInset.width := 0;
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setTextContainerInset(nsInset);
// To avoid messing text on formatting
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
layoutManager.setAllowsNonContiguousLayout(False);
// Open file from paramater on console
if ParamStrUTF8(1) <> '' then
begin
if ParamStrUTF8(1) = '-' then
begin
stFileName := '';
CreateYAML;
LabelFileNameChars;
end
else
if FileExistsUTF8(ParamStrUTF8(1)) = True then
try
stFileName := ParamStrUTF8(1);
DeactForm(stFileName);
dbText.Lines.LoadFromFile(stFileName);
ResetFilterGrid;
if FileExistsUTF8(ExtractFileNameWithoutExt(stFileName) + '.csv') then
begin
sgTable.LoadFromCSVFile(ExtractFileNameWithoutExt(stFileName) + '.csv',
#9, False);
sgTable.RowCount := csTableRowCount;
stGridLoaded := stTableLoaded;
end
else
begin
stGridLoaded := '';
end;
MoveToPos;
iBookmarkPos := 0;
LabelFileNameChars;
if blDisableFormatting = False then
begin
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
checkTextInDocument(nil);
end;
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
undoManager.removeAllActions;
UpdateLastFile;
ShowCurrentTitleTodo;
blFileMod := False;
blTableMod := False;
except
MessageDlg(msg004, mtWarning, [mbOK], 0);
end;
end
else
if stFileName <> '' then
begin
if FileExistsUTF8(stFileName) then
try
odOpen.FileName := stFileName;
DeactForm(stFileName);
dbText.Lines.LoadFromFile(stFileName);
ResetFilterGrid;
if FileExistsUTF8(ExtractFileNameWithoutExt(stFileName) + '.csv') then
begin
sgTable.LoadFromCSVFile(ExtractFileNameWithoutExt(stFileName) + '.csv',
#9, False);
sgTable.RowCount := csTableRowCount;
stGridLoaded := stTableLoaded;
end
else
begin
stGridLoaded := '';
end;
MoveToPos;
iBookmarkPos := 0;
LabelFileNameChars;
if blDisableFormatting = False then
begin
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
checkTextInDocument(nil);
end;
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
undoManager.removeAllActions;
UpdateLastFile;
ShowCurrentTitleTodo;
blFileMod := False;
blTableMod := False;
except
MessageDlg(msg006, mtWarning, [mbOK], 0);
end
else
begin
stFileName := '';
end;
end;
end;
procedure TfmMain.FormDropFiles(Sender: TObject; const FileNames: array of string);
begin
// Open file from file association
if FileExistsUTF8(FileNames[0]) = True then
try
stFileName := FileNames[0];
DeactForm(stFileName);
dbText.Lines.LoadFromFile(stFileName);
ResetFilterGrid;
if FileExistsUTF8(ExtractFileNameWithoutExt(stFileName) + '.csv') then
begin
sgTable.LoadFromCSVFile(ExtractFileNameWithoutExt(stFileName) + '.csv',
#9, False);
sgTable.RowCount := csTableRowCount;
stGridLoaded := stTableLoaded;
end
else
begin
stGridLoaded := '';
end;
MoveToPos;
iBookmarkPos := 0;
LabelFileNameChars;
if blDisableFormatting = False then
begin
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
checkTextInDocument(nil);
end;
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
undoManager.removeAllActions;
UpdateLastFile;
ShowCurrentTitleTodo;
blFileMod := False;
blTableMod := False;
except
MessageDlg(msg004, mtWarning, [mbOK], 0);
end;
end;
procedure TfmMain.FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
var
rng: NSRange;
begin
if ((key = 27) and (blIsPresenting = True)) then
begin
DisablePresenting;
FormatListTitleTodo;
key := 0;
end
else
if ((key = Ord('T')) and (Shift = [ssShift, ssMeta])) then
begin
if pnGrid.Height = 1 then
begin
pnGrid.Height := 400;
sgTable.SetFocus;
end
else
begin
pnGrid.Height := 1;
dbText.SetFocus;
end;
key := 0;
end
else
if ((key = Ord('F')) and (Shift = [ssCtrl, ssShift, ssMeta])) then
begin
if ((pnGrid.Height > 1) and (edFilterGrid.Visible = True)) then
begin
edFilterGrid.SetFocus;
end;
key := 0;
end
else
if ((key = Ord('F')) and (Shift = [ssCtrl, ssShift])) then
begin
if ((pnGrid.Height > 1) and (edFindGrid.Visible = True)) then
begin
edFilterGrid.Clear;
ResetFilterGrid;
end;
key := 0;
end
else
if ((key = Ord('F')) and (Shift = [ssCtrl, ssMeta])) then
begin
if ((pnGrid.Height > 1) and (edFindGrid.Visible = True)) then
begin
edFindGrid.SetFocus;
end;
key := 0;
end
else
if ((key = 187) and (Shift = [ssMeta])) then
begin
if ((dbText.Font.Size < 128) and (blIsPresenting = False)) then
begin
dbText.Font.Size := dbText.Font.Size + 1;
FormatListTitleTodo;
rng := TCocoaTextView(NSScrollView(dbText.Handle).documentView).
textStorage.string_.paragraphRangeForRange(TCocoaTextView(
NSScrollView(dbText.Handle).documentView).selectedRange);
Application.ProcessMessages;
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
scrollRangeToVisible(rng);
end;
key := 0;
end
else
if ((key = 189) and (Shift = [ssMeta])) then
begin
if ((dbText.Font.Size > 6) and (blIsPresenting = False)) then
begin
dbText.Font.Size := dbText.Font.Size - 1;
FormatListTitleTodo;
rng := TCocoaTextView(NSScrollView(dbText.Handle).documentView).
textStorage.string_.paragraphRangeForRange(TCocoaTextView(
NSScrollView(dbText.Handle).documentView).selectedRange);
Application.ProcessMessages;
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
scrollRangeToVisible(rng);
end;
key := 0;
end
else
if ((key = 187) and (Shift = [ssMeta, ssCtrl])) then
begin
if ((iFontMonoSize < 128) and (blIsPresenting = False)) then
begin
iFontMonoSize := iFontMonoSize + 1;
FormatListTitleTodo;
rng := TCocoaTextView(NSScrollView(dbText.Handle).documentView).
textStorage.string_.paragraphRangeForRange(TCocoaTextView(
NSScrollView(dbText.Handle).documentView).selectedRange);
Application.ProcessMessages;
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
scrollRangeToVisible(rng);
end;
key := 0;
end
else
if ((key = 189) and (Shift = [ssMeta, ssCtrl])) then
begin
if ((iFontMonoSize > 6) and (blIsPresenting = False)) then
begin
iFontMonoSize := iFontMonoSize - 1;
FormatListTitleTodo;
rng := TCocoaTextView(NSScrollView(dbText.Handle).documentView).
textStorage.string_.paragraphRangeForRange(TCocoaTextView(
NSScrollView(dbText.Handle).documentView).selectedRange);
Application.ProcessMessages;
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
scrollRangeToVisible(rng);
end;
key := 0;
end;
end;
procedure TfmMain.miEditDisSpellClick(Sender: TObject);
begin
if miEditDisSpell.Checked = False then
begin
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setContinuousSpellCheckingEnabled(False);
miEditDisSpell.Checked := True;
end
else
begin
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
setContinuousSpellCheckingEnabled(True);
miEditDisSpell.Checked := False;
end;
end;
procedure TfmMain.FormActivate(Sender: TObject);
var
rng: NSRange;
begin
LabelFileNameChars;
if blIsPresenting = False then
begin
FormatListTitleTodo;
end;
// scrollRangeToVisible in MoveToPos doesn't work OnCreate
rng.location := dbText.SelStart;
rng.length := 1;
TCocoaTextView(NSScrollView(dbText.Handle).documentView).
scrollRangeToVisible(rng);
if pnGrid.Height = 1 then
begin
dbText.SetFocus;
end
else
begin
sgTable.SetFocus;
end;
end;
procedure TfmMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
var
MyIni: TIniFile;
begin
if SaveFile = False then
begin
Abort;
end;
try
MyIni := TIniFile.Create(myHomeDir + myConfigFile);
if fmMain.WindowState = wsMaximized then
begin
MyIni.WriteString('mxmarkedit', 'maximize', 'true');
end
else
begin
MyIni.WriteString('mxmarkedit', 'maximize', 'false');
MyIni.WriteInteger('mxmarkedit', 'top', fmMain.Top);
MyIni.WriteInteger('mxmarkedit', 'left', fmMain.Left);
MyIni.WriteInteger('mxmarkedit', 'width', fmMain.Width);
MyIni.WriteInteger('mxmarkedit', 'heigth', fmMain.Height);
end;
MyIni.WriteString('mxmarkedit', 'fontname', dbText.Font.Name);