-
Notifications
You must be signed in to change notification settings - Fork 5
/
librarylistview.pas
134 lines (114 loc) · 4.2 KB
/
librarylistview.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
unit libraryListView;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, applicationconfig,TreeListView, libraryParser;
type
{ TLibraryListView }
TLibraryListView = class(TTreeListView)
lastCollapsed: TTreeListItem;
procedure LibraryListViewClick({%H-}sender: TObject);
procedure LibraryListViewCustomRecordItemDraw({%H-}sender: TObject; eventTyp_cdet: TCustomDrawEventTyp; recordItem: TTreeListRecordItem;
var {%H-}defaultDraw: Boolean);
procedure LibraryListViewItemCollapsed({%H-}sender: TObject; item: TTreeListItem);
public
constructor create(aowner: TComponent);
function selectedLibrary: TLibrary;
procedure DoSelect(item: TTreeListItem); override;
end;
implementation
uses bbutils, strutils, Graphics;
{ TLibraryListView }
procedure TLibraryListView.LibraryListViewItemCollapsed(sender: TObject; item: TTreeListItem);
begin
lastCollapsed := item;
end;
procedure lazyLoad(item: TTreeListItem);
begin
if (item.SubItems.Count = 0) and (item.data.obj = nil) and (item.RecordItems.Count > 1) then begin
item.data.obj := libraryManager.get(item.RecordItemsText[1]);
if item.data.obj <> nil then item.Text := (item.data.obj as TLibrary).prettyName;
end;
end;
procedure TLibraryListView.LibraryListViewClick(sender: TObject);
var
i: Integer;
begin
if (Selected <> nil) then begin
BeginUpdate;
if (Selected.data.obj = nil) and (Selected.SubItems.Count>0) and (Selected <> lastCollapsed) then begin
Selected.Expand;
for i := 0 to Selected.SubItems.Count - 1 do
lazyLoad(selected.SubItems[i]);
Selected := Selected.SubItems[0];
if (selected.Parent.SubItems.Count = 1) and (Selected.SubItems.Count > 0) and (Selected.data.obj = nil) then begin
Selected.Expand;
for i := 0 to Selected.SubItems.Count - 1 do
lazyLoad(selected.SubItems[i]);
Selected := Selected.SubItems[0];
end;
end;
EndUpdate;
lastCollapsed := nil;
end;
end;
procedure TLibraryListView.LibraryListViewCustomRecordItemDraw(sender: TObject; eventTyp_cdet: TCustomDrawEventTyp;
recordItem: TTreeListRecordItem; var defaultDraw: Boolean);
var
lib: TLibrary;
begin
if recordItem.Parent.data.p = nil then exit;
lib := TLibrary(recordItem.Parent.data.p);
if lib.tableComment = '' then exit;
if recordItem.Index <> 0 then exit;
canvas.Font.Color := clGray;
canvas.Font.Style := [fsItalic];
drawTextRect(lib.tableComment, canvas.TextWidth(recordItem.Text) + 15 * recordItem.Parent.Indent + 20, taLeftJustify, F_DrawingRecordItemRect, false);
recordItem.selectFont(canvas);
end;
constructor TLibraryListView.create(aowner: TComponent);
var
enumerator: TLibraryMetaDataEnumerator;
currentCountryStateItem, currentLocationItem: TTreeListItem;
begin
inherited;
BeginUpdate;
currentCountryStateItem := nil;
currentLocationItem := nil;
enumerator := libraryManager.enumerateLibraryMetaData;
while enumerator.MoveNext do with enumerator do begin
if enumerator.newCountryState then begin
if currentCountryStateItem <> nil then currentCountryStateItem.Collapse;
currentCountryStateItem := Items.Add(IfThen(prettyCountryState = '- - -', rsCustomLibrary, prettyCountryState));
end;
if enumerator.newLocation then begin
if currentLocationItem <> nil then currentLocationItem.Collapse;
currentLocationItem := currentCountryStateItem.SubItems.Add(IfThen(prettyLocation = '-', rsCustomLibrary, prettyLocation));
end;
currentLocationItem.SubItems.Add('').RecordItemsText[1] := libraryId;
end;
if currentCountryStateItem <> nil then currentCountryStateItem.Collapse;
if currentLocationItem <> nil then currentLocationItem.Collapse;
HeaderVisible:=false;
OnItemCollapsed:=@LibraryListViewItemCollapsed;
OnClick:=@LibraryListViewClick;
EndUpdate;
RowHeight:=RowHeight+5;
{$ifdef android}
RowHeight:=RowHeight*2-10;
{$endif}
OnCustomRecordItemDraw:=@LibraryListViewCustomRecordItemDraw;
end;
function TLibraryListView.selectedLibrary: TLibrary;
var
item: TTreeListItem;
begin
item := Selected;
if (item = nil) or (item.data.obj = nil) then exit(nil);
result := item.data.obj as TLibrary;
end;
procedure TLibraryListView.DoSelect(item: TTreeListItem);
begin
inherited DoSelect(item);
end;
end.