-
Notifications
You must be signed in to change notification settings - Fork 9
/
logtreeview.pas
292 lines (267 loc) · 7.16 KB
/
logtreeview.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
unit LogTreeView;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Comctrls, Controls, MultiLog, LResources, Graphics;
type
{ TLogTreeView }
TLogTreeView = class (TCustomTreeView)
private
FImgList: TImageList;
FChannel: TLogChannel;
FLastNode: TTreeNode;
FParentNode: TTreeNode;
FShowTime: Boolean;
FTimeFormat: String;
function GetChannel: TLogChannel;
public
constructor Create(AnOwner: TComponent); override;
destructor Destroy; override;
procedure AddMessage (AMsg: TLogMessage);
procedure Clear;
property Channel: TLogChannel read GetChannel;
published
property Align;
property Anchors;
property AutoExpand;
property BorderSpacing;
//property BiDiMode;
property BackgroundColor;
property BorderStyle;
property BorderWidth;
property Color;
property Constraints;
property DefaultItemHeight;
property DragKind;
property DragCursor;
property DragMode;
property Enabled;
property ExpandSignType;
property Font;
property HideSelection;
property HotTrack;
//property Images;
property Indent;
//property ParentBiDiMode;
property ParentColor default False;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property RightClickSelect;
property RowSelect;
property ScrollBars;
property SelectionColor;
property ShowButtons;
property ShowHint;
property ShowLines;
property ShowRoot;
property ShowTime: Boolean read FShowTime write FShowTime;
property SortType;
property StateImages;
property TabOrder;
property TabStop default True;
property Tag;
property TimeFormat: String read FTimeFormat write FTimeFormat;
property ToolTips;
property Visible;
property OnAdvancedCustomDraw;
property OnAdvancedCustomDrawItem;
property OnChange;
property OnChanging;
property OnClick;
property OnCollapsed;
property OnCollapsing;
property OnCompare;
property OnContextPopup;
property OnCustomCreateItem;
property OnCustomDraw;
property OnCustomDrawItem;
property OnDblClick;
property OnDeletion;
property OnDragDrop;
property OnDragOver;
property OnEdited;
property OnEditing;
//property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnExpanded;
property OnExpanding;
property OnGetImageIndex;
property OnGetSelectedIndex;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnSelectionChanged;
property Options;
//property OnStartDock;
property OnStartDrag;
//property Items;
property TreeLineColor;
property ExpandSignColor;
end;
implementation
type
{ TLogTreeViewChannel }
TLogTreeViewChannel = class (TLogChannel)
private
FControl: TLogTreeView;
public
constructor Create (AControl: TLogTreeView);
procedure Clear; override;
procedure Deliver(const AMsg: TLogMessage);override;
end;
{ TLogTreeViewChannel }
constructor TLogTreeViewChannel.Create(AControl: TLogTreeView);
begin
FControl:=AControl;
Active:=True;
end;
procedure TLogTreeViewChannel.Clear;
begin
FControl.Clear;
end;
procedure TLogTreeViewChannel.Deliver(const AMsg: TLogMessage);
begin
FControl.AddMessage(AMsg);
end;
{ TLogTreeView }
function TLogTreeView.GetChannel: TLogChannel;
begin
if FChannel = nil then
FChannel:=TLogTreeViewChannel.Create(Self);
Result:=FChannel;
end;
constructor TLogTreeView.Create(AnOwner: TComponent);
begin
inherited Create(AnOwner);
FTimeFormat := 'hh:nn:ss:zzz';
FImgList:=TImageList.Create(nil);
with FImgList do
begin
AddLazarusResource('info', clDefault);
AddLazarusResource('error', clDefault);
AddLazarusResource('warning', clDefault);
AddLazarusResource('value', clDefault);
AddLazarusResource('entermethod', clDefault);
AddLazarusResource('exitmethod', clDefault);
AddLazarusResource('whatisthis', clDefault); //conditional
AddLazarusResource('check', clDefault);
AddLazarusResource('strings', clDefault);
AddLazarusResource('callstack', clDefault);
AddLazarusResource('object', clDefault);
AddLazarusResource('error', clDefault);
AddLazarusResource('image', clDefault);
AddLazarusResource('whatisthis', clDefault); //heap
AddLazarusResource('whatisthis', clDefault); //memory
AddLazarusResource('whatisthis', clDefault); //custom data
end;
Images:=FImgList;
end;
destructor TLogTreeView.Destroy;
begin
FImgList.Destroy;
FreeAndNil(FChannel);
inherited Destroy;
end;
procedure TLogTreeView.AddMessage(AMsg: TLogMessage);
procedure ParseStream(AStream:TStream);
var
i: Integer;
AStrList: TStringList;
begin
//todo: Parse the String in Stream directly instead of using StringList ??
AStrList:=TStringList.Create;
AStream.Position:=0;
AStrList.LoadFromStream(AStream);
for i:= 0 to AStrList.Count - 1 do
Items.AddChild(FLastNode,AStrList[i]);
FLastNode.Text:=FLastNode.Text+' ('+IntToStr(AStrList.Count)+' Items)';
AStrList.Destroy;
end;
var
TempStream:TStream;
AText: String;
begin
AText := AMsg.MsgText;
if FShowTime then
AText := FormatDateTime(FTimeFormat, Time) + ' ' + AText;
with Items, AMsg do
begin
case AMsg.MsgType of
ltEnterMethod:
begin
FLastNode:=AddChild(FParentNode,AText);
FParentNode:=FLastNode;
end;
ltExitMethod:
begin
if FParentNode <> nil then
FLastNode:=AddChild(FParentNode.Parent,AText)
else
FLastNode:=AddChild(nil,AText);
FParentNode:=FLastNode.Parent;
end;
ltCallStack,ltStrings,ltHeapInfo,ltException:
begin
FLastNode:=AddChild(FParentNode,AText);
if Assigned(Data) and (Data.Size>0) then
ParseStream(Data)
else
FLastNode.Text:=FLastNode.Text+' (No Items)';
end;
ltObject:
begin
FLastNode:=AddChild(FParentNode,AText);
if Assigned(Data) and (Data.Size>0) then
begin
Data.Position:=0;
TempStream:=TStringStream.Create('');
ObjectBinaryToText(Data,TempStream);
ParseStream(TempStream);
TempStream.Destroy;
end;
end;
else
begin
FLastNode:=AddChild(FParentNode,AText);
end;
end;
end;
//todo: hook TCustomTreeView to auto expand
if FLastNode.Parent <> nil then
FLastNode.Parent.Expanded:=True;
FLastNode.GetFirstChild;
//todo: optimize painting
FLastNode.ImageIndex:=AMsg.MsgType;
FLastNode.SelectedIndex:=AMsg.MsgType;
end;
procedure TLogTreeView.Clear;
begin
Items.Clear;
FLastNode:=nil;
FParentNode:=nil;
end;
initialization
{$i logimages.lrs}
end.
.Parent.Expanded:=True;
FLastNode.GetFirstChild;
//todo: optimize painting
FLastNode.ImageIndex:=AMsg.MsgType;
FLastNode.SelectedIndex:=AMsg.MsgType;
end;
procedure TLogTreeView.Clear;
begin
Items.Clear;
FLastNode:=nil;
FParentNode:=nil;
end;
initialization
{$i logimages.lrs}
end.