2014-05-20 06:59:10 +00:00
|
|
|
unit X2Log.Observer.MonitorForm;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
2014-05-20 08:49:57 +00:00
|
|
|
System.Classes,
|
|
|
|
System.Generics.Collections,
|
2014-05-31 20:10:10 +00:00
|
|
|
System.Types,
|
2016-10-15 07:37:58 +00:00
|
|
|
Vcl.ActnList,
|
2014-05-20 19:17:23 +00:00
|
|
|
Vcl.ComCtrls,
|
2014-05-20 06:59:10 +00:00
|
|
|
Vcl.Controls,
|
2014-05-30 12:51:01 +00:00
|
|
|
Vcl.Dialogs,
|
2014-05-20 19:17:23 +00:00
|
|
|
Vcl.ExtCtrls,
|
2014-05-20 06:59:10 +00:00
|
|
|
Vcl.Forms,
|
2016-10-15 07:37:58 +00:00
|
|
|
Vcl.Grids,
|
2014-05-20 08:49:57 +00:00
|
|
|
Vcl.ImgList,
|
2014-10-22 18:36:44 +00:00
|
|
|
Vcl.Menus,
|
2014-05-20 19:17:23 +00:00
|
|
|
Vcl.StdCtrls,
|
|
|
|
Vcl.ToolWin,
|
2016-10-15 07:37:58 +00:00
|
|
|
Vcl.ValEdit,
|
2014-05-20 08:49:57 +00:00
|
|
|
VirtualTrees,
|
2014-05-20 06:59:10 +00:00
|
|
|
Winapi.Messages,
|
|
|
|
|
2014-06-01 13:32:21 +00:00
|
|
|
X2Log.Details.Intf,
|
2016-10-15 07:37:58 +00:00
|
|
|
X2Log.Intf;
|
2014-05-20 06:59:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
CM_REENABLE = WM_APP + 1;
|
|
|
|
|
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
var
|
|
|
|
DefaultMaxEntries: Cardinal = 1000;
|
|
|
|
|
|
|
|
|
2014-05-20 06:59:10 +00:00
|
|
|
type
|
2014-05-31 20:10:10 +00:00
|
|
|
TX2LogObserverMonitorForm = class;
|
|
|
|
TMonitorFormDictionary = TObjectDictionary<IX2LogObservable,TX2LogObserverMonitorForm>;
|
|
|
|
|
2016-10-15 07:37:58 +00:00
|
|
|
TCopyHandler = procedure of object;
|
|
|
|
|
2014-05-31 20:10:10 +00:00
|
|
|
|
2014-05-20 06:59:10 +00:00
|
|
|
TX2LogObserverMonitorForm = class(TForm, IX2LogObserver)
|
2014-05-20 08:49:57 +00:00
|
|
|
vstLog: TVirtualStringTree;
|
|
|
|
ilsLog: TImageList;
|
2014-05-20 09:19:04 +00:00
|
|
|
splDetails: TSplitter;
|
2014-08-19 14:06:25 +00:00
|
|
|
hcDetails: THeaderControl;
|
2014-05-20 09:19:04 +00:00
|
|
|
pnlDetails: TPanel;
|
|
|
|
reDetails: TRichEdit;
|
|
|
|
pnlLog: TPanel;
|
|
|
|
tbLog: TToolBar;
|
|
|
|
tbDetails: TToolBar;
|
|
|
|
pnlBorder: TPanel;
|
|
|
|
tbClear: TToolButton;
|
|
|
|
tbSaveDetails: TToolButton;
|
|
|
|
sbStatus: TStatusBar;
|
2014-05-20 19:17:23 +00:00
|
|
|
tbCopyDetails: TToolButton;
|
|
|
|
alLog: TActionList;
|
|
|
|
actClear: TAction;
|
|
|
|
actCopyDetails: TAction;
|
|
|
|
actSaveDetails: TAction;
|
|
|
|
actPause: TAction;
|
|
|
|
tbPause: TToolButton;
|
2014-05-30 12:51:01 +00:00
|
|
|
sdDetails: TSaveDialog;
|
2014-05-31 20:47:52 +00:00
|
|
|
tbShowVerbose: TToolButton;
|
|
|
|
tbShowInfo: TToolButton;
|
|
|
|
tbShowWarning: TToolButton;
|
|
|
|
tbShowError: TToolButton;
|
|
|
|
actShowVerbose: TAction;
|
|
|
|
actShowInfo: TAction;
|
|
|
|
actShowWarning: TAction;
|
|
|
|
actShowError: TAction;
|
|
|
|
lblFilter: TLabel;
|
2014-06-01 13:32:21 +00:00
|
|
|
sbDetailsImage: TScrollBox;
|
|
|
|
imgDetailsImage: TImage;
|
2014-08-19 14:06:25 +00:00
|
|
|
tbWordWrap: TToolButton;
|
|
|
|
tbDetailsSep1: TToolButton;
|
|
|
|
actWordWrap: TAction;
|
2014-10-08 12:33:11 +00:00
|
|
|
mmMain: TMainMenu;
|
|
|
|
mmMainFile: TMenuItem;
|
|
|
|
mmMainLog: TMenuItem;
|
|
|
|
mmMainDetails: TMenuItem;
|
|
|
|
mmMainWindow: TMenuItem;
|
|
|
|
actClose: TAction;
|
|
|
|
mmMainFileClose: TMenuItem;
|
|
|
|
mmMainLogClear: TMenuItem;
|
|
|
|
mmMainLogPause: TMenuItem;
|
|
|
|
mmMainLogSep1: TMenuItem;
|
|
|
|
mmMainLogVerbose: TMenuItem;
|
|
|
|
mmMainLogInfo: TMenuItem;
|
|
|
|
mmMainLogWarning: TMenuItem;
|
|
|
|
mmMainLogError: TMenuItem;
|
|
|
|
mmMainDetailsCopy: TMenuItem;
|
|
|
|
mmMainDetailsSave: TMenuItem;
|
|
|
|
mmMainDetailsWordWrap: TMenuItem;
|
|
|
|
mmMainDetailsSep1: TMenuItem;
|
|
|
|
actAlwaysOnTop: TAction;
|
|
|
|
mmMainWindowAlwaysOnTop: TMenuItem;
|
|
|
|
actSaveAs: TAction;
|
|
|
|
mmMainFileSep1: TMenuItem;
|
|
|
|
mmMainFileSaveAs: TMenuItem;
|
|
|
|
sdSaveAs: TSaveDialog;
|
2016-10-14 15:02:27 +00:00
|
|
|
vleDetailsDictionary: TValueListEditor;
|
2014-05-20 08:49:57 +00:00
|
|
|
|
|
|
|
procedure FormShow(Sender: TObject);
|
|
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|
|
|
procedure vstLogFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
|
|
|
procedure vstLogGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
|
|
|
|
procedure vstLogGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer);
|
2014-05-20 09:19:04 +00:00
|
|
|
procedure vstLogFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
|
2016-10-15 07:37:58 +00:00
|
|
|
procedure vleDetailsDictionaryKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
2014-10-08 12:33:11 +00:00
|
|
|
procedure actCloseExecute(Sender: TObject);
|
2014-05-20 19:17:23 +00:00
|
|
|
procedure actClearExecute(Sender: TObject);
|
|
|
|
procedure actCopyDetailsExecute(Sender: TObject);
|
2014-05-30 12:51:01 +00:00
|
|
|
procedure actSaveDetailsExecute(Sender: TObject);
|
2014-05-20 19:17:23 +00:00
|
|
|
procedure actPauseExecute(Sender: TObject);
|
2014-05-31 20:10:10 +00:00
|
|
|
procedure ToolbarCustomDraw(Sender: TToolBar; const ARect: TRect; var DefaultDraw: Boolean);
|
2014-05-31 20:47:52 +00:00
|
|
|
procedure actShowVerboseExecute(Sender: TObject);
|
|
|
|
procedure actShowInfoExecute(Sender: TObject);
|
|
|
|
procedure actShowWarningExecute(Sender: TObject);
|
|
|
|
procedure actShowErrorExecute(Sender: TObject);
|
2014-08-19 14:06:25 +00:00
|
|
|
procedure actWordWrapExecute(Sender: TObject);
|
2014-10-08 12:33:11 +00:00
|
|
|
procedure actAlwaysOnTopExecute(Sender: TObject);
|
|
|
|
procedure actSaveAsExecute(Sender: TObject);
|
2014-05-20 08:49:57 +00:00
|
|
|
private class var
|
2014-05-31 20:10:10 +00:00
|
|
|
FInstances: TMonitorFormDictionary;
|
2014-05-20 08:49:57 +00:00
|
|
|
private
|
|
|
|
FFreeOnClose: Boolean;
|
2014-08-19 10:50:59 +00:00
|
|
|
FClosed: Boolean;
|
|
|
|
FLockCount: Integer;
|
2014-05-31 20:10:10 +00:00
|
|
|
FLogObservable: IX2LogObservable;
|
2014-05-20 08:49:57 +00:00
|
|
|
FLogAttached: Boolean;
|
2014-05-20 19:17:23 +00:00
|
|
|
FPausedLogCount: Integer;
|
2014-05-30 12:51:01 +00:00
|
|
|
FDetails: IX2LogDetails;
|
2014-05-31 20:47:52 +00:00
|
|
|
FVisibleLevels: TX2LogLevels;
|
2014-08-19 10:50:59 +00:00
|
|
|
FMaxEntries: Cardinal;
|
2014-08-19 14:06:25 +00:00
|
|
|
FWordWrap: Boolean;
|
2016-10-15 07:37:58 +00:00
|
|
|
FCopyHandler: TCopyHandler;
|
2014-05-20 06:59:10 +00:00
|
|
|
protected
|
2014-05-31 20:10:10 +00:00
|
|
|
class function GetInstance(ALog: IX2LogObservable; out AForm: TX2LogObserverMonitorForm): Boolean;
|
2014-05-20 08:49:57 +00:00
|
|
|
class procedure RemoveInstance(AForm: TX2LogObserverMonitorForm);
|
|
|
|
class procedure CleanupInstances;
|
|
|
|
|
2014-05-20 06:59:10 +00:00
|
|
|
procedure CreateParams(var Params: TCreateParams); override;
|
|
|
|
|
|
|
|
procedure WMEnable(var Msg: TWMEnable); message WM_ENABLE;
|
|
|
|
procedure CMReenable(var Msg: TMessage); message CM_REENABLE;
|
2014-05-20 08:49:57 +00:00
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
procedure AttachLog;
|
|
|
|
procedure DetachLog;
|
|
|
|
|
2014-05-20 19:17:23 +00:00
|
|
|
procedure UpdateUI;
|
|
|
|
procedure UpdateStatus;
|
2014-05-31 20:47:52 +00:00
|
|
|
procedure UpdateFilter;
|
|
|
|
|
|
|
|
function GetPaused: Boolean;
|
|
|
|
procedure ToggleVisibleLevel(AAction: TObject; ALevel: TX2LogLevel);
|
2014-05-20 19:17:23 +00:00
|
|
|
|
2014-05-30 12:51:01 +00:00
|
|
|
procedure SetDetails(ADetails: IX2LogDetails);
|
|
|
|
procedure SetBinaryDetails(ADetails: IX2LogDetailsBinary);
|
2014-06-01 13:32:21 +00:00
|
|
|
procedure SetGraphicDetails(ADetails: IX2LogDetailsGraphic);
|
2016-10-14 15:02:27 +00:00
|
|
|
procedure SetDictionaryDetails(ADetails: IX2LogDetailsDictionary);
|
2016-10-15 07:37:58 +00:00
|
|
|
procedure CopyDictionaryDetails;
|
2014-06-01 13:32:21 +00:00
|
|
|
|
|
|
|
procedure SetVisibleDetails(AControl: TControl);
|
2014-08-19 14:06:25 +00:00
|
|
|
procedure SetWordWrap(AValue: Boolean);
|
2014-05-30 12:51:01 +00:00
|
|
|
|
2014-10-08 12:33:11 +00:00
|
|
|
procedure ExportLog(ALog: IX2LogBase);
|
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
property Closed: Boolean read FClosed;
|
2014-05-30 12:51:01 +00:00
|
|
|
property Details: IX2LogDetails read FDetails;
|
2014-08-19 10:50:59 +00:00
|
|
|
property LockCount: Integer read FLockCount;
|
2014-05-31 20:10:10 +00:00
|
|
|
property LogObservable: IX2LogObservable read FLogObservable;
|
2014-05-20 08:49:57 +00:00
|
|
|
property LogAttached: Boolean read FLogAttached;
|
2014-05-20 19:17:23 +00:00
|
|
|
property Paused: Boolean read GetPaused;
|
|
|
|
property PausedLogCount: Integer read FPausedLogCount write FPausedLogCount;
|
2014-05-31 20:47:52 +00:00
|
|
|
property VisibleLevels: TX2LogLevels read FVisibleLevels write FVisibleLevels;
|
2014-05-20 06:59:10 +00:00
|
|
|
public
|
2014-05-31 20:10:10 +00:00
|
|
|
class function Instance(ALog: IX2LogObservable): TX2LogObserverMonitorForm;
|
2014-05-20 08:49:57 +00:00
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
{ Locked instances will always receive log messages, but will not be visible until
|
|
|
|
ShowInstance is called and will hide instead of closing until UnlockInstance is called. }
|
|
|
|
class procedure LockInstance(ALog: IX2LogObservable);
|
|
|
|
class procedure UnlockInstance(ALog: IX2LogObservable);
|
|
|
|
|
2014-05-31 20:10:10 +00:00
|
|
|
class procedure ShowInstance(ALog: IX2LogObservable);
|
|
|
|
class procedure CloseInstance(ALog: IX2LogObservable);
|
2014-05-20 08:49:57 +00:00
|
|
|
|
2014-05-31 20:10:10 +00:00
|
|
|
constructor Create(AOwner: TComponent; ALogObservable: IX2LogObservable = nil); reintroduce;
|
2014-05-20 08:49:57 +00:00
|
|
|
destructor Destroy; override;
|
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
procedure Lock;
|
|
|
|
procedure Unlock;
|
|
|
|
|
2014-05-20 06:59:10 +00:00
|
|
|
{ IX2LogObserver }
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure Log(ALevel: TX2LogLevel; const AMessage, ACategory: string; ADetails: IX2LogDetails); overload;
|
|
|
|
procedure Log(ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage, ACategory: string; ADetails: IX2LogDetails); overload;
|
2014-05-20 08:49:57 +00:00
|
|
|
|
|
|
|
property FreeOnClose: Boolean read FFreeOnClose write FFreeOnClose;
|
2014-08-19 10:50:59 +00:00
|
|
|
property MaxEntries: Cardinal read FMaxEntries write FMaxEntries;
|
2014-05-20 06:59:10 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
2014-05-20 08:49:57 +00:00
|
|
|
System.DateUtils,
|
2014-05-30 12:51:01 +00:00
|
|
|
System.Math,
|
2014-05-20 08:49:57 +00:00
|
|
|
System.SysUtils,
|
2014-05-20 19:17:23 +00:00
|
|
|
Vcl.Clipbrd,
|
2014-05-31 20:10:10 +00:00
|
|
|
Vcl.Themes,
|
2014-05-20 08:49:57 +00:00
|
|
|
Winapi.Windows,
|
|
|
|
|
2014-10-08 12:33:11 +00:00
|
|
|
X2Log.Constants,
|
|
|
|
X2Log.Observer.LogFile;
|
2014-05-20 06:59:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
2014-05-20 08:49:57 +00:00
|
|
|
type
|
|
|
|
TLogEntryNodeData = record
|
|
|
|
Time: TDateTime;
|
2014-08-19 10:50:59 +00:00
|
|
|
Paused: Boolean;
|
2014-05-20 08:49:57 +00:00
|
|
|
Level: TX2LogLevel;
|
2014-10-20 12:07:44 +00:00
|
|
|
Category: string;
|
2014-05-20 08:49:57 +00:00
|
|
|
Message: string;
|
2014-05-30 12:51:01 +00:00
|
|
|
Details: IX2LogDetails;
|
2014-05-20 08:49:57 +00:00
|
|
|
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure Initialize(APaused: Boolean; ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage, ACategory: string; ADetails: IX2LogDetails);
|
2014-05-20 08:49:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
PLogEntryNodeData = ^TLogEntryNodeData;
|
|
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
ColumnLevel = 0;
|
|
|
|
ColumnTime = 1;
|
2014-10-20 12:07:44 +00:00
|
|
|
ColumnCategory = 2;
|
|
|
|
ColumnMessage = 3;
|
2014-05-20 08:49:57 +00:00
|
|
|
|
2014-05-31 20:47:52 +00:00
|
|
|
LevelImageIndex: array[TX2LogLevel] of TImageIndex = (0, 1, 2, 3);
|
|
|
|
|
2014-05-20 08:49:57 +00:00
|
|
|
|
|
|
|
{ TLogEntryNode }
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure TLogEntryNodeData.Initialize(APaused: Boolean; ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage, ACategory: string; ADetails: IX2LogDetails);
|
2014-05-20 08:49:57 +00:00
|
|
|
begin
|
2014-10-08 12:33:11 +00:00
|
|
|
Self.Time := ADateTime;
|
2014-08-19 10:50:59 +00:00
|
|
|
Self.Paused := APaused;
|
2014-05-30 13:25:10 +00:00
|
|
|
Self.Level := ALevel;
|
2014-10-20 12:07:44 +00:00
|
|
|
Self.Category := ACategory;
|
2014-05-30 13:25:10 +00:00
|
|
|
Self.Message := AMessage;
|
|
|
|
Self.Details := ADetails;
|
2014-05-20 08:49:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-20 06:59:10 +00:00
|
|
|
{ TX2LogObserverMonitorForm }
|
2014-05-31 20:10:10 +00:00
|
|
|
class function TX2LogObserverMonitorForm.Instance(ALog: IX2LogObservable): TX2LogObserverMonitorForm;
|
2014-05-20 08:49:57 +00:00
|
|
|
var
|
2014-05-31 20:10:10 +00:00
|
|
|
log: IX2LogObservable;
|
2014-05-20 08:49:57 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
{ Explicit cast ensures we're getting the same pointer every time if, for example,
|
|
|
|
the implementing interface is a descendant of IX2Log }
|
2014-05-31 20:10:10 +00:00
|
|
|
log := (ALog as IX2LogObservable);
|
2014-05-20 08:49:57 +00:00
|
|
|
|
|
|
|
if not Assigned(FInstances) then
|
2014-05-31 20:10:10 +00:00
|
|
|
FInstances := TMonitorFormDictionary.Create([doOwnsValues]);
|
2014-05-20 08:49:57 +00:00
|
|
|
|
|
|
|
if not FInstances.TryGetValue(log, Result) then
|
|
|
|
begin
|
|
|
|
Result := TX2LogObserverMonitorForm.Create(nil, log);
|
|
|
|
Result.FreeOnClose := True;
|
|
|
|
|
|
|
|
FInstances.Add(log, Result);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
class procedure TX2LogObserverMonitorForm.LockInstance(ALog: IX2LogObservable);
|
|
|
|
begin
|
|
|
|
Instance(ALog).Lock;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
class procedure TX2LogObserverMonitorForm.UnlockInstance(ALog: IX2LogObservable);
|
|
|
|
begin
|
|
|
|
Instance(ALog).Unlock;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-31 20:10:10 +00:00
|
|
|
class procedure TX2LogObserverMonitorForm.ShowInstance(ALog: IX2LogObservable);
|
2014-05-20 08:49:57 +00:00
|
|
|
begin
|
|
|
|
Instance(ALog).Show;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-31 20:10:10 +00:00
|
|
|
class procedure TX2LogObserverMonitorForm.CloseInstance(ALog: IX2LogObservable);
|
2014-05-20 08:49:57 +00:00
|
|
|
var
|
|
|
|
monitorForm: TX2LogObserverMonitorForm;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if GetInstance(ALog, monitorForm) then
|
|
|
|
monitorForm.Close;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-31 20:10:10 +00:00
|
|
|
class function TX2LogObserverMonitorForm.GetInstance(ALog: IX2LogObservable; out AForm: TX2LogObserverMonitorForm): Boolean;
|
2014-05-20 08:49:57 +00:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
if Assigned(FInstances) then
|
|
|
|
Result := FInstances.TryGetValue(ALog as IX2Log, AForm);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
class procedure TX2LogObserverMonitorForm.RemoveInstance(AForm: TX2LogObserverMonitorForm);
|
|
|
|
var
|
2014-05-31 20:10:10 +00:00
|
|
|
log: IX2LogObservable;
|
2014-05-20 08:49:57 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Assigned(FInstances) then
|
|
|
|
begin
|
|
|
|
for log in FInstances.Keys do
|
|
|
|
begin
|
|
|
|
if FInstances[log] = AForm then
|
|
|
|
begin
|
2014-05-30 13:25:10 +00:00
|
|
|
FInstances.ExtractPair(log);
|
2014-05-20 08:49:57 +00:00
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
class procedure TX2LogObserverMonitorForm.CleanupInstances;
|
|
|
|
begin
|
|
|
|
if Assigned(FInstances) then
|
|
|
|
FreeAndNil(FInstances);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-31 20:10:10 +00:00
|
|
|
constructor TX2LogObserverMonitorForm.Create(AOwner: TComponent; ALogObservable: IX2LogObservable);
|
2014-05-20 08:49:57 +00:00
|
|
|
var
|
|
|
|
captionFormat: string;
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
FClosed := True;
|
2014-05-31 20:10:10 +00:00
|
|
|
FLogObservable := ALogObservable;
|
2014-08-19 10:50:59 +00:00
|
|
|
FMaxEntries := DefaultMaxEntries;
|
2014-05-20 08:49:57 +00:00
|
|
|
|
|
|
|
captionFormat := GetLogResourceString(@LogMonitorFormCaption);
|
|
|
|
if Pos('%s', captionFormat) > 0 then
|
|
|
|
Caption := Format(captionFormat, [Application.Title])
|
|
|
|
else
|
|
|
|
Caption := captionFormat;
|
|
|
|
|
|
|
|
vstLog.NodeDataSize := SizeOf(TLogEntryNodeData);
|
|
|
|
vstLog.Header.Columns[ColumnTime].Text := GetLogResourceString(@LogMonitorFormColumnTime);
|
2014-10-20 12:07:44 +00:00
|
|
|
vstLog.Header.Columns[ColumnCategory].Text := GetLogResourceString(@LogMonitorFormColumnCategory);
|
2014-05-20 08:49:57 +00:00
|
|
|
vstLog.Header.Columns[ColumnMessage].Text := GetLogResourceString(@LogMonitorFormColumnMessage);
|
2014-05-20 09:19:04 +00:00
|
|
|
|
2014-10-08 12:33:11 +00:00
|
|
|
mmMainFile.Caption := GetLogResourceString(@LogMonitorFormMenuFile);
|
|
|
|
mmMainLog.Caption := GetLogResourceString(@LogMonitorFormMenuLog);
|
|
|
|
mmMainDetails.Caption := GetLogResourceString(@LogMonitorFormMenuDetails);
|
|
|
|
mmMainWindow.Caption := GetLogResourceString(@LogMonitorFormMenuWindow);
|
|
|
|
|
|
|
|
actSaveAs.Caption := GetLogResourceString(@LogMonitorFormMenuFileSaveAs);
|
|
|
|
actClose.Caption := GetLogResourceString(@LogMonitorFormMenuFileClose);
|
2014-05-31 20:47:52 +00:00
|
|
|
actClear.Caption := GetLogResourceString(@LogMonitorFormButtonClear);
|
|
|
|
actPause.Caption := GetLogResourceString(@LogMonitorFormButtonPause);
|
|
|
|
actCopyDetails.Caption := GetLogResourceString(@LogMonitorFormButtonCopyDetails);
|
|
|
|
actSaveDetails.Caption := GetLogResourceString(@LogMonitorFormButtonSaveDetails);
|
2014-10-08 12:33:11 +00:00
|
|
|
actAlwaysOnTop.Caption := GetLogResourceString(@LogMonitorFormMenuWindowAlwaysOnTop);
|
2014-05-20 19:17:23 +00:00
|
|
|
|
2014-05-30 12:51:01 +00:00
|
|
|
sdDetails.Filter := GetLogResourceString(@LogMonitorFormSaveDetailsFilter);
|
2014-10-08 12:33:11 +00:00
|
|
|
sdSaveAs.Filter := GetLogResourceString(@LogMonitorFormSaveDetailsSaveAs);
|
2014-05-30 12:51:01 +00:00
|
|
|
|
2014-05-31 20:47:52 +00:00
|
|
|
lblFilter.Caption := ' ' + GetLogResourceString(@LogMonitorFormButtonFilter) + ' ';
|
|
|
|
actShowVerbose.Caption := GetLogLevelText(TX2LogLevel.Verbose);
|
|
|
|
actShowInfo.Caption := GetLogLevelText(TX2LogLevel.Info);
|
|
|
|
actShowWarning.Caption := GetLogLevelText(TX2LogLevel.Warning);
|
|
|
|
actShowError.Caption := GetLogLevelText(TX2LogLevel.Error);
|
|
|
|
|
|
|
|
FVisibleLevels := [Low(TX2LogLevel)..High(TX2LogLevel)];
|
2016-10-15 07:37:58 +00:00
|
|
|
SetVisibleDetails(nil);
|
2014-05-20 19:17:23 +00:00
|
|
|
UpdateUI;
|
2014-05-20 08:49:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-20 06:59:10 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.CreateParams(var Params: TCreateParams);
|
|
|
|
begin
|
|
|
|
inherited CreateParams(Params);
|
|
|
|
|
|
|
|
Params.WndParent := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.AttachLog;
|
|
|
|
begin
|
|
|
|
if Assigned(FLogObservable) and (not FLogAttached) then
|
|
|
|
begin
|
|
|
|
FLogObservable.Attach(Self);
|
|
|
|
FLogAttached := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.DetachLog;
|
2014-05-20 08:49:57 +00:00
|
|
|
begin
|
2014-05-31 20:10:10 +00:00
|
|
|
if Assigned(FLogObservable) and FLogAttached then
|
2014-08-19 10:50:59 +00:00
|
|
|
begin
|
2014-05-31 20:10:10 +00:00
|
|
|
FLogObservable.Detach(Self);
|
2014-08-19 10:50:59 +00:00
|
|
|
FLogAttached := False;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.Lock;
|
|
|
|
begin
|
|
|
|
Inc(FLockCount);
|
|
|
|
AttachLog;
|
|
|
|
end;
|
|
|
|
|
2014-05-20 08:49:57 +00:00
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.Unlock;
|
|
|
|
begin
|
|
|
|
if FLockCount > 0 then
|
|
|
|
begin
|
|
|
|
Dec(FLockCount);
|
|
|
|
|
|
|
|
{ Lock may have prevented a proper close, try again }
|
|
|
|
if Closed then
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TX2LogObserverMonitorForm.Destroy;
|
|
|
|
begin
|
|
|
|
DetachLog;
|
2014-05-20 08:49:57 +00:00
|
|
|
RemoveInstance(Self);
|
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.FormShow(Sender: TObject);
|
|
|
|
begin
|
2014-08-19 10:50:59 +00:00
|
|
|
FClosed := False;
|
|
|
|
AttachLog;
|
2014-05-20 08:49:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.FormClose(Sender: TObject; var Action: TCloseAction);
|
|
|
|
begin
|
2014-08-19 10:50:59 +00:00
|
|
|
if LockCount = 0 then
|
2014-05-20 08:49:57 +00:00
|
|
|
begin
|
2014-08-19 10:50:59 +00:00
|
|
|
DetachLog;
|
2014-05-20 08:49:57 +00:00
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
if FreeOnClose then
|
|
|
|
Action := caFree
|
|
|
|
else
|
|
|
|
Action := caHide;
|
|
|
|
end else
|
|
|
|
begin
|
2014-05-20 08:49:57 +00:00
|
|
|
Action := caHide;
|
2014-08-19 10:50:59 +00:00
|
|
|
FClosed := True;
|
|
|
|
end;
|
2014-05-20 08:49:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.Log(ALevel: TX2LogLevel; const AMessage, ACategory: string; ADetails: IX2LogDetails);
|
2014-10-08 12:33:11 +00:00
|
|
|
begin
|
2014-10-20 12:07:44 +00:00
|
|
|
Log(ALevel, Now, AMessage, ACategory, ADetails);
|
2014-10-08 12:33:11 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.Log(ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage, ACategory: string; ADetails: IX2LogDetails);
|
2014-05-20 08:49:57 +00:00
|
|
|
var
|
|
|
|
node: PVirtualNode;
|
|
|
|
nodeData: PLogEntryNodeData;
|
|
|
|
|
2014-05-20 06:59:10 +00:00
|
|
|
begin
|
2014-05-20 19:17:23 +00:00
|
|
|
{ Ensure thread safety; TThread.Queue will run the procedure immediately
|
|
|
|
if Log is called from the main thread, or queue it asynchronously }
|
|
|
|
TThread.Queue(nil,
|
|
|
|
procedure
|
2014-05-30 13:25:10 +00:00
|
|
|
var
|
|
|
|
scroll: Boolean;
|
|
|
|
|
2014-05-20 19:17:23 +00:00
|
|
|
begin
|
2014-08-19 10:50:59 +00:00
|
|
|
scroll := (not Paused) and (vstLog.RootNodeCount > 0) and (vstLog.BottomNode = vstLog.GetLast);
|
2014-05-30 13:25:10 +00:00
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
vstLog.BeginUpdate;
|
|
|
|
try
|
2014-05-20 19:17:23 +00:00
|
|
|
node := vstLog.AddChild(nil);
|
|
|
|
nodeData := vstLog.GetNodeData(node);
|
2014-05-20 09:19:04 +00:00
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
{ BeginUpdate causes OnInitNode to be triggered on-demand,
|
|
|
|
moved Initialize call here }
|
|
|
|
Initialize(nodeData^);
|
2014-10-20 12:07:44 +00:00
|
|
|
nodeData^.Initialize(Paused, ALevel, ADateTime, AMessage, ACategory, ADetails);
|
2014-08-19 10:50:59 +00:00
|
|
|
|
|
|
|
vstLog.IsVisible[node] := (not Paused) and (ALevel in VisibleLevels);
|
2014-05-31 20:47:52 +00:00
|
|
|
|
2014-05-30 13:25:10 +00:00
|
|
|
|
2014-08-19 10:50:59 +00:00
|
|
|
while vstLog.RootNodeCount > MaxEntries do
|
|
|
|
vstLog.DeleteNode(vstLog.GetFirst);
|
|
|
|
finally
|
|
|
|
vstLog.EndUpdate;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if scroll then
|
|
|
|
vstLog.ScrollIntoView(node, False);
|
|
|
|
|
|
|
|
UpdateUI;
|
|
|
|
|
|
|
|
if Paused then
|
2014-05-20 19:17:23 +00:00
|
|
|
begin
|
|
|
|
PausedLogCount := PausedLogCount + 1;
|
|
|
|
UpdateStatus;
|
|
|
|
end;
|
|
|
|
end);
|
2014-05-20 06:59:10 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.WMEnable(var Msg: TWMEnable);
|
|
|
|
begin
|
|
|
|
if not Msg.Enabled then
|
|
|
|
{ Modal forms disable all other forms, ensure we're still accessible }
|
|
|
|
PostMessage(Self.Handle, CM_REENABLE, 0, 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.CMReenable(var Msg: TMessage);
|
|
|
|
begin
|
|
|
|
EnableWindow(Self.Handle, True);
|
|
|
|
end;
|
|
|
|
|
2014-05-20 08:49:57 +00:00
|
|
|
|
2014-05-20 19:17:23 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.UpdateUI;
|
|
|
|
begin
|
|
|
|
actClear.Enabled := (vstLog.RootNodeCount > 0);
|
2014-10-08 12:33:11 +00:00
|
|
|
actSaveAs.Enabled := (vstLog.RootNodeCount > 0);
|
2014-05-20 19:17:23 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.UpdateStatus;
|
|
|
|
begin
|
|
|
|
if Paused then
|
|
|
|
sbStatus.SimpleText := ' ' + Format(GetLogResourceString(@LogMonitorFormStatusPaused), [PausedLogCount])
|
|
|
|
else
|
|
|
|
sbStatus.SimpleText := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-31 20:47:52 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.UpdateFilter;
|
|
|
|
var
|
|
|
|
node: PVirtualNode;
|
|
|
|
nodeData: PLogEntryNodeData;
|
|
|
|
|
|
|
|
begin
|
|
|
|
vstLog.BeginUpdate;
|
|
|
|
try
|
|
|
|
for node in vstLog.Nodes do
|
|
|
|
begin
|
|
|
|
nodeData := vstLog.GetNodeData(node);
|
2014-08-19 10:50:59 +00:00
|
|
|
vstLog.IsVisible[node] := (not nodeData^.Paused) and (nodeData^.Level in VisibleLevels);
|
2014-05-31 20:47:52 +00:00
|
|
|
end;
|
|
|
|
finally
|
|
|
|
vstLog.EndUpdate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2LogObserverMonitorForm.GetPaused: Boolean;
|
|
|
|
begin
|
|
|
|
Result := actPause.Checked;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.ToggleVisibleLevel(AAction: TObject; ALevel: TX2LogLevel);
|
|
|
|
begin
|
|
|
|
if ALevel in VisibleLevels then
|
|
|
|
Exclude(FVisibleLevels, ALevel)
|
|
|
|
else
|
|
|
|
Include(FVisibleLevels, ALevel);
|
|
|
|
|
|
|
|
(AAction as TCustomAction).Checked := (ALevel in VisibleLevels);
|
|
|
|
UpdateFilter;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-30 12:51:01 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.SetDetails(ADetails: IX2LogDetails);
|
|
|
|
var
|
2014-06-01 13:32:21 +00:00
|
|
|
logDetailsGraphic: IX2LogDetailsGraphic;
|
2014-05-30 12:51:01 +00:00
|
|
|
logDetailsBinary: IX2LogDetailsBinary;
|
2016-10-14 15:02:27 +00:00
|
|
|
logDetailsDictionary: IX2LogDetailsDictionary;
|
2014-05-30 12:51:01 +00:00
|
|
|
logDetailsText: IX2LogDetailsText;
|
2014-08-19 14:06:25 +00:00
|
|
|
canWrap: Boolean;
|
2014-05-30 12:51:01 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
FDetails := ADetails;
|
2014-08-19 14:06:25 +00:00
|
|
|
canWrap := False;
|
2016-10-15 07:37:58 +00:00
|
|
|
FCopyHandler := nil;
|
2014-05-30 12:51:01 +00:00
|
|
|
|
|
|
|
if Assigned(Details) then
|
|
|
|
begin
|
2014-06-01 13:32:21 +00:00
|
|
|
if Supports(ADetails, IX2LogDetailsGraphic, logDetailsGraphic) then
|
|
|
|
SetGraphicDetails(logDetailsGraphic)
|
|
|
|
|
|
|
|
else if Supports(ADetails, IX2LogDetailsBinary, logDetailsBinary) then
|
2014-05-30 12:51:01 +00:00
|
|
|
SetBinaryDetails(logDetailsBinary)
|
|
|
|
|
2016-10-14 15:02:27 +00:00
|
|
|
else if Supports(ADetails, IX2LogDetailsDictionary, logDetailsDictionary) then
|
|
|
|
SetDictionaryDetails(logDetailsDictionary)
|
|
|
|
|
2014-05-30 12:51:01 +00:00
|
|
|
else if Supports(ADetails, IX2LogDetailsText, logDetailsText) then
|
2014-06-01 13:32:21 +00:00
|
|
|
begin
|
2014-05-30 12:51:01 +00:00
|
|
|
reDetails.Text := logDetailsText.AsString;
|
2014-08-19 14:06:25 +00:00
|
|
|
canWrap := True;
|
2014-06-01 13:32:21 +00:00
|
|
|
SetVisibleDetails(reDetails);
|
|
|
|
end;
|
2014-05-30 12:51:01 +00:00
|
|
|
end else
|
2014-06-01 13:32:21 +00:00
|
|
|
SetVisibleDetails(nil);
|
2014-05-30 12:51:01 +00:00
|
|
|
|
|
|
|
|
2016-10-15 07:37:58 +00:00
|
|
|
actCopyDetails.Enabled := Assigned(FCopyHandler) or Supports(ADetails, IX2LogDetailsCopyable);
|
2014-05-30 12:51:01 +00:00
|
|
|
actSaveDetails.Enabled := Supports(ADetails, IX2LogDetailsStreamable);
|
2014-08-19 14:06:25 +00:00
|
|
|
actWordWrap.Enabled := canWrap;
|
|
|
|
actWordWrap.Checked := canWrap and FWordWrap;
|
|
|
|
|
|
|
|
SetWordWrap(actWordWrap.Checked);
|
2014-05-30 12:51:01 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.SetBinaryDetails(ADetails: IX2LogDetailsBinary);
|
|
|
|
const
|
|
|
|
BufferSize = 4096;
|
|
|
|
|
|
|
|
BytesPerLine = 16;
|
|
|
|
HexSplitPos = 7;
|
|
|
|
HexSplitSpacing = 1;
|
|
|
|
|
|
|
|
HexDigits = 2;
|
|
|
|
TextDigits = 1;
|
|
|
|
HexSpacing = 0;
|
|
|
|
HexTextSpacing = 2;
|
|
|
|
|
|
|
|
ReadableCharacters = [32..126, 161..255];
|
|
|
|
UnreadableCharacter = '.';
|
|
|
|
|
|
|
|
|
|
|
|
procedure ResetLine(var ALine: string);
|
|
|
|
var
|
|
|
|
linePos: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for linePos := 1 to Length(ALine) do
|
|
|
|
ALine[linePos] := ' ';
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
stream: TStream;
|
|
|
|
buffer: array[0..Pred(BufferSize)] of Byte;
|
|
|
|
readBytes: Integer;
|
|
|
|
linePosition: Integer;
|
|
|
|
line: string;
|
|
|
|
bufferIndex: Integer;
|
|
|
|
hexValue: string;
|
|
|
|
hexPos: Integer;
|
|
|
|
textPos: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
stream := ADetails.AsStream;
|
|
|
|
linePosition := 0;
|
|
|
|
|
|
|
|
SetLength(line, (BytesPerLine * (HexDigits + HexSpacing + TextDigits)) + HexTextSpacing +
|
|
|
|
IfThen(HexSplitPos < BytesPerLine, HexSplitSpacing, 0));
|
|
|
|
ResetLine(line);
|
|
|
|
|
|
|
|
reDetails.Lines.BeginUpdate;
|
|
|
|
try
|
|
|
|
reDetails.Lines.Clear;
|
|
|
|
|
|
|
|
while True do
|
|
|
|
begin
|
|
|
|
readBytes := stream.Read(buffer, SizeOf(buffer));
|
|
|
|
if readBytes = 0 then
|
|
|
|
break;
|
|
|
|
|
|
|
|
for bufferIndex := 0 to Pred(readBytes) do
|
|
|
|
begin
|
|
|
|
hexValue := IntToHex(buffer[bufferIndex], HexDigits);
|
|
|
|
|
|
|
|
if linePosition >= BytesPerLine then
|
|
|
|
begin
|
|
|
|
reDetails.Lines.Add(line);
|
|
|
|
|
|
|
|
ResetLine(line);
|
|
|
|
linePosition := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
hexPos := (linePosition * (HexDigits + HexSpacing));
|
|
|
|
if linePosition > HexSplitPos then
|
|
|
|
Inc(hexPos, HexSplitSpacing);
|
|
|
|
|
|
|
|
line[hexPos + 1] := hexValue[1];
|
|
|
|
line[hexPos + 2] := hexValue[2];
|
|
|
|
|
|
|
|
textPos := (BytesPerLine * (HexDigits + HexSpacing)) + HexTextSpacing + (linePosition * TextDigits);
|
|
|
|
if HexSplitPos < BytesPerLine then
|
|
|
|
Inc(textPos, HexSplitSpacing);
|
|
|
|
|
|
|
|
if buffer[bufferIndex] in ReadableCharacters then
|
|
|
|
line[textPos] := Chr(buffer[bufferIndex])
|
|
|
|
else
|
|
|
|
line[textPos] := UnreadableCharacter;
|
|
|
|
|
|
|
|
Inc(linePosition);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if linePosition > 0 then
|
|
|
|
reDetails.Lines.Add(line);
|
|
|
|
finally
|
|
|
|
reDetails.Lines.EndUpdate;
|
2014-06-01 13:32:21 +00:00
|
|
|
|
|
|
|
SetVisibleDetails(reDetails);
|
2014-05-30 12:51:01 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-06-01 13:32:21 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.SetGraphicDetails(ADetails: IX2LogDetailsGraphic);
|
|
|
|
begin
|
|
|
|
imgDetailsImage.Picture.Assign(ADetails.AsGraphic);
|
|
|
|
SetVisibleDetails(sbDetailsImage);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2016-10-14 15:02:27 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.SetDictionaryDetails(ADetails: IX2LogDetailsDictionary);
|
|
|
|
var
|
|
|
|
key: string;
|
|
|
|
|
|
|
|
begin
|
|
|
|
vleDetailsDictionary.Strings.Clear;
|
|
|
|
|
|
|
|
for key in ADetails.Keys do
|
2016-10-15 09:22:51 +00:00
|
|
|
vleDetailsDictionary.Values[key] := ADetails.DisplayValue[key];
|
2016-10-14 15:02:27 +00:00
|
|
|
|
2016-10-15 07:37:58 +00:00
|
|
|
FCopyHandler := CopyDictionaryDetails;
|
2016-10-14 15:02:27 +00:00
|
|
|
SetVisibleDetails(vleDetailsDictionary);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2016-10-15 07:37:58 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.CopyDictionaryDetails;
|
|
|
|
var
|
|
|
|
y: Integer;
|
|
|
|
x: Integer;
|
|
|
|
selectedText: TStringBuilder;
|
|
|
|
|
|
|
|
begin
|
|
|
|
selectedText := TStringBuilder.Create;
|
|
|
|
try
|
|
|
|
for y := vleDetailsDictionary.Selection.Top to vleDetailsDictionary.Selection.Bottom do
|
|
|
|
begin
|
|
|
|
for x := vleDetailsDictionary.Selection.Left to vleDetailsDictionary.Selection.Right do
|
|
|
|
selectedText.Append(vleDetailsDictionary.Cells[x, y]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Clipboard.AsText := selectedText.ToString;
|
|
|
|
finally
|
|
|
|
FreeAndNil(selectedText);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-06-01 13:32:21 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.SetVisibleDetails(AControl: TControl);
|
2017-12-27 13:01:10 +00:00
|
|
|
var
|
|
|
|
text: string;
|
|
|
|
|
2014-06-01 13:32:21 +00:00
|
|
|
begin
|
|
|
|
if Assigned(AControl) then
|
|
|
|
begin
|
|
|
|
AControl.BringToFront;
|
2017-12-27 13:01:10 +00:00
|
|
|
|
|
|
|
if (AControl = reDetails) and (not reDetails.HandleAllocated) then
|
|
|
|
begin
|
|
|
|
// TRichEdit clears it's text when it is first shown, at least on Delphi XE2
|
|
|
|
text := reDetails.Text;
|
|
|
|
reDetails.Visible := True;
|
|
|
|
reDetails.Text := text;
|
|
|
|
end else
|
|
|
|
AControl.Visible := True;
|
2014-06-01 13:32:21 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
reDetails.Visible := (AControl = reDetails);
|
|
|
|
sbDetailsImage.Visible := (AControl = sbDetailsImage);
|
2016-10-14 15:02:27 +00:00
|
|
|
vleDetailsDictionary.Visible := (AControl = vleDetailsDictionary);
|
2014-06-01 13:32:21 +00:00
|
|
|
|
|
|
|
if not reDetails.Visible then
|
|
|
|
reDetails.Clear;
|
|
|
|
|
|
|
|
if not sbDetailsImage.Visible then
|
|
|
|
imgDetailsImage.Picture.Assign(nil);
|
2016-10-14 15:02:27 +00:00
|
|
|
|
|
|
|
if not vleDetailsDictionary.Visible then
|
|
|
|
vleDetailsDictionary.Strings.Clear;
|
2014-06-01 13:32:21 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-08-19 14:06:25 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.SetWordWrap(AValue: Boolean);
|
|
|
|
begin
|
|
|
|
reDetails.WordWrap := AValue;
|
|
|
|
|
|
|
|
if AValue then
|
|
|
|
reDetails.ScrollBars := ssVertical
|
|
|
|
else
|
|
|
|
reDetails.ScrollBars := ssBoth;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-08 12:33:11 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.ExportLog(ALog: IX2LogBase);
|
|
|
|
var
|
|
|
|
node: PVirtualNode;
|
|
|
|
nodeData: PLogEntryNodeData;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for node in vstLog.Nodes do
|
|
|
|
begin
|
|
|
|
nodeData := vstLog.GetNodeData(node);
|
2014-10-20 12:07:44 +00:00
|
|
|
ALog.Log(nodeData^.Level, nodeData^.Time, nodeData^.Message, nodeData^.Category, nodeData^.Details);
|
2014-10-08 12:33:11 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-20 08:49:57 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.vstLogFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
|
|
|
var
|
|
|
|
nodeData: PLogEntryNodeData;
|
|
|
|
|
|
|
|
begin
|
|
|
|
nodeData := Sender.GetNodeData(Node);
|
|
|
|
Finalize(nodeData^);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.vstLogGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
|
|
|
|
TextType: TVSTTextType; var CellText: string);
|
|
|
|
var
|
|
|
|
nodeData: PLogEntryNodeData;
|
|
|
|
|
|
|
|
begin
|
|
|
|
CellText := '';
|
|
|
|
nodeData := Sender.GetNodeData(Node);
|
|
|
|
|
|
|
|
case Column of
|
|
|
|
ColumnTime:
|
|
|
|
CellText := DateTimeToStr(nodeData^.Time);
|
|
|
|
|
2014-10-20 12:07:44 +00:00
|
|
|
ColumnCategory:
|
|
|
|
CellText := nodeData^.Category;
|
|
|
|
|
2014-05-20 08:49:57 +00:00
|
|
|
ColumnMessage:
|
|
|
|
CellText := nodeData^.Message;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.vstLogGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind;
|
|
|
|
Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer);
|
|
|
|
var
|
|
|
|
nodeData: PLogEntryNodeData;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if Kind in [ikNormal, ikSelected] then
|
|
|
|
begin
|
|
|
|
nodeData := Sender.GetNodeData(Node);
|
|
|
|
|
|
|
|
case Column of
|
|
|
|
ColumnLevel:
|
2014-05-31 20:47:52 +00:00
|
|
|
ImageIndex := LevelImageIndex[nodeData^.Level];
|
2014-05-20 08:49:57 +00:00
|
|
|
|
|
|
|
ColumnMessage:
|
2014-05-30 12:51:01 +00:00
|
|
|
if Assigned(nodeData^.Details) then
|
2014-05-20 08:49:57 +00:00
|
|
|
ImageIndex := 4;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-05-20 09:19:04 +00:00
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.vstLogFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
|
|
|
|
var
|
|
|
|
nodeData: PLogEntryNodeData;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if Assigned(Node) then
|
|
|
|
begin
|
|
|
|
nodeData := Sender.GetNodeData(Node);
|
2014-05-30 12:51:01 +00:00
|
|
|
SetDetails(nodeData^.Details);
|
2014-05-20 09:19:04 +00:00
|
|
|
end else
|
2014-05-30 12:51:01 +00:00
|
|
|
SetDetails(nil);
|
2014-05-20 19:17:23 +00:00
|
|
|
|
|
|
|
UpdateUI;
|
2014-05-20 09:19:04 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2016-10-15 07:37:58 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.vleDetailsDictionaryKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|
|
|
begin
|
|
|
|
if (Shift = [ssCtrl]) and (Key = Ord('C')) then
|
|
|
|
begin
|
|
|
|
CopyDictionaryDetails;
|
|
|
|
Key := 0;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-08 12:33:11 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.actCloseExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-20 19:17:23 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.actClearExecute(Sender: TObject);
|
2014-05-20 09:19:04 +00:00
|
|
|
begin
|
|
|
|
vstLog.Clear;
|
2014-06-01 13:32:21 +00:00
|
|
|
SetDetails(nil);
|
|
|
|
|
2014-05-20 19:17:23 +00:00
|
|
|
UpdateUI;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.actCopyDetailsExecute(Sender: TObject);
|
2014-05-30 12:51:01 +00:00
|
|
|
var
|
|
|
|
logDetailsCopyable: IX2LogDetailsCopyable;
|
|
|
|
|
|
|
|
begin
|
2016-10-15 07:37:58 +00:00
|
|
|
if Assigned(FCopyHandler) then
|
|
|
|
FCopyHandler
|
|
|
|
|
|
|
|
else if Supports(Details, IX2LogDetailsCopyable, logDetailsCopyable) then
|
2014-05-30 12:51:01 +00:00
|
|
|
logDetailsCopyable.CopyToClipboard;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.actSaveDetailsExecute(Sender: TObject);
|
|
|
|
var
|
|
|
|
logDetailsStreamable: IX2LogDetailsStreamable;
|
|
|
|
outputStream: TFileStream;
|
|
|
|
|
2014-05-20 19:17:23 +00:00
|
|
|
begin
|
2014-05-30 12:51:01 +00:00
|
|
|
if Supports(Details, IX2LogDetailsStreamable, logDetailsStreamable) then
|
|
|
|
begin
|
|
|
|
if sdDetails.Execute then
|
|
|
|
begin
|
|
|
|
outputStream := TFileStream.Create(sdDetails.FileName, fmCreate or fmShareDenyWrite);
|
|
|
|
try
|
|
|
|
logDetailsStreamable.SaveToStream(outputStream);
|
|
|
|
finally
|
|
|
|
FreeAndNil(outputStream);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2014-05-20 19:17:23 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-08-19 14:06:25 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.actWordWrapExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
FWordWrap := actWordWrap.Checked;
|
|
|
|
SetWordWrap(FWordWrap);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-20 19:17:23 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.actPauseExecute(Sender: TObject);
|
2014-08-19 10:50:59 +00:00
|
|
|
var
|
|
|
|
node: PVirtualNode;
|
|
|
|
nodeData: PLogEntryNodeData;
|
|
|
|
|
2014-05-20 19:17:23 +00:00
|
|
|
begin
|
2014-08-19 10:50:59 +00:00
|
|
|
if not Paused then
|
|
|
|
begin
|
|
|
|
{ Clear Paused status from nodes }
|
|
|
|
vstLog.BeginUpdate;
|
|
|
|
try
|
|
|
|
for node in vstLog.Nodes do
|
|
|
|
begin
|
|
|
|
nodeData := vstLog.GetNodeData(node);
|
|
|
|
|
|
|
|
if nodeData^.Paused then
|
|
|
|
begin
|
|
|
|
nodeData^.Paused := False;
|
|
|
|
vstLog.IsVisible[node] := (nodeData^.Level in VisibleLevels);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
vstLog.EndUpdate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-05-20 19:17:23 +00:00
|
|
|
PausedLogCount := 0;
|
|
|
|
UpdateStatus;
|
2014-05-20 09:19:04 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-30 13:06:47 +00:00
|
|
|
|
2014-05-31 20:47:52 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.actShowVerboseExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ToggleVisibleLevel(Sender, TX2LogLevel.Verbose);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.actShowInfoExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ToggleVisibleLevel(Sender, TX2LogLevel.Info);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.actShowWarningExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ToggleVisibleLevel(Sender, TX2LogLevel.Warning);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.actShowErrorExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ToggleVisibleLevel(Sender, TX2LogLevel.Error);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-08 12:33:11 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.actAlwaysOnTopExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
actAlwaysOnTop.Checked := not actAlwaysOnTop.Checked;
|
|
|
|
|
|
|
|
if actAlwaysOnTop.Checked then
|
|
|
|
SetWindowPos(Self.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE)
|
|
|
|
else
|
|
|
|
SetWindowPos(Self.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogObserverMonitorForm.actSaveAsExecute(Sender: TObject);
|
|
|
|
var
|
|
|
|
logFile: IX2LogBase;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if sdSaveAs.Execute then
|
|
|
|
begin
|
|
|
|
{ Default behaviour of the LogFile observer is to append }
|
|
|
|
System.SysUtils.DeleteFile(sdSaveAs.FileName);
|
|
|
|
|
|
|
|
logFile := TX2LogFileObserver.Create(sdSaveAs.FileName, X2LogLevelsAll);
|
|
|
|
ExportLog(logFile);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-31 20:10:10 +00:00
|
|
|
procedure TX2LogObserverMonitorForm.ToolbarCustomDraw(Sender: TToolBar; const ARect: TRect; var DefaultDraw: Boolean);
|
|
|
|
var
|
|
|
|
element: TThemedElementDetails;
|
|
|
|
rect: TRect;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if StyleServices.Enabled then
|
|
|
|
begin
|
|
|
|
rect := Sender.ClientRect;
|
|
|
|
if Assigned(Self.Menu) then
|
|
|
|
Dec(rect.Top, GetSystemMetrics(SM_CYMENU));
|
|
|
|
|
|
|
|
element := StyleServices.GetElementDetails(trRebarRoot);
|
|
|
|
StyleServices.DrawElement(Sender.Canvas.Handle, element, rect);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-30 13:06:47 +00:00
|
|
|
initialization
|
|
|
|
finalization
|
|
|
|
TX2LogObserverMonitorForm.CleanupInstances;
|
|
|
|
|
2014-05-20 06:59:10 +00:00
|
|
|
end.
|