forked from blikblum/multilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogtreeview.pas
330 lines (298 loc) · 9.68 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
unit LogTreeView;
{
Copyright (C) 2006 Luiz Américo Pereira Câmara
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,and
to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a
module which is not derived from or based on this library. If you modify
this library, you may extend this exception to your version of the library,
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Comctrls, Controls, MultiLog, LResources, Graphics;
type
{ TLogTreeView }
{$REGION 'Xls: Comments section'}
{ TLogTreeView is a way to display the TIntegratedLogger'messages, with images.}
{$ENDREGION}
TLogTreeView = class (TCustomTreeView)
private
FoImgList: TImageList;
FoChannel: TLogChannel;
Fo_LastNode: TTreeNode;
Fo_ParentNode: TTreeNode;
FbShowTime: Boolean;
FbShowPrefixMethod: Boolean;
FbShowDynamicFilter_forWhatReasonsToLogActually: Boolean;
FsTimeFormat: String;
function GetChannel: TLogChannel;
public
constructor Create(AnOwner: TComponent); override;
destructor Destroy; override;
procedure AddMessage(AMsg: TrecLogMessage);
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 SortType;
property StateImages;
property TabOrder;
property TabStop default True;
property Tag;
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;
property TimeFormat: String read FsTimeFormat write FsTimeFormat;
property ShowTime: Boolean read FbShowTime write FbShowTime;
property ShowPrefixMethod: Boolean read FbShowPrefixMethod write FbShowPrefixMethod;
property ShowDynamicFilter_forWhatReasonsToLogActually: Boolean read FbShowDynamicFilter_forWhatReasonsToLogActually write FbShowDynamicFilter_forWhatReasonsToLogActually;
end;
{ TLogTreeViewChannel }
TLogTreeViewChannel = class (TLogChannel)
private
Fo_Control: TLogTreeView;
public
constructor Create(AControl: TLogTreeView);
procedure Clear; override;
procedure Deliver(const AMsg: TrecLogMessage);override;
end;
implementation
{ TLogTreeViewChannel }
constructor TLogTreeViewChannel.Create(AControl: TLogTreeView);
begin
Fo_Control:= AControl;
Active:= True;
FbShowPrefixMethod:= false;
FbShowTime:= false;
FbShow_DynamicFilter_forWhatReasonsToLogActually:= false;
end;
procedure TLogTreeViewChannel.Clear;
begin
Fo_Control.Clear;
end;
procedure TLogTreeViewChannel.Deliver(const AMsg: TrecLogMessage);
begin
Fo_Control.AddMessage(AMsg);
end;
{ TLogTreeView }
function TLogTreeView.GetChannel: TLogChannel;
begin
if FoChannel = nil then
FoChannel:= TLogTreeViewChannel.Create(Self);
Result:= FoChannel;
end;
constructor TLogTreeView.Create(AnOwner: TComponent);
begin
inherited Create(AnOwner);
FsTimeFormat := 'hh:nn:ss:zzz';
FoImgList:= TImageList.Create(nil);
with FoImgList 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:= FoImgList;
end;
destructor TLogTreeView.Destroy;
begin
FoImgList.Destroy; FoImgList:= nil;
FreeAndNil(FoChannel);
inherited Destroy;
end;
procedure TLogTreeView.AddMessage(AMsg: TrecLogMessage);
procedure ParseStream(AStream:TStream);
var
i: Integer;
oStrList: TStringList;
begin
//todo: Parse the String in Stream directly instead of using StringList ??
oStrList:= TStringList.Create;
AStream.Position:=0;
oStrList.LoadFromStream(AStream);
for i:= 0 to oStrList.Count - 1 do
Items.AddChild(Fo_LastNode,oStrList[i]);
Fo_LastNode.Text:= Fo_LastNode.Text+' ('+IntToStr(oStrList.Count)+' Items)';
oStrList.Destroy;
end;
var
oTempStream: TStream;
sWholeMsg: String;
begin
sWholeMsg:= '';
if FbShowTime then
sWholeMsg:= FormatDateTime(FsTimeFormat, Time) + ' ';
if FbShowPrefixMethod then
sWholeMsg:= sWholeMsg + (ctsLogPrefixesMethod[AMsg.iMethUsed] + ': ');
//write second qualifier explaining for which tracking purposes Msg are Logged
if FbShowDynamicFilter_forWhatReasonsToLogActually then
sWholeMsg:= sWholeMsg + TLogChannelUtils.SetofToString(AMsg.setFilterDynamic);
sWholeMsg:= sWholeMsg + AMsg.sMsgText;
with Items, AMsg do begin
case AMsg.iMethUsed of
methEnterMethod:
begin
Fo_LastNode:= AddChild(Fo_ParentNode,sWholeMsg);
Fo_ParentNode:= Fo_LastNode;
end;
methExitMethod:
begin
if Fo_ParentNode <> nil then
Fo_LastNode:= AddChild(Fo_ParentNode.Parent,sWholeMsg)
else
Fo_LastNode:= AddChild(nil,sWholeMsg);
Fo_ParentNode:= Fo_LastNode.Parent;
end;
methTStrings, methCallStack, methHeapInfo, methException, methMemory:
begin
Fo_LastNode:= AddChild(Fo_ParentNode,sWholeMsg);
if Assigned(pData) and (pData.Size>0) then
ParseStream(pData)
else
Fo_LastNode.Text:= Fo_LastNode.Text+' (No Items)';
end;
methObject:
begin
Fo_LastNode:= AddChild(Fo_ParentNode,sWholeMsg);
if Assigned(pData) and (pData.Size>0) then begin
pData.Position:= 0;
oTempStream:= TStringStream.Create('');
ObjectBinaryToText(pData,oTempStream);
ParseStream(oTempStream);
oTempStream.Destroy;
end;
end;
else
begin
Fo_LastNode:= AddChild(Fo_ParentNode,sWholeMsg);
end;
end;
end;
//todo: hook TCustomTreeView to auto expand
if Fo_LastNode.Parent <> nil then
Fo_LastNode.Parent.Expanded:= True;
Fo_LastNode.GetFirstChild;
//todo: optimize painting
Fo_LastNode.ImageIndex:= AMsg.iMethUsed;
Fo_LastNode.SelectedIndex:= AMsg.iMethUsed;
end;
procedure TLogTreeView.Clear;
begin
Items.Clear;
Fo_LastNode:=nil;
Fo_ParentNode:=nil;
end;
initialization
{$i logimages.lrs}
end.
procedure TLogTreeView.Clear;
begin
Items.Clear;
FLastNode:=nil;
FParentNode:=nil;
end;
initialization
{$i logimages.lrs}
end.