forked from dpradov/keynote-nf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknt.App.pas
More file actions
1188 lines (943 loc) · 33.9 KB
/
Copy pathknt.App.pas
File metadata and controls
1188 lines (943 loc) · 33.9 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
unit knt.App;
(****** LICENSE INFORMATION **************************************************
- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
------------------------------------------------------------------------------
(c) 2000-2005 Marek Jedlinski <marek@tranglos.com> (Poland)
(c) 2007-2015 Daniel Prado Velasco <dprado.keynote@gmail.com> (Spain) [^]
[^]: Changes since v. 1.7.0. Fore more information, please see 'README.md'
and 'doc/README_SourceCode.txt' in https://github.com/dpradov/keynote-nf
*****************************************************************************)
interface
uses
Winapi.Windows,
Winapi.Messages,
Winapi.ShellAPI,
Winapi.RichEdit,
System.Classes,
System.SysUtils,
System.StrUtils,
System.AnsiStrings,
System.IniFiles,
Vcl.Clipbrd,
Vcl.Graphics,
Vcl.FileCtrl,
Vcl.Controls,
Vcl.ComCtrls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ExtCtrls,
VirtualTrees,
gf_misc,
gf_miscvcl,
kn_ImagesMng,
kn_AlertMng,
kn_global,
kn_info,
kn_const,
kn_cmd,
kn_KntFile,
kn_KntFolder,
knt.model.note,
kn_EditorUtils,
knt.ui.editor,
knt.ui.tree,
kn_Main
;
type
TKeyboardState = record //==================== KEYBOARD / HOTKEY
HotKeySuccess : boolean; // if true, we registered the hotkey successully, so we will remember to unregister it when we shut down
OtherCommandsKeys: TList; // List of TKeyOtherCommandItem
LastRTFKey : TKeyCode;
RxRTFKeyProcessed : boolean; // for TAB handling; some tabs are eaten by TRichEdit, others must not be
RTFUpdating : boolean; // TRUE while in RxRTFSelectionChange; some things cannot be done during that time
end;
TTagsState = (tsHidden, tsPendingUpdate, tsVisible);
TNNodeSelectedEvent = procedure(NNode: TNoteNode) of object;
TFolderSelectedEvent = procedure(Folder: TKntFolder) of object;
TKntRichEditList = TSimpleObjList<TKntRichEdit>;
TKntApp = class
private class var
fInstance: TKntApp; // For Singleton pattern
public class var
Kbd: TKeyboardState;
//================================================== OPTIONS
{ These options are seperate from KeyOptions, because then may also be set via commandline. Basically, the logic is:
opt_XXX := ( commandline_argument_XXX OR inifile_options_XXX );
}
opt_Minimize : boolean; // minimize on startup
//opt_Setup : boolean; // run setup (OBSOLETE, unused)
opt_Debug : boolean; // debug info
opt_NoRegistry : boolean; // use .MRU file instead, do not use registry
opt_NoReadOpt : boolean; // do not read config files (if TRUE, then opt_NoSaveOpt is also set to TRUE)
opt_NoSaveOpt : boolean; // do not save config files
opt_NoDefaults : boolean; // do not load .DEF file (editor and tree defaults)
opt_RegExt : boolean; // register .KNT and .KNE extensions
opt_SaveDefaultIcons : boolean; // save default tab icons to file
opt_NoUserIcons : boolean; // do not use custom .ICN file
opt_SaveToolbars : boolean; // save default toolbar state (debug)
opt_SaveMenus : boolean; // save menu item information
opt_DoNotDisturb : boolean; // Ignore for purposes of "SingleInstance"
opt_Title: string; // Title to use in main window (mainly for its use with kntLauncher)
opt_Clean : boolean; // Clean the file, actually looking for invalid hyperlinks (see issue #59: http://code.google.com/p/keynote-nf/issues/detail?id=59
opt_ConvKNTLinks: boolean; // Convert Knt Links to the new format (using GID)
ShowingImageOnTrack: boolean;
private
fNNodeSelected: TNNodeSelectedEvent;
fFolderSelected: TFolderSelectedEvent;
fAvailableEditors: TKntRichEditList;
fVirtualUnEncryptWarningDone: boolean;
fUI_RTL: boolean;
fTagsState: TTagsState;
constructor Create;
procedure Initialize;
protected
procedure UpdateEnabledActionsAndRTFState(Editor: TKntRichEdit);
procedure EditorSelected (Editor: TKntRichEdit; Focused: boolean); overload;
procedure EnsureContentEditorUpdated (Editor: TKntRichEdit);
procedure FolderSelected(Folder: TKntFolder; PrevFolder: TKntFolder);
procedure NNodeSelected(NNode: TNoteNode);
procedure ShowWordCountInfoInStatusBar(const str: string);
function GetWordCountInfoInStatusBar: string;
public
class function GetInstance: TKntApp; static;
class procedure FileSetModified; inline;
procedure ApplyBiDiMode;
procedure ApplyBiDiModeOnForm(Form: TForm);
property UI_RTL: boolean read fUI_RTL write fUI_RTL;
property OnNNodeSelected: TNNodeSelectedEvent read FNNodeSelected write FNNodeSelected;
property OnFolderSelected: TFolderSelectedEvent read FFolderSelected write FFolderSelected;
procedure AuxEditorFocused(Sender: TObject);
procedure SetTopMost(hWND: HWND; OnlyWithFloatingEditor: boolean = True);
procedure HideNestedFloatingEditors;
procedure EditorAvailable (Editor: TKntRichEdit);
procedure EditorUnavailable (Editor: TKntRichEdit);
procedure EditorFocused (Editor: TKntRichEdit);
procedure EditorReloaded (Editor: TKntRichEdit; Focused: boolean);
procedure EditorSaved (Editor: TKntRichEdit);
procedure ChangeInEditor (Editor: TKntRichEdit);
procedure NEntryModified (NEntry: TNoteEntry; Note: TNote; Folder: TKntFolder);
procedure EditorPropertiesModified (Editor: TKntRichEdit);
procedure SetEditorZoom( ZoomValue : integer; const ZoomString : string; Increment: integer= 0);
procedure ShowCurrentZoom (Zoom: integer);
procedure TreeFocused (Tree: TKntTreeUI);
procedure NNodeFocused(NNode: TNoteNode);
procedure FolderDeleted (Folder: TKntFolder; TabIndex: integer);
procedure FolderPropertiesModified (Folder: TKntFolder);
procedure FileNew (aFile: TKntFile);
procedure FileOpening (aFile: TKntFile);
procedure FileOpen (aFile: TKntFile);
procedure FileClosed (aFile: TKntFile);
procedure ActivateFolder (Folder: TKntFolder); overload;
procedure ActivateFolder (TabIndex: Integer); overload;
procedure NoteNameModified(Note: TNote);
property WordCountInfoInStatusBar: string read GetWordCountInfoInStatusBar write ShowWordCountInfoInStatusBar;
procedure ShowStatistics;
procedure ShowTipOfTheDay;
function CheckActiveEditor: boolean;
function CheckActiveEditorNotReadOnly: boolean;
procedure TagsUpdated;
property TagsState: TTagsState read fTagsState write fTagsState;
procedure ShowInfoInStatusBar(const str: string);
procedure WarnEditorIsReadOnly;
procedure WarnNoTextSelected;
function DoMessageBox(const Str: string; DlgType: TMsgDlgType;
const Buttons: TMsgDlgButtons;
DefButton: TMsgDlgDefBtn = def1;
HelpCtx: Longint = 0; hWnd: HWND= 0): integer;
function PopUpMessage(const Str: string; const mType: TMsgDlgType;
const Buttons: TMsgDlgButtons;
const DefButton: TMsgDlgDefBtn = def1;
const HelpCtx: integer= 0): word;
procedure InfoPopup(const aStr: string);
procedure WarningPopup(const aStr: string);
procedure ErrorPopup(const aStr: string); overload;
procedure ErrorPopup(const E: Exception = nil; const Str: string = ''); overload;
procedure WarnFunctionNotImplemented(const aStr: string);
procedure WarnCommandNotImplemented(const aStr: string);
property Virtual_UnEncrypt_Warning_Done: boolean read fVirtualUnEncryptWarningDone write fVirtualUnEncryptWarningDone;
end;
function GetCurrentTreeNode : PVirtualNode;
function GetTreeUI(TV: TVirtualStringTree): TKntTreeUI;
procedure Application_Minimize; inline;
procedure Application_Restore; inline;
procedure Application_BringToFront; inline;
var
App: TKntApp;
ActiveFile : TKntFile;
ActiveFolder : TKntFolder;
ActiveNNode : TNoteNode;
ActiveNEntry : TNoteEntry;
ActiveEditor : TKntRichEdit;
ActiveTreeUI : TKntTreeUI;
Form_Main: TForm_Main;
ImageMng: TImageMng;
AlarmMng: TAlarmMng;
ClipCapMng: TClipCapMng;
ActiveFileIsBusy : boolean;
AFileIsLoading: boolean;
HandlingTimerTick: boolean;
UpdatingTextPlain: boolean;
IgnoringEditorChanges: boolean;
FloatingEditorCannotBeSaved: boolean;
//================================================ APPLICATION OPTIONS
// these are declared in kn_Info.pas
KeyOptions : TKeyOptions; // general program config
TabOptions : TTabOptions; // options related to tabs, icons etc
ClipOptions : TClipOptions; // clipboard capture options
EditorOptions : TEditorOptions;
ResPanelOptions : TResPanelOptions;
KntTreeOptions : TKntTreeOptions;
FindOptions : TFindOptions;
//================================================== DEFAULT PROPERTIES
DefaultEditorProperties : TFolderEditorProperties;
DefaultTabProperties : TFolderTabProperties;
DefaultEditorChrome : TChrome;
DefaultTreeChrome : TChrome;
DefaultTreeProperties : TFolderTreeProperties;
LongDateToFileSettings: TFormatSettings;
implementation
uses
GFTipDlg,
gf_Lang,
kn_MacroMng,
kn_VCLControlsMng,
kn_LinksMng,
kn_FindReplaceMng,
kn_NoteFileMng,
knt.ui.TagMng,
knt.ui.tagSelector,
knt.RS;
//---------------------------------------------------------------------------------
// Safe replacements to use with MainFormOnTaskbar := True
{ *1
It seems that the change needed to solve issue #830 is the cause of this issue #854, besides issue #858
I have solved issue #858 while maintaining the change necessary to fix issue #830 (Application.MainFormOnTaskbar := True)
but the impact in other aspects, like this issue #854, are more complex, specially by the influence on other controls like VirtualTreeView and RichText.
I think I will revert that change in #830. Only when all other issues are identified and solved I will try to reincorporate it.
}
procedure Application_Minimize; inline;
begin
Application.Minimize;
{ *1
Form_Main.WindowState := wsMinimized;
Form_Main.AppMinimize(Form_Main);
}
end;
procedure Application_Restore; inline;
begin
Application.Restore;
{ *1
Form_Main.WindowState := wsNormal;
Form_Main.AppRestore(Form_Main);
}
end;
procedure Application_BringToFront; inline;
begin
Application.BringToFront;
{ *1
if Form_Main.WindowState = wsMinimized then
Form_Main.WindowState := wsNormal;
SetForegroundWindow(Form_Main.Handle);
}
end;
//---------------------------------------------------------------------------------
constructor TKntApp.Create;
begin
inherited Create;
Initialize;
end;
class function TKntApp.GetInstance: TKntApp;
begin
if (fInstance = nil) then // Singleton pattern
fInstance:= TKntApp.Create;
result:= fInstance;
end;
procedure TKntApp.Initialize;
begin
Kbd.RTFUpdating := false;
ShowingImageOnTrack:= false;
fUI_RTL:= false;
opt_Minimize := false;
//opt_Setup := false;
opt_Debug := false;
opt_NoRegistry := false;
opt_NoReadOpt := false;
opt_NoSaveOpt := false;
opt_NoDefaults := false;
opt_RegExt := false;
opt_SaveDefaultIcons := false;
opt_NoUserIcons := false;
opt_SaveToolbars := false;
opt_SaveMenus := false;
opt_DoNotDisturb:= false;
opt_Title:= '';
opt_Clean := false;
opt_ConvKNTLinks:= false;
fAvailableEditors:= TKntRichEditList.Create;
fVirtualUnEncryptWarningDone:= false;
ActiveFile := nil;
ActiveEditor := nil;
ActiveFolder := nil;
ActiveFileIsBusy := false;
IgnoringEditorChanges:= false;
HandlingTimerTick:= false;
UpdatingTextPlain:= false;
fTagsState:= tsPendingUpdate;
LongDateToFileSettings:= TFormatSettings.Create;
with LongDateToFileSettings do begin
DateSeparator := _DATESEPARATOR;
TimeSeparator := _TIMESEPARATOR;
ShortDateFormat := _SHORTDATEFMT;
LongDateFormat := _LONG_DATETIME_TOFILE; // I don't thik this field is used to parse a string..
LongTimeFormat := _LONGTIMEFMT; // Idem..
end;
end;
procedure TKntApp.ApplyBiDiMode;
var
BiDi: TBidiMode;
i: integer;
begin
if Form_Main = nil then exit;
BiDi:= bdLeftToRight;
if fUI_RTL then
BiDi:= bdRightToLeft;
if Form_Main.BiDiMode <> BiDi then begin
Form_Main.BiDiMode:= BiDi;
Form_Main.Menu_TV.BiDiMode:= BiDi;
Form_Main.Menu_RTF.BiDiMode:= BiDi;
if BiDi = bdRightToLeft then
BiDi:= bdRightToLeftNoAlign;
Form_Main.Combo_Font.BiDiMode:= BiDi;
// *1 To ensure icon is shown after changing BiDiMode
// TabSheet (TTab95Sheet) is an old component and has not BiDiMode property..
if ActiveFile <> nil then
for i := 0 to ActiveFile.Folders.Count -1 do begin
ActiveFile.Folders[i].UpdateTabSheet; // *1
ActiveFile.Folders[i].TreeUI.ApplyBiDiMode;
end;
end;
if (BiDI = bdLeftToRight) and IsRightToLeftLanguage() then begin // UserDefaultUILanguage is RTL...
Form_Main.Combo_ResFind.BiDiMode:= bdRightToLeft;
Form_Main.Dock_Top.BiDiMode:= bdRightToLeftNoAlign;
Form_Main.Dock_Bottom.BiDiMode:= bdRightToLeftNoAlign;
if ActiveFile <> nil then
for i := 0 to ActiveFile.Folders.Count -1 do
ActiveFile.Folders[i].TreeUI.ApplyBiDiMode;
end;
end;
procedure TKntApp.ApplyBiDiModeOnForm(Form: TForm);
begin
if fUI_RTL = (Form.BiDiMode = bdRightToLeft) then exit;
if fUI_RTL then begin
Form.BiDiMode:= bdRightToLeft;
AdjustRTLControls(Form);
end
else
Form.BiDiMode:= bdLeftToRight;
end;
function TKntApp.CheckActiveEditor: boolean;
begin
Result:= False;
if not assigned(ActiveEditor) then begin
ShowInfoInStatusBar(GetRS(sApp02));
exit;
end;
Result:= True;
end;
function TKntApp.CheckActiveEditorNotReadOnly: boolean;
begin
Result:= False;
if not assigned(ActiveEditor) then begin
ShowInfoInStatusBar(GetRS(sApp02));
exit;
end;
if ActiveEditor.ReadOnly then begin
WarnEditorIsReadOnly;
exit;
end;
Result:= True;
end;
procedure TKntApp.ActivateFolder (TabIndex: integer);
begin
ActivateFolder (ActiveFile.GetFolderByTabIndex(TabIndex));
end;
procedure TKntApp.ActivateFolder (Folder: TKntFolder);
var
TabIndex: integer;
FocusedOk: boolean;
begin
if not assigned(ActiveFile) then exit;
with Form_Main do begin
if not assigned(Folder) then begin
Folder:= ActiveFile.GetFolderByID(ActiveFile.SavedActiveFolderID);
end;
if assigned(Folder) then
TabIndex:= Folder.TabIndex
else begin
TabIndex:= 0;
Folder:= ActiveFile.GetFolderByTabIndex(TabIndex);
end;
if ( Pages.PageCount > TabIndex ) then
Pages.ActivePage := Pages.Pages[TabIndex];
if assigned(Folder) then begin
FocusedOk:= false;
if not Initializing and (Folder.FocusMemory <> focNil) then
try
if (Folder.FocusMemory = focTree) and not Folder.TreeHidden then
Folder.TV.SetFocus
else
Folder.Editor.SetFocus;
FocusedOk:= true;
except
// On E : Exception do ShowMessage( E.Message );
end;
if not FocusedOk or (ActiveFolder <> Folder) then // (ActiveFolder <> Folder) Puede ocurrir si se ha ejecutado Editor.BeginUpdate ...
EditorSelected(Folder.Editor, false);
if not initializing then
CheckFilterOnTags(True);
end;
end;
end;
procedure TKntApp.NoteNameModified(Note: TNote);
var
i: integer;
nnf: TNoteNodeInFolder;
Folder: TKntFolder;
begin
if ActiveFileIsBusy or AFileIsLoading then exit;
for i:= 0 to High(Note.NNodes) do begin
nnf:= Note.NNodes[i];
Folder:= TKntFolder(nnf.Folder);
TKntFolder(nnf.Folder).NoteNameModified(nnf.NNode);
end;
end;
procedure TKntApp.UpdateEnabledActionsAndRTFState(Editor: TKntRichEdit);
var
Edit_PlainText, Edit_SupportsImages, Edit_SupportsRegImages, Edit_NoteObj, Edit_Enabled: boolean;
begin
if (Editor = nil) or not Editor.Enabled then begin
Edit_PlainText:= true;
Edit_SupportsImages:= false;
Edit_SupportsRegImages:= false;
Edit_NoteObj:= false;
Edit_Enabled:= false;
end
else begin
Edit_PlainText:= Editor.PlainText;
Edit_SupportsImages:= Editor.SupportsImages;
Edit_SupportsRegImages:= Editor.SupportsRegisteredImages;
Edit_NoteObj:= (Editor.NNodeObj <> nil);
Edit_Enabled:= not Editor.ReadOnly;
end;
Form_Main.EnableActionsForEditor(not Edit_PlainText, Edit_Enabled);
Form_Main.EnableActionsForEditor(Edit_NoteObj, Edit_SupportsImages, Edit_SupportsRegImages);
Form_Main.RxChangedSelection(Editor, true);
Form_Main.UpdateWordWrap;
ClipCapMng.ShowState;
end;
procedure TKntApp.SetTopMost(hWND: HWND; OnlyWithFloatingEditor: boolean = True);
begin
if IntroducingTagsState = itWithTagSelector then begin
IgnoreSelectorForTagSubsr := cTagSelector.SelectedTagName;
cTagSelector.CloseTagSelector(false);
SetForegroundWindow(hWND);
end;
if OnlyWithFloatingEditor and ((ActiveFolder = nil) or (ActiveFolder.Editor.FloatingEditor = nil)) then exit;
SetWindowPos(hWND, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE)
end;
procedure TKntApp.HideNestedFloatingEditors;
begin
if (ActiveFolder <> nil) and (ActiveFolder.Editor.FloatingEditor <> nil) then
ActiveFolder.Editor.HideNestedFloatingEditor;
end;
procedure TKntApp.AuxEditorFocused(Sender: TObject);
begin
EditorFocused(TKntRichEdit(Sender));
end;
procedure TKntApp.EditorFocused (Editor: TKntRichEdit);
begin
EditorSelected(Editor, true);
if Form_Main.ShortcutAltDownMenuItem <> nil then
Form_Main.ShortcutAltDownMenuItem.Enabled:= True;
end;
procedure TKntApp.EditorReloaded (Editor: TKntRichEdit; Focused: boolean);
begin
if Editor = nil then exit;
EditorSelected(Editor, Focused); // Focused=False: Will not set ActiveFolder.FocusMemory:= focRTF (but will not set := focTree either)
end;
procedure TKntApp.EditorSelected (Editor: TKntRichEdit; Focused: boolean);
var
OldNNode: TNoteNode;
OldFolder: TKntFolder;
begin
EnsureContentEditorUpdated (Editor);
ActiveEditor:= Editor;
if Focused then begin
UpdateEnabledActionsAndRTFState(Editor);
ShowCurrentZoom(Editor.GetZoom);
Editor.UpdateCursorPos;
end;
if assigned(Editor.NNodeObj) then begin
OldFolder:= ActiveFolder;
OldNNode:= ActiveNNode;
ActiveNEntry:= TNoteEntry(Editor.NEntryObj);
ActiveNNode:= TNoteNode(Editor.NNodeObj);
ActiveFolder:= TKntFolder(Editor.FolderObj);
ActiveFile:= TKntFile(Editor.FileObj);
ActiveTreeUI:= nil;
if ActiveFolder <> nil then
ActiveTreeUI:= ActiveFolder.TreeUI;
if Focused then begin
ActiveFolder.FocusMemory:= focRTF;
if (ActiveTreeUI.TV.SelectedCount <> 1) and (ActiveTreeUI.TV.FocusedNode <> nil) then begin
ActiveTreeUI.TV.ClearSelection;
ActiveTreeUI.TV.Selected[ActiveTreeUI.TV.FocusedNode] := True;
end;
end;
if OldFolder <> ActiveFolder then
FolderSelected(ActiveFolder, OldFolder);
if OldNNode <> ActiveNNode then
NNodeSelected(ActiveNNode);
end;
end;
procedure TKntApp.EditorAvailable (Editor: TKntRichEdit);
begin
if fAvailableEditors.IndexOf(Editor) < 0 then
fAvailableEditors.Add(Editor);
end;
procedure TKntApp.EditorUnavailable (Editor: TKntRichEdit);
begin
fAvailableEditors.Remove(Editor);
end;
procedure TKntApp.EditorSaved (Editor: TKntRichEdit);
var
NNodeSavedEditor, NNode: TNoteNode;
NoteSavedEditor: TNote;
E: TKntRichEdit;
i: integer;
SP: TPoint;
SS,SL: integer;
begin
if Editor = nil then exit;
NNodeSavedEditor:= TNoteNode(Editor.NNodeObj);
if NNodeSavedEditor = nil then exit;
NoteSavedEditor:= NNodeSavedEditor.Note;
if NoteSavedEditor.NumNNodes <= 1 then exit;
for i:= 0 to fAvailableEditors.Count-1 do begin
E:= fAvailableEditors[i];
if (E = Editor) then continue;
NNode:= TNoteNode(E.NNodeObj);
if NNode = nil then continue;
if NoteSavedEditor = NNode.Note then begin
SP:= E.GetScrollPosInEditor;
SS := E.SelStart;
SL := E.SelLength;
TKntFolder(E.FolderObj).ReloadEditorFromDataModel(false);
E.SelStart:= SS;
E.SelLength:= SL;
E.SetScrollPosInEditor(SP);
end;
end;
end;
procedure TKntApp.EnsureContentEditorUpdated (Editor: TKntRichEdit);
var
NNodeSelecEditor, NNode: TNoteNode;
NoteSelecEditor: TNote;
E: TKntRichEdit;
i: integer;
begin
if Editor = nil then exit;
NNodeSelecEditor:= TNoteNode(Editor.NNodeObj);
if NNodeSelecEditor = nil then exit;
NoteSelecEditor:= NNodeSelecEditor.Note;
if NoteSelecEditor.NumNNodes <= 1 then exit;
for i:= 0 to fAvailableEditors.Count-1 do begin
E:= fAvailableEditors[i];
if (E = Editor) or (not E.Modified) then continue;
NNode:= TNoteNode(E.NNodeObj);
if NNode = nil then continue;
if NoteSelecEditor = NNode.Note then begin
TKntFolder(E.FolderObj).SaveEditorToDataModel; // Will force reload from any Editor with the same (linked) NNode open => App.EditorSaved()
exit;
end;
end;
end;
procedure TKntApp.NNodeFocused(NNode: TNoteNode);
begin
ActiveNNode:= NNode;
NNodeSelected(NNode);
end;
procedure TKntApp.NNodeSelected(NNode: TNoteNode);
begin
if assigned(NNode) then begin
if ActiveFolder.FocusMemory = focTree then
Form_Main.ShowNodeChromeState (ActiveFolder.TreeUI);
end
else
UpdateEnabledActionsAndRTFState(TKntRichEdit(nil));
if assigned(fNNodeSelected) then
OnNNodeSelected(NNode);
end;
procedure TKntApp.ChangeInEditor (Editor: TKntRichEdit);
var
NNodeObj, NEntryObj, FolderObj: TObject;
begin
with Form_Main do begin
TB_EditUndo.Enabled := Editor.CanUndo;
TB_EditRedo.Enabled := Editor.CanRedo;
RTFMUndo.Enabled := TB_EditUndo.Enabled;
end;
if CopyFormatMode= cfEnabled then
EnableCopyFormat(False);
if not Editor.VinculatedNNode(NNodeObj, NEntryObj, FolderObj) then exit; // Eg. Scratchpad (or a floating editor of Scratchpad)
NEntryModified (TNoteEntry(NEntryObj), TNoteNode(NNodeObj).Note, TKntFolder(FolderObj));
end;
procedure TKntApp.NEntryModified(NEntry: TNoteEntry; Note: TNote; Folder: TKntFolder);
begin
if ActiveFileIsBusy then exit;
NEntry.Modified:= true;
Note.Modified:= true; // Will also update last modified in note
Folder.Modified := true; // => KntFile.Modified := true;
end;
procedure TKntApp.EditorPropertiesModified (Editor: TKntRichEdit);
begin
if (Editor = ActiveEditor) and (ActiveEditor.Focused or (ActiveFolder.FocusMemory= focRTF)) then
Self.UpdateEnabledActionsAndRTFState(Editor);
end;
procedure TKntApp.FolderPropertiesModified (Folder: TKntFolder);
begin
if (Folder = ActiveFolder) and (ActiveFolder.FocusMemory= focTree) then
Form_Main.EnableActionsForTree(Folder.TreeUI, Folder.ReadOnly);
end;
procedure TKntApp.TreeFocused (Tree: TKntTreeUI);
var
PrevFolder: TKntFolder;
begin
if Tree <> ActiveTreeUI then begin
PrevFolder:= ActiveFolder;
ActiveTreeUI:= Tree;
ActiveFolder:= TKntFolder(Tree.Folder);
ActiveNNode:= ActiveFolder.FocusedNNode;
ActiveFile:= TKntFile(ActiveFolder.KntFile);
ActiveEditor:= ActiveFolder.Editor;
EnsureContentEditorUpdated (ActiveEditor);
FolderSelected(ActiveFolder, PrevFolder);
NNodeSelected(ActiveNNode);
end
else
ActiveFolder.FocusMemory:= focTree;
if ActiveFolder.FocusMemory = focTree then
Form_Main.EnableActionsForTree(Tree, ActiveFolder.ReadOnly);
if Form_Main.ShortcutAltDownMenuItem <> nil then
Form_Main.ShortcutAltDownMenuItem.Enabled:= True;
end;
procedure TKntApp.FolderSelected(Folder: TKntFolder; PrevFolder: TKntFolder);
var
ModifiedDataStream: TMemoryStream;
begin
try
if assigned(Folder) then begin
if assigned(PrevFolder) then begin
Form_Main.CheckRestoreAppWindowWidth (true);
if not _Executing_History_Jump then begin
AddHistoryLocation (PrevFolder, true); // true: add to local history maintaining it's index, and without removing forward history
_LastMoveWasHistory := false;
end;
end;
Folder.ImagesMode := ImageMng.ImagesMode;
Form_Main.TAM_ActiveName.Caption := Folder.Name;
Form_Main.TB_Color.AutomaticColor := Folder.EditorChrome.Font.Color;
end
else begin
Form_Main.TB_Color.AutomaticColor := clWindowText;
Form_Main.TAM_ActiveName.Caption := GetRS(sApp04);
end;
finally
Form_Main.UpdateFolderDisplay;
if assigned(Folder) then
Folder.Editor.CheckWordCount(true);
if not _Executing_History_Jump then
UpdateHistoryCommands;
ShowInfoInStatusBar('');
end;
if assigned(FFolderSelected) then
OnFolderSelected(Folder);
end;
procedure TKntApp.FolderDeleted (Folder: TKntFolder; TabIndex: integer);
begin
if Folder = ActiveFolder then begin
ActiveFolder:= nil;
ActiveNNode:= nil;
ActiveTreeUI:= nil;
if ActiveEditor.NNodeObj <> nil then
ActiveEditor:= nil;
end;
ActivateFolder (TabIndex-1);
end;
procedure TKntApp.FileClosed (aFile: TKntFile);
begin
if aFile = ActiveFile then begin
try
ActiveFolder:= nil;
ActiveNNode:= nil;
ActiveFile:= nil;
ActiveTreeUI:= nil;
ActiveFileIsBusy:= false;
if AppIsClosing then exit;
if assigned(ActiveEditor) and (ActiveEditor.NNodeObj <> nil) then begin
ActiveEditor:= nil;
with Form_Main do
if (Pages_Res.ActivePage = ResTab_RTF) and (ResTab_RTF.Visible) then
Res_RTF.SetFocus
else
UpdateEnabledActionsAndRTFState(TKntRichEdit(nil));
end;
Form_Main.FindTagsIncl:= nil;
Form_Main.FindTagsExcl:= nil;
if Form_Main.Ntbk_ResFind.PageIndex = 0 then
Form_Main.Btn_ResFlipClick(nil); // Display the search options panel
except
end;
end;
end;
procedure TKntApp.FileNew (aFile: TKntFile);
begin
ActiveFolder:= nil;
ActiveNNode:= nil;
ActiveFile:= aFile;
ActiveTreeUI:= nil;
if assigned(ActiveEditor) and (ActiveEditor.NNodeObj <> nil) then
ActiveEditor:= nil;
end;
procedure TKntApp.FileOpening (aFile: TKntFile);
begin
ActiveFile:= aFile;
ActiveFileIsBusy := true;
AFileIsLoading:= True;
end;
procedure TKntApp.FileOpen (aFile: TKntFile); // aFile can be nil (file open failed)
begin
ActiveFile:= aFile;
ActiveFileIsBusy := false;
AFileIsLoading:= false;
if aFile <> nil then begin
TagMng.ImportTagsFromFile(Tags_FN, True); // Import common tags (new or modified tags)
with Form_Main do
if KeyOptions.ResPanelShow and (Pages_Res.ActivePage = ResTab_Find) then begin
// Make sure the labels are interpreted according to this file
CheckTagsField(txtTagsIncl, FindTagsIncl);
CheckTagsField(txtTagsExcl, FindTagsExcl);
end;
end;
end;
procedure TKntApp.TagsUpdated;
begin
if ActiveFile = nil then begin
Form_Main.TVTags.RootNodeCount:= 0;
Form_Main.TVTags.PopupMenu:= nil;
exit;
end
else
Form_Main.TVTags.PopupMenu:= Form_Main.Menu_Tags;
if App.TagsState = tsVisible then begin
ActiveFile.SortNoteTags;
Form_Main.TVTags.RootNodeCount:= ActiveFile.NoteTags.Count;
Form_Main.CheckFilterTags;
end
else
App.TagsState := tsPendingUpdate;
end;
class procedure TKntApp.FileSetModified;
begin
ActiveFile.Modified:= true;
end;
procedure TKntApp.SetEditorZoom( ZoomValue : integer; const ZoomString : string; Increment: integer= 0);
var
Folder: TKntFolder;
i: integer;
begin
if not assigned(ActiveFile) and not assigned(ActiveEditor) then exit;
if ( _LoadedRichEditVersion < 3 ) then exit; // cannot zoom
if CtrlDown then begin
if assigned(ActiveEditor) then
ActiveEditor.SetZoom (ZoomValue, ZoomString, Increment)
end
else begin
if assigned(ActiveFile) then
for i := 0 to ActiveFile.Folders.Count -1 do
ActiveFile.Folders[i].Editor.SetZoom (ZoomValue, ZoomString, Increment);
Form_Main.Res_RTF.SetZoom (ZoomValue, ZoomString, Increment);
end;
end;
procedure TKntApp.ShowCurrentZoom (Zoom: integer);
begin
Form_Main.Combo_Zoom.Text := Format('%d%%', [Zoom] );
end;
procedure TKntApp.ShowInfoInStatusBar(const str: string);
begin
Form_Main.StatusBar.Panels[PANEL_HINT].Text := str;
end;
procedure TKntApp.WarnEditorIsReadOnly;
begin
ShowInfoInStatusBar(GetRS(sApp01));
end;
procedure TKntApp.WarnNoTextSelected;
begin
ShowInfoInStatusBar(GetRS(sApp05));
end;
procedure TKntApp.InfoPopup(const aStr: string);
begin