diff --git a/components/tvplanit/source/vpdata.pas b/components/tvplanit/source/vpdata.pas index 49f055371..12c475d11 100644 --- a/components/tvplanit/source/vpdata.pas +++ b/components/tvplanit/source/vpdata.pas @@ -1406,6 +1406,9 @@ begin { Category } { 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. } + if AEntry.PickedCategory > -1 then + FCategory := AEntry.PickedCategory + else if AEntry.CategoryCount > 0 then begin datastore := TVpCustomDatastore(Owner.Owner.Owner.Owner); k := -1; @@ -1777,8 +1780,8 @@ begin begin previewForm := TVpImportPreviewICalEventForm.Create(nil); previewForm.Position := poMainFormCenter; - previewForm.Calendar := ical; previewForm.Datastore := datastore; + previewForm.Calendar := ical; if ADefaultCategory <> -1 then previewForm.DefaultCategory := datastore.CategoryColorMap.GetCategoryName(ADefaultCategory); if not previewForm.Execute then diff --git a/components/tvplanit/source/vpical.pas b/components/tvplanit/source/vpical.pas index 20098341f..a8064cf68 100644 --- a/components/tvplanit/source/vpical.pas +++ b/components/tvplanit/source/vpical.pas @@ -67,6 +67,7 @@ type FRecurrenceByXXX: String; FAlarm: TVpICalAlarm; FCategories: TStrings; + FPickedCategory: Integer; function GetCategory(AIndex: Integer): String; function GetCategoryCount: Integer; function GetEndTime(UTC: Boolean): TDateTime; @@ -90,6 +91,7 @@ type property RecurrenceEndDate: TDateTime read FRecurrenceEndDate; property RecurrenceCount: Integer read FRecurrenceCount; property RecurrenceByXXX: String read FRecurrenceByXXX; + property PickedCategory: Integer read FPickedCategory write FPickedCategory; end; TVpICalToDo = class(TVpICalEntry) @@ -325,6 +327,7 @@ begin FCategories := TStringList.Create; FCategories.Delimiter := VALUE_DELIMITER; FCategories.StrictDelimiter := True; + FCategories.SkipLastLineBreak := True; end; destructor TVpICalEvent.Destroy; diff --git a/components/tvplanit/source/vpimportpreview_icalevent.lfm b/components/tvplanit/source/vpimportpreview_icalevent.lfm index f99a076ab..933da93e1 100644 --- a/components/tvplanit/source/vpimportpreview_icalevent.lfm +++ b/components/tvplanit/source/vpimportpreview_icalevent.lfm @@ -22,6 +22,9 @@ inherited VpImportPreviewICalEventForm: TVpImportPreviewICalEventForm Title.Caption = 'Items' Width = 634 end> + OnGetEditText = GridGetEditText + OnPickListSelect = GridPickListSelect + OnSetEditText = GridSetEditText ColWidths = ( 33 634 diff --git a/components/tvplanit/source/vpimportpreview_icalevent.pas b/components/tvplanit/source/vpimportpreview_icalevent.pas index 00410f0f9..cfbb46666 100644 --- a/components/tvplanit/source/vpimportpreview_icalevent.pas +++ b/components/tvplanit/source/vpimportpreview_icalevent.pas @@ -4,15 +4,20 @@ unit VpImportPreview_ICalEvent; interface -uses +uses lazlogger, Classes, SysUtils, Forms, Controls, Graphics, Dialogs, - VpData, VpBaseDS, VpImportPreview, VpICal; + VpData, VpBaseDS, VpImportPreview, VpICal, Grids; type { TVpImportPreviewICalEventForm } 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 FCalendar: TVpICalendar; FDatastore: TVpCustomDatastore; @@ -32,8 +37,6 @@ type property Calendar: TVpICalendar read FCalendar write SetCalendar; property Datastore: TVpCustomDatastore read FDatastore write FDatastore; property DefaultCategory: String read FDefaultCategory write FDefaultCategory; -// property Kind: TVpICalItemKind read FKind write SetKind; - end; var @@ -66,14 +69,19 @@ end; function TVpImportPreviewICalEventForm.GetCellText(ACol, ARow: Integer): String; var - item: TVpICalEntry; + event: TVpICalEvent; begin Result := ''; - if (ACol = 1) and (ARow >= Grid.FixedRows) then + if (ARow >= Grid.FixedRows) then begin - item := TVpICalEntry(FItems[ARow - Grid.FixedRows]); - if item <> nil then - Result := GetEventText(TVpICalEvent(item)); + event := TVpICalEvent(FItems[ARow - Grid.FixedRows]); + if event <> nil then + 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; @@ -109,8 +117,10 @@ begin // Categories if Assigned(FDatastore) then begin - cat := FDatastore.FindBestEventCategory(AEvent.Categories); - if cat = '' then cat := FDefaultCategory; + cat := AEvent.Categories.Text; + if cat = '' then cat := '(none)'; +// cat := FDatastore.FindBestEventCategory(AEvent.Categories); +// if cat = '' then cat := FDefaultCategory; Result := Result + cat; end; @@ -170,6 +180,44 @@ begin Result := Result + LineEnding + RSNoAlarm; 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; var item: TVpICalEntry; @@ -185,6 +233,9 @@ end; procedure TVpImportPreviewICalEventForm.PrepareItems; var i: Integer; + L: TStrings; + event: TVpICalEvent; + cat: String; begin FItems.Clear; if FCalendar <> nil then @@ -192,6 +243,33 @@ begin if (FCalendar.Entry[i] is TVpICalEvent) then FItems.Add(FCalendar.Entry[i]); 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; procedure TVpImportPreviewICalEventForm.SetCalendar(const AValue: TVpICalendar); diff --git a/components/tvplanit/source/vpimportpreview_icaltask.lfm b/components/tvplanit/source/vpimportpreview_icaltask.lfm index 8b5509edc..266da2526 100644 --- a/components/tvplanit/source/vpimportpreview_icaltask.lfm +++ b/components/tvplanit/source/vpimportpreview_icaltask.lfm @@ -20,11 +20,11 @@ inherited VpImportPreviewICalTaskForm: TVpImportPreviewICalTaskForm PickList.Strings = ( ) ReadOnly = True Title.Caption = 'Items' - Width = 630 + Width = 634 end> ColWidths = ( 33 - 630 + 634 ) end inherited ButtonPanel: TPanel