-
Notifications
You must be signed in to change notification settings - Fork 56
/
knt.App.pas
990 lines (779 loc) · 27.5 KB
/
knt.App.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
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 <[email protected]> (Poland)
(c) 2007-2015 Daniel Prado Velasco <[email protected]> (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;
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;
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;
property OnNNodeSelected: TNNodeSelectedEvent read FNNodeSelected write FNNodeSelected;
property OnFolderSelected: TFolderSelectedEvent read FFolderSelected write FFolderSelected;
procedure ScratchpadFocused(Sender: TObject);
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 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;
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;
IgnoringEditorChanges: 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,
kn_MacroMng,
kn_VCLControlsMng,
kn_LinksMng,
kn_FindReplaceMng,
kn_NoteFileMng,
knt.RS;
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;
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;
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;
function TKntApp.CheckActiveEditor: boolean;
begin
Result:= False;
if not assigned(ActiveEditor) then begin
ShowInfoInStatusBar(sApp02);
exit;
end;
Result:= True;
end;
function TKntApp.CheckActiveEditorNotReadOnly: boolean;
begin
Result:= False;
if not assigned(ActiveEditor) then begin
ShowInfoInStatusBar(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);
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: boolean;
begin
if (Editor = nil) or not Editor.Enabled then begin
Edit_PlainText:= true;
Edit_SupportsImages:= false;
Edit_SupportsRegImages:= false;
Edit_NoteObj:= false;
end
else begin
Edit_PlainText:= Editor.PlainText or Editor.ReadOnly;
Edit_SupportsImages:= Editor.SupportsImages;
Edit_SupportsRegImages:= Editor.SupportsRegisteredImages;
Edit_NoteObj:= (Editor.NNodeObj <> nil);
end;
Form_Main.EnableActionsForEditor(not Edit_PlainText);
Form_Main.EnableActionsForEditor(Edit_NoteObj, Edit_SupportsImages, Edit_SupportsRegImages);
Form_Main.RxChangedSelection(Editor, true);
Form_Main.UpdateWordWrap;
ClipCapMng.ShowState;
end;
procedure TKntApp.ScratchpadFocused(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
ActiveFolder.FocusMemory:= focRTF;
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
NNode: TNoteNode;
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);
NNode:= TNoteNode(Editor.NNodeObj);
if not assigned(NNode) then exit; // Eg. Scratchpad
NEntryModified (TNoteEntry(Editor.NEntryObj), NNode.Note, TKntFolder(Editor.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 := 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;
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;
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(sApp01);
end;
procedure TKntApp.WarnNoTextSelected;
begin
ShowInfoInStatusBar(sApp05);
end;
procedure TKntApp.InfoPopup(const aStr: string);
begin
PopupMessage(aStr, TMsgDlgType.mtInformation, [mbOK]);
end;
procedure TKntApp.WarningPopup(const aStr: string);
begin
PopupMessage(aStr, TMsgDlgType.mtWarning, [mbOK]);
end;
procedure TKntApp.ErrorPopup(const aStr: string);
begin
PopupMessage(aStr, TMsgDlgType.mtError, [mbOK]);
end;
procedure TKntApp.WarnFunctionNotImplemented(const aStr: string);
begin
WarningPopup(sApp03 + aStr);
{$IFDEF KNT_DEBUG}
Log.Add( 'Not implemented call: ' + aStr );
{$ENDIF}
end;
procedure TKntApp.ErrorPopup(const E: Exception = nil; const Str: string = '');
var
msg: string;
begin
if Str = '' then
msg:= sApp07
else
msg:= Str;
if E <> nil then
msg:= msg + #13 + E.Message;
ErrorPopup(msg);
end;
procedure TKntApp.WarnCommandNotImplemented(const aStr: string);
begin
WarningPopup(sApp06 + aStr);
{$IFDEF KNT_DEBUG}
Log.Add( 'Not implemented call: ' + aStr );
{$ENDIF}
end;
procedure TKntApp.ShowWordCountInfoInStatusBar(const str: string);
begin
Form_Main.StatusBar.Panels[PANEL_CARETPOS].Text := str;
end;
function TKntApp.GetWordCountInfoInStatusBar: string;
begin
Result:= Form_Main.StatusBar.Panels[PANEL_CARETPOS].Text;
end;
procedure TKntApp.ShowStatistics;
var
s: string;
numChars, numAlpChars, numWords, numNodes : integer;
begin
if not assigned(ActiveEditor) and not assigned(ActiveFolder) then exit;
s:= '';
if assigned(ActiveEditor) then
s:= ActiveEditor.GetStatistics (numChars, numAlpChars, numWords);
if assigned(ActiveFolder) then begin
numNodes := ActiveFolder.TV.TotalCount;
s := s + Format( sApp08, [numNodes] );
end;
App.ShowInfoInStatusBar(Format(sApp09, [numChars, numAlpChars, numWords] ));
if ( MessageDlg( s + sApp10, mtInformation, [mbOK,mbCancel], 0 ) = mrOK ) then
Clipboard.SetTextBuf( Pchar( s ));
end;
procedure TKntApp.ShowTipOfTheDay;
var
TipDlg : TGFTipDlg;
wasiconic : boolean;
begin
if ( not fileexists( TIP_FN )) then begin
PopupMessage( Format(sApp11, [extractfilename( TIP_FN )] ), mtInformation, [mbOK] );
// turn tips off, so that we don't get this error message
// every time KeyNote starts. (e.g. if user deleted the .tip file)
KeyOptions.TipOfTheDay := false;
exit;
end;
wasiconic := ( IsIconic(Application.Handle) = TRUE );
if wasiconic then
Application.Restore;
Application.BringToFront;
TipDlg := TGFTipDlg.Create( Form_Main );
try
with TipDlg do begin
ShowAtStartup := KeyOptions.TipOfTheDay;
TipFile := TIP_FN;
DlgCaption := Program_Name + sApp12;
PanelColor := _GF_CLWINDOW;
TipFont.Size := 10;
TipTitleFont.Size := 12;
SelectedTip := KeyOptions.TipOfTheDayIdx;
Execute;
KeyOptions.TipOfTheDayIdx := SelectedTip;
KeyOptions.TipOfTheDay := ShowAtStartup;
end;
finally
TipDlg.Free;
end;
if wasiconic then
Application.Minimize;
end; // ShowTipOfTheDay
function GetCaptionMessage: string;
begin
if assigned(ActiveFile) then
Result:= ExtractFilename(ActiveFile.FileName) + ' - ' + Program_Name
else
Result:= Program_Name;
end;
function TKntApp.DoMessageBox (const Str: string; DlgType: TMsgDlgType;
const Buttons: TMsgDlgButtons;
DefButton: TMsgDlgDefBtn = def1;
HelpCtx: Longint = 0; hWnd: HWND= 0): integer;
begin
Result:= gf_miscvcl.DoMessageBox(Str, GetCaptionMessage, DlgType, Buttons,DefButton, HelpCtx, hWnd);
end;
function TKntApp.PopUpMessage( const Str: string; const mType: TMsgDlgType;
const Buttons: TMsgDlgButtons;
const DefButton: TMsgDlgDefBtn = def1;
const HelpCtx: integer= 0): word;
begin
Result:= gf_miscvcl.PopUpMessage(Str, GetCaptionMessage, mType, Buttons, DefButton, HelpCtx);
end;
function GetCurrentTreeNode : PVirtualNode;
begin
result := nil;
if not assigned(ActiveTreeUI) then exit;
result:= ActiveTreeUI.FocusedNode;
end;
function GetTreeUI(TV: TVTree): TKntTreeUI;
var
i: Cardinal;
Folder: TKntFolder;
begin
Result:= nil;
for i := 0 to ActiveFile.Folders.Count-1 do begin
Folder := ActiveFile.Folders[i];
if Folder.TV = TV then begin
Result:= Folder.TreeUI;
exit;
end;
end;
end;
Initialization
App:= TKntApp.GetInstance;
end.