From 774c1feda36cb18946c120d919885dc3851d5814 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 20 Aug 2022 19:38:02 +0000 Subject: [PATCH] tvplanit: TVpWeekView supports export of events to ical files. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8403 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpdayview.pas | 6 +- components/tvplanit/source/vpweekview.pas | 86 ++++++++++++++++------- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/components/tvplanit/source/vpdayview.pas b/components/tvplanit/source/vpdayview.pas index 9f85917e3..15b3a34d9 100644 --- a/components/tvplanit/source/vpdayview.pas +++ b/components/tvplanit/source/vpdayview.pas @@ -2411,10 +2411,8 @@ end; procedure TVpDayview.ExportICalFile(const AFileName: String; const AEvents: TVpEventArr); begin - if (not Assigned(Datastore)) or (not Assigned(Datastore.Resource)) then - exit; - - Datastore.Resource.Schedule.ExportICalFile(AFileName, AEvents); + if Assigned(Datastore) and Assigned(Datastore.Resource) then + Datastore.Resource.Schedule.ExportICalFile(AFileName, AEvents); end; { Reads the events listed in the specified ical file and adds them to the diff --git a/components/tvplanit/source/vpweekview.pas b/components/tvplanit/source/vpweekview.pas index 8dcf7711b..8fb5663f7 100644 --- a/components/tvplanit/source/vpweekview.pas +++ b/components/tvplanit/source/vpweekview.pas @@ -205,10 +205,12 @@ type { Popup } function GetPopupMenu: TPopupMenu; override; + procedure InitializeDefaultPopup; procedure PopupAddEvent(Sender: TObject); - procedure PopupAddFromICalFile(Sender: TObject); procedure PopupDeleteEvent(Sender: TObject); procedure PopupEditEvent(Sender: TObject); + procedure PopupExportToICalFile(Sender: TObject); + procedure PopupImportFromICalFile(Sender: TObject); procedure PopupToday(Sender: TObject); procedure PopupNextWeek(Sender: TObject); procedure PopupPrevWeek(Sender: TObject); @@ -218,7 +220,6 @@ type procedure PopupPrevYear(Sender: TObject); procedure PopupCustomDate(Sender: TObject); procedure PopupPickResourceGroupEvent(Sender: TObject); - procedure InitializeDefaultPopup; { internal methods } procedure SpinButtonClick(Sender: TObject); @@ -279,6 +280,7 @@ type procedure LoadLanguage; procedure DeleteActiveEvent(Verify: Boolean); procedure DragDrop(Source: TObject; X, Y: Integer); override; + procedure ExportICalFile(const AFileName: String; const AEvents: TVpEventArr); function ImportICalFile(const AFileName: String; APreview: Boolean = false; ADefaultCategory: Integer = -1): TVpEventArr; procedure Invalidate; override; @@ -1106,6 +1108,13 @@ begin end; end; +procedure TVpWeekView.ExportICalFile(const AFileName: String; + const AEvents: TVpEventArr); +begin + if Assigned(Datastore) and Assigned(Datastore.Resource) then + Datastore.Resource.Schedule.ExportICalFile(AFileName, AEvents); +end; + { Reads the events listed in the specified ical file and adds them to the day view control. All events imported are collected in the Result array. ADefaultCategory is the category to which the event is assigned if no fitting @@ -1230,12 +1239,20 @@ begin if RSPopupImportEventFromICal <> '' then begin NewItem := TVpMenuItem.Create(Self); NewItem.Kind := mikImportEventFromICal; // Import from iCal - NewItem.OnClick := PopupAddFromICalFile; + NewItem.OnClick := PopupImportFromICalFile; NewItem.Tag := 0; FDefaultPopup.Items.Add(NewItem); end; - NewItem := TVpMenuItem.Create(Self); // --- + if RSPopupExportEventToICal <> '' then begin + NewItem := TVpMenuItem.Create(Self); + NewItem.Kind := mikExportEventToICal; // Export to iCal + NewItem.OnClick := PopupExportToICalFile; + NewItem.Tag := 1; + FDefaultPopup.Items.Add(NewItem); + end; + + NewItem := TVpMenuItem.Create(Self); // --- NewItem.Kind := mikSeparator; FDefaultPopup.Items.Add(NewItem); @@ -1352,9 +1369,47 @@ begin { edit this new event } wvSpawnEventEditDialog(True); end; -{=====} -procedure TVpWeekView.PopupAddFromICalFile(Sender: TObject); +procedure TVpWeekView.PopupDeleteEvent(Sender: TObject); +begin + if ReadOnly then + Exit; + if ActiveEvent <> nil then + DeleteActiveEvent (True); +end; + +procedure TVpWeekView.PopupEditEvent(Sender: TObject); +begin + if ReadOnly then + Exit; + if ActiveEvent <> nil then + { edit this Event } + wvSpawnEventEditDialog(False); +end; + +procedure TVpWeekView.PopupExportToICalFile(Sender: TObject); +var + dlg: TSaveDialog; +begin + if (not Assigned(Datastore)) or (not Assigned(Datastore.Resource)) or + (FActiveEvent = nil) + then + exit; + + dlg := TSaveDialog.Create(nil); + try + dlg.Title := RSSaveICalTitle; + dlg.Filter := RSICalFilter; + dlg.FileName := ''; + dlg.Options := dlg.Options - [ofAllowMultiSelect] + [ofOverwritePrompt]; + if dlg.Execute then + ExportICalFile(dlg.FileName, [FActiveEvent]); + finally + dlg.Free; + end; +end; + +procedure TVpWeekView.PopupImportFromICalFile(Sender: TObject); var dlg: TOpenDialog; fn: String; @@ -1379,25 +1434,6 @@ begin end; end; -procedure TVpWeekView.PopupDeleteEvent(Sender: TObject); -begin - if ReadOnly then - Exit; - if ActiveEvent <> nil then - DeleteActiveEvent (True); -end; -{=====} - -procedure TVpWeekView.PopupEditEvent(Sender: TObject); -begin - if ReadOnly then - Exit; - if ActiveEvent <> nil then - { edit this Event } - wvSpawnEventEditDialog(False); -end; -{=====} - procedure TVpWeekView.EditSelectedEvent(IsNewEvent: Boolean = false); begin if ActiveEvent <> nil then