1
0
mirror of synced 2024-11-08 14:19:16 +00:00

Added: FS#3 - Filter buttons for log level

This commit is contained in:
Mark van Renswoude 2014-05-31 20:47:52 +00:00
parent a9cf1b75f6
commit bf0bb05983
6 changed files with 168 additions and 24 deletions

View File

@ -384,7 +384,7 @@ object MainForm: TMainForm
Left = 552
Top = 176
Bitmap = {
494C01010200140038000C000C00FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
494C0101020014003C000C000C00FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000300000000C00000001002000000000000009
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000

View File

@ -111,9 +111,10 @@ begin
SetLogResourceString(@LogMonitorFormColumnMessage, 'Melding');
SetLogResourceString(@LogMonitorFormButtonClear, 'Wissen');
SetLogResourceString(@LogMonitorFormButtonPause, 'Pauzeren');
SetLogResourceString(@LogMonitorFormButtonCopyDetails, 'Kopieren');
SetLogResourceString(@LogMonitorFormButtonSaveDetails, 'Opslaan');
SetLogResourceString(@LogMonitorFormStatusPaused, 'Gepauseerd: %d melding(en) overgeslagen');
SetLogResourceString(@LogMonitorFormStatusPaused, 'Gepauzeerd: %d melding(en) overgeslagen');
SetLogResourceString(@LogMonitorFormSaveDetailsFilter, 'Alle bestanden (*.*)|*.*');
@ -201,8 +202,7 @@ end;
procedure TMainForm.btnMonitorFormClick(Sender: TObject);
begin
// TX2LogObserverMonitorForm.ShowInstance(FLog);
TX2LogObserverMonitorForm.ShowInstance(Tx2globallog.Instance);
TX2LogObserverMonitorForm.ShowInstance(FLog);
end;

View File

@ -40,9 +40,12 @@ resourcestring
{ Caption of the toolbar buttons }
LogMonitorFormButtonClear = 'Clear';
LogMonitorFormButtonPause = 'Pause';
LogMonitorFormButtonCopyDetails = 'Copy';
LogMonitorFormButtonSaveDetails = 'Save';
LogMonitorFormButtonFilter = 'Filter:';
{ Status messages }
LogMonitorFormStatusPaused = 'Paused: %d log message(s) skipped';

View File

@ -8,6 +8,7 @@ uses
type
TX2LogLevel = (Verbose, Info, Warning, Error);
TX2LogLevels = set of TX2LogLevel;
const

View File

@ -148,7 +148,7 @@ object X2LogObserverMonitorForm: TX2LogObserverMonitorForm
end
item
Position = 2
Width = 428
Width = 424
WideText = 'Message'
end>
end
@ -158,7 +158,7 @@ object X2LogObserverMonitorForm: TX2LogObserverMonitorForm
Width = 602
Height = 22
AutoSize = True
ButtonWidth = 56
ButtonWidth = 67
Caption = 'tbLog'
Images = ilsLog
List = True
@ -175,6 +175,43 @@ object X2LogObserverMonitorForm: TX2LogObserverMonitorForm
Left = 56
Top = 0
Action = actPause
AutoSize = True
Style = tbsCheck
end
object lblFilter: TLabel
Left = 116
Top = 0
Width = 46
Height = 22
Caption = ' Filter: '
Layout = tlCenter
end
object tbShowVerbose: TToolButton
Left = 162
Top = 0
Action = actShowVerbose
AutoSize = True
Style = tbsCheck
end
object tbShowInfo: TToolButton
Left = 232
Top = 0
Action = actShowInfo
AutoSize = True
Style = tbsCheck
end
object tbShowWarning: TToolButton
Left = 283
Top = 0
Action = actShowWarning
AutoSize = True
Style = tbsCheck
end
object tbShowError: TToolButton
Left = 354
Top = 0
Action = actShowError
AutoSize = True
Style = tbsCheck
end
end
@ -196,7 +233,7 @@ object X2LogObserverMonitorForm: TX2LogObserverMonitorForm
Left = 448
Top = 48
Bitmap = {
494C0101090040009C0010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
494C010109004000B80010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000003000000001002000000000000030
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
@ -626,6 +663,30 @@ object X2LogObserverMonitorForm: TX2LogObserverMonitorForm
ImageIndex = 8
OnExecute = actPauseExecute
end
object actShowVerbose: TAction
Caption = 'Verbose'
Checked = True
ImageIndex = 0
OnExecute = actShowVerboseExecute
end
object actShowInfo: TAction
Caption = 'Info'
Checked = True
ImageIndex = 1
OnExecute = actShowInfoExecute
end
object actShowWarning: TAction
Caption = 'Warning'
Checked = True
ImageIndex = 2
OnExecute = actShowWarningExecute
end
object actShowError: TAction
Caption = 'Error'
Checked = True
ImageIndex = 3
OnExecute = actShowErrorExecute
end
end
object sdDetails: TSaveDialog
Options = [ofOverwritePrompt, ofHideReadOnly, ofEnableSizing]

View File

@ -51,6 +51,15 @@ type
actPause: TAction;
tbPause: TToolButton;
sdDetails: TSaveDialog;
tbShowVerbose: TToolButton;
tbShowInfo: TToolButton;
tbShowWarning: TToolButton;
tbShowError: TToolButton;
actShowVerbose: TAction;
actShowInfo: TAction;
actShowWarning: TAction;
actShowError: TAction;
lblFilter: TLabel;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
@ -65,6 +74,10 @@ type
procedure actSaveDetailsExecute(Sender: TObject);
procedure actPauseExecute(Sender: TObject);
procedure ToolbarCustomDraw(Sender: TToolBar; const ARect: TRect; var DefaultDraw: Boolean);
procedure actShowVerboseExecute(Sender: TObject);
procedure actShowInfoExecute(Sender: TObject);
procedure actShowWarningExecute(Sender: TObject);
procedure actShowErrorExecute(Sender: TObject);
private class var
FInstances: TMonitorFormDictionary;
private
@ -73,8 +86,7 @@ type
FLogAttached: Boolean;
FPausedLogCount: Integer;
FDetails: IX2LogDetails;
function GetPaused: Boolean;
FVisibleLevels: TX2LogLevels;
protected
class function GetInstance(ALog: IX2LogObservable; out AForm: TX2LogObserverMonitorForm): Boolean;
class procedure RemoveInstance(AForm: TX2LogObserverMonitorForm);
@ -87,6 +99,10 @@ type
procedure UpdateUI;
procedure UpdateStatus;
procedure UpdateFilter;
function GetPaused: Boolean;
procedure ToggleVisibleLevel(AAction: TObject; ALevel: TX2LogLevel);
procedure SetDetails(ADetails: IX2LogDetails);
procedure SetBinaryDetails(ADetails: IX2LogDetailsBinary);
@ -96,6 +112,7 @@ type
property LogAttached: Boolean read FLogAttached;
property Paused: Boolean read GetPaused;
property PausedLogCount: Integer read FPausedLogCount write FPausedLogCount;
property VisibleLevels: TX2LogLevels read FVisibleLevels write FVisibleLevels;
public
class function Instance(ALog: IX2LogObservable): TX2LogObserverMonitorForm;
@ -145,6 +162,8 @@ const
ColumnTime = 1;
ColumnMessage = 2;
LevelImageIndex: array[TX2LogLevel] of TImageIndex = (0, 1, 2, 3);
{ TLogEntryNode }
procedure TLogEntryNodeData.Initialize(ALevel: TX2LogLevel; const AMessage: string; ADetails: IX2LogDetails);
@ -249,12 +268,20 @@ begin
vstLog.Header.Columns[ColumnTime].Text := GetLogResourceString(@LogMonitorFormColumnTime);
vstLog.Header.Columns[ColumnMessage].Text := GetLogResourceString(@LogMonitorFormColumnMessage);
tbClear.Caption := GetLogResourceString(@LogMonitorFormButtonClear);
tbCopyDetails.Caption := GetLogResourceString(@LogMonitorFormButtonCopyDetails);
tbSaveDetails.Caption := GetLogResourceString(@LogMonitorFormButtonSaveDetails);
actClear.Caption := GetLogResourceString(@LogMonitorFormButtonClear);
actPause.Caption := GetLogResourceString(@LogMonitorFormButtonPause);
actCopyDetails.Caption := GetLogResourceString(@LogMonitorFormButtonCopyDetails);
actSaveDetails.Caption := GetLogResourceString(@LogMonitorFormButtonSaveDetails);
sdDetails.Filter := GetLogResourceString(@LogMonitorFormSaveDetailsFilter);
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)];
UpdateUI;
end;
@ -325,6 +352,8 @@ begin
nodeData := vstLog.GetNodeData(node);
nodeData^.Initialize(ALevel, AMessage, ADetails);
vstLog.IsVisible[node] := (ALevel in VisibleLevels);
if scroll then
vstLog.ScrollIntoView(node, False);
@ -367,6 +396,43 @@ begin
end;
procedure TX2LogObserverMonitorForm.UpdateFilter;
var
node: PVirtualNode;
nodeData: PLogEntryNodeData;
begin
vstLog.BeginUpdate;
try
for node in vstLog.Nodes do
begin
nodeData := vstLog.GetNodeData(node);
vstLog.IsVisible[node] := (nodeData^.Level in VisibleLevels);
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;
procedure TX2LogObserverMonitorForm.SetDetails(ADetails: IX2LogDetails);
var
logDetailsBinary: IX2LogDetailsBinary;
@ -487,12 +553,6 @@ begin
end;
function TX2LogObserverMonitorForm.GetPaused: Boolean;
begin
Result := actPause.Checked;
end;
procedure TX2LogObserverMonitorForm.vstLogInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates);
var
@ -559,12 +619,7 @@ begin
case Column of
ColumnLevel:
case nodeData^.Level of
TX2LogLevel.Verbose: ImageIndex := 0;
TX2LogLevel.Info: ImageIndex := 1;
TX2LogLevel.Warning: ImageIndex := 2;
TX2LogLevel.Error: ImageIndex := 3;
end;
ImageIndex := LevelImageIndex[nodeData^.Level];
ColumnMessage:
if Assigned(nodeData^.Details) then
@ -635,6 +690,30 @@ begin
end;
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;
procedure TX2LogObserverMonitorForm.ToolbarCustomDraw(Sender: TToolBar; const ARect: TRect; var DefaultDraw: Boolean);
var
element: TThemedElementDetails;