-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkn_EditorUtils.pas
1912 lines (1678 loc) · 55.5 KB
/
kn_EditorUtils.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
unit kn_EditorUtils;
interface
uses
kn_NoteObj;
// glossary management
procedure ExpandTermProc;
procedure AddGlossaryTerm;
procedure EditGlossaryTerms;
function GetWordCount( const t : string ) : longint;
procedure UpdateWordCount;
procedure CleanWordCount;
procedure MatchBracket;
procedure TrimBlanks( const TrimWhat : integer );
procedure CompressWhiteSpace;
procedure EvaluateExpression;
procedure InsertSpecialCharacter;
procedure InsertPictureOrObject( const AsPicture : boolean );
procedure ArabicToRoman;
procedure RomanToArabic;
procedure ShowStatistics;
procedure WordWebLookup;
procedure EnableOrDisableUAS;
procedure ConfigureUAS;
// clipboard capture and paste
procedure TryPasteRTF(const Editor: TTabRichEdit; HTMLText: string='');
procedure TryOfferRTFinClipboard(const Editor: TTabRichEdit; HTMLText: string='');
procedure ToggleClipCap( const TurnOn : boolean; const aNote : TTabNote );
procedure SetClipCapState( const IsOn : boolean );
procedure PasteOnClipCap (ClpStr: WideString);
procedure PasteAsWebClip;
procedure PasteIntoNew( const AsNewNote : boolean );
procedure PrintRTFNote;
procedure RunSpellcheckerForNote;
function GetEditorZoom : integer;
procedure SetEditorZoom( ZoomValue : integer; ZoomString : string );
procedure ShowTipOfTheDay;
implementation
uses
{ Borland units }
Windows, Messages, SysUtils, Classes,
Controls, Forms, Dialogs, Clipbrd,ComCtrls,
RichEdit, mmsystem, Graphics,ExtDlgs,WideStrings,
{ 3rd-party units }
BrowseDr, TreeNT, Parser,FreeWordWeb, UAS, RxGIF,RichPrint,
RxRichEd,AJBSpeller,
{ Own units - covered by KeyNote's MPL}
gf_misc, gf_files, gf_Const,
gf_strings, gf_miscvcl,
kn_INI, kn_const, kn_Cmd, kn_Msgs,
kn_Info, kn_FileObj, kn_NewNote,
kn_NodeList, kn_ExpandObj, kn_MacroMng,
Kn_Global, kn_Chars, kn_NoteMng, kn_ClipUtils,
kn_ExpTermDef, kn_Glossary, kn_VCLControlsMng,
kn_NoteFileMng, kn_Main, kn_TreeNoteMng, GFTipDlg,
kn_ExportImport, kn_RTFUtils;
resourcestring
STR_Gloss_01 = ' Function not available';
STR_Gloss_02 = ' No word at cursor';
STR_Gloss_03 = ' Word not in glossary. Use Shift+F7 to add.';
STR_Gloss_04 = 'Term expansion glossary "%s" is not loaded.';
STR_Gloss_05 = 'Glossary term already exists: "%s" -> "%s". OK to redefine term as "%s"?';
STR_Gloss_06 = ' Added to glossary: "%s" -> "%s"';
STR_Bracket_01 = ' No valid bracket at cursor position ';
STR_Bracket_02 = ' Matching bracket FOUND';
STR_Bracket_03 = ' Matching bracket NOT FOUND';
STR_Trim_01 = 'OK to trim white space characters in whole note?';
STR_Compress_01 = 'OK to compress white space characters in whole note?';
STR_Eval_01 = ' Result: ';
STR_Eval_02 = 'Paste last eval result: ';
STR_Eval_03 = 'Expression %s evaluates to: %s' + #13#13 + 'Result was copied to clipboard. Click OK to insert.';
STR_Img_01 = 'Select image to insert';
STR_ConvDec_01 = 'Convert decimal to Roman';
STR_ConvDec_02 = 'Enter a decimal number:';
STR_ConvDec_03 = '%s is not a valid number';
STR_ConvRoman_01 = 'Convert Roman to decimal';
STR_ConvRoman_02 = 'Enter a Roman number:';
STR_ConvRoman_03 = '%s is not a valid Roman number';
STR_Statistics_01 = ' Calculating statistics... Please wait';
STR_Statistics_02 = 'Selected text';
STR_Statistics_03 = 'Note text';
STR_Statistics_04 = '%s statistics' + #13#13 +
'Characters: %s' + #13 +
'Alphabetic: %s' + #13 +
'Whitespace: %s' + #13#13 +
'Words: %s' + #13 +
'Lines: %s';
STR_Statistics_05 = 'Number of nodes in tree: %d';
STR_Statistics_06 = 'Chars: %d Alph: %d Words: %d';
STR_Statistics_07 = 'Clik OK to copy information to clipboard.';
STR_WordWeb_01 = 'Lookup in WordWeb';
STR_WordWeb_02 = 'Enter word to look up:';
STR_WordWeb_03 = 'Error loading WordWeb. The program may not be installed ' +
'on your computer. See file "wordweb.txt" for more information.' +
#13#13 +
'Error message: ';
STR_UAS_01 = 'UAS path';
STR_UAS_02 = 'Please specify full path to uas.exe';
STR_UAS_03 = 'KeyNote cannot find the location of uas.exe. UltimaShell Autocompletion Server will not be loaded.';
STR_UAS_04 = ' UltimaShell Autocompletion Server loaded.';
STR_UAS_05 = 'Cannot load UltimaShell Autocompletion Server. It may not be installed. Would you like to go to the UAS website and download the application?';
STR_UAS_06 = ' UltimaShell Autocompletion Server unloaded.';
STR_UAS_07 = ' UltimaShell Autocompletion Server is not loaded.';
STR_ClipCap_01 = 'A Read-Only note cannot be used for clipboard capture.';
STR_ClipCap_02 = 'a new node';
STR_ClipCap_03 = 'whichever node is currently selected';
STR_ClipCap_04 = 'This is a %s note. Each copied item will be pasted into %s in the tree. Continue?';
STR_ClipCap_05 = ' Clipboard capture is now ';
STR_ClipCap_06 = ' Capturing text from clipboard';
STR_ClipCap_07 = 'Cannot obtain tree node for pasting data.';
STR_ClipCap_08 = '[source: ';
STR_ClipCap_09 = ' Clipboard capture done';
STR_Print_01 = 'Current note is a Tree-type note and contains more than one node. Do you want to print all nodes? Answer No to only print the selected node.';
STR_Print_02 = 'Replace editor contents with result from spellchecker?';
STR_Zoom_01 = 'Invalid zoom ratio: ';
STR_Tip_01 = 'Cannot display Tip of the Day: file "%s" not found.';
STR_Tip_02 = ': Tip of the Day';
//=================================================================
// ExpandTermProc
//=================================================================
procedure ExpandTermProc;
var
w, replw : wideString;
wordlen : integer;
begin
with Form_Main do begin
if ( not ( assigned( GlossaryList ) and assigned( ActiveNote ) and ( ActiveNote.FocusMemory = focRTF ))) then
begin
StatusBar.Panels[PANEL_HINT].Text := STR_Gloss_01;
exit;
end;
if NoteIsReadOnly( ActiveNote, true ) then exit;
UpdateLastCommand( ecExpandTerm );
if IsRecordingMacro then
AddMacroEditCommand( ecExpandTerm );
if ( ActiveNote.Editor.SelLength = 0 ) then
w := ActiveNote.Editor.GetWordAtCursorNew( true )
else
w := ActiveNote.Editor.SelTextW;
wordlen := length( w );
if ( length( w ) = 0 ) then
begin
StatusBar.Panels[PANEL_HINT].Text := STR_Gloss_02;
exit;
end;
replw := GlossaryList.Values[w];
if ( replw = '' ) then
begin
StatusBar.Panels[PANEL_HINT].Text := STR_Gloss_03;
exit;
end;
StatusBar.Panels[PANEL_HINT].Text := WideFormat( ' %s -> %s', [w,replw] );
replw := ExpandMetaChars( replw );
ActiveNote.Editor.SelTextW := replw;
ActiveNote.Editor.SelStart := ActiveNote.Editor.SelStart + ActiveNote.Editor.SelLength;
NoteFile.Modified := true;
UpdateNoteFileState( [fscModified] );
end;
end; // ExpandTermProc
//=================================================================
// AddGlossaryTerm
//=================================================================
procedure AddGlossaryTerm;
var
Form_TermDef : TForm_TermDef;
nstr, vstr : wideString;
begin
if ( not assigned( GlossaryList )) then
begin
showmessage( Format(STR_Gloss_04, [Glossary_FN] ));
exit;
end;
nstr := '';
vstr := '';
if assigned( ActiveNote ) then
begin
if ( ActiveNote.Editor.SelLength > 0 ) then
nstr := trim( copy( ActiveNote.Editor.SelTextW, 1, 255 ))
else
nstr := ActiveNote.Editor.GetWordAtCursorNew( true );
if ( nstr <> '' ) then
vstr := GlossaryList.Values[nstr];
end;
Form_TermDef := TForm_TermDef.Create( Form_Main );
try
with Form_TermDef do
begin
Edit_Term.Text := nstr;
Edit_Exp.Text := vstr;
if ( ShowModal = mrOK ) then
begin
nstr := trim( Edit_Term.Text );
vstr := trim( Edit_Exp.Text );
if (( nstr <> '' ) and ( vstr <> '' ) and ( nstr <> vstr )) then
begin
if ( GlossaryList.IndexOfName( nstr ) >= 0 ) then
begin
if ( messagedlg( Format(STR_Gloss_05,
[nstr,GlossaryList.Values[nstr],vstr] ),
mtConfirmation, [mbYes,mbNo], 0 ) <> mrYes ) then exit;
end;
try
try
GlossaryList.Sorted := false;
GlossaryList.Values[nstr] := vstr;
finally
GlossaryList.Sorted := true;
end;
SaveGlossaryInfo(Glossary_FN);
Form_Main.StatusBar.Panels[PANEL_HINT].Text := WideFormat(STR_Gloss_06, [nstr,vstr] );
except
on E : Exception do
showmessage( E.Message );
end;
end;
end;
end;
finally
Form_TermDef.Free;
end;
end; // AddGlossaryTerm
procedure EditGlossaryTerms;
var
Form_Glossary : TForm_Glossary;
begin
Form_Glossary := TForm_Glossary.Create( Form_Main );
try
Form_Glossary.ShowModal;
finally
Form_Glossary.Free;
end;
end; // EditGlossaryTerms
//=================================================================
// GetWordCount
//=================================================================
function GetWordCount( const t : string ) : longint;
const
WordDelimiters = [#9, #10, #13, #32];
var
i, len : longint;
begin
len := length( t );
result := 0;
if ( len > 0 ) then
begin
i := 1;
repeat
if ( t[i] in WordDelimiters ) then
begin
inc( i );
continue;
end
else
inc( result );
// scan to end of word
while (( i <= len ) and ( not ( t[i] in WordDelimiters ))) do
begin
inc( i );
end;
until ( i > len );
end;
end; // GetWordCount
//=================================================================
// UpdateWordCount
//=================================================================
procedure UpdateWordCount;
var
p, s : string;
wc : longint;
begin
if ( not assigned( ActiveNote )) then exit;
if EditorOptions.WordCountTrack then
begin
if ( ActiveNote.Editor.SelLength = 0 ) then
wc := GetWordCount( ActiveNote.Editor.Lines.Text )
else
wc := GetWordCount( ActiveNote.Editor.SelText );
if ( wc > 0 ) then
begin
if ( EditorOptions.WordsPerPage > 0 ) then
begin
p := ' / ' + FloatToStr( wc / EditorOptions.WordsPerPage );
end
else
begin
p := '';
end;
s := Format( ' W: %d', [wc] ) + p;
end
else
begin
s := ' W: 0';
end;
Form_Main.StatusBar.Panels[PANEL_CARETPOS].Text := s;
end
else
begin
if ( not EditorOptions.TrackCaretPos ) then
begin
Form_Main.StatusBar.Panels[PANEL_CARETPOS].Text := '';
exit;
end;
end;
end; // UpdateWordCount
procedure CleanWordCount;
begin
Form_Main.StatusBar.Panels[PANEL_CARETPOS].Text := ' W: ... / ...';
end;
//=================================================================
// MatchBracket
//=================================================================
procedure MatchBracket;
type
TDir = ( dirFwd, dirBack );
const
OpenBrackets = '([{<';
CloseBrackets = ')]}>';
var
startch, seekch, curch : char;
i, stack, startsel, curcol, curline : integer;
p : TPoint;
dir : TDir;
Found : boolean;
begin
if ( not Form_Main.HaveNotes( true, true ) and assigned( ActiveNote )) then exit;
startsel := ActiveNote.Editor.SelStart;
p := ActiveNote.Editor.CaretPos;
if (( ActiveNote.Editor.Lines.Count = 0 ) or
( length( ActiveNote.Editor.Lines[p.y] ) = 0 )) then
exit;
if ( ActiveNote.Editor.SelLength = 0 ) then
inc( p.x );
startch := ActiveNote.Editor.Lines[p.y][p.x];
i := pos( startch, OpenBrackets );
if ( i > 0 ) then
begin
seekch := CloseBrackets[i];
dir := dirFwd;
end
else
begin
i := pos( startch, CloseBrackets );
if ( i > 0 ) then
begin
seekch := OpenBrackets[i];
dir := dirBack;
end
else
begin
Form_Main.StatusBar.Panels[PANEL_HINT].Text := STR_Bracket_01;
exit;
end;
end;
// StatusBar.Panels[PANEL_HINT].Text := Format( 'line: %d col: %d %s -> %s', [p.y,p.x,startch, seekch] );
curline := p.y;
stack := 0;
Found := false;
case dir of
dirFwd : begin
curcol := p.x+1;
while ( curline < ActiveNote.Editor.Lines.Count ) do
begin
while ( curcol <= length( ActiveNote.Editor.Lines[curline] )) do
begin
curch := ActiveNote.Editor.Lines[curline][curcol];
if ( curch = startch ) then
begin
inc( stack );
end
else
if ( curch = seekch ) then
begin
if ( stack > 0 ) then
begin
dec( stack );
end
else
begin
p.x := curcol;
p.y := curline;
Found := true;
break;
end;
end;
inc( curcol );
end;
if Found then
break;
curcol := 1;
inc( curline );
end;
end;
dirBack : begin
curcol := p.x-1;
while ( curline >= 0 ) do
begin
while( curcol > 0 ) do
begin
curch := ActiveNote.Editor.Lines[curline][curcol];
if ( curch = startch ) then
begin
inc( stack );
end
else
if ( curch = seekch ) then
begin
if ( stack > 0 ) then
begin
dec( stack );
end
else
begin
p.x := curcol;
p.y := curline;
Found := true;
break;
end;
end;
dec( curcol );
end;
if Found then
break;
dec( curline );
if ( curline >= 0 ) then
curcol := length( ActiveNote.Editor.Lines[curline] );
end;
end;
end;
if Found then
begin
Form_Main.StatusBar.Panels[PANEL_HINT].Text := STR_Bracket_02;
with ActiveNote.Editor do
begin
SelStart := Perform( EM_LINEINDEX, p.y, 0 );
SelStart := SelStart + pred( p.x );
Perform( EM_SCROLLCARET, 0, 0 );
SelLength := 1;
end;
end
else
begin
Form_Main.StatusBar.Panels[PANEL_HINT].Text := STR_Bracket_03;
end;
end; // MatchBracket
//=================================================================
// TrimBlanks
//=================================================================
procedure TrimBlanks( const TrimWhat : integer );
var
i : integer;
tempList : TWideStringList;
wholeNote: boolean;
begin
if ( not Form_Main.HaveNotes( true, true ) and assigned( ActiveNote )) then exit;
if Form_Main.NoteIsReadOnly( ActiveNote, true ) then exit;
if ( ActiveNote.Editor.Lines.Count < 1 ) then exit;
if ( ActiveNote.Editor.SelLength = 0 ) then
begin
wholeNote:= true;
if ( messagedlg( STR_Trim_01,
mtConfirmation, [mbYes,mbNo], 0 ) <> mrYes ) then exit;
end
else
wholeNote:= false;
ActiveNote.Editor.Lines.BeginUpdate;
Screen.Cursor := crHourGlass;
try
tempList := TWideStringList.Create;
try
if wholeNote then
tempList.Text:= ActiveNote.Editor.GetTextRange(0, ActiveNote.Editor.TextLength)
else
tempList.Text := ActiveNote.Editor.SelTextW;
if ( tempList.Count > 0 ) then
for i := 0 to tempList.Count-1 do
begin
case TrimWhat of
ITEM_TAG_TRIMLEFT : begin
tempList[i] := trimleft( tempList[i] );
end;
ITEM_TAG_TRIMRIGHT : begin
tempList[i] := trimright( tempList[i] );
end;
ITEM_TAG_TRIMBOTH : begin
tempList[i] := trim( tempList[i] );
end;
end;
end;
if wholeNote then
ActiveNote.Editor.SetSelection(0, ActiveNote.Editor.TextLength, true);
ActiveNote.Editor.SelTextW := tempList.Text;
if wholeNote then
ActiveNote.Editor.SelStart := 0;
finally
tempList.Free;
end;
finally
ActiveNote.Editor.Lines.EndUpdate;
Screen.Cursor := crDefault;
NoteFile.Modified := true;
UpdateNoteFileState( [fscModified] );
end;
end; // TrimBlanks
//=================================================================
// CompressWhiteSpace
//=================================================================
procedure CompressWhiteSpace;
const
WhiteSpace : set of char = [#9, #32];
var
WasWhite : boolean;
i, l : integer;
s : wideString;
begin
if ( not Form_Main.HaveNotes( true, true ) and assigned( ActiveNote )) then exit;
if Form_Main.NoteIsReadOnly( ActiveNote, true ) then exit;
if ( ActiveNote.Editor.Lines.Count < 1 ) then exit;
if ( ActiveNote.Editor.SelLength = 0 ) then
begin
if ( messagedlg( STR_Compress_01,
mtConfirmation, [mbYes,mbNo], 0 ) <> mrYes ) then exit;
end;
ActiveNote.Editor.Lines.BeginUpdate;
Screen.Cursor := crHourGlass;
WasWhite := false;
try
if ( ActiveNote.Editor.SelLength = 0 ) then
begin
for l := 0 to ActiveNote.Editor.Lines.Count-1 do
begin
if ( ActiveNote.Editor.Lines[l] = '' ) then continue;
WasWhite := false;
i := 1;
s := ActiveNote.Editor.Lines[l];
while ( i <= length( s )) do
begin
if ( s[i] in WhiteSpace ) then
begin
if WasWhite then
delete( s, i, 1 )
else
inc( i );
WasWhite := true;
end
else
begin
WasWhite := false;
inc( i );
end;
end;
ActiveNote.Editor.Lines[l] := s;
end;
ActiveNote.Editor.SelStart := 0;
end
else
begin
s := ActiveNote.Editor.SelTextW;
i := 1;
while ( i <= length( s )) do
begin
if ( s[i] in WhiteSpace ) then
begin
if WasWhite then
delete( s, i, 1 )
else
inc( i );
WasWhite := true;
end
else
begin
WasWhite := false;
inc( i );
end;
end;
ActiveNote.Editor.SelTextW := s;
ActiveNote.Editor.SelLength := 0;
end;
finally
ActiveNote.Editor.Lines.EndUpdate;
Screen.Cursor := crDefault;
NoteFile.Modified := true;
UpdateNoteFileState( [fscModified] );
end;
end; // CompressWhiteSpace
//=================================================================
// EvaluateExpression
//=================================================================
procedure EvaluateExpression;
var
src : string;
i, l, lineindex : integer;
MathParser : TMathParser;
begin
with Form_Main do begin
if ( not assigned( ActiveNote )) then exit;
if ( ActiveNote.Editor.SelLength = 0 ) then
with ActiveNote.Editor do
begin
lineindex := perform( EM_EXLINEFROMCHAR, 0, SelStart );
SelStart := perform( EM_LINEINDEX, lineindex, 0 );
SelLength := perform( EM_LINEINDEX, lineindex + 1, 0 ) - ( SelStart+1 );
end;
src := trim( ActiveNote.Editor.SelText );
if ( src = '' ) then
begin
ErrNoTextSelected;
exit;
end;
UpdateLastCommand( ecEvaluateExpression );
if IsRecordingMacro then
AddMacroEditCommand( ecEvaluateExpression );
if ( src[length( src )] = '=' ) then
delete( src, length( src ), 1 );
l := length( src );
for i := 1 to l do
begin
if ( src[i] = ',' ) then
src[i] := '.';
end;
MathParser := TMathParser.Create( Form_Main );
try
with MathParser do
begin
OnParseError := MathParserParseError;
MathParser.ParseString := src;
Parse;
LastEvalExprResult := FloatToStrF(ParseValue, ffGeneral, 15, 2);
end;
if ( not MathParser.ParseError ) then
begin
Clipboard.SetTextBuf( PChar( LastEvalExprResult ));
StatusBar.Panels[PANEL_HINT].Text := STR_Eval_01 + LastEvalExprResult;
MMEditPasteEval.Hint := STR_Eval_02 + LastEvalExprResult;
if ( KeyOptions.AutoPasteEval and ( not NoteIsReadOnly( ActiveNote, false ))) then
begin
begin
ActiveNote.Editor.SelStart := ActiveNote.Editor.SelStart + ActiveNote.Editor.SelLength;
ActiveNote.Editor.SelText := #32 + LastEvalExprResult;
end;
end
else
begin
if ( messagedlg( Format( STR_Eval_03, [src,LastEvalExprResult] ), mtInformation, [mbOK,mbCancel], 0 ) = mrOK ) then
begin
if ( not NoteIsReadOnly( ActiveNote, true )) then
begin
ActiveNote.Editor.SelStart := ActiveNote.Editor.SelStart + ActiveNote.Editor.SelLength;
ActiveNote.Editor.SelText := #32 + LastEvalExprResult;
end;
end;
end;
end;
finally
MathParser.Free;
end;
end;
end; // EvaluateExpression
//=================================================================
// InsertSpecialCharacter
//=================================================================
procedure InsertSpecialCharacter;
begin
with Form_Main do begin
if ( not ( HaveNotes( true, true ) and assigned( ActiveNote ))) then
exit;
if ( Form_Chars = nil ) then
begin
Form_Chars := TForm_Chars.Create( Form_Main );
with Form_Chars.FontDlg.Font do
begin
if ( KeyOptions.InsCharKeepFont and ( InsCharFont.Size > 0 )) then
begin
Name := InsCharFont.Name;
Charset := InsCharFont.Charset;
Size := InsCharFont.Size;
Form_Chars.myFontChanged := true;
end
else
begin
Name := NoteSelText.Name;
Charset := NoteSelText.Charset;
Size := NoteSelText.Size;
end;
end;
with Form_Chars do
begin
ShowHint := KeyOptions.ShowTooltips;
CharInsertEvent := CharInsertProc;
FormCloseEvent := Form_Main.Form_CharsClosed;
myShowFullSet := KeyOptions.InsCharFullSet;
if KeyOptions.InsCharWinClose then
Button_Insert.ModalResult := mrOK
else
Button_Insert.ModalResult := mrNone;
end;
end;
try
Form_Chars.Show;
except
on E : Exception do
begin
showmessage( E.Message );
end;
end;
end;
end; // InsertSpecialCharacter
//=================================================================
// InsertPictureOrObject
//=================================================================
procedure InsertPictureOrObject( const AsPicture : boolean );
var
Pict: TPicture;
wasmodified : boolean;
OpenPictureDlg : TOpenPictureDialog;
begin
if ( not Form_Main.HaveNotes( true, true )) then exit;
if ( not assigned( ActiveNote )) then exit;
if Form_Main.NoteIsReadOnly( ActiveNote, true ) then exit;
wasmodified := false;
OpenPictureDlg := TOpenPictureDialog.Create( Form_Main );
try
if AsPicture then
begin
with OpenPictureDlg do
begin
Options := [ofHideReadOnly,ofPathMustExist,ofFileMustExist];
Title := STR_Img_01;
Filter := Format( '%s|%s|%s', [
GraphicFilter(TBitmap),
GraphicFilter(TGIFImage),
// GraphicFilter(TJPEGImage),
GraphicFilter(TMetafile)
]);
if Execute then
begin
Pict := TPicture.Create;
try
Pict.LoadFromFile(FileName);
Clipboard.Assign(Pict);
Activenote.Editor.PasteFromClipboard;
finally
Pict.Free;
wasmodified := true;
end;
end;
end;
end
else
begin
if Activenote.Editor.InsertObjectDialog then
wasmodified := true;
end;
finally
if wasmodified then
begin
NoteFile.Modified := true;
UpdateNoteFileState( [fscModified] );
end;
OpenPictureDlg.Free;
end;
end; // InsertPictureOrObject
//=================================================================
// ArabicToRoman
//=================================================================
procedure ArabicToRoman;
var
s : string;
i : integer;
begin
if ( not assigned( ActiveNote )) then exit;
if Form_Main.NoteIsReadOnly( ActiveNote, true ) then exit;
s := ActiveNote.Editor.SelText;
if ( s = '' ) then
InputQuery( STR_ConvDec_01, STR_ConvDec_02, s );
if ( s = '' ) then exit;
try
s := trim( s );
i := strtoint( s );
s := DecToRoman( i );
except
messagedlg( Format( STR_ConvDec_03, [s] ), mtError, [mbOK], 0 );
exit;
end;
ActiveNote.Editor.SelText := s;
end; // ArabicToRoman;
//=================================================================
// RomanToArabic
//=================================================================
procedure RomanToArabic;
var
s : string;
i : integer;
begin
if ( not assigned( ActiveNote )) then exit;
if Form_Main.NoteIsReadOnly( ActiveNote, true ) then exit;
i := -1;
s := ActiveNote.Editor.SelText;
if ( s = '' ) then
InputQuery( STR_ConvRoman_01, STR_ConvRoman_02, s );
if ( s = '' ) then exit;
try
s := uppercase( trim( s ));
i := RomanToDec( s );
except
messagedlg( Format( STR_ConvRoman_03, [s] ), mtError, [mbOK], 0 );
exit;
end;
if ( i < 0 ) then exit;
ActiveNote.Editor.SelText := inttostr( i );
end; // RomanToArabic
//=================================================================
// ShowStatistics
//=================================================================
procedure ShowStatistics;
var
s, title : string;
lista : TStringList;
i, l, len, numChars, numSpaces, numAlpChars,
numLines, numWords, numNodes : integer;
WasAlpha : boolean;
ch : char;
begin
if ( not Form_Main.HaveNotes( true, true ) and assigned( ActiveNote )) then exit;
Form_Main.StatusBar.Panels[PANEL_HINT].Text := STR_Statistics_01;
screen.Cursor := crHourGlass;
lista := TStringList.Create;
try
if ( ActiveNote.Editor.SelLength > 0 ) then
begin
lista.Text := ActiveNote.Editor.SelText;
title := STR_Statistics_02;
end
else
begin
lista.Text := ActiveNote.Editor.Lines.Text;
title := STR_Statistics_03;
end;
numLines := lista.count;
numChars := 0;
numSpaces := 0;
numAlpChars := 0;
numWords := 0;
for l := 0 to lista.count-1 do
begin
s := lista[l];
len := length( s );
inc( numChars, len );
WasAlpha := false;
for i := 1 to len do
begin
ch := s[i];
if IsCharAlphaA( ch ) then
begin
inc( numAlpChars );
WasAlpha := true;
end
else
begin
if ( ch in [#9,#32] ) then
inc( numSpaces );
if WasAlpha then
inc( numWords );
WasAlpha := false;
end;
end;
if WasAlpha then
inc( numWords );
end;
finally
lista.Free;
screen.Cursor := crDefault;
end;
s := format(STR_Statistics_04,[Title,inttostr( numChars ),inttostr( numAlpChars ),
inttostr( numSpaces ),inttostr( numWords ),inttostr( numLines )]);
if ( ActiveNote.Kind = ntTree ) then
begin
numNodes := TTreeNote( ActiveNote ).TV.Items.Count;
s := s + #13#13 + Format( STR_Statistics_05, [numNodes] );
end;