You've already forked lazarus-ccr
tvplanit: Refactor ical and vcard import forms to reduce duplicate code.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8397 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -6,6 +6,7 @@ object VpImportPreviewForm: TVpImportPreviewForm
|
||||
Caption = 'VpImportPreviewForm'
|
||||
ClientHeight = 295
|
||||
ClientWidth = 603
|
||||
LCLVersion = '2.3.0.0'
|
||||
object Grid: TDrawGrid
|
||||
Left = 0
|
||||
Height = 258
|
||||
@ -13,7 +14,7 @@ object VpImportPreviewForm: TVpImportPreviewForm
|
||||
Width = 603
|
||||
Align = alClient
|
||||
AutoFillColumns = True
|
||||
ColCount = 2
|
||||
ColCount = 3
|
||||
Columns = <
|
||||
item
|
||||
Alignment = taCenter
|
||||
@ -24,8 +25,14 @@ object VpImportPreviewForm: TVpImportPreviewForm
|
||||
end
|
||||
item
|
||||
ReadOnly = True
|
||||
Title.Caption = 'Items'
|
||||
Width = 566
|
||||
Title.Caption = 'Title'
|
||||
Width = 410
|
||||
end
|
||||
item
|
||||
ButtonStyle = cbsPickList
|
||||
SizePriority = 0
|
||||
Title.Caption = 'Title'
|
||||
Width = 160
|
||||
end>
|
||||
ExtendedSelect = False
|
||||
FixedCols = 0
|
||||
@ -37,7 +44,8 @@ object VpImportPreviewForm: TVpImportPreviewForm
|
||||
OnSetCheckboxState = GridSetCheckboxState
|
||||
ColWidths = (
|
||||
33
|
||||
566
|
||||
410
|
||||
160
|
||||
)
|
||||
end
|
||||
object ButtonPanel: TPanel
|
||||
|
@ -1,7 +1,8 @@
|
||||
{"version":1,"strings":[
|
||||
{"hash":185343357,"name":"tvpimportpreviewform.caption","sourcebytes":[86,112,73,109,112,111,114,116,80,114,101,118,105,101,119,70,111,114,109],"value":"VpImportPreviewForm"},
|
||||
{"hash":4294967295,"name":"tvpimportpreviewform.grid.columns[0].title.caption","sourcebytes":[],"value":""},
|
||||
{"hash":5286979,"name":"tvpimportpreviewform.grid.columns[1].title.caption","sourcebytes":[73,116,101,109,115],"value":"Items"},
|
||||
{"hash":5966629,"name":"tvpimportpreviewform.grid.columns[1].title.caption","sourcebytes":[84,105,116,108,101],"value":"Title"},
|
||||
{"hash":5966629,"name":"tvpimportpreviewform.grid.columns[2].title.caption","sourcebytes":[84,105,116,108,101],"value":"Title"},
|
||||
{"hash":202226323,"name":"tvpimportpreviewform.btnexecute.caption","sourcebytes":[73,109,112,111,114,116,32,99,104,101,99,107,101,100,32,105,116,101,109,115],"value":"Import checked items"},
|
||||
{"hash":77089212,"name":"tvpimportpreviewform.btncancel.caption","sourcebytes":[67,97,110,99,101,108],"value":"Cancel"}
|
||||
]}
|
||||
|
@ -6,7 +6,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Graphics, Types,
|
||||
Forms, Controls, Dialogs, Grids, ExtCtrls, StdCtrls;
|
||||
Forms, Controls, Dialogs, Grids, ExtCtrls, StdCtrls, VpBaseDS;
|
||||
|
||||
type
|
||||
{ TVpImportPreviewForm }
|
||||
@ -25,6 +25,8 @@ type
|
||||
procedure GridSetCheckboxState(Sender: TObject; {%H-}ACol, ARow: Integer;
|
||||
const Value: TCheckboxState);
|
||||
private
|
||||
FDatastore: TVpCustomDatastore;
|
||||
procedure SetDatastore(const AValue: TVpCustomDatastore);
|
||||
|
||||
protected
|
||||
FItems: TFPList;
|
||||
@ -38,6 +40,7 @@ type
|
||||
procedure CheckItem({%H-}ARow: Integer; {%H-}AChecked: Boolean); virtual;
|
||||
function Execute: Boolean;
|
||||
function IsChecked({%H-}ARow: Integer): Boolean; virtual;
|
||||
property Datastore: TVpCustomDatastore read FDatastore write SetDatastore;
|
||||
|
||||
end;
|
||||
|
||||
@ -176,5 +179,14 @@ begin
|
||||
CalcRowHeights;
|
||||
end;
|
||||
|
||||
procedure TVpImportPreviewForm.SetDatastore(const AValue: TVpCustomDatastore);
|
||||
begin
|
||||
if AValue <> FDatastore then
|
||||
begin
|
||||
FDatastore := AValue;
|
||||
PrepareItems;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -4,31 +4,6 @@ inherited VpImportPreviewICalEventForm: TVpImportPreviewICalEventForm
|
||||
Caption = ''
|
||||
ClientHeight = 400
|
||||
ClientWidth = 667
|
||||
inherited Grid: TDrawGrid
|
||||
Height = 363
|
||||
Width = 667
|
||||
Columns = <
|
||||
item
|
||||
Alignment = taCenter
|
||||
ButtonStyle = cbsCheckboxColumn
|
||||
PickList.Strings = ( )
|
||||
SizePriority = 0
|
||||
Title.Caption = ''
|
||||
Width = 33
|
||||
end
|
||||
item
|
||||
PickList.Strings = ( )
|
||||
ReadOnly = True
|
||||
Title.Caption = 'Items'
|
||||
Width = 634
|
||||
end>
|
||||
OnGetEditText = GridGetEditText
|
||||
OnSetEditText = GridSetEditText
|
||||
ColWidths = (
|
||||
33
|
||||
634
|
||||
)
|
||||
end
|
||||
inherited ButtonPanel: TPanel
|
||||
Top = 369
|
||||
Width = 655
|
||||
|
@ -1,5 +1,3 @@
|
||||
{"version":1,"strings":[
|
||||
{"hash":4294967295,"name":"tvpimportpreviewicaleventform.caption","sourcebytes":[],"value":""},
|
||||
{"hash":4294967295,"name":"tvpimportpreviewicaleventform.grid.columns[0].title.caption","sourcebytes":[],"value":""},
|
||||
{"hash":5286979,"name":"tvpimportpreviewicaleventform.grid.columns[1].title.caption","sourcebytes":[73,116,101,109,115],"value":"Items"}
|
||||
{"hash":4294967295,"name":"tvpimportpreviewicaleventform.caption","sourcebytes":[],"value":""}
|
||||
]}
|
||||
|
@ -19,7 +19,6 @@ type
|
||||
const Value: string);
|
||||
private
|
||||
FCalendar: TVpICalendar;
|
||||
FDatastore: TVpCustomDatastore;
|
||||
FDefaultCategory: String;
|
||||
FTimeFormat: String;
|
||||
function GetEventText(AEvent: TVpICalEvent): String;
|
||||
@ -35,7 +34,6 @@ type
|
||||
procedure CheckItem(ARow: Integer; AChecked: Boolean); override;
|
||||
function IsChecked(ARow: Integer): Boolean; override;
|
||||
property Calendar: TVpICalendar read FCalendar write SetCalendar;
|
||||
property Datastore: TVpCustomDatastore read FDatastore write FDatastore;
|
||||
property DefaultCategory: String read FDefaultCategory write FDefaultCategory;
|
||||
end;
|
||||
|
||||
@ -52,6 +50,10 @@ uses
|
||||
constructor TVPImportPreviewICalEventForm.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited;
|
||||
|
||||
Grid.OnGetEditText := @GridGetEditText;
|
||||
Grid.OnSetEditText := @GridSetEditText;
|
||||
|
||||
Caption := RSImportICalEvent;
|
||||
FTimeFormat := 'c'; // short date + long time format
|
||||
end;
|
||||
@ -114,7 +116,7 @@ begin
|
||||
RSDescriptionLbl + ' ' + AEvent.Summary;
|
||||
|
||||
// Categories
|
||||
if Assigned(FDatastore) then
|
||||
if Assigned(Datastore) then
|
||||
begin
|
||||
cat := AEvent.Categories.CommaText;
|
||||
if cat = '' then cat := RSNoneStr;
|
||||
@ -215,46 +217,38 @@ var
|
||||
L: TStrings;
|
||||
event: TVpICalEvent;
|
||||
cat: String;
|
||||
begin
|
||||
FItems.Clear;
|
||||
if FCalendar <> nil then
|
||||
for i := 0 to FCalendar.Count-1 do
|
||||
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
|
||||
Grid.Columns[1].Title.Caption := RSEventItems;
|
||||
Grid.Columns[2].Title.Caption := RSAssignedCategory;
|
||||
|
||||
with Grid.Columns.Add do
|
||||
begin
|
||||
SizePriority := 0;
|
||||
Width := 160;
|
||||
Title.Caption := RSAssignedCategory;
|
||||
ButtonStyle := cbsPickList;
|
||||
// Populate picklist in column 2
|
||||
L := TStringList.Create;
|
||||
try
|
||||
for i := 0 to 9 do
|
||||
L.Add(FDatastore.CategoryColorMap.GetName(i));
|
||||
PickList.Assign(L);
|
||||
L.Add(Datastore.CategoryColorMap.GetName(i));
|
||||
Grid.Columns[2].PickList.Assign(L);
|
||||
finally
|
||||
L.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
for i := 0 to FItems.Count-1 do
|
||||
FItems.Clear;
|
||||
if (FCalendar <> nil) and (Datastore <> nil) then
|
||||
for i := 0 to FCalendar.Count-1 do
|
||||
if (FCalendar.Entry[i] is TVpICalEvent) then
|
||||
begin
|
||||
event := TVpICalEvent(FItems[i]);
|
||||
cat := FDatastore.FindBestEventCategory(event.Categories);
|
||||
// Add ical event
|
||||
event := TVpIcalEvent(FCalendar.Entry[i]);
|
||||
FItems.Add(event);
|
||||
// Select best category in picklist column
|
||||
cat := Datastore.FindBestEventCategory(event.Categories);
|
||||
if cat = '' then cat := FDefaultCategory;
|
||||
if cat <> '' then
|
||||
event.PickedCategory := Grid.Columns[2].PickList.IndexOf(cat)
|
||||
else
|
||||
event.PickedCategory := 0;
|
||||
end;
|
||||
end;
|
||||
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TVpImportPreviewICalEventForm.SetCalendar(const AValue: TVpICalendar);
|
||||
|
@ -4,31 +4,6 @@ inherited VpImportPreviewICalTaskForm: TVpImportPreviewICalTaskForm
|
||||
Caption = ''
|
||||
ClientHeight = 400
|
||||
ClientWidth = 667
|
||||
inherited Grid: TDrawGrid
|
||||
Height = 363
|
||||
Width = 667
|
||||
Columns = <
|
||||
item
|
||||
Alignment = taCenter
|
||||
ButtonStyle = cbsCheckboxColumn
|
||||
PickList.Strings = ( )
|
||||
SizePriority = 0
|
||||
Title.Caption = ''
|
||||
Width = 33
|
||||
end
|
||||
item
|
||||
PickList.Strings = ( )
|
||||
ReadOnly = True
|
||||
Title.Caption = 'Items'
|
||||
Width = 634
|
||||
end>
|
||||
OnGetEditText = GridGetEditText
|
||||
OnSetEditText = GridSetEditText
|
||||
ColWidths = (
|
||||
33
|
||||
634
|
||||
)
|
||||
end
|
||||
inherited ButtonPanel: TPanel
|
||||
Top = 369
|
||||
Width = 655
|
||||
|
@ -1,5 +1,3 @@
|
||||
{"version":1,"strings":[
|
||||
{"hash":4294967295,"name":"tvpimportpreviewicaltaskform.caption","sourcebytes":[],"value":""},
|
||||
{"hash":4294967295,"name":"tvpimportpreviewicaltaskform.grid.columns[0].title.caption","sourcebytes":[],"value":""},
|
||||
{"hash":5286979,"name":"tvpimportpreviewicaltaskform.grid.columns[1].title.caption","sourcebytes":[73,116,101,109,115],"value":"Items"}
|
||||
{"hash":4294967295,"name":"tvpimportpreviewicaltaskform.caption","sourcebytes":[],"value":""}
|
||||
]}
|
||||
|
@ -19,7 +19,6 @@ type
|
||||
const Value: string);
|
||||
private
|
||||
FCalendar: TVpICalendar;
|
||||
FDatastore: TVpCustomDatastore;
|
||||
FDefaultCategory: String;
|
||||
FTimeFormat: String;
|
||||
function GetTaskText(AToDo: TVpICalToDo): String;
|
||||
@ -34,7 +33,6 @@ type
|
||||
procedure CheckItem(ARow: Integer; AChecked: Boolean); override;
|
||||
function IsChecked(ARow: Integer): Boolean; override;
|
||||
property Calendar: TVpICalendar read FCalendar write SetCalendar;
|
||||
property Datastore: TVpCustomDatastore read FDatastore write FDatastore;
|
||||
property DefaultCategory: String read FDefaultCategory write FDefaultCategory;
|
||||
|
||||
end;
|
||||
@ -52,6 +50,10 @@ uses
|
||||
constructor TVPImportPreviewICalTaskForm.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited;
|
||||
|
||||
Grid.OnGetEditText := @GridGetEditText;
|
||||
Grid.OnSetEditText := @GridSetEditText;
|
||||
|
||||
Caption := RSImportICalTask;
|
||||
FTimeFormat := 'c'; // short date + long time format
|
||||
end;
|
||||
@ -149,51 +151,43 @@ end;
|
||||
|
||||
procedure TVpImportPreviewICalTaskForm.PrepareItems;
|
||||
var
|
||||
i: Integer;
|
||||
i, j: Integer;
|
||||
ct: TVpCategoryType;
|
||||
cat: String;
|
||||
L: TStrings;
|
||||
task: TVpICalToDo;
|
||||
begin
|
||||
FItems.Clear;
|
||||
if FCalendar <> nil then
|
||||
for i := 0 to FCalendar.Count-1 do
|
||||
if (FCalendar.Entry[i] is TVpICalToDo) then
|
||||
FItems.Add(FCalendar.Entry[i]);
|
||||
|
||||
inherited;
|
||||
|
||||
if (FCalendar <> nil) and (FDataStore <> nil) and (Grid.Columns.Count = 2) then
|
||||
begin
|
||||
Grid.Columns[1].Title.Caption := RSTaskItems;
|
||||
|
||||
with Grid.Columns.Add do
|
||||
begin
|
||||
SizePriority := 0;
|
||||
Width := 160;
|
||||
Title.Caption := RSAssignedCategory;
|
||||
ButtonStyle := cbsPickList;
|
||||
Grid.Columns[2].Title.Caption := RSAssignedCategory;
|
||||
// Populate picklist in column 2
|
||||
L := TStringList.Create;
|
||||
try
|
||||
for ct in TVpCategoryType do
|
||||
L.Add(CategoryLabel(ct));
|
||||
PickList.Assign(L);
|
||||
Grid.Columns[2].PickList.Assign(L);
|
||||
finally
|
||||
L.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
for i := 0 to FItems.Count-1 do
|
||||
FItems.Clear;
|
||||
if (FCalendar <> nil) and (Datastore <> nil) then
|
||||
for i := 0 to FCalendar.Count-1 do
|
||||
if (FCalendar.Entry[i] is TVpICalToDo) then
|
||||
begin
|
||||
task := TVpICalToDo(FItems[i]);
|
||||
cat := FDatastore.FindBestCategory(task.Categories);
|
||||
// Add ical todo item
|
||||
task := TVpICalToDo(FCalendar.Entry[i]);
|
||||
FItems.Add(task);
|
||||
|
||||
// Select best category in picklist column
|
||||
cat := Datastore.FindBestCategory(task.Categories);
|
||||
if cat = '' then cat := FDefaultCategory;
|
||||
if cat <> '' then
|
||||
task.PickedCategory := Grid.Columns[2].PickList.IndexOf(cat)
|
||||
else
|
||||
task.PickedCategory := ord(ctOther);
|
||||
end;
|
||||
end;
|
||||
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TVpImportPreviewICalTaskForm.SetCalendar(const AValue: TVpICalendar);
|
||||
|
@ -4,31 +4,6 @@ inherited VpImportPreviewVCardForm: TVpImportPreviewVCardForm
|
||||
Caption = ''
|
||||
ClientHeight = 400
|
||||
ClientWidth = 667
|
||||
inherited Grid: TDrawGrid
|
||||
Height = 363
|
||||
Width = 667
|
||||
Columns = <
|
||||
item
|
||||
Alignment = taCenter
|
||||
ButtonStyle = cbsCheckboxColumn
|
||||
PickList.Strings = ( )
|
||||
SizePriority = 0
|
||||
Title.Caption = ''
|
||||
Width = 33
|
||||
end
|
||||
item
|
||||
PickList.Strings = ( )
|
||||
ReadOnly = True
|
||||
Title.Caption = 'Items'
|
||||
Width = 630
|
||||
end>
|
||||
OnGetEditText = GridGetEditText
|
||||
OnSetEditText = GridSetEditText
|
||||
ColWidths = (
|
||||
33
|
||||
630
|
||||
)
|
||||
end
|
||||
inherited ButtonPanel: TPanel
|
||||
Top = 369
|
||||
Width = 655
|
||||
|
@ -1,5 +1,3 @@
|
||||
{"version":1,"strings":[
|
||||
{"hash":4294967295,"name":"tvpimportpreviewvcardform.caption","sourcebytes":[],"value":""},
|
||||
{"hash":4294967295,"name":"tvpimportpreviewvcardform.grid.columns[0].title.caption","sourcebytes":[],"value":""},
|
||||
{"hash":5286979,"name":"tvpimportpreviewvcardform.grid.columns[1].title.caption","sourcebytes":[73,116,101,109,115],"value":"Items"}
|
||||
{"hash":4294967295,"name":"tvpimportpreviewvcardform.caption","sourcebytes":[],"value":""}
|
||||
]}
|
||||
|
@ -19,7 +19,6 @@ type
|
||||
const Value: string);
|
||||
private
|
||||
FVCards: TVpVCards;
|
||||
FDatastore: TVpCustomDatastore;
|
||||
FDefaultCategory: String;
|
||||
function GetCardText(ACard: TVpVCard): String;
|
||||
procedure SetVCards(const AValue: TVpVCards);
|
||||
@ -33,7 +32,6 @@ type
|
||||
procedure CheckItem(ARow: Integer; AChecked: Boolean); override;
|
||||
function IsChecked(ARow: Integer): Boolean; override;
|
||||
property VCards: TVpVCards read FVCards write SetVCards;
|
||||
property Datastore: TVpCustomDatastore read FDatastore write FDatastore;
|
||||
property DefaultCategory: String read FDefaultCategory write FDefaultCategory;
|
||||
end;
|
||||
|
||||
@ -51,6 +49,8 @@ constructor TVPImportPreviewVCardForm.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited;
|
||||
Caption := RSImportVCard;
|
||||
Grid.OnGetEditText := @GridGetEditText;
|
||||
Grid.OnSetEditText := @GridSetEditText;
|
||||
end;
|
||||
|
||||
procedure TVpImportPreviewVCardForm.CheckItem(ARow: Integer; AChecked: Boolean);
|
||||
@ -146,47 +146,37 @@ var
|
||||
ct: TVpCategoryType;
|
||||
L: TStrings;
|
||||
begin
|
||||
FItems.Clear;
|
||||
if FVCards <> nil then
|
||||
for i := 0 to FVCards.Count-1 do
|
||||
FItems.Add(FVCards.Card[i]);
|
||||
|
||||
inherited;
|
||||
|
||||
Grid.Columns[1].Title.Caption := RSContactItems;
|
||||
Grid.Columns[2].Title.Caption := RSAssignedCategory;
|
||||
|
||||
if (FVCards <> nil) and (FDataStore <> nil) and (Grid.Columns.Count = 2) then
|
||||
begin
|
||||
Grid.Columns[1].Title.Caption := RSContactItems;
|
||||
|
||||
with Grid.Columns.Add do
|
||||
begin
|
||||
SizePriority := 0;
|
||||
Width := 160;
|
||||
Title.Caption := RSAssignedCategory;
|
||||
ButtonStyle := cbsPickList;
|
||||
// Populate picklist in column 2
|
||||
L := TStringList.Create;
|
||||
try
|
||||
for ct in TVpCategoryType do
|
||||
L.Add(CategoryLabel(ct));
|
||||
PickList.Assign(L);
|
||||
Grid.Columns[2].PickList.Assign(L);
|
||||
finally
|
||||
L.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
for i := 0 to FItems.Count-1 do
|
||||
FItems.Clear;
|
||||
if (FVCards <> nil) and (Datastore <> nil) then
|
||||
for i := 0 to FVCards.Count-1 do
|
||||
begin
|
||||
card := TVpVCard(FItems[i]);
|
||||
cat := FDatastore.FindBestCategory(card.Categories);
|
||||
// Add vcard
|
||||
card := FVCards.Card[i];
|
||||
FItems.Add(card);
|
||||
|
||||
// Select best category in picklist columns
|
||||
cat := Datastore.FindBestCategory(card.Categories);
|
||||
if cat = '' then cat := FDefaultCategory;
|
||||
if cat <> '' then
|
||||
card.PickedCategory := Grid.Columns[2].PickList.IndexOf(cat)
|
||||
else
|
||||
card.PickedCategory := ord(ctOther);
|
||||
end;
|
||||
end;
|
||||
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TVpImportPreviewVCardForm.SetVCards(const AValue: TVpVCards);
|
||||
|
Reference in New Issue
Block a user