-
Notifications
You must be signed in to change notification settings - Fork 2
/
unit1.pas
4085 lines (3968 loc) · 120 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
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
// ***********************************************************************
// ***********************************************************************
// WordStatix 2.x
// Author and copyright: Massimo Nardello, Modena (Italy) 2016 - 2020.
// 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+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
StdCtrls, ExtCtrls, ComCtrls, Menus, LazUTF8, TAGraph, TASources, TASeries,
TATools, IniFiles, Clipbrd, zipper, LCLIntf, CheckLst, Types, LazFileUtils,
gettext, DefaultTranslator;
type
TRecWordList = record
stRecWord: string;
iRecFreq: integer;
stRecWordPos: string;
stRecBookPos: string;
end;
TRecWordTextual = record
stRecWordTextual: string;
end;
{ TfmMain }
TfmMain = class(TForm)
apAppProp: TApplicationProperties;
bnDeselConc: TButton;
bnFindFirst: TButton;
bnFindNext: TButton;
bnReplace: TButton;
bnReplaceAll: TButton;
bnDeselDiag: TButton;
cbCollatedSort: TCheckBox;
cbComboDiag1: TComboBox;
cbComboDiag2: TComboBox;
cbComboDiag3: TComboBox;
cbComboDiag4: TComboBox;
cbComboDiag5: TComboBox;
cbSkipNumbers: TCheckBox;
chChartBarSeries4: TBarSeries;
chChartBarSeries5: TBarSeries;
csChartSource4: TListChartSource;
csChartSource5: TListChartSource;
chChart: TChart;
chChartBarSeries1: TBarSeries;
chChartBarSeries2: TBarSeries;
chChartBarSeries3: TBarSeries;
clDiagBookmark: TCheckListBox;
csChartSource2: TListChartSource;
csChartSource3: TListChartSource;
edFltStart: TEdit;
edFltEnd: TEdit;
edFind: TEdit;
edLocate: TEdit;
edReplace: TEdit;
edWordsCont: TEdit;
lbDiagBookmark: TLabel;
lbDiag3: TLabel;
lbDiag2: TLabel;
lbDiag1: TLabel;
lbBookmarks: TListBox;
lbDiag4: TLabel;
lbDiag5: TLabel;
lbLocate: TLabel;
lbReplace: TLabel;
lbFind: TLabel;
lbFltStart: TLabel;
lbFltEnd: TLabel;
lbWordsCont: TLabel;
lbContext: TLabel;
lbNoWord: TLabel;
lsContext: TListBox;
csChartSource1: TListChartSource;
miFileCopyright: TMenuItem;
miFileManual: TMenuItem;
miLineManual: TMenuItem;
miLine1: TMenuItem;
miFileSaveConc: TMenuItem;
miFileOpenConc: TMenuItem;
miStatisticSortFreq: TMenuItem;
miStatisticSortName: TMenuItem;
miLine9: TMenuItem;
miLine5: TMenuItem;
miConcordanceJoin: TMenuItem;
miDiagramShowGrid: TMenuItem;
miDiagramAllWordNoBook: TMenuItem;
miConcordanceRefreshGrid: TMenuItem;
miLine6: TMenuItem;
miDiagramAllWordsBook: TMenuItem;
miLine13: TMenuItem;
miDiagramShowVal: TMenuItem;
miDiaZoomIn: TMenuItem;
miDiaZoomOut: TMenuItem;
miDiaZoomNormal: TMenuItem;
miLine14: TMenuItem;
miLine12: TMenuItem;
miDiagramSave: TMenuItem;
miDiagramSingleWordsBook: TMenuItem;
miDiagram: TMenuItem;
miConcordanceRemove: TMenuItem;
miManual: TMenuItem;
miLineCopyright: TMenuItem;
miFileNew: TMenuItem;
miStatisticSave: TMenuItem;
miStatisticCreate: TMenuItem;
miLine10: TMenuItem;
miStatistic: TMenuItem;
miFileSaveAs: TMenuItem;
miLine8: TMenuItem;
miConcordanceDelCont: TMenuItem;
miLineFileBottom: TMenuItem;
miFileUpdBookmark: TMenuItem;
miFileSetBookmark: TMenuItem;
miConcordanceOpenSkip: TMenuItem;
miConcordanceSaveSkip: TMenuItem;
miLine4: TMenuItem;
miConcodanceShowSelected: TMenuItem;
miFileSave: TMenuItem;
miLine7: TMenuItem;
miConcordanceSaveRep: TMenuItem;
miCopyrightForm: TMenuItem;
miCopyright: TMenuItem;
miLine3: TMenuItem;
miConcordanceAddSkip: TMenuItem;
miConcordanceCreate: TMenuItem;
miFileOpen: TMenuItem;
miLine0: TMenuItem;
miFileExit: TMenuItem;
mmMenu: TMainMenu;
miConcordance: TMenuItem;
miFile: TMenuItem;
meText: TMemo;
meSkipList: TMemo;
odOpenDialog: TOpenDialog;
pnDiagram: TPanel;
pnListBookmark: TPanel;
pnTextBottom: TPanel;
pcMain: TPageControl;
rgCondFlt: TRadioGroup;
rgSortBy: TRadioGroup;
sbDiagram: TScrollBox;
sdSaveDialog: TSaveDialog;
sgWordList: TStringGrid;
sbStatusBar: TStatusBar;
sgStatistic: TStringGrid;
spDiagram: TSplitter;
spText: TSplitter;
tsDiagram: TTabSheet;
tsStatistic: TTabSheet;
tsFile: TTabSheet;
tsConcordance: TTabSheet;
udWordsCont: TUpDown;
procedure apAppPropException(Sender: TObject; E: Exception);
procedure bnDeselConcClick(Sender: TObject);
procedure bnFindFirstClick(Sender: TObject);
procedure bnFindNextClick(Sender: TObject);
procedure bnReplaceAllClick(Sender: TObject);
procedure bnReplaceClick(Sender: TObject);
procedure bnDeselDiagClick(Sender: TObject);
procedure cbCollatedSortChange(Sender: TObject);
procedure cbComboDiag2KeyDown(Sender: TObject; var Key: word;
Shift: TShiftState);
procedure cbComboDiag3KeyDown(Sender: TObject; var Key: word;
Shift: TShiftState);
procedure cbComboDiag4KeyDown(Sender: TObject; var Key: word;
Shift: TShiftState);
procedure cbComboDiag5KeyDown(Sender: TObject; var Key: word;
Shift: TShiftState);
procedure clDiagBookmarkKeyUp(Sender: TObject; var Key: word;
Shift: TShiftState);
procedure edFindKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure edFltEndExit(Sender: TObject);
procedure edFltStartExit(Sender: TObject);
procedure edLocateKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure edReplaceKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure edWordsContChange(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);
procedure lbBookmarksClick(Sender: TObject);
procedure meSkipListExit(Sender: TObject);
procedure meTextChange(Sender: TObject);
procedure meTextKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure meTextMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: integer; MousePos: TPoint; var Handled: boolean);
procedure miConcodanceShowSelectedClick(Sender: TObject);
procedure miConcordanceAddSkipClick(Sender: TObject);
procedure miConcordanceCreateClick(Sender: TObject);
procedure miConcordanceJoinClick(Sender: TObject);
procedure miFileOpenConcClick(Sender: TObject);
procedure miConcordanceOpenSkipClick(Sender: TObject);
procedure miConcordanceRefreshGridClick(Sender: TObject);
procedure miConcordanceRemoveClick(Sender: TObject);
procedure miFileSaveConcClick(Sender: TObject);
procedure miConcordanceSaveRepClick(Sender: TObject);
procedure miConcordanceDelContClick(Sender: TObject);
procedure miConcordanceSaveSkipClick(Sender: TObject);
procedure miCopyrightFormClick(Sender: TObject);
procedure miDiagramAllWordNoBookClick(Sender: TObject);
procedure miDiagramShowGridClick(Sender: TObject);
procedure miDiagramSingleWordsBookClick(Sender: TObject);
procedure miDiagramAllWordsBookClick(Sender: TObject);
procedure miDiagramSaveClick(Sender: TObject);
procedure miDiagramShowValClick(Sender: TObject);
procedure miDiaZoomInClick(Sender: TObject);
procedure miDiaZoomNormalClick(Sender: TObject);
procedure miDiaZoomOutClick(Sender: TObject);
procedure miFileNewClick(Sender: TObject);
procedure miManualClick(Sender: TObject);
procedure miStatisticCreateClick(Sender: TObject);
procedure miFileSaveAsClick(Sender: TObject);
procedure miFileSetBookmarkClick(Sender: TObject);
procedure miFileUpdBookmarkClick(Sender: TObject);
procedure miFileExitClick(Sender: TObject);
procedure miFileOpenClick(Sender: TObject);
procedure miFileSaveClick(Sender: TObject);
procedure miStatisticSaveClick(Sender: TObject);
procedure miStatisticSortFreqClick(Sender: TObject);
procedure miStatisticSortNameClick(Sender: TObject);
procedure pcMainChange(Sender: TObject);
procedure pcMainChanging(Sender: TObject; var AllowChange: boolean);
procedure pmCopyClick(Sender: TObject);
procedure pmCutClick(Sender: TObject);
procedure pmPasteClick(Sender: TObject);
procedure pmSelAllClick(Sender: TObject);
procedure rgSortBySelectionChanged(Sender: TObject);
procedure sgStatisticPrepareCanvas(Sender: TObject; aCol, aRow: integer;
aState: TGridDrawState);
procedure sgStatisticSelectCell(Sender: TObject; aCol, aRow: integer;
var CanSelect: boolean);
procedure sgWordListKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure sgWordListSelection(Sender: TObject; aCol, aRow: integer);
procedure tsDiagramResize(Sender: TObject);
private
procedure CompileGrid(blSort: boolean);
procedure CreateConc(stStartText: string);
function CreateContext(GridRow: integer; blSetCursor: boolean): string;
procedure AddSkipWord;
function CheckFilter(stWord: string): boolean;
function CleanField(myField: string): string;
function CleanXML(stXMLText: string): string;
procedure CreateDiagramAllWordsBook;
procedure CreateDiagramAllWordsNoBook;
procedure CreateDiagramSingleWordsBook;
procedure CreateStatistic;
procedure DisableMenuItems;
procedure EnableMenuItems;
function FindNextWord(blMessage: boolean): boolean;
procedure OpenConcordance;
procedure SaveConcordance;
procedure SaveReport(stFileName: string);
procedure CreateBookmarks(blSetCursor: boolean);
procedure SortWordFreq(var arWordList: array of TRecWordList;
flField: shortint);
{ private declarations }
public
{ public declarations }
end;
var
fmMain: TfmMain;
arWordList: array of TRecWordList;
arWordTextual: array of TRecWordTextual;
myHomeDir: string;
myConfigFile: string;
stFileName: string;
iWordsUsed: integer = 0;
iWordsTotal: integer = 0;
iWordsStartTot: integer = 0;
ttStart, ttEnd: TTime;
blSortMod: boolean = False;
blStopConcordance: boolean = False;
blConInProc: boolean = False;
blTextModSave: boolean = False;
blTextModConc: boolean = False;
stDiagTitle: string;
stCpr1: string = '';
stCpr2: string = '';
stCpr3: string = '';
resourcestring
msg001 = 'Operation not correct.';
msg002 = 'Compact all paragraphs not separated by an empty line, ' +
'clean the text from double spaces and check the spaces ' +
'after the punctuation marks?';
msg003 = 'No recurrences of the text to look for.';
msg004 = 'No text is selected.';
msg005 = 'Replace all the recurrences of';
msg006 = 'with';
msg007 = 'in the current text?';
msg008 = 'The word looked for has been replaced';
msg009 = 'times.';
msg010 = 'Create a new text and a new concordance ' +
'closing the existing ones?';
msg011 = 'The current text has been changed but has not been saved. ' +
'Reject the changes and open a new text?';
msg012 = 'It is not possible to open the selected file.';
msg013 = 'It is not possible to save the selected file.';
msg014 = 'It is not possible to save the selected file.';
msg015 = 'There is no word to remove.';
msg016 = 'No concordance has been created.';
msg017 = 'No words are selected.';
msg018 = 'Associate all the recurrences of the selected words ' +
'to those of the current word';
msg019 = 'Some changes have been made to the concordance grid. ' +
'Do you want to reject them and recreate the list of words?';
msg020 = 'It is not possible to open the skip list.';
msg021 = 'It is not possible to save the skip list.';
msg022 = 'There is no recurrence to delete.';
msg023 = 'There is no selected recurrence to delete.';
msg024 = 'No concordance has been created.';
msg025 = 'It is not possible to save the report.';
msg026 = 'No statistic available.';
msg027 = 'No statistic available.';
msg028 = 'There is no statistic to save.';
msg029 = 'It is not possible to save the selected file.';
msg030 = 'There is no diagram to save.';
msg031 = 'It is not possible to save the diagram.';
msg032 = 'No manual available in the folder of WordStatix. ' +
'Download it from the website of the software:';
msg033 = 'A bookmark is not open or closed properly ' +
'with double square brackets.';
msg034 = 'A bookmark seems to be too long. ' +
'Check the text to control that there are ' +
'no unwanted double square brackets.';
msg035 = 'A bookmark seems to be incorrect. ' +
'Check the text to control that there are ' +
'no unwanted double square brackets.';
msg036 = 'The bookmark';
msg037 = 'is used more than once. ' +
'Check the text and make all its recurrences unique.';
msg038 = 'Bookmarks cannot contain commas, spaces or be an asterisk. ' +
'The incorrect bookmarks have been changed accordingly.';
msg039 = 'No more recurrences of the text to look for.';
msg040 = 'No text available.';
msg041 = 'Replace the current concordance with a new one?';
msg042 = 'The concordance has been created.';
msg043 = 'Total words (without bookmarks):';
msg044 = 'Unique words:';
msg045 = 'Concordance done in';
msg046 = 'There is no word to add to the skip list.';
msg047 = 'No text available.';
msg048 = 'No concordance available.';
msg049 = 'The text or the settings of the software useful to create ' +
'the concordance have been changed after the last one was processed. ' +
'Recreate the concordance to be able to save it along with its text.';
msg050 = 'It is not possibile to save the concordance.';
msg051 = 'The current text has been changed but has not been saved. ' +
'Reject the changes and open a new concordance with its text?';
msg052 = 'The selected file was not created ' +
'with WordStatix, and so cannot be opened.';
msg053 = 'It is not possibile to open the concordance.';
msg054 = 'No concordance available.';
msg055 = 'No words are selected in the concordance grid.';
msg056 = 'No active statistic.';
msg057 = 'No bookmark available.';
msg058 = 'At least one bookmark must be selected.';
msg059 = 'No word selected in Word 1 field.';
msg060 = 'The fields "Word" must be compiled contiguously.';
msg061 = 'The same word has been selected twice.';
msg062 = 'No active statistic.';
msg063 = 'No bookmark available.';
msg064 = 'At least one bookmark must be selected.';
msg065 = 'No active statistic.';
msg066 = 'No bookmark available.';
msg067 = 'At least one bookmark must be selected.';
// Status bar messages
sbr001 = 'No active concordance.';
sbr002 = 'The file has been opened.';
sbr003 = 'The text has been saved.';
sbr004 = 'The text has been saved.';
sbr005 = 'The report has been saved.';
sbr006 = 'The statistic has been saved.';
sbr007 = 'The diagram has been saved.';
sbr008 = 'Concordance interrupted.';
sbr009 = 'Concordance in processing, please wait.';
sbr010 = 'Concordance in processing, press Ctrl + Shift + H to stop. ' +
'Analyzed words:';
sbr011 = 'of';
sbr012 = 'Unique words found:';
sbr013 = 'Concordance in processing, press Ctrl + Shift + H to stop. ' +
'Analyzed words:';
sbr014 = 'of';
sbr015 = 'Unique words found:';
sbr016 = 'Total words (without bookmarks):';
sbr017 = 'Unique words:';
sbr018 = 'Concordance done in';
sbr019 = 'No active concordance.';
sbr020 = 'Sorting the list of words, press Ctrl + Shift + H to stop.';
sbr021 = 'Filling the concordance grid, please wait.';
sbr022 = 'Total words (without bookmarks):';
sbr023 = 'Unique words:';
sbr024 = 'Sorting interrupted.';
sbr025 = 'The concordance has been saved.';
sbr026 = 'Opening concordance, please wait.';
sbr027 = 'Total words (without bookmarks):';
sbr028 = 'Unique words:';
sbr029 = 'Concordance loaded in';
// Dialogs and files captions
dgc001 = 'Open file';
dgc002 = 'All formats|*.txt;*.odt;*.docx|' +
'Text file|*.txt|Writer files|*.odt|' + 'Word files|*.docx|All files|*';
dgc003 = 'Save file';
dgc004 = 'Text file|*.txt|All files|*';
dgc005 = 'Open skip list';
dgc006 = 'Text file|*.txt|All files|*';
dgc007 = 'Save skip list';
dgc008 = 'Text file|*.txt|All files|*';
dgc009 = 'Save report';
dgc010 = 'Text file|*.txt|HTML file|*.html|All files|*';
dgc011 = 'Save statistic';
dgc012 = 'CSV file|*.csv|All files|*';
dgc013 = 'Save diagram';
dgc014 = 'JPEG file|*.jpg|PNG file|*.png|All files|*';
dgc015 = 'Open concordance';
dgc016 = 'WordStatix files|*.wsx|All files|*';
dgc017 = 'Title of report';
dgc018 = 'Insert the title of the report';
dgc019 = 'Concordance made with WordStatix';
dgc020 = 'recurrences';
dgc021 = 'Total';
dgc022 = 'Title of diagram';
dgc023 = 'Insert the title of the diagram.';
srb001 = 'Sort by recurrences';
srb002 = 'Sort by words';
man001 = 'manual-wordstatix.pdf';
implementation
{$R *.lfm}
uses unit2, Copyright;
{ TfmMain }
// ********************************************************** //
// ***************** Events of the main form **************** //
// ********************************************************** //
procedure TfmMain.FormCreate(Sender: TObject);
var
MyIni: TIniFile;
begin
// Set data on start
{$ifdef Linux}
myHomeDir := GetEnvironmentVariable('HOME') + DirectorySeparator +
'.config' + DirectorySeparator + 'wordstatix' + DirectorySeparator;
myConfigFile := 'wordstatix';
{$endif}
{$ifdef Windows}
myHomeDir := GetAppConfigDir(False);
myConfigFile := 'wordstatix.ini';
fmMain.Color := clWhite;
lbBookmarks.Color := clWhite;
clDiagBookmark.Color := clWhite;
chChart.Color := clWhite;
chChart.BackColor := clWhite;
chChart.Title.Font.Color := clBlack;
chChart.Title.Brush.Color := clWhite;
{$endif}
{$ifdef Darwin}
myHomeDir := GetEnvironmentVariable('HOME') + DirectorySeparator +
'Library' + DirectorySeparator + 'Preferences' + DirectorySeparator;
myConfigFile := 'wordstatix.plist';
miFileOpen.ShortCut := 16463 - 12288;
miFileSave.ShortCut := 16467 - 12288;
miFileOpenConc.ShortCut := 24655 - 12288;
miFileSaveConc.ShortCut := 24659 - 12288;
miFileSetBookmark.ShortCut := 16466 - 12288;
miFileUpdBookmark.ShortCut := 16469 - 12288;
miFileExit.ShortCut := 16465 - 12288;
miConcordanceCreate.ShortCut := 16462 - 12288;
miConcodanceShowSelected.ShortCut := 16460 - 12288;
miConcordanceAddSkip.ShortCut := 24651 - 12288;
miConcordanceRemove.ShortCut := 16459 - 12288;
miConcordanceJoin.ShortCut := 16458 - 12288;
miConcordanceRefreshGrid.ShortCut := 24661 - 12288;
miConcordanceDelCont.ShortCut := 24644 - 12288;
miConcordanceSaveRep.ShortCut := 24659 - 12288;
miStatisticCreate.ShortCut := 16468 - 12288;
miStatisticSortName.ShortCut := 16473 - 12288;
miStatisticSortFreq.ShortCut := 24665 - 12288;
miDiagramAllWordNoBook.ShortCut := 16457 - 12288;
miDiagramAllWordsBook.ShortCut := 24649 - 12288;
miDiagramSingleWordsBook.ShortCut := 57417 - 12288;
miDiaZoomIn.ShortCut := 16571 - 12288;
miDiaZoomOut.ShortCut := 16573 - 12288;
miDiaZoomNormal.ShortCut := 16432 - 12288;
miFile.Caption := #$EF#$A3#$BF;
miFileCopyright.Visible := True;
miFileManual.Visible := True;
miLineManual.Visible := True;
miCopyright.Visible := False;
miLineFileBottom.Visible := False;
miFileExit.Visible := False;
{$endif}
sgWordList.FocusRectVisible := False;
sgStatistic.FocusRectVisible := False;
lbBookmarks.ScrollWidth := 0;
clDiagBookmark.ScrollWidth := 0;
miFileSave.Enabled := False;
rgSortBy.Items.Clear;
rgSortBy.Items.Add(srb001);
rgSortBy.Items.Add(srb002);
rgSortBy.ItemIndex := 0;
if DirectoryExists(myHomeDir) = False then
begin
CreateDirUTF8(myHomeDir);
end;
if FileExistsUTF8(myHomeDir + 'skipwords') then
begin
meSkipList.Lines.LoadFromFile(myHomeDir + 'skipwords');
end;
if FileExistsUTF8(myHomeDir + myConfigFile) then
begin
try
MyIni := TIniFile.Create(myHomeDir + myConfigFile);
if MyIni.ReadString('wordstatix', 'maximize', '') = 'true' then
begin
fmMain.WindowState := wsMaximized;
end
else
begin
fmMain.Top := MyIni.ReadInteger('wordstatix', 'top', 0);
fmMain.Left := MyIni.ReadInteger('wordstatix', 'left', 0);
if MyIni.ReadInteger('wordstatix', 'width', 0) > 100 then
fmMain.Width := MyIni.ReadInteger('wordstatix', 'width', 0)
else
fmMain.Width := 1000;
if MyIni.ReadInteger('wordstatix', 'heigth', 0) > 100 then
fmMain.Height := MyIni.ReadInteger('wordstatix', 'heigth', 0)
else
fmMain.Height := 600;
end;
if MyIni.ReadInteger('wordstatix', 'sortby', 0) > -1 then
begin
rgSortBy.ItemIndex := MyIni.ReadInteger('wordstatix', 'sortby', 0);
end;
if MyIni.ReadString('wordstatix', 'wordscont', '') <> '' then
begin
edWordsCont.Text := MyIni.ReadString('wordstatix', 'wordscont', '6');
end;
if MyIni.ReadString('wordstatix', 'collatesort', '') = 't' then
begin
cbCollatedSort.Checked := True;
end;
if MyIni.ReadString('wordstatix', 'skipnum', '') = 't' then
begin
cbSkipNumbers.Checked := True;
end;
finally
MyIni.Free;
end;
end;
end;
procedure TfmMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
var
MyIni: TIniFile;
begin
// Save data on close
blStopConcordance := True;
meSkipList.Lines.SaveToFile(myHomeDir + 'skipwords');
try
MyIni := TIniFile.Create(myHomeDir + myConfigFile);
if fmMain.WindowState = wsMaximized then
begin
MyIni.WriteString('wordstatix', 'maximize', 'true');
end
else
begin
MyIni.WriteString('wordstatix', 'maximize', 'false');
MyIni.WriteInteger('wordstatix', 'top', fmMain.Top);
MyIni.WriteInteger('wordstatix', 'left', fmMain.Left);
MyIni.WriteInteger('wordstatix', 'width', fmMain.Width);
MyIni.WriteInteger('wordstatix', 'heigth', fmMain.Height);
end;
MyIni.WriteString('wordstatix', 'wordscont', edWordsCont.Text);
MyIni.WriteInteger('wordstatix', 'sortby', rgSortBy.ItemIndex);
if cbCollatedSort.Checked = True then
begin
MyIni.WriteString('wordstatix', 'collatesort', 't');
end
else
begin
MyIni.WriteString('wordstatix', 'collatesort', 'f');
end;
if cbSkipNumbers.Checked = True then
begin
MyIni.WriteString('wordstatix', 'skipnum', 't');
end
else
begin
MyIni.WriteString('wordstatix', 'skipnum', 'f');
end;
finally
MyIni.Free;
end;
end;
procedure TfmMain.FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
begin
// Select tab
if ((Key = Ord('1')) and (Shift = [ssCtrl])) then
begin
pcMain.ActivePage := tsFile;
key := 0;
end
else if ((Key = Ord('2')) and (Shift = [ssCtrl])) then
begin
pcMain.ActivePage := tsConcordance;
key := 0;
end
else if ((Key = Ord('3')) and (Shift = [ssCtrl])) then
begin
pcMain.ActivePage := tsStatistic;
key := 0;
end
else if ((Key = Ord('4')) and (Shift = [ssCtrl])) then
begin
pcMain.ActivePage := tsDiagram;
key := 0;
end;
// Zoom the diagram
if ((pcMain.ActivePage = tsDiagram) and (chChart.Visible = True)) then
begin
if key = 37 then
begin
sbDiagram.HorzScrollBar.Position :=
sbDiagram.HorzScrollBar.Position - 50;
key := 0;
end
else if key = 39 then
begin
sbDiagram.HorzScrollBar.Position :=
sbDiagram.HorzScrollBar.Position + 50;
key := 0;
end;
end;
// Stop concordance
if ((Key = Ord('H')) and (Shift = [ssShift, ssCtrl])) then
begin
blStopConcordance := True;
end;
end;
procedure TfmMain.FormShow(Sender: TObject);
begin
// Focus on text
pcMain.ActivePage := tsFile;
meText.SetFocus;
end;
procedure TfmMain.FormActivate(Sender: TObject);
begin
// Hack to fix some misalignments in Gnome > 2.16
// Do not set properties of components with modified anchors
{$ifdef Linux}
bnDeselConc.Top := edLocate.Top + edLocate.Height - bnDeselConc.Height;
{$endif}
end;
procedure TfmMain.apAppPropException(Sender: TObject; E: Exception);
begin
// Error handling
MessageDlg(msg001, mtError, [mbOK], 0);
end;
procedure TfmMain.lbBookmarksClick(Sender: TObject);
begin
// Go to bookmark
if ((lbBookmarks.Items.Count > 0) and
(lbBookmarks.ItemIndex > -1)) then
begin
meText.SelStart := UTF8Pos('[[' +
lbBookmarks.Items[lbBookmarks.ItemIndex] + ']]', meText.Text) - 1;
meText.SelLength := UTF8Length(lbBookmarks.Items[lbBookmarks.ItemIndex]) + 4;
meText.SetFocus;
end;
end;
procedure TfmMain.pcMainChange(Sender: TObject);
begin
// Selecting the tsConcordance the sdGrid do not accept focus, so...
if pcMain.ActivePage = tsConcordance then
tsConcordance.SetFocus;
end;
procedure TfmMain.pcMainChanging(Sender: TObject; var AllowChange: boolean);
begin
// Prevent change tab during concordance
if blConInProc = True then
begin
AllowChange := False;
end
else
begin
AllowChange := True;
end;
end;
procedure TfmMain.pmCutClick(Sender: TObject);
begin
// Cut
meText.CutToClipboard;
end;
procedure TfmMain.pmCopyClick(Sender: TObject);
begin
// Copy
meText.CopyToClipboard;
end;
procedure TfmMain.pmPasteClick(Sender: TObject);
begin
// Paste
meText.PasteFromClipboard;
end;
procedure TfmMain.pmSelAllClick(Sender: TObject);
begin
// Select all
meText.SelectAll;
end;
procedure TfmMain.rgSortBySelectionChanged(Sender: TObject);
begin
// Changed settings for concordance
// also for rgCondFlt
blTextModConc := True;
end;
procedure TfmMain.cbCollatedSortChange(Sender: TObject);
begin
// Changed settings for concordance
// also for all other Edit and Memo components
blTextModConc := True;
end;
procedure TfmMain.sgWordListKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
begin
// Select and deselect the word
if key = 32 then
begin
sgWordList.Col := 0;
if sgWordList.Cells[2, sgWordList.Row] = '0' then
begin
sgWordList.Cells[2, sgWordList.Row] := '1';
end
else
begin
sgWordList.Cells[2, sgWordList.Row] := '0';
end;
if sgWordList.Row < sgWordList.RowCount - 1 then
begin
sgWordList.Row := sgWordList.Row + 1;
end;
end;
end;
procedure TfmMain.bnDeselConcClick(Sender: TObject);
var
i: integer;
begin
// Select and deselect all words
if sgWordList.RowCount > 1 then
begin
if sgWordList.Cells[2, 1] = '1' then
begin
for i := 1 to sgWordList.RowCount - 1 do
begin
sgWordList.Cells[2, i] := '0';
end;
end
else
begin
for i := 1 to sgWordList.RowCount - 1 do
begin
sgWordList.Cells[2, i] := '1';
end;
end;
end;
end;
procedure TfmMain.sgWordListSelection(Sender: TObject; aCol, aRow: integer);
begin
// Create the list of context
if sgWordList.RowCount > 1 then
begin
if sgWordList.RowHeights[sgWordList.Row] > 0 then
begin
lsContext.Clear;
lsContext.Items.Text := CreateContext(sgWordList.Row, True);
{$ifdef Windows}
// Due to a bug in Windows...
if lsContext.Items[0] = '' then
lsContext.Items.Delete(0);
{$endif}
lsContext.ItemIndex := 0;
end;
end;
end;
procedure TfmMain.sgStatisticPrepareCanvas(Sender: TObject;
aCol, aRow: integer; aState: TGridDrawState);
begin
// Font of the last row and second col in Statistic
if aRow = sgStatistic.RowCount - 1 then
begin
sgStatistic.Canvas.Font.Style := [fsBold];
sgStatistic.Canvas.Brush.Color := clBtnFace;
end
else
if aCol = 1 then
begin
sgStatistic.Canvas.Font.Style := [fsBold];
end;
end;
procedure TfmMain.sgStatisticSelectCell(Sender: TObject; aCol, aRow: integer;
var CanSelect: boolean);
begin
// Avoid select last row
if aRow = sgStatistic.RowCount - 1 then
begin
CanSelect := False;
end;
end;
procedure TfmMain.edWordsContChange(Sender: TObject);
begin
// Create the list of context
if sgWordList.RowCount > 1 then
begin
if sgWordList.RowHeights[sgWordList.Row] > 0 then
begin
lsContext.Clear;
lsContext.Items.Text := CreateContext(sgWordList.Row, True);
{$ifdef Windows}
// Due to a bug in Windows...
if lsContext.Items[0] = '' then
lsContext.Items.Delete(0);
{$endif}
lsContext.ItemIndex := 0;
end;
end;
end;
procedure TfmMain.meSkipListExit(Sender: TObject);
begin
// Clean skip words on exit
meSkipList.Text := CleanField(meSkipList.Text);
end;
procedure TfmMain.meTextChange(Sender: TObject);
begin
// Set the text as modified
blTextModSave := True;
miFileSave.Enabled := blTextModSave;
blTextModConc := True;
end;
procedure TfmMain.edFltStartExit(Sender: TObject);
begin
// Clean filter start with on exit
edFltStart.Text := CleanField(edFltStart.Text);
end;
procedure TfmMain.edLocateKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
var
i: integer;
begin
// Locate word in concordance
if edLocate.Text <> '' then
begin
if ((key = 13) and (Shift = [ssCtrl])) then
begin
if sgWordList.Row < sgWordList.RowCount - 1 then
begin
for i := sgWordList.Row + 1 to sgWordList.RowCount - 1 do
begin
if UTF8LowerCase(UTF8Copy(sgWordList.Cells[0, i], 1,
UTF8Length(edLocate.Text))) = UTF8LowerCase(edLocate.Text) then
begin
if sgWordList.RowHeights[i] > 0 then
begin
sgWordList.Row := i;
end;
Break;
end;
end;
end;
end
else
if key = 13 then
begin
for i := 1 to sgWordList.RowCount - 1 do
begin
if UTF8LowerCase(UTF8Copy(sgWordList.Cells[0, i], 1,
UTF8Length(edLocate.Text))) = UTF8LowerCase(edLocate.Text) then
begin
if sgWordList.RowHeights[i] > 0 then
begin
sgWordList.Row := i;
end;
Break;
end;
end;
end;
end;
end;
procedure TfmMain.edFindKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
var
stClip: string;
begin
// Insert indivisible space
if ((Key = Ord(' ')) and (Shift = [ssCtrl])) then
begin
stClip := Clipboard.AsText;
Clipboard.AsText := ' ';
edFind.PasteFromClipboard;
Clipboard.AsText := stClip;
end;
end;
procedure TfmMain.edReplaceKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
var
stClip: string;
begin
// Insert indivisible space
if ((Key = Ord(' ')) and (Shift = [ssCtrl])) then
begin
stClip := Clipboard.AsText;
Clipboard.AsText := ' ';
edReplace.PasteFromClipboard;
Clipboard.AsText := stClip;
end;
end;
procedure TfmMain.edFltEndExit(Sender: TObject);
begin
// Clean filter end on exit
edFltEnd.Text := CleanField(edFltEnd.Text);
end;
procedure TfmMain.meTextMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: integer; MousePos: TPoint; var Handled: boolean);
begin
// Change Zoom with mouse weel
{$ifdef Linux}
if Shift = [ssCtrl] then
begin
if WheelDelta > 0 then
begin
if meText.Font.Size < 48 then
meText.Font.Size := meText.Font.Size + 1;
end
else
begin
if meText.Font.Size > 6 then
meText.Font.Size := meText.Font.Size - 1;
end;
end;
{$endif}
{$ifdef Windows}
if Shift = [ssCtrl] then
begin
if WheelDelta > 0 then
begin
if meText.Font.Size < 48 then
meText.Font.Size := meText.Font.Size + 1;
end
else
begin
if meText.Font.Size > 6 then