tvplanit: Alternate solution for issue #39061

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9090 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-12-17 23:18:28 +00:00
parent 58b00ac007
commit 7548f46b4f
13 changed files with 674 additions and 58 deletions

View File

@ -4,27 +4,43 @@ unit VpImportPreview_ICalEvent;
interface
uses lazlogger,
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
VpData, VpBaseDS, VpImportPreview, VpICal, Grids;
uses
LCLVersion, Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
VpData, VpBaseDS, VpImportPreview, VpICal, Grids, StdCtrls, Spin;
type
{ TVpImportPreviewICalEventForm }
TVpImportPreviewICalEventForm = class(TVpImportPreviewForm)
procedure GridGetEditText(Sender: TObject; {%H-}ACol, {%H-}ARow: Integer;
lblOpenEndDuration: TLabel;
rbOpenEndDuration30mins: TRadioButton;
rbOpenEndDuration1Hr: TRadioButton;
rbOpenEndDuration2Hrs: TRadioButton;
rbOpenEndDuration4Hrs: TRadioButton;
procedure btnExecuteClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure GridGetEditText(Sender: TObject; {%H-}ACol, {%H-}ARow: Integer;
var Value: string);
procedure GridSetEditText(Sender: TObject; {%H-}ACol, {%H-}ARow: Integer;
const Value: string);
private
FActivated: Boolean;
FCalendar: TVpICalendar;
FDefaultCategory: String;
FTimeFormat: String;
function GetEventText(AEvent: TVpICalEvent): String;
procedure SetCalendar(const AValue: TVpICalendar);
{$IF LCL_FullVersion >= 3000000}
private
FCanCloseTaskDialog: Boolean;
procedure OpenEndEventsDialog;
procedure OpenendEventsDialogButtonClicked(Sender: TObject;
AModalResult: TModalResult; var ACanClose: Boolean);
procedure OpenEndEventsDialogRadioButtonClicked(Sender: TObject);
{$ENDIF}
protected
function GetCellText(ACol, ARow: Integer): String; override;
procedure PrepareItems; override;
@ -55,6 +71,12 @@ begin
Grid.OnSetEditText := @GridSetEditText;
Caption := RSImportICalEvent;
lblOpenEndDuration.Caption := RSOpenEndEventsDurationLbl;
rbOpenEndDuration30mins.Caption := RS30Minutes;
rbOpenEndDuration1Hr.Caption := RS1Hour;
rbOpenEndDuration2Hrs.Caption := RS2Hours;
rbOpenEndDuration4Hrs.Caption := RS4Hours;
FTimeFormat := 'c'; // short date + long time format
end;
@ -196,6 +218,49 @@ begin
Value := Grid.Columns[2].PickList[event.PickedCategory];
end;
procedure TVpImportPreviewICalEventForm.btnExecuteClick(Sender: TObject);
begin
if FCalendar.ContainsOpenEndEvents then
begin
{$IF LCL_FullVersion >= 3000000}
OpenEndEventsDialog;
{$ELSE}
if not (rbOpenEndDuration30mins.Checked or rbOpenEndDuration1Hr.Checked or
rbOpenEndDuration2Hrs.Checked or rbOpenEndDuration4Hrs.Checked) then
begin
MessageDlg(RSDurationForOpenEndEvents, mtInformation, [mbOK], 0);
ModalResult := mrNone;
exit;
end;
if rbOpenEndDuration30mins.Checked then
FCalendar.FixOpenEndEvents(0.5/24)
else if rbOpenEndDuration1Hr.Checked then
FCalendar.FixOpenEndEvents(1.0/24)
else if rbOpenEndDuration2Hrs.Checked then
FCalendar.FixOpenEndEvents(2.0/24)
else if rbOpenEndDuration4Hrs.Checked then
FCalendar.FixOpenEndEvents(4.0/24);
{$IFEND}
end;
end;
procedure TVpImportPreviewICalEventForm.FormActivate(Sender: TObject);
var
x1: Integer = 0;
x2: Integer;
begin
if not FActivated then
begin
FActivated := true;
{$IF LCL_FullVersion < 3000000} // This part is only seen without Taskdialog
x1 := rbOpenEndDuration4Hrs.Left + rbOpenEndDuration4Hrs.Width;
{$IFEND}
x2 := ClientWidth - btnExecute.Left + btnExecute.BorderSpacing.Left;
Constraints.MinWidth := x1 + x2;
if Width < Constraints.MinWidth then Width := 0;
end;
end;
procedure TVpImportPreviewICalEventForm.GridSetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: string);
var
@ -217,7 +282,55 @@ begin
if (item <> nil) then
Result := item.Checked;
end;
{$IF LCL_FullVersion >= 3000000}
procedure TVpImportPreviewICalEventForm.OpenendEventsDialog;
const
DURATIONS: array[0..3] of Double = (0.5/24, 1.0/24, 2.0/24, 4.0/24);
var
dlg: TTaskDialog;
begin
dlg := TTaskDialog.Create(nil);
try
dlg.Caption := RSImportICalendarEvents;
dlg.Title := RSOpenEndEvents;
dlg.Text := RSDurationForOpenEndEvents;
dlg.RadioButtons.Add.Caption := RSHalfAnHour;
dlg.RadioButtons.Add.Caption := RSOneHour;
dlg.RadioButtons.Add.Caption := RSTwoHours;
dlg.RadioButtons.Add.Caption := RSFourHours;
dlg.OnButtonClicked := @OpenEndEventsDialogButtonClicked;
dlg.OnRadioButtonClicked := @OpenEndEventsDialogRadioButtonClicked;
dlg.Flags := dlg.Flags + [tfNoDefaultRadioButton];
dlg.Execute;
if dlg.ModalResult = mrOK then
FCalendar.FixOpenEndEvents(DURATIONS[dlg.RadioButton.Index]);
finally
dlg.Free;
end;
end;
procedure TVpImportPreviewICalEventForm.OpenendEventsDialogButtonClicked(
Sender: TObject; AModalResult: TModalResult; var ACanClose: Boolean);
var
i: Integer;
begin
if AModalResult = mrCancel then
exit;
with TTaskDialog(Sender) do
ACanClose := FCanCloseTaskDialog;
if not ACanClose then
MessageDlg(RSNoEventDurationSelected, mtError, [mbOK], 0);
end;
procedure TVpImportPreviewICalEventForm.OpenEndEventsDialogRadioButtonClicked(Sender: TObject);
begin
FCanCloseTaskDialog := true;
end;
{$ENDIF}
procedure TVpImportPreviewICalEventForm.PrepareItems;
var
i: Integer;
@ -240,6 +353,7 @@ begin
FItems.Clear;
if (FCalendar <> nil) and (Datastore <> nil) then
begin
for i := 0 to FCalendar.Count-1 do
if (FCalendar.Entry[i] is TVpICalEvent) then
begin
@ -254,7 +368,16 @@ begin
else
event.PickedCategory := 0;
end;
{$IF LCL_FullVersion < 3000000}
lblOpenEndDuration.Visible := FCalendar.ContainsOpenEndEvents;
rbOpenEndDuration30mins.Visible := lblOpenEndDuration.Visible;
rbOpenEndDuration1Hr.Visible := lblOpenEndDuration.Visible;
rbOpenEndDuration2Hrs.Visible := lblOpenEndDuration.Visible;
rbOpenEndDuration4Hrs.Visible := lblOpenEndDuration.Visible;
{$IFEND}
end;
inherited;
end;