tvplanit: Add option to select category to ical event import form.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8382 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-08-12 09:50:18 +00:00
parent d97209a2a3
commit 5d091a3a05
5 changed files with 101 additions and 14 deletions

View File

@ -1406,6 +1406,9 @@ begin
{ Category } { Category }
{ tvplanit has only 1 category, ical may have several. We pick the first one { tvplanit has only 1 category, ical may have several. We pick the first one
defined in the datastore. If none is defined we create the first one. } defined in the datastore. If none is defined we create the first one. }
if AEntry.PickedCategory > -1 then
FCategory := AEntry.PickedCategory
else
if AEntry.CategoryCount > 0 then begin if AEntry.CategoryCount > 0 then begin
datastore := TVpCustomDatastore(Owner.Owner.Owner.Owner); datastore := TVpCustomDatastore(Owner.Owner.Owner.Owner);
k := -1; k := -1;
@ -1777,8 +1780,8 @@ begin
begin begin
previewForm := TVpImportPreviewICalEventForm.Create(nil); previewForm := TVpImportPreviewICalEventForm.Create(nil);
previewForm.Position := poMainFormCenter; previewForm.Position := poMainFormCenter;
previewForm.Calendar := ical;
previewForm.Datastore := datastore; previewForm.Datastore := datastore;
previewForm.Calendar := ical;
if ADefaultCategory <> -1 then if ADefaultCategory <> -1 then
previewForm.DefaultCategory := datastore.CategoryColorMap.GetCategoryName(ADefaultCategory); previewForm.DefaultCategory := datastore.CategoryColorMap.GetCategoryName(ADefaultCategory);
if not previewForm.Execute then if not previewForm.Execute then

View File

@ -67,6 +67,7 @@ type
FRecurrenceByXXX: String; FRecurrenceByXXX: String;
FAlarm: TVpICalAlarm; FAlarm: TVpICalAlarm;
FCategories: TStrings; FCategories: TStrings;
FPickedCategory: Integer;
function GetCategory(AIndex: Integer): String; function GetCategory(AIndex: Integer): String;
function GetCategoryCount: Integer; function GetCategoryCount: Integer;
function GetEndTime(UTC: Boolean): TDateTime; function GetEndTime(UTC: Boolean): TDateTime;
@ -90,6 +91,7 @@ type
property RecurrenceEndDate: TDateTime read FRecurrenceEndDate; property RecurrenceEndDate: TDateTime read FRecurrenceEndDate;
property RecurrenceCount: Integer read FRecurrenceCount; property RecurrenceCount: Integer read FRecurrenceCount;
property RecurrenceByXXX: String read FRecurrenceByXXX; property RecurrenceByXXX: String read FRecurrenceByXXX;
property PickedCategory: Integer read FPickedCategory write FPickedCategory;
end; end;
TVpICalToDo = class(TVpICalEntry) TVpICalToDo = class(TVpICalEntry)
@ -325,6 +327,7 @@ begin
FCategories := TStringList.Create; FCategories := TStringList.Create;
FCategories.Delimiter := VALUE_DELIMITER; FCategories.Delimiter := VALUE_DELIMITER;
FCategories.StrictDelimiter := True; FCategories.StrictDelimiter := True;
FCategories.SkipLastLineBreak := True;
end; end;
destructor TVpICalEvent.Destroy; destructor TVpICalEvent.Destroy;

View File

@ -22,6 +22,9 @@ inherited VpImportPreviewICalEventForm: TVpImportPreviewICalEventForm
Title.Caption = 'Items' Title.Caption = 'Items'
Width = 634 Width = 634
end> end>
OnGetEditText = GridGetEditText
OnPickListSelect = GridPickListSelect
OnSetEditText = GridSetEditText
ColWidths = ( ColWidths = (
33 33
634 634

View File

@ -4,15 +4,20 @@ unit VpImportPreview_ICalEvent;
interface interface
uses uses lazlogger,
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
VpData, VpBaseDS, VpImportPreview, VpICal; VpData, VpBaseDS, VpImportPreview, VpICal, Grids;
type type
{ TVpImportPreviewICalEventForm } { TVpImportPreviewICalEventForm }
TVpImportPreviewICalEventForm = class(TVpImportPreviewForm) TVpImportPreviewICalEventForm = class(TVpImportPreviewForm)
procedure GridGetEditText(Sender: TObject; ACol, ARow: Integer;
var Value: string);
procedure GridPickListSelect(Sender: TObject);
procedure GridSetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: string);
private private
FCalendar: TVpICalendar; FCalendar: TVpICalendar;
FDatastore: TVpCustomDatastore; FDatastore: TVpCustomDatastore;
@ -32,8 +37,6 @@ type
property Calendar: TVpICalendar read FCalendar write SetCalendar; property Calendar: TVpICalendar read FCalendar write SetCalendar;
property Datastore: TVpCustomDatastore read FDatastore write FDatastore; property Datastore: TVpCustomDatastore read FDatastore write FDatastore;
property DefaultCategory: String read FDefaultCategory write FDefaultCategory; property DefaultCategory: String read FDefaultCategory write FDefaultCategory;
// property Kind: TVpICalItemKind read FKind write SetKind;
end; end;
var var
@ -66,14 +69,19 @@ end;
function TVpImportPreviewICalEventForm.GetCellText(ACol, ARow: Integer): String; function TVpImportPreviewICalEventForm.GetCellText(ACol, ARow: Integer): String;
var var
item: TVpICalEntry; event: TVpICalEvent;
begin begin
Result := ''; Result := '';
if (ACol = 1) and (ARow >= Grid.FixedRows) then if (ARow >= Grid.FixedRows) then
begin begin
item := TVpICalEntry(FItems[ARow - Grid.FixedRows]); event := TVpICalEvent(FItems[ARow - Grid.FixedRows]);
if item <> nil then if event <> nil then
Result := GetEventText(TVpICalEvent(item)); case ACol of
1: Result := GetEventText(event);
2: Result := Grid.Columns[2].PickList[event.PickedCategory];
//if FDatastore <> nil then
// Result := FDatastore.FindBestEventCategory(TVpICalEvent(item).Categories);
end;
end; end;
end; end;
@ -109,8 +117,10 @@ begin
// Categories // Categories
if Assigned(FDatastore) then if Assigned(FDatastore) then
begin begin
cat := FDatastore.FindBestEventCategory(AEvent.Categories); cat := AEvent.Categories.Text;
if cat = '' then cat := FDefaultCategory; if cat = '' then cat := '(none)';
// cat := FDatastore.FindBestEventCategory(AEvent.Categories);
// if cat = '' then cat := FDefaultCategory;
Result := Result + cat; Result := Result + cat;
end; end;
@ -170,6 +180,44 @@ begin
Result := Result + LineEnding + RSNoAlarm; Result := Result + LineEnding + RSNoAlarm;
end; end;
procedure TVpImportPreviewICalEventForm.GridGetEditText(Sender: TObject; ACol,
ARow: Integer; var Value: string);
var
event: TVpICalEvent;
begin
DebugLn('GetEditText: "' + Value + '"');
event := TVpICalEvent(FItems[Grid.Row - Grid.FixedRows]);
if event <> nil then
Value := Grid.Columns[2].PickList[event.PickedCategory];
end;
procedure TVpImportPreviewICalEventForm.GridPickListSelect(Sender: TObject);
var
item: TVpICalEntry;
cat: String;
col: TGridcolumn;
begin
item := TVpICalEntry(FItems[Grid.Row - Grid.FixedRows]);
if item <> nil then
begin
col := Grid.Columns[2];
//TVpICalEvent(item).PickedCategory := Grid.Columns[2].PickList.IndexOf(ItemIndex);
end;
end;
procedure TVpImportPreviewICalEventForm.GridSetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: string);
var
event: TVpICalEvent;
begin
event := TVpICalEvent(FItems[Grid.Row - Grid.FixedRows]);
if event <> nil then
event.PickedCategory := Grid.Columns[2].PickList.IndexOf(Value);;
// DebugLn('SetEditText: "' + Value + '"');
end;
function TVpImportPreviewICalEventForm.IsChecked(ARow: Integer): Boolean; function TVpImportPreviewICalEventForm.IsChecked(ARow: Integer): Boolean;
var var
item: TVpICalEntry; item: TVpICalEntry;
@ -185,6 +233,9 @@ end;
procedure TVpImportPreviewICalEventForm.PrepareItems; procedure TVpImportPreviewICalEventForm.PrepareItems;
var var
i: Integer; i: Integer;
L: TStrings;
event: TVpICalEvent;
cat: String;
begin begin
FItems.Clear; FItems.Clear;
if FCalendar <> nil then if FCalendar <> nil then
@ -192,6 +243,33 @@ begin
if (FCalendar.Entry[i] is TVpICalEvent) then if (FCalendar.Entry[i] is TVpICalEvent) then
FItems.Add(FCalendar.Entry[i]); FItems.Add(FCalendar.Entry[i]);
inherited; inherited;
if (FCalendar <> nil) and (FDataStore <> nil) and (Grid.Columns.Count = 2) then
begin
with Grid.Columns.Add do
begin
SizePriority := 0;
Width := 160;
Title.Caption := 'Category';
ButtonStyle := cbsPickList;
L := TStringList.Create;
try
for i := 0 to 9 do
L.Add(FDatastore.CategoryColorMap.GetName(i));
PickList.Assign(L);
finally
L.Free;
end;
end;
for i := 0 to FItems.Count-1 do
begin
event := TVpICalEvent(FItems[i]);
cat := FDatastore.FindBestEventCategory(event.Categories);
if cat = '' then cat := FDefaultCategory;
event.PickedCategory := Grid.Columns[2].PickList.IndexOf(cat)
end;
end;
end; end;
procedure TVpImportPreviewICalEventForm.SetCalendar(const AValue: TVpICalendar); procedure TVpImportPreviewICalEventForm.SetCalendar(const AValue: TVpICalendar);

View File

@ -20,11 +20,11 @@ inherited VpImportPreviewICalTaskForm: TVpImportPreviewICalTaskForm
PickList.Strings = ( ) PickList.Strings = ( )
ReadOnly = True ReadOnly = True
Title.Caption = 'Items' Title.Caption = 'Items'
Width = 630 Width = 634
end> end>
ColWidths = ( ColWidths = (
33 33
630 634
) )
end end
inherited ButtonPanel: TPanel inherited ButtonPanel: TPanel