diff --git a/Draw.pas b/Draw.pas new file mode 100644 index 0000000..b57a07b --- /dev/null +++ b/Draw.pas @@ -0,0 +1,125 @@ +Unit Draw; + +Interface + +Uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Imaging.Pngimage, System.IOUtils, + Vcl.StdCtrls, Vcl.ActnMan, Vcl.ActnColorMaps; + +Type + TDrawForm = class(TForm) + NoteDrawImage: TImage; + ClearCanvas: TButton; + PenColorBox: TColorBox; + Procedure FormCreate(Sender: TObject); + procedure NoteDrawImageMouseMove(Sender: TObject; Shift: TShiftState; X, + Y: Integer); + procedure FormClose(Sender: TObject; var Action: TCloseAction); + procedure ClearCanvasClick(Sender: TObject); + procedure PenColorBoxChange(Sender: TObject); + Private + { Private declarations } + Public + { Public declarations } + End; + +Var + DrawForm: TDrawForm; + +Implementation + +{$R *.dfm} + +Const + FILE_IMAGE: String = '\ReMind\image.png'; + +Var + PenColor: TColor = clBlack; + +Procedure MakeImageSameSizeAsFormIs(NoteDrawImage: TImage); +Begin + NoteDrawImage.Width := DrawForm.Width; + NoteDrawImage.Height := DrawForm.Height; +End; + +Procedure TDrawForm.ClearCanvasClick(Sender: TObject); +Begin + With NoteDrawImage.Canvas do + Begin + Pen.Color := clWhite; + Brush.Color := clWhite; + Rectangle(0, 0, Width, Height); + End; +End; + +Procedure SetPenColor(NoteDrawImage: TImage; ColorPicker: TComboBox); +Begin + PenColor := StringToColor(ColorPicker.Text); +End; + +Procedure TDrawForm.PenColorBoxChange(Sender: TObject); +Begin + PenColor := PenColorBox.Selected; +End; + +Procedure TDrawForm.FormClose(Sender: TObject; var Action: TCloseAction); +Var + Bmp: TBitmap; + Png: TPngImage; +Begin + Bmp := TBitmap.Create; + Try + Bmp.SetSize(NoteDrawImage.Canvas.ClipRect.Right, NoteDrawImage.Canvas.ClipRect.Bottom); + BitBlt(Bmp.Canvas.Handle, 0, 0, Width, Height, NoteDrawImage.Canvas.Handle, 0, 0, SRCCOPY); + Png := TPngImage.Create; + Try + Png.Assign(Bmp); + Png.SaveToFile(TPath.GetDocumentsPath + FILE_IMAGE); + Finally + Png.Free; + End; + Finally + Bmp.Free; + End; +End; + +Procedure SetColorPicker(ColorPicker: TComboBox); +Begin + With ColorPicker.Items do + Begin + Add('clBlack'); + Add('clRed'); + Add('clYellow'); + Add('clGreen'); + Add('clBlue'); + Add('clWhite'); + End; +End; + +Procedure TDrawForm.FormCreate(Sender: TObject); +Var + PNG: TPNGObject; +Begin + MakeImageSameSizeAsFormIs(NoteDrawImage); + PNG := TPNGObject.Create; + PNG.LoadFromFile(TPath.GetDocumentsPath + FILE_IMAGE); + NoteDrawImage.Canvas.Draw(0, 0, PNG); + //SetColorPicker(ColorPicker); +End; + +Procedure TDrawForm.NoteDrawImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); +Begin + With NoteDrawImage.Canvas do + Begin + If ssLeft in Shift then + Begin + Pixels[X, Y] := PenColor; + Pixels[X + 1, Y] := PenColor; + Pixels[X, Y + 1] := PenColor; + Pixels[X + 1, Y + 1] := PenColor; + End; + End; +End; + +End. diff --git a/Edit.pas b/Edit.pas index 87f09b4..fdfdd3f 100644 --- a/Edit.pas +++ b/Edit.pas @@ -5,7 +5,7 @@ Uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.WinXCalendars, System.DateUtils, - System.Actions, Vcl.ActnList; + System.Actions, Vcl.ActnList, Vcl.ComCtrls, Vcl.WinXPickers; Type TEditForm = class(TForm) @@ -17,7 +17,6 @@ TEditForm = class(TForm) DatePick1: TCalendarPicker; EditButton1: TButton; CloseButton1: TButton; - SelectedRowIndicator: TLabel; EditActionList: TActionList; aSetPriorities: TAction; DeleteButton1: TButton; diff --git a/Main.pas b/Main.pas index 217c15c..89a3965 100644 --- a/Main.pas +++ b/Main.pas @@ -6,7 +6,7 @@ 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; + Vcl.ExtCtrls, Vcl.AppEvnts; Type TMainForm = class(TForm) @@ -16,7 +16,6 @@ TMainForm = class(TForm) MainActionList: TActionList; aAddNew: TAction; tbAddNew: TToolButton; - aSettings: TAction; aAddRecord: TAction; aEditRecord: TAction; aDeleteRecord: TAction; @@ -26,12 +25,17 @@ TMainForm = class(TForm) tbNotes: TToolButton; MainTrayIcon: TTrayIcon; MainApplicationEvents: TApplicationEvents; + aDrawNote: TAction; + tbDrawNote: TToolButton; + aSetNotification: TAction; + tbSetNotification: TToolButton; + aChangeTheme: TAction; + tbChangeTheme: TToolButton; Procedure FormCreate(Sender: TObject); Procedure FormResize(Sender: TObject); Procedure Settings1Click(Sender: TObject); Procedure AddNew1Click(Sender: TObject); Procedure aAddNewExecute(Sender: TObject); - Procedure aSettingsExecute(Sender: TObject); Procedure aAddRecordExecute(Sender: TObject); Procedure MainGridDblClick(Sender: TObject); Procedure aEditRecordExecute(Sender: TObject); @@ -40,11 +44,15 @@ TMainForm = class(TForm) 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 MainTrayIconClick(Sender: TObject); - procedure MainApplicationEventsException(Sender: TObject; E: Exception); + 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); Private { Private declarations } Public @@ -58,14 +66,15 @@ TMainForm = class(TForm) {$R *.dfm} -Uses Settings, AddNew, Edit, Notes; +Uses Settings, AddNew, Edit, Notes, Draw, Notification; Const - ProgramVersion = '1.1b'; + ProgramVersion = '1.3.1'; PriorityArray: Array[1..3] of String = ('Low', 'Normal', 'High'); FixedRowCaptionsArray: Array[0..3] of String = ('â„–', 'Information', 'Due To', 'Priority'); - FILE_INFO: String = '\ReMind\err_log.dat'; + FILE_LOGS: String = '\ReMind\logs.dat'; FILE_REMINDERS: String = '\ReMind\reminders.dat'; + Type TLog = Record @@ -73,7 +82,6 @@ TMainForm = class(TForm) About: String[255]; Priority: Byte; DueTo: TDateTime; - IsDone: Boolean; End; TListElem = ^TElement; TElement = Record @@ -89,6 +97,8 @@ TMainForm = class(TForm) Var MainList, SortedList: TList; OrderAsc: Boolean = True; + EditingRowIndicator: Integer; + IsLightTheme: Boolean = True; Procedure DeleteList(var GivenList : TList); Var @@ -147,11 +157,6 @@ TMainForm = class(TForm) End; End; -Function CheckFirstLaunch() : Boolean; -Begin - CheckFirstLaunch := not FileExists(TPath.GetDocumentsPath + FILE_INFO); -End; - Function GetListSize(const GivenList: TList) : Integer; Var Size: Integer; @@ -167,21 +172,12 @@ TMainForm = class(TForm) GetListSize := Size; End; -Procedure CreateNewFiles(); -Var - NewFile: TextFile; -Begin - Createdir(TPath.GetDocumentsPath + '\ReMind\'); - AssignFile(NewFile, TPath.GetDocumentsPath + FILE_INFO); - Rewrite(NewFile); -End; - Procedure RewriteGeneralFiles(); Var GeneralFile: TextFile; LaunchTime: TDateTime; Begin - AssignFile(GeneralFile, TPath.GetDocumentsPath + FILE_INFO); + AssignFile(GeneralFile, TPath.GetDocumentsPath + FILE_LOGS); Rewrite(GeneralFile); WriteLn(GeneralFile, 'Re:Mind version ' + ProgramVersion); LaunchTime := Now; @@ -194,108 +190,13 @@ TMainForm = class(TForm) GeneralFile: TextFile; ErrorTime: TDateTime; Begin - AssignFile(GeneralFile, TPath.GetDocumentsPath + FILE_INFO); + AssignFile(GeneralFile, TPath.GetDocumentsPath + FILE_LOGS); Append(GeneralFile); ErrorTime := Now; Writeln(GeneralFile, '[' + TimeToStr(ErrorTime) + '] ' + ErrorMessage); Close(GeneralFile); End; -Function GetLogDescription(Line: String; LineAddress: Integer; Var CurrentChar: Integer) : String; -Var - LogDescription: String; -Begin - LogDescription := ''; - If (Line[1] = '[') then - Begin - CurrentChar := 2; - While Line[CurrentChar] <> ']' do - Begin - LogDescription := LogDescription + Line[CurrentChar]; - Inc(CurrentChar); - End; - End - Else - AddGeneralErrorReport('Corrupted reminder description found at line #' + IntToStr(LineAddress)); - GetLogDescription := LogDescription; -End; - -Function GetLogDue(Line: String; LineAddress: Integer; Var CurrentChar: Integer) : TDateTime; -Var - Day, Month, Year: String[4]; -Begin - Inc(CurrentChar, 2); - - While Line[CurrentChar] <> '/' do - Begin - Month := Month + Line[CurrentChar]; - Inc(CurrentChar); - End; - Inc(CurrentChar); - - While Line[CurrentChar] <> '/' do - Begin - Day := Day + Line[CurrentChar]; - Inc(CurrentChar); - End; - Inc(CurrentChar); - - While Length(Year) <> 4 do - Begin - Year := Year + Line[CurrentChar]; - Inc(CurrentChar); - End; - - GetLogDue := EncodeDate(StrToInt(Year), StrToInt(Month), StrToInt(Day)); -End; - -Function GetLogPriority(Line: String; LineAdress: Integer; Var CurrentChar: Integer) : Byte; -Var - Priority: Byte; -Begin - Priority := 0; - Inc(CurrentChar); - Try - Priority := StrToInt(Line[CurrentChar]); - Except - AddGeneralErrorReport('Corrupted reminder priority found at line #' + IntToStr(LineAdress)); - End; - GetLogPriority := Priority; -End; - -Function GetDoneStatus(Line: String; LineAdress: Integer; Var CurrentChar: Integer) : Boolean; -Var - IsDone: Boolean; -Begin - IsDone := False; - Inc(CurrentChar, 2); - - If Line[CurrentChar] = 'D' then - IsDone := True - Else If Line[CurrentChar] = 'N' then - IsDone := False - Else - AddGeneralErrorReport('Corrupted reminder status found at line #' + IntToStr(LineAdress)); - GetDoneStatus := IsDone; -End; - -Function DistributeElement(Line: String; LineAddress: Integer) : TListElem; -Var - CreatedLogElement: TListElem; - CurrentChar: Integer; -Begin - New(CreatedLogElement); - CurrentChar := 1; - With CreatedLogElement.Data do - Begin - About := GetLogDescription(Line, LineAddress, CurrentChar); - DueTo := GetLogDue(Line, LineAddress, CurrentChar); - Priority := GetLogPriority(Line, LineAddress, CurrentChar); - IsDone := GetDoneStatus(Line, LineAddress, CurrentChar); - End; - DistributeElement := CreatedLogElement; -End; - Function ElementIsUnique(NewElement: TListElem) : Boolean; Var CurrentElem: TListElem; @@ -314,10 +215,8 @@ TMainForm = class(TForm) Procedure ReadFileData(); Var - FReminders: TextFile; - NewLine: String; + FReminders: File of TLog; NewElement: TListElem; - LineAddress: Integer; Begin AssignFile(FReminders, TPath.GetDocumentsPath + FILE_REMINDERS); If not FileExists(TPath.GetDocumentsPath + FILE_REMINDERS) then @@ -326,25 +225,19 @@ TMainForm = class(TForm) End Else Reset(FReminders); - - LineAddress := 1; - While not EoF(FReminders) do + While not Eof(FReminders) do Begin - ReadLn(FReminders, NewLine); - //New(NewElement); - If NewLine <> '' then + New(NewElement); + Read(FReminders, NewElement.Data); + If ElementIsUnique(NewElement) then Begin - NewElement := DistributeElement(NewLine, LineAddress); - 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; - Inc(LineAddress); + 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; @@ -431,7 +324,7 @@ TMainForm = class(TForm) Procedure SaveList(); Var - FToDoLog: TextFile; + FToDoLog: File of TLog; CurrentElem: TListElem; Begin AssignFile(FToDoLog, TPath.GetDocumentsPath + FILE_REMINDERS); @@ -441,10 +334,7 @@ TMainForm = class(TForm) Begin With CurrentElem.Data do Begin - If IsDone then - WriteLn(FTodoLog, '[' + About + '] ' + DateToStr(DueTo) + ' ' + IntToStr(Priority) + ' ' + 'D') - Else - WriteLn(FTodoLog, '[' + About + '] ' + DateToStr(DueTo) + ' ' + IntToStr(Priority) + ' ' + 'N'); + Write(FToDoLog, CurrentElem.Data); CurrentElem := CurrentElem.PNext; End; End; @@ -457,12 +347,12 @@ TMainForm = class(TForm) IsFound: Boolean; Begin IsFound := False; - CurrentElem := SortedList.PFirst; + CurrentElem := SortedList.PLast; While (CurrentElem <> nil) and not IsFound do Begin If CurrentElem.Data.Number = Key then IsFound := True; - CurrentElem := CurrentElem.PNext; + CurrentElem := CurrentElem.PPrev; End; IsAlreadyAdded := IsFound; End; @@ -533,49 +423,80 @@ TMainForm = class(TForm) 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 InsB(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 - ComparingElement, CurrentElement, NewElement: TListElem; + CurrentElement, NewElement, ComparingElement: TListElem; + IsSortedElem: Boolean; Begin - While GetListSize(SortedList) <> GetListSize(MainList) do + CurrentElement := MainList.PFirst; + New(NewElement); + NewElement.Data := CurrentElement.Data; + AddNextElement(NewElement, SortedList); + CurrentElement := CurrentElement.PNext; + While CurrentElement <> nil do Begin - - CurrentElement := MainList.PFirst; - While CurrentElement <> nil do + ComparingElement := SortedList.PFirst; + IsSortedElem := False; + While (ComparingElement <> nil) and not IsSortedElem do Begin - If not IsAlreadyAdded(CurrentElement.Data.Number) then + If GeneralComporator(SortBy, CurrentElement, ComparingElement, IsAsc) = 1 then Begin - ComparingElement := CurrentElement; - Break; - End; - CurrentElement := CurrentElement.PNext; - End; - CurrentElement := MainList.PFirst; - - While CurrentElement <> nil do - Begin - Case SortBy of - 1: - If (CompareDescription(IsAsc, ComparingElement.Data.About[1], CurrentElement.Data.About[1]) = 1) and not (IsAlreadyAdded(CurrentElement.Data.Number)) then - Begin - ComparingElement := CurrentElement; - End; - 2: - If (CompareDate(IsAsc, ComparingElement.Data.DueTo, CurrentElement.Data.DueTo) = 1) and not (IsAlreadyAdded(CurrentElement.Data.Number)) then - Begin - ComparingElement := CurrentElement; - End; - 3: - If (ComparePriority(IsAsc, ComparingElement.Data.Priority, CurrentElement.Data.Priority) = 1) and not (IsAlreadyAdded(CurrentElement.Data.Number)) then - Begin - ComparingElement := CurrentElement; - End; + New(NewElement); + NewElement.Data := CurrentElement.Data; + InsB(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; - CurrentElement := CurrentElement.PNext; + ComparingElement := ComparingElement.PNext; End; - New(NewElement); - NewElement.Data := ComparingElement.Data; - AddNextElement(NewElement, SortedList); + CurrentElement := CurrentElement.PNext; End; End; @@ -584,7 +505,7 @@ TMainForm = class(TForm) FoundIn, I: Byte; Begin FoundIn := 100; - For I := 0 to 3 do + 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; @@ -604,7 +525,6 @@ TMainForm = class(TForm) Begin With AddNewForm do Begin - IsDone := False; DueTo := DatePick1.Date; Priority := PriorityBox1.ItemIndex + 1; About := InformationMemo1.Text; @@ -630,6 +550,33 @@ TMainForm = class(TForm) 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; + 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; + End; +End; + Procedure TMainForm.aClearAllExecute(Sender: TObject); Var IsConfirmed: Byte; @@ -646,7 +593,7 @@ TMainForm = class(TForm) Procedure TMainForm.AddNew1Click(Sender: TObject); Begin - AddNewForm.Show; + AddNewForm.ShowModal; End; Procedure DeleteListItem(var GivenList: TList; var DeletingElem : TListElem); @@ -715,7 +662,7 @@ TMainForm = class(TForm) Var DeletingElement: TListElem; Begin - DeletingElement := GetByNum(MainList, StrToInt(EditForm.SelectedRowIndicator.Caption)); + DeletingElement := GetByNum(MainList, EditingRowIndicator); DeleteListItem(MainList, DeletingElement); SaveList; OrderListAgain; @@ -728,6 +675,11 @@ TMainForm = class(TForm) End; End; +Procedure TMainForm.aDrawNoteExecute(Sender: TObject); +Begin + DrawForm.ShowModal; +End; + Procedure TMainForm.aEditRecordExecute(Sender: TObject); Var CurrentElem: TListElem; @@ -739,7 +691,7 @@ TMainForm = class(TForm) IsAlreadyEdited := False; While (CurrentElem <> nil) and not (IsAlreadyEdited) do Begin - If ElementNumber = StrToInt(EditForm.SelectedRowIndicator.Caption) then + If ElementNumber = EditingRowIndicator then Begin With CurrentElem.Data do Begin @@ -767,13 +719,14 @@ TMainForm = class(TForm) Procedure TMainForm.aNotesEditorExecute(Sender: TObject); Begin - NotesForm.Show; + NotesForm.ShowModal; NotesForm.aStartController.Execute; End; -Procedure TMainForm.aSettingsExecute(Sender: TObject); +Procedure TMainForm.aSetNotificationExecute(Sender: TObject); Begin - SettingsForm.Show; + NotificationForm.aSetComboBox.Execute; + NotificationForm.ShowModal; End; Procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean); @@ -786,25 +739,23 @@ TMainForm = class(TForm) Else Begin CanClose := False; - MainForm.Visible := False; - MainTrayIcon.Icon := Application.Icon; - MainTrayIcon.Visible := True; End; End; +Procedure CreateNewDirectory; +Begin + If not TDirectory.Exists(TPath.GetDocumentsPath + '\ReMind\') then + TDirectory.CreateDirectory(TPath.GetDocumentsPath + '\ReMind\'); +End; + Procedure TMainForm.FormCreate(Sender: TObject); -Var - IsFirstLaunch, FileHasUserName: Boolean; Begin DeleteList(MainList); SetColsWidth(MainGrid); NameFixedRows(MainGrid); - IsFirstLaunch := CheckFirstLaunch; - If IsFirstLaunch then - CreateNewFiles(); + CreateNewDirectory; RewriteGeneralFiles; ReadFileData; - //EditReadOnlyStatus(False); PrintList(MainGrid, MainList); Self.Caption := Self.Caption + ' v' + ProgramVersion; End; @@ -815,8 +766,6 @@ TMainForm = class(TForm) End; Procedure SetEditFormProperties(MainGrid: TStringGrid; Row: Integer); -Var - CaretPosition: TPoint; Begin With EditForm do Begin @@ -831,9 +780,9 @@ TMainForm = class(TForm) PriorityBox1.ItemIndex := 1 Else If Cells[3, Row] = 'Low' then PriorityBox1.ItemIndex := 0; - SelectedRowIndicator.Caption := Cells[0, Row]; + EditingRowIndicator := StrToInt(Cells[0, Row]); End; - Show; + ShowModal; End; End; @@ -845,7 +794,6 @@ TMainForm = class(TForm) Procedure TMainForm.MainApplicationEventsMinimize(Sender: TObject); Begin MainForm.Visible := False; - MainTrayIcon.Icon := Application.Icon; MainTrayIcon.Visible := True; End; @@ -871,7 +819,6 @@ TMainForm = class(TForm) MainGrid.Cells[ACol, ARow] := FixedRowCaptionsArray[ACol] + ' â–²' Else MainGrid.Cells[ACol, ARow] := FixedRowCaptionsArray[ACol] + ' â–¼'; - OrderAsc := not OrderAsc; PrintList(MainGrid, SortedList); End; If ACol = 0 then @@ -887,8 +834,8 @@ TMainForm = class(TForm) MainGrid.Cells[ACol, ARow] := FixedRowCaptionsArray[ACol] + ' â–²'; PrintListBackwards(MainGrid, MainList, GetListSize(MainList)); End; - OrderAsc := not OrderAsc; End; + OrderAsc := not OrderAsc; End; Procedure TMainForm.MainGridKeyPress(Sender: TObject; var Key: Char); @@ -899,16 +846,18 @@ TMainForm = class(TForm) End; End; -Procedure TMainForm.MainTrayIconClick(Sender: TObject); +Procedure TMainForm.MainTrayIconDblClick(Sender: TObject); Begin - MainTrayIcon.Visible := False; + MainTrayIcon.Visible := False; MainForm.Visible := True; MainForm.WindowState := wsNormal; + MainForm.FormStyle := fsStayOnTop; + MainForm.FormStyle := fsNormal; End; Procedure TMainForm.Settings1Click(Sender: TObject); Begin - SettingsForm.Show; + SettingsForm.ShowModal; End; Procedure TMainForm.tbDeleteAllClick(Sender: TObject); @@ -916,4 +865,9 @@ TMainForm = class(TForm) aClearAll.Execute; End; +Procedure TMainForm.tbDrawClick(Sender: TObject); +Begin + DrawForm.ShowModal; +End; + End. diff --git a/Notification.pas b/Notification.pas new file mode 100644 index 0000000..26c64c6 --- /dev/null +++ b/Notification.pas @@ -0,0 +1,278 @@ +Unit Notification; + +Interface + +Uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.WinXCalendars, System.IOUtils, + Vcl.WinXPickers, System.Actions, Vcl.ActnList, Vcl.Samples.Spin, DateUtils, Vcl.ExtCtrls, + System.Notification; + +Type + TNotificationForm = class(TForm) + DescriptionComboBox: TComboBox; + CustomDesc: TEdit; + SelectDesc: TLabel; + SelectTime: TLabel; + TimePicker: TTimePicker; + DatePicker: TCalendarPicker; + InformationMemo: TMemo; + AddButton: TButton; + NotificationsActionList: TActionList; + aSetComboBox: TAction; + DeleteSpinEdit: TSpinEdit; + DeleteButton: TButton; + NotificationTime: TTimer; + NotificationCenter: TNotificationCenter; + aLoadAndClose: TAction; + procedure FormActivate(Sender: TObject); + Procedure aSetComboBoxExecute(Sender: TObject); + Procedure DescriptionComboBoxChange(Sender: TObject); + Procedure AddButtonClick(Sender: TObject); + Procedure DeleteButtonClick(Sender: TObject); + Procedure NotificationTimeTimer(Sender: TObject); + Procedure aLoadAndCloseExecute(Sender: TObject); + Private + { Private declarations } + Public + { Public declarations } + End; + +Var + NotificationForm: TNotificationForm; + +Implementation + +{$R *.dfm} + +Uses Main; + +Type + TNotificationInfo = Record + Description: String[128]; + NotificationTime: TDateTime; + End; + +Const + FILE_NOTIFICATIONS: String = '\ReMind\notification.dat'; + +Var + ANotifications: Array of TNotificationInfo; + +Procedure QuickSort(var A: Array of TNotificationInfo; Min, Max: Integer); +Var + I, J: Integer; + Supp: TDateTime; + Temp: TNotificationInfo; +Begin + Supp := A[Max-((max-min) div 2)].NotificationTime; + I := Min; + J := Max; + While I Supp do + J := J - 1; + If i<=j then + Begin + Temp := A[I]; + A[I] := A[J]; + A[J] := Temp; + I := I + 1; + J := J - 1; + End; + End; + If Min < j then + QuickSort(A, min, J); + If I < Max then + QuickSort(A, I, Max); +End; + +Procedure AddNewNotificationToFile(); +Var + FNotification: File of TNotificationInfo; + I: Integer; +Begin + AssignFile(FNotification, TPath.GetDocumentsPath + FILE_NOTIFICATIONS); + Rewrite(FNotification); + For I := 0 to Length(ANotifications) - 1 do + Begin + Write(FNotification, ANotifications[I]); + End; + Close(FNotification); +End; + +Procedure AddNewNotificationToArray(Notification: TNotificationInfo); +Begin + SetLength(ANotifications, Length(ANotifications) + 1); + ANotifications[Length(ANotifications) - 1] := Notification; +End; + +Procedure ReadFileData(); +Var + FNotification: File of TNotificationInfo; + Notification: TNotificationInfo; +Begin + AssignFile(FNotification, TPath.GetDocumentsPath + FILE_NOTIFICATIONS); + If not FileExists(TPath.GetDocumentsPath + FILE_NOTIFICATIONS) then + Begin + Rewrite(FNotification); + End + Else + Reset(FNotification); + + While not Eof(FNotification) do + Begin + Read(FNotification, Notification); + AddNewNotificationToArray(Notification); + End; + Close(FNotification); +End; + +Procedure PrintNotifications(InformationMemo: TMemo); +Var + I: Integer; +Begin + InformationMemo.Clear; + For I := 0 to Length(ANotifications) - 1 do + Begin + With ANotifications[I] do + Begin + InformationMemo.Lines.Add(Description + ' ' + TimeToStr(NotificationTime) + ' • ' + DateToStr(NotificationTime)); + End; + End; +End; + +Procedure SetSpinEditValues(SE: TSpinEdit; DeleteButton: TButton); +Begin + If Length(ANotifications) = 0 then + Begin + SE.Text := '0'; + SE.MinValue := 0; + End + Else + SE.MinValue := 1; + SE.MaxValue := Length(ANotifications); + DeleteButton.Enabled := Length(ANotifications) > 0; +End; + +Procedure TNotificationForm.AddButtonClick(Sender: TObject); +Var + NewNotification: TNotificationInfo; + NotificationTime: TDateTime; +Begin + If DescriptionComboBox.ItemIndex = DescriptionComboBox.Items.Count - 1 then + NewNotification.Description := CustomDesc.Text + Else + NewNotification.Description := DescriptionComboBox.Text; + + ReplaceDate(NewNotification.NotificationTime, DatePicker.Date); + ReplaceTime(NewNotification.NotificationTime, TimePicker.Time); + AddNewNotificationToArray(NewNotification); + AddNewNotificationToFile(); + + QuickSort(ANotifications, 0, Length(ANotifications) - 1); + PrintNotifications(InformationMemo); + + aSetComboBox.Execute; + CustomDesc.Text := ''; + CustomDesc.Visible := False; + SetSpinEditValues(DeleteSpinEdit, DeleteButton); +End; + +Procedure TNotificationForm.aLoadAndCloseExecute(Sender: TObject); +Begin + Self.Hide; +End; + +Procedure TNotificationForm.aSetComboBoxExecute(Sender: TObject); +Var + I: Integer; +Begin + DescriptionComboBox.Clear; + For I := 1 to MainForm.MainGrid.RowCount - 1 do + Begin + DescriptionComboBox.Items.Add(MainForm.MainGrid.Cells[1, I]); + End; + DescriptionComboBox.Items.Add('Custom...'); + DatePicker.Date := Now; + TimePicker.Time := Now; +End; + +Procedure DeleteArrayElement(DIndex: Integer); +Var + I: Integer; +Begin + For I := DIndex to Length(ANotifications) - 2 do + Begin + ANotifications[I] := ANotifications[I + 1]; + End; + SetLength(ANotifications, Length(ANotifications) - 1); +End; + +Procedure TNotificationForm.DeleteButtonClick(Sender: TObject); +Var + DeletingItem: Integer; +Begin + DeletingItem := StrToInt(DeleteSpinEdit.Text) - 1; + DeleteArrayElement(DeletingItem); + PrintNotifications(InformationMemo); + SetSpinEditValues(DeleteSpinEdit, DeleteButton); + AddNewNotificationToFile(); +End; + +Procedure TNotificationForm.DescriptionComboBoxChange(Sender: TObject); +Begin + CustomDesc.Visible := DescriptionComboBox.ItemIndex = DescriptionComboBox.Items.Count - 1; +End; + +Procedure TNotificationForm.FormActivate(Sender: TObject); +Begin + InformationMemo.Clear; + SetLength(ANotifications, 0); + ReadFileData(); + If Length(ANotifications) <> 0 then + QuickSort(ANotifications, 0, Length(ANotifications) - 1); + PrintNotifications(InformationMemo); + SetSpinEditValues(DeleteSpinEdit, DeleteButton); +End; + +Procedure TNotificationForm.NotificationTimeTimer(Sender: TObject); +Var + Hour, Min, Sec, MSec: Word; + FHour, FMin, FSec, FMSec: Word; + NewTime, ExistingTime: TDateTime; + NewNotification: TNotification; +Begin + If Length(ANotifications) > 0 then + Begin + If CompareDate(Date, ANotifications[0].NotificationTime) = 0 then + Begin + DecodeTime(Now, Hour, Min, Sec, MSec); + NewTime := EncodeTime(Hour, Min, 0, 0); + ExistingTime := ANotifications[0].NotificationTime; + DecodeTime(ExistingTime, FHour, FMin, FSec, FMSec); + ExistingTime := EncodeTime(FHour, FMin, 0, 0); + If CompareTime(NewTime, ExistingTime) = 0 then + Begin + NewNotification := NotificationCenter.CreateNotification; + Try + NewNotification.Name := 'Name'; + NewNotification.Title := 'Re:Minder Notification'; + With ANotifications[0] do + NewNotification.AlertBody := Description + #13#10 + TimeToStr(NotificationTime) + ' • ' + DateToStr(NotificationTime); + NotificationCenter.PresentNotification(NewNotification); + Finally + NewNotification.Free; + End; + DeleteArrayElement(0); + PrintNotifications(InformationMemo); + SetSpinEditValues(DeleteSpinEdit, DeleteButton); + AddNewNotificationToFile(); + End; + End; + End; +End; + +End.