-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunit5.pas
More file actions
392 lines (360 loc) · 9.39 KB
/
unit5.pas
File metadata and controls
392 lines (360 loc) · 9.39 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
// ***********************************************************************
// ***********************************************************************
// 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 Unit5;
{$mode ObjFPC}{$H+}
{$modeswitch objectivec1}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids, ExtCtrls,
StdCtrls, LazUTF8, translate, CocoaUtils, Clipbrd, IniFiles, LazFileUtils;
type
{ TfmWords }
TfmWords = class(TForm)
bnCopy: TButton;
bnRefresh: TButton;
bnRemove: TButton;
lbResults: TLabel;
lbSkip: TLabel;
pnWords: TPanel;
rgSkip: TRadioGroup;
sgWords: TStringGrid;
bnOK: TButton;
meSkip: TMemo;
procedure bnCopyClick(Sender: TObject);
procedure bnOKClick(Sender: TObject);
procedure bnRefreshClick(Sender: TObject);
procedure bnRemoveClick(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 meSkipExit(Sender: TObject);
procedure rgSkipClick(Sender: TObject);
private
procedure CreateWordsList;
procedure SortSkipWords;
public
end;
var
fmWords: TfmWords;
resourcestring
msgsk001 = 'Words used:';
msgsk002 = 'Sort by words';
msgsk003 = 'Sort by recurrences';
implementation
uses Unit1;
{$R *.lfm}
{ TfmTasks }
procedure TfmWords.FormCreate(Sender: TObject);
var
MyIni: TIniFile;
begin
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);
meSkip.Text := MyIni.ReadString('mxmarkedit', 'skipwords', '');
finally
MyIni.Free;
end;
end;
sgWords.FocusRectVisible := False;
rgSkip.Items[0] := msgsk002;
rgSkip.Items[1] := msgsk003;
rgSkip.ItemIndex := 1;
if IsAppDark = True then
begin
sgWords.SelectedColor := $005E5E5E;
end
else
begin
sgWords.SelectedColor := $00EBEBEB;
meSkip.Color := $00ECECEB;
end;
end;
procedure TfmWords.bnOKClick(Sender: TObject);
begin
Close;
end;
procedure TfmWords.bnRefreshClick(Sender: TObject);
begin
CreateWordsList;
end;
procedure TfmWords.bnRemoveClick(Sender: TObject);
begin
if sgWords.RowCount > 1 then
begin
if meSkip.Text = '' then
begin
meSkip.Text := sgWords.Cells[0, sgWords.Row];
end
else
begin
meSkip.Text := sgWords.Cells[0, sgWords.Row] + ', ' + meSkip.Text;
end;
SortSkipWords;
sgWords.DeleteRow(sgWords.Row);
end;
end;
procedure TfmWords.FormActivate(Sender: TObject);
begin
rgSkip.ItemIndex := 1;
CreateWordsList;
end;
procedure TfmWords.FormClose(Sender: TObject; var CloseAction: TCloseAction);
var
MyIni: TIniFile;
begin
try
MyIni := TIniFile.Create(myHomeDir + myConfigFile);
MyIni.WriteString('mxmarkedit', 'skipwords', meSkip.Text);
finally
MyIni.Free;
end;
end;
procedure TfmWords.bnCopyClick(Sender: TObject);
var
stClip: String = '';
i: Integer;
begin
if sgWords.RowCount > 1 then
begin
stClip := sgWords.Columns[0].Title.Caption + #9 +
sgWords.Columns[1].Title.Caption + LineEnding;
for i := 1 to sgWords.RowCount - 1 do
begin
stClip := stClip + sgWords.Cells[0, i] + #9 +
sgWords.Cells[1, i] + LineEnding;
end;
end;
Clipboard.AsText := stClip;
end;
procedure TfmWords.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = 27 then
begin
key := 0;
Close
end;
end;
procedure TfmWords.meSkipExit(Sender: TObject);
begin
SortSkipWords
end;
procedure TfmWords.rgSkipClick(Sender: TObject);
var
i: Integer;
begin
if rgSkip.ItemIndex = 0 then
begin
sgWords.SortOrder := soAscending;
sgWords.SortColRow(True, 0);
sgWords.Row := 1;
end
else
if rgSkip.ItemIndex = 1 then
begin
for i := 1 to sgWords.RowCount - 1 do
begin
sgWords.Cells[1, i] := FormatFloat('0000000',
StrToInt(sgWords.Cells[1, i]));
end;
sgWords.SortOrder := soDescending;
sgWords.SortColRow(True, 1);
for i := 1 to sgWords.RowCount - 1 do
begin
sgWords.Cells[1, i] := FormatFloat('0',
StrToInt(sgWords.Cells[1, i]));
end;
end;
end;
procedure TfmWords.CreateWordsList;
var
iPosWord, i, n, iLen: integer;
slListWords, slListRec, slListSkip: TStringList;
stItem, stText: WideString;
stSkip, stWord: String;
stSeparators: String = '.,;:+=&^-–(){}[]/\''"’‘”“«»?¿!¡ ' + #13 + #9 + LineEnding;
stNumbers: String = '1234567890';
begin
try
Screen.Cursor := crHourGlass;
slListWords := TStringList.Create;
slListRec := TStringList.Create;
slListSkip := TStringList.Create;
stText := WideString(fmMain.dbText.Text + ' ');
iLen := Length(stText);
stItem := '';
if fmMain.dbText.Lines[0] = '---' then
begin
i := Pos('---', stText, 4) + 3;
end
else
begin
i := 1;
end;
if meSkip.Text <> '' then
begin
stSkip := meSkip.Text;
slListSkip.Sorted := True;
slListSkip.Duplicates := dupIgnore;
stWord := '';
for n := 1 to Length(stSkip) + 1 do
begin
if ((stSkip[n] = ',') or (n = Length(stSkip) + 1)) then
begin
stWord := Trim(stWord);
if stWord <> '' then
begin
slListSkip.Add(stWord);
end;
stWord := '';
end
else
begin
stWord := stWord + stSkip[n];
end;
end;
end;
while i <= iLen do
begin
if Pos(stText[i], stSeparators) > 0 then
begin
if slListSkip.IndexOf(UTF8LowerCase(stItem)) > -1 then
begin
stItem := '';
Continue;
end
else
begin
if stItem <> '' then
begin
iPosWord := slListWords.IndexOf(UTF8LowerCase(stItem));
if iPosWord > -1 then
begin
slListRec[iPosWord] := IntToStr(StrToInt(slListRec[iPosWord]) + 1);
end
else
begin
slListWords.Add(UTF8LowerCase(stItem));
slListRec.Add('1');
end;
stItem := '';
end;
end;
end
else
begin
if ((stText[i] <> '*') and (stText[i] <> '#') and (stText[i] <> '_')
and (stText[i] <> '`') and (Pos(stText[i], stNumbers) < 1)) then
begin
stItem := stItem + stText[i];
end;
end;
Inc(i);
end;
if slListWords.Count > 0 then
begin
sgWords.RowCount := slListWords.Count + 1;
for i := 0 to slListWords.Count - 1 do
begin
sgWords.Cells[0, i + 1] := slListWords[i];
sgWords.Cells[1, i + 1] := FormatFloat('0000000',
StrToInt(slListRec[i]));
end;
sgWords.SortOrder := soDescending;
sgWords.SortColRow(True, 1);
for i := 1 to sgWords.RowCount - 1 do
begin
sgWords.Cells[1, i] := FormatFloat('0',
StrToInt(sgWords.Cells[1, i]));
end;
sgWords.Row := 1;
end
else
begin
sgWords.RowCount := 1;
end;
lbResults.Caption := msgsk001 + ' ' + IntToStr(sgWords.RowCount - 1);
sgWords.SetFocus;
Screen.Cursor := crDefault;
finally
Screen.Cursor := crDefault;
slListWords.Free;
slListRec.Free;
slListSkip.Free;
end;
end;
procedure TfmWords.SortSkipWords;
var
slListSkip: TStringList;
stSkip, stWord: String;
i: Integer;
begin
if meSkip.Text = '' then
begin
Exit;
end;
try
slListSkip := TStringList.Create;
stSkip := meSkip.Text;
slListSkip.Sorted := True;
slListSkip.Duplicates := dupIgnore;
stWord := '';
for i := 1 to Length(stSkip) + 1 do
begin
if ((stSkip[i] = ',') or (i = Length(stSkip) + 1)) then
begin
stWord := Trim(stWord);
if stWord <> '' then
begin
slListSkip.Add(stWord);
end;
stWord := '';
end
else
begin
stWord := stWord + stSkip[i];
end;
end;
if slListSkip.Count > 0 then
begin
stSkip := '';
for i := 0 to slListSkip.Count - 1 do
begin
stSkip := stSkip + slListSkip[i];
if i < slListSkip.Count - 1 then
begin
stSkip := stSkip + ', ';
end;
end;
meSkip.Text := stSkip;
end;
finally
slListSkip.Free;
end;
end;
end.