-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.pas
More file actions
1005 lines (927 loc) · 29.2 KB
/
Copy pathMain.pas
File metadata and controls
1005 lines (927 loc) · 29.2 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 Main;
Interface
Uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.Grids, Vcl.StdCtrls, System.IOUtils,
System.Actions, Vcl.ActnList, System.ImageList, Vcl.ImgList, Vcl.ToolWin, Vcl.ComCtrls,
Vcl.ExtCtrls, Vcl.AppEvnts;
Type
TMainForm = class(TForm)
MainGrid: TStringGrid;
MainToolBar: TToolBar;
AppIconsList: TImageList;
MainActionList: TActionList;
aAddNew: TAction;
tbAddNew: TToolButton;
aAddRecord: TAction;
aEditRecord: TAction;
aDeleteRecord: TAction;
aClearAll: TAction;
tbDeleteAll: TToolButton;
aNotesEditor: TAction;
tbNotes: TToolButton;
MainTrayIcon: TTrayIcon;
MainApplicationEvents: TApplicationEvents;
aDrawNote: TAction;
tbDrawNote: TToolButton;
aSetNotification: TAction;
tbSetNotification: TToolButton;
aChangeTheme: TAction;
tbChangeTheme: TToolButton;
aSafeNotes: TAction;
tbSafe: TToolButton;
MainSaveDialog: TSaveDialog;
aSaveRecords: TAction;
tbSaveRec: TToolButton;
aHelp: TAction;
tbHelp: TToolButton;
MainTimer: TTimer;
Procedure FormCreate(Sender: TObject);
Procedure FormResize(Sender: TObject);
Procedure Settings1Click(Sender: TObject);
Procedure AddNew1Click(Sender: TObject);
Procedure aAddNewExecute(Sender: TObject);
Procedure aAddRecordExecute(Sender: TObject);
Procedure MainGridDblClick(Sender: TObject);
Procedure aEditRecordExecute(Sender: TObject);
Procedure MainGridFixedCellClick(Sender: TObject; ACol, ARow: Integer);
Procedure aDeleteRecordExecute(Sender: TObject);
Procedure aClearAllExecute(Sender: TObject);
Procedure tbDeleteAllClick(Sender: TObject);
Procedure aNotesEditorExecute(Sender: TObject);
Procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
Procedure MainGridKeyPress(Sender: TObject; var Key: Char);
Procedure MainApplicationEventsMinimize(Sender: TObject);
Procedure MainApplicationEventsException(Sender: TObject; E: Exception);
Procedure MainTrayIconDblClick(Sender: TObject);
Procedure tbDrawClick(Sender: TObject);
Procedure aDrawNoteExecute(Sender: TObject);
Procedure aSetNotificationExecute(Sender: TObject);
Procedure aChangeThemeExecute(Sender: TObject);
Procedure aSafeNotesExecute(Sender: TObject);
Procedure aSaveRecordsExecute(Sender: TObject);
Procedure aHelpExecute(Sender: TObject);
procedure MainTimerTimer(Sender: TObject);
Private
{ Private declarations }
Public
{ Public declarations }
End;
Var
MainForm: TMainForm;
Implementation
{$R *.dfm}
Uses Settings, AddNew, Edit, Notes, Draw, Notification, Login, Secrets;
Const
ProgramVersion = '1.4';
PriorityArray: Array[1..3] of String = ('Low', 'Normal', 'High');
FixedRowCaptionsArray: Array[0..3] of String = ('№', 'Information', 'Due To', 'Priority');
FILE_LOGS: String = '\ReMind\logs.dat';
FILE_REMINDERS: String = '\ReMind\reminders.dat';
FILE_SECRETS: String = '\ReMind\secrets.dat';
Type
TReminder = Record
Number: Integer;
About: String[255];
Priority: Byte;
DueTo: TDateTime;
End;
TListElem = ^TElement;
TElement = Record
Data: TReminder;
PNext: TListElem;
PPrev: TListElem;
End;
TList = Record
PFirst: TListElem;
PLast: TListElem;
End;
Var
MainList, SortedList: TList;
OrderAsc: Boolean = True;
EditingRowIndicator: Integer;
IsLightTheme: Boolean = True;
Procedure DeleteList(var GivenList : TList);
Var
PNext, PDel: TListElem;
IsCorrect: Boolean;
Begin
IsCorrect := GivenList.PFirst = nil;
If not IsCorrect then
Begin
PNext := GivenList.PFirst;
While PNext <> nil do begin
PDel := PNext;
PNext := PNext^.PNext;
Dispose(PDel);
End;
GivenList.PFirst := nil;
GivenList.PLast := nil;
End;
End;
Procedure AddNextElement(const NewElement : TListElem; var GivenList: TList);
Var
IsNilElement: Boolean;
Begin
IsNilElement := NewElement = nil;
If not IsNilElement then
Begin
NewElement^.PNext := nil;
NewElement^.PPrev := nil;
If (GivenList.PFirst = nil) then
Begin
GivenList.PFirst := NewElement;
GivenList.PLast := NewElement;
End
Else
Begin
GivenList.PLast^.PNext := NewElement;
NewElement^.PPrev := GivenList.PLast;
GivenList.PLast := NewElement;
End;
End;
End;
Procedure NameFixedRows(MainGrid: TStringGrid);
Var
I: Integer;
Begin
For I := 0 to 3 do
Begin
With MainGrid do
Begin
Cells[I, 0] := FixedRowCaptionsArray[I];
End;
End;
End;
Function GetListSize(const GivenList: TList) : Integer;
Var
Size: Integer;
CurrentElem: TListElem;
Begin
CurrentElem := GivenList.PFirst;
Size := 0;
While CurrentElem <> nil do
Begin
Inc(Size);
CurrentElem := CurrentElem.PNext;
End;
GetListSize := Size;
End;
Procedure RewriteGeneralFiles();
Var
GeneralFile: TextFile;
LaunchTime: TDateTime;
Begin
AssignFile(GeneralFile, TPath.GetDocumentsPath + FILE_LOGS);
Rewrite(GeneralFile);
WriteLn(GeneralFile, 'Re:Mind version ' + ProgramVersion);
LaunchTime := Now;
WriteLn(GeneralFile, 'Last launched at ' + TimeToStr(LaunchTime) + ', ' + DateToStr(LaunchTime));
Close(GeneralFile);
End;
Procedure AddGeneralErrorReport(ErrorMessage: String);
Var
GeneralFile: TextFile;
ErrorTime: TDateTime;
Begin
AssignFile(GeneralFile, TPath.GetDocumentsPath + FILE_LOGS);
Append(GeneralFile);
ErrorTime := Now;
Writeln(GeneralFile, '[' + TimeToStr(ErrorTime) + '] ' + ErrorMessage);
Close(GeneralFile);
End;
Function ElementIsUnique(NewElement: TListElem) : Boolean;
Var
CurrentElem: TListElem;
IsUnique: Boolean;
Begin
IsUnique := True;
CurrentElem := MainList.PFirst;
While (CurrentElem <> nil) and IsUnique do
Begin
If (CurrentElem.Data.About = NewElement.Data.About) then
IsUnique := False;
CurrentElem := CurrentElem.PNext;
End;
ElementIsUnique := IsUnique;
End;
Procedure ReadFileData();
Var
FReminders: File of TReminder;
NewElement: TListElem;
Begin
AssignFile(FReminders, TPath.GetDocumentsPath + FILE_REMINDERS);
If not FileExists(TPath.GetDocumentsPath + FILE_REMINDERS) then
Begin
Rewrite(FReminders);
End
Else
Reset(FReminders);
While not Eof(FReminders) do
Begin
New(NewElement);
Read(FReminders, NewElement.Data);
If ElementIsUnique(NewElement) then
Begin
NewElement.Data.Number := GetListSize(MainList) + 1;
AddNextElement(NewElement, MainList)
End
Else
ShowMessage('Reminder you are trying to add is already exists!')
End;
Close(FReminders);
End;
Procedure ClearGrid(MainGrid: TStringGrid);
Var
I: Integer;
Begin
MainGrid.RowCount := 2;
For I := 0 to MainGrid.ColCount - 1 do
Begin
MainGrid.Cells[I, 1] := '';
End;
End;
Procedure PrintList(MainGrid: TStringGrid; const GList: TList);
Var
CurrentElem: TListElem;
I: Integer;
Begin
ClearGrid(MainGrid);
CurrentElem := GList.PFirst;
I := 1;
While CurrentElem <> nil do
Begin
With CurrentElem.Data do
Begin
With MainGrid do
Begin
Cells[0, I] := IntToStr(Number);
Cells[1, I] := About;
Cells[2, I] := DateToStr(DueTo);
Cells[3, I] := PriorityArray[Priority];
End;
End;
Inc(I);
MainGrid.RowCount := I;
CurrentElem := CurrentElem.PNext;
End;
End;
Procedure PrintListBackwards(MainGrid: TStringGrid; const GList: TList; ListSize: Integer);
Var
CurrentElem: TListElem;
I: Integer;
Begin
ClearGrid(MainGrid);
CurrentElem := GList.PLast;
I := 1;
While CurrentElem <> nil do
Begin
With CurrentElem.Data do
Begin
With MainGrid do
Begin
Cells[0, I] := IntToStr(Number);
Cells[1, I] := About;
Cells[2, I] := DateToStr(DueTo);
Cells[3, I] := PriorityArray[Priority];
End;
End;
Inc(I);
Dec(ListSize);
MainGrid.RowCount := I;
CurrentElem := CurrentElem.PPrev;
End;
End;
Procedure SetColsWidth(MainGrid: TStringGrid);
Begin
MainGrid.Width := MainForm.ClientWidth;
With MainGrid do
Begin
ColWidths[0] := Round(ClientWidth * 0.1);
ColWidths[1] := Round(ClientWidth * 0.6);
ColWidths[2] := Round(ClientWidth * 0.15);
ColWidths[3] := Round(ClientWidth * 0.15);
End;
End;
Procedure TMainForm.aAddNewExecute(Sender: TObject);
Begin
AddNewForm.ShowModal;
End;
Procedure SaveList();
Var
FToDoLog: File of TReminder;
CurrentElem: TListElem;
Begin
AssignFile(FToDoLog, TPath.GetDocumentsPath + FILE_REMINDERS);
Rewrite(FTodoLog);
CurrentElem := MainList.PFirst;
While CurrentElem <> nil do
Begin
With CurrentElem.Data do
Begin
Write(FToDoLog, CurrentElem.Data);
CurrentElem := CurrentElem.PNext;
End;
End;
Close(FToDoLog);
End;
Function IsAlreadyAdded(Key: Integer) : Boolean;
Var
CurrentElem: TListElem;
IsFound: Boolean;
Begin
IsFound := False;
CurrentElem := SortedList.PLast;
While (CurrentElem <> nil) and not IsFound do
Begin
If CurrentElem.Data.Number = Key then
IsFound := True;
CurrentElem := CurrentElem.PPrev;
End;
IsAlreadyAdded := IsFound;
End;
Function CompareDate(IsAsc: Boolean; A: TDateTime; B: TDateTime) : Integer;
Begin
If IsAsc then
Begin
If A > B then
Result := 1
Else If A < B then
Result := -1
Else If A = B then
Result := 0;
End
Else
Begin
If A > B then
Result := -1
Else If A < B then
Result := 1
Else If A = B then
Result := 0;
End;
End;
Function CompareDescription(IsAsc: Boolean; A: AnsiChar; B: AnsiChar) : Integer;
Begin
If IsAsc then
Begin
If A > B then
Result := 1
Else If A < B then
Result := -1
Else If A = B then
Result := 0;
End
Else
Begin
If A > B then
Result := -1
Else If A < B then
Result := 1
Else If A = B then
Result := 0;
End;
End;
Function ComparePriority(IsAsc: Boolean; A: Byte; B: Byte) : Integer;
Begin
If IsAsc then
Begin
If A > B then
Result := 1
Else If A < B then
Result := -1
Else If A = B then
Result := 0;
End
Else
Begin
If A > B then
Result := -1
Else If A < B then
Result := 1
Else If A = B then
Result := 0;
End;
End;
Function GeneralComporator(ComparatorID: Byte; GivenElemA, GivenElemB: TListElem; IsAsc: Boolean) : Integer;
Begin
Case ComparatorID of
1: Result := CompareDescription(IsAsc, GivenElemA.Data.About[1], GivenElemB.Data.About[1]);
2: Result := CompareDate(IsAsc, GivenElemA.Data.DueTo, GivenElemB.Data.DueTo);
3: Result := ComparePriority(IsAsc, GivenElemA.Data.Priority, GivenElemB.Data.Priority);
End;
End;
Procedure AddAsFirstElement(var GivenList: TList; const NewElem: TListElem);
Begin
NewElem^.PNext := nil;
NewElem^.PPrev := nil;
If GivenList.PFirst = nil then
Begin
GivenList.PFirst := NewElem;
GivenList.PLast := NewElem;
End
Else
Begin
NewElem^.PNext := GivenList.PFirst;
GivenList.PFirst^.PPrev := NewElem;
GivenList.PFirst := NewElem;
End;
End;
Procedure InsertBefore(var GivenList: TList; const BeforeThisElem, NewElem: TListElem);
Begin
If (GivenList.PFirst = nil) or (BeforeThisElem = nil) or (BeforeThisElem = GivenList.PFirst) then
Begin
AddAsFirstElement(GivenList, NewElem);
End
Else
Begin
NewElem^.PPrev := BeforeThisElem^.PPrev;
NewElem^.PNext := BeforeThisElem;
BeforeThisElem^.PPrev := NewElem;
NewElem^.PPrev^.PNext := NewElem;
End;
End;
Procedure SortList(IsAsc: Boolean; SortBy: Byte);
Var
CurrentElement, NewElement, ComparingElement: TListElem;
IsSortedElem: Boolean;
Begin
CurrentElement := MainList.PFirst;
New(NewElement);
NewElement.Data := CurrentElement.Data;
AddNextElement(NewElement, SortedList);
CurrentElement := CurrentElement.PNext;
While CurrentElement <> nil do
Begin
ComparingElement := SortedList.PFirst;
IsSortedElem := False;
While (ComparingElement <> nil) and not IsSortedElem do
Begin
If GeneralComporator(SortBy, CurrentElement, ComparingElement, IsAsc) = 1 then
Begin
New(NewElement);
NewElement.Data := CurrentElement.Data;
InsertBefore(SortedList, ComparingElement, NewElement);
IsSortedElem := True;
End
Else If ComparingElement.PNext = nil then
Begin
New(NewElement);
NewElement.Data := CurrentElement.Data;
AddNextElement(NewElement, SortedList);
IsSortedElem := True;
End;
ComparingElement := ComparingElement.PNext;
End;
CurrentElement := CurrentElement.PNext;
End;
End;
Function GetCurrentlySortedCol(MainGrid: TStringGrid) : Byte;
Var
FoundIn, I: Byte;
Begin
FoundIn := 100;
For I := 0 to MainGrid.ColCount - 1 do
Begin
If (MainGrid.Cells[I, 0] = FixedRowCaptionsArray[I] + ' ▲') or (MainGrid.Cells[I, 0] = FixedRowCaptionsArray[I] + ' ▼') then
FoundIn := I;
End;
GetCurrentlySortedCol := FoundIn;
End;
Procedure MakeChangesSorted(MainGrid: TStringGrid);
Begin
If GetCurrentlySortedCol(MainGrid) = 100 then
PrintList(MainGrid, MainList)
Else
Begin
OrderAsc := not OrderAsc;
MainGrid.OnFixedCellClick(MainGrid, GetCurrentlySortedCol(MainGrid), 0);
End;
End;
Procedure TMainForm.aAddRecordExecute(Sender: TObject);
Var
NewListElement: TListElem;
Begin
New(NewListElement);
With NewListElement.Data do
Begin
With AddNewForm do
Begin
DueTo := DatePick1.Date;
Priority := PriorityBox1.ItemIndex + 1;
About := String(InformationMemo1.Text);
End;
End;
If ElementIsUnique(NewListElement) then
Begin
NewListElement.Data.Number := GetListSize(MainList) + 1;
AddNextElement(NewListElement, MainList);
End
Else
ShowMessage('Reminder you are trying to add is already exists!');
MakeChangesSorted(MainGrid);
SaveList;
AddNewForm.Close;
End;
Procedure TMainForm.aChangeThemeExecute(Sender: TObject);
Begin
IsLightTheme := not IsLightTheme;
If IsLightTheme then
Begin
// GRID_LIGHT
MainGrid.Color := clWhite;
MainGrid.Font.Color := clBlack;
MainGrid.GradientStartColor := clSkyBlue;
MainGrid.GradientEndColor := clSkyBlue;
// TOOLBAR_LIGHT
MainToolBar.GradientStartColor := clSkyBlue;
MainToolBar.GradientEndColor := clSkyBlue;
// ADDNEW_LIGHT
AddNewForm.Color := clWhite;
AddNewForm.Font.Color := clBlack;
// NOTES_LIGHT
NotesForm.NotesMemo.Color := clWhite;
NotesForm.NotesMemo.Font.Color := clBlack;
// NOTIF_LIGHT
NotificationForm.Color := clWhite;
NotificationForm.Font.Color := clBlack;
// LOGIN_LIGHT
LoginForm.Color := clWhite;
LoginForm.Font.Color := clBlack;
// SECRET_LIGHT
SecretForm.Color := clWhite;
SecretForm.Font.Color := clBlack;
// EDIT_LIGHT
EditForm.Color := clWhite;
EditForm.Font.Color := clBlack;
aChangeTheme.ImageIndex := 5;
End
Else
Begin
// GRID_DARK
MainGrid.Color := $323232;
MainGrid.Font.Color := clWhite;
MainGrid.GradientStartColor := $515151;
MainGrid.GradientEndColor := $515151;
// TOOLBAR_DARK
MainToolBar.GradientStartColor := $515151;
MainToolBar.GradientEndColor := $515151;
// ADDNEW_DARK
AddNewForm.Color := $323232;
AddNewForm.Font.Color := clWhite;
// NOTES_DARK
NotesForm.NotesMemo.Color := $323232;
NotesForm.NotesMemo.Font.Color := clWhite;// NOTIF_LIGHT
// NOTIF_DARK
NotificationForm.Color := $323232;
NotificationForm.Font.Color := clWhite;
// LOGIN_DARK
LoginForm.Color := $323232;
LoginForm.Font.Color := clWhite;
// SECRETS_DARK
SecretForm.Color := $323232;
SecretForm.Font.Color := clWhite;
// EDIT_DARK
EditForm.Color := $323232;
EditForm.Font.Color := clWhite;
aChangeTheme.ImageIndex := 7;
End;
End;
Procedure TMainForm.aClearAllExecute(Sender: TObject);
Var
IsConfirmed: Byte;
Begin
IsConfirmed := MessageDlg('Are you sure that you want to clear all records? This action can''t be undone!', mtConfirmation, mbYesNo, 0);
If IsConfirmed = mrYes then
Begin
DeleteList(MainList);
SaveList;
PrintList(MainGrid, MainList);
End;
End;
Procedure TMainForm.AddNew1Click(Sender: TObject);
Begin
AddNewForm.ShowModal;
End;
Procedure DeleteListItem(var GivenList: TList; var DeletingElem : TListElem);
Begin
If DeletingElem = GivenList.PFirst then
Begin
GivenList.PFirst := DeletingElem^.PNext;
If GivenList.PFirst = nil then
GivenList.PLast := nil
Else
GivenList.PFirst^.PPrev := nil;
End
Else If DeletingElem = GivenList.PLast then
Begin
GivenList.PLast := DeletingElem^.PPrev;
If GivenList.PLast = nil then
GivenList.PFirst := nil
Else
GivenList.PLast^.PNext := nil;
End
Else
Begin
DeletingElem^.PPrev^.PNext := DeletingElem^.PNext;
DeletingElem^.PNext^.PPrev := DeletingElem^.PPrev;
End;
Dispose(DeletingElem);
DeletingElem := nil;
End;
Function GetByNum(const GivenList: TList; const Key: Integer) : TListElem;
Var
I : Integer;
PNext : TListElem;
Begin
Result := nil;
I := 1;
PNext := GivenList.PFirst;
While (I <= Key) and (PNext <> nil) do
Begin
If I = Key then begin
Result := PNext;
Break;
End;
Inc(i);
PNext := PNext^.PNext;
End;
End;
Procedure OrderListAgain();
Var
CurrentElem: TListELem;
I: Integer;
Begin
CurrentElem := MainList.PFirst;
I := 1;
While CurrentElem <> nil do
Begin
CurrentElem.Data.Number := I;
CurrentElem := CurrentElem.PNext;
Inc(I);
End;
End;
Procedure TMainForm.aDeleteRecordExecute(Sender: TObject);
Var
DeletingElement: TListElem;
Begin
DeletingElement := GetByNum(MainList, EditingRowIndicator);
DeleteListItem(MainList, DeletingElement);
SaveList;
OrderListAgain;
MakeChangesSorted(MainGrid);
End;
Procedure TMainForm.aDrawNoteExecute(Sender: TObject);
Begin
DrawForm.ShowModal;
End;
Procedure TMainForm.aEditRecordExecute(Sender: TObject);
Var
CurrentElem: TListElem;
ElementNumber: Integer;
IsAlreadyEdited: Boolean;
Begin
CurrentElem := MainList.PFirst;
ElementNumber := 1;
IsAlreadyEdited := False;
While (CurrentElem <> nil) and not (IsAlreadyEdited) do
Begin
If ElementNumber = EditingRowIndicator then
Begin
With CurrentElem.Data do
Begin
With EditForm do
Begin
DueTo := DatePick1.Date;
Priority := PriorityBox1.ItemIndex + 1;
About := InformationMemo1.Text;
End
End;
IsAlreadyEdited := True;
End;
Inc(ElementNumber);
CurrentElem := CurrentElem.PNext;
End;
SaveList;
MakeChangesSorted(MainGrid);
End;
Procedure TMainForm.aHelpExecute(Sender: TObject);
Begin
ShowMessage('Welcome to Re:Mind Aplication! This is short user guide.' + #13#10 + #13#10 +
'[Adding new record] Press first Button in toolbar (Plus icon), fill in the fields, and press add.' + #13#10 + #13#10 +
'[Sorting] Pressing on fixed cells, will sort your records, according on field to sort you clicked.' + #13#10 + #13#10 +
'[Editing] Double click on record, to show edit form. After editing, click "Edit" button to save your changes.' + #13#10 + #13#10 +
'[Deleting] Double click on record you want to delete, then in right low corner press "Delete" button to delete record.' + #13#10 + #13#10 +
'[Note Editor] Press second button in toolbar (Note icon). Now you can write down anything, then just close this form. Thing that you wrote, would be saved and available next time.' + #13#10 + #13#10 +
'[Drawing] Press third button in toolbar (Palette icon). Select color and draw, drawings would be saved. Furthermore, drawn image saved in your Documents path.' + #13#10 + #13#10 +
'[Notifications] Press fourth button in toolbar (Bell icon). Fill the fields and you will be notificated when time runs out.' + #13#10 + #13#10 +
'[Secret space] Press fifth button in toolbar (Lock icon). First time, set your password, next times re-enter it. All your secret data would be encrypted and saved.' + #13#10 + #13#10 +
'[Export Record] Press sixth button in toolbar (Down arrow icon). Select location and file, then click save. In set path, will created .txt file with your records' + #13#10 + #13#10 +
'[Change Theme] Press eighth button in toolbar (Display icon) to change theme. Next click will revert theme.' + #13#10 + #13#10 +
'[Delete All Records] Press ninth button in toolbar (Cross icon) to delete all records.' + #13#10 + #13#10 +
'[Minimizing application] By minimizing your main window, application will stay in tray. You can maximize it back by double clicking tray icon.' + #13#10 + #13#10 +
'Created by Azam "gthanksg" Alamov, 2022. Made by the power of love, coffee and deadlines <3');
End;
Procedure TMainForm.aNotesEditorExecute(Sender: TObject);
Begin
NotesForm.ShowModal;
NotesForm.aStartController.Execute;
End;
Function PasswordIsCreated() : Boolean;
Var
FSecrets: TextFile;
LineWithPassword: String[20];
Begin
Result := False;
AssignFile(FSecrets, TPath.GetDocumentsPath + FILE_SECRETS);
If FileExists(TPath.GetDocumentsPath + FILE_SECRETS) then
Begin
Reset(FSecrets);
ReadLn(FSecrets, LineWithPassword);
If (LineWithPassword <> '') and (LineWithPassword[1] = '!') then
Result := True;
End
Else
Begin
Rewrite(FSecrets);
End;
Close(FSecrets);
End;
Procedure TMainForm.aSafeNotesExecute(Sender: TObject);
Var
PasswordExists: Boolean;
Begin
PasswordExists := PasswordIsCreated();
If not PasswordExists then
LoginForm.InformationLabel.Caption := 'Set up password:'
Else
LoginForm.InformationLabel.Caption := 'Input your password:';
LoginForm.ShowModal;
End;
Procedure TMainForm.aSaveRecordsExecute(Sender: TObject);
Var
FRes: TextFile;
I, J: Integer;
Begin
MainSaveDialog.InitialDir := TPath.GetDownloadsPath;
If MainSaveDialog.Execute() then
Begin
AssignFile(FRes, MainSaveDialog.FileName);
Rewrite(FRes);
For I := 1 to MainGrid.RowCount do
Begin
For J := 0 to MainGrid.ColCount - 1 do
Begin
With MainGrid do
Begin
Write(FRes, Cells[J, I] + ' ');
End;
End;
WriteLn(FRes);
End;
CloseFile(FRes);
ShowMessage('Records saved to: [' + MainSaveDialog.FileName + ']');
End;
End;
Procedure TMainForm.aSetNotificationExecute(Sender: TObject);
Begin
NotificationForm.aSetComboBox.Execute;
NotificationForm.ShowModal;
End;
Procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
Var
IsConfirmed: Byte;
Begin
IsConfirmed := MessageDlg('You sure that you want to exit?', mtConfirmation, mbYesNo, 0);
If IsConfirmed = mrYes then
CanClose := True
Else
Begin
CanClose := False;
End;
End;
Procedure ShowHints();
Begin
ShowMessage('Welcome!' + #13#10 + #13#10 + 'To feel yourself comfortable here, don''t forget to read short manual. Just press Ctrl + H or Hint icon on Taskbar.');
End;
Procedure CreateNewDirectory;
Begin
If not TDirectory.Exists(TPath.GetDocumentsPath + '\ReMind\') then
Begin
TDirectory.CreateDirectory(TPath.GetDocumentsPath + '\ReMind\');
ShowHints;
End;
End;
Procedure TMainForm.FormCreate(Sender: TObject);
Begin
DeleteList(MainList);
SetColsWidth(MainGrid);
NameFixedRows(MainGrid);
CreateNewDirectory;
RewriteGeneralFiles;
ReadFileData;
PrintList(MainGrid, MainList);
Self.Caption := Self.Caption + ' v' + ProgramVersion;
End;
Procedure TMainForm.FormResize(Sender: TObject);
Begin
SetColsWidth(MainGrid);
End;
Procedure SetEditFormProperties(MainGrid: TStringGrid; Row: Integer);
Begin
With EditForm do
Begin
With MainGrid do
Begin
InformationMemo1.Text := Cells[1, Row];
DatePick1.Date := StrToDate(Cells[2, Row]);
aSetPriorities.Execute;
If Cells[3, Row] = 'High' then
PriorityBox1.ItemIndex := 2
Else If Cells[3, Row] = 'Normal' then
PriorityBox1.ItemIndex := 1
Else If Cells[3, Row] = 'Low' then
PriorityBox1.ItemIndex := 0;
EditingRowIndicator := StrToInt(Cells[0, Row]);
End;
ShowModal;
End;
End;
Procedure TMainForm.MainApplicationEventsException(Sender: TObject; E: Exception);
Begin
AddGeneralErrorReport(E.ToString);
End;
Procedure TMainForm.MainApplicationEventsMinimize(Sender: TObject);
Begin
MainForm.Visible := False;
MainTrayIcon.Visible := True;
End;
Procedure TMainForm.MainGridDblClick(Sender: TObject);
Var
SelectedRow: Integer;
Begin
If not (MainGrid.Row = 0) then
Begin
SelectedRow := MainGrid.Row;
SetEditFormProperties(MainGrid, SelectedRow);
End;
End;
Procedure TMainForm.MainGridFixedCellClick(Sender: TObject; ACol, ARow: Integer);
Begin
NameFixedRows(MainGrid);
If not (ACol = 0) then
Begin
DeleteList(SortedList);
SortList(OrderAsc, ACol);
If OrderAsc then
MainGrid.Cells[ACol, ARow] := FixedRowCaptionsArray[ACol] + ' ▼'
Else
MainGrid.Cells[ACol, ARow] := FixedRowCaptionsArray[ACol] + ' ▲';
PrintList(MainGrid, SortedList);
End
Else If ACol = 0 then
Begin
If OrderAsc then
PrintList(MainGrid, MainList)
Else
Begin
MainGrid.Cells[ACol, ARow] := FixedRowCaptionsArray[ACol] + ' ▼';
PrintListBackwards(MainGrid, MainList, GetListSize(MainList));
End;
End;
OrderAsc := not OrderAsc;
End;
Procedure TMainForm.MainGridKeyPress(Sender: TObject; var Key: Char);
Begin
If (Key = #13) and (MainGrid.Row <> 0) then
Begin
SetEditFormProperties(MainGrid, MainGrid.Row);
End;
End;
Procedure TMainForm.MainTimerTimer(Sender: TObject);
Begin
MainTimer.Enabled := False;
NotificationForm.aSetComboBox.Execute;
//NotificationForm.ShowModal;
End;
Procedure TMainForm.MainTrayIconDblClick(Sender: TObject);
Begin
MainTrayIcon.Visible := False;
MainForm.Visible := True;
MainForm.WindowState := wsNormal;
MainForm.FormStyle := fsStayOnTop;
MainForm.FormStyle := fsNormal;
End;
Procedure TMainForm.Settings1Click(Sender: TObject);
Begin
SettingsForm.ShowModal;
End;
Procedure TMainForm.tbDeleteAllClick(Sender: TObject);
Begin
aClearAll.Execute;
End;
Procedure TMainForm.tbDrawClick(Sender: TObject);