📄 umessagefilterform.pas
字号:
{ JADD - Just Another DelphiDoc: Documentation from Delphi Source Code
Copyright (C) 2006-2008 Gerold Veith
This file is part of JADD - Just Another DelphiDoc.
DelphiDoc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
DelphiDoc 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
}
unit UMessageFilterForm;
{Contains a simple dialog to select what messages, created while generating the
documentation, should be shown and what messages should be filtered out. }
interface
uses
Windows, SysUtils, Classes, Forms, Controls, StdCtrls, Buttons, ComCtrls,
ImgList,
UGenerationMessages;
type
{A simple dialog to select what messages, created while generating the
documentation, should be shown and what messages should be filtered out. }
TFormMessageFilter = class(TForm)
ImageList: TImageList;
TreeView: TTreeView;
MemoDescription: TMemo;
BitBtnOK: TBitBtn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TreeViewChange(Sender: TObject; Node: TTreeNode);
procedure TreeViewMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure TreeViewKeyPress(Sender: TObject; var Key: Char);
private
//all currently possible kinds of messages
FDescriptions: TMessageDescriptionsList;
//the filter for the messages to edit
FFilter: TMessageFilter;
//Fill the TreeView with all currently possible kinds of messages.
procedure FillItems;
//Set the state for each item in the TreeView whether filtered or not.
procedure UpdateCheckBoxes;
//Toggle the state of an item in the TreeView whether filtered or not.
procedure ToggleCheckBox(Node: TTreeNode);
public
//Creates the dialog and shows what messages are filtered and what are not.
constructor Create(const Descriptions: TMessageDescriptionsList;
Filter: TMessageFilter); reintroduce;
end;
//Allows the user to filter kinds of messages generated while generating the
//documentation.
function EditMessageFilter(const Descriptions: TMessageDescriptionsList;
Filter: TMessageFilter): Boolean;
implementation
{$R *.dfm}
uses USettingsKeeper;
{Allows the user to filter kinds of messages generated while generating the
documentation.
~param Descriptions all currently possible kinds of messages
~param Filter the filter for messages to edit
~result whether the filter has possibly been changed }
function EditMessageFilter(const Descriptions: TMessageDescriptionsList;
Filter: TMessageFilter): Boolean;
begin
with TFormMessageFilter.Create(Descriptions, Filter) do //create the form
try
// Result := ShowModal = mrOk;
ShowModal; //show the dialog
finally
Free;
end;
Result := True; //refresh messages
end;
{Creates the dialog and shows what messages are filtered and what are not.
~param Descriptions all currently possible kinds of messages
~param Filter the filter for messages to edit }
constructor TFormMessageFilter.Create(const Descriptions:
TMessageDescriptionsList;
Filter: TMessageFilter);
begin
inherited Create(nil); //create the form
FDescriptions := Descriptions; //save the parameters
FFilter := Filter;
FillItems; //fill possible kinds of messages
UpdateCheckBoxes; //show whether they are filtered
TFormSettings.SaveBasicFormValues(Self); //read the basic form values
end;
{Fill the TreeView with all currently possible kinds of messages. }
procedure TFormMessageFilter.FillItems;
{Fill a branch with all kinds of messages under a heading.
~param MsgRoot the node to add the messages under
~param Desc the list of messages of a heading }
procedure FillMessages(MsgRoot: TTreeNode; Desc: TMessageDescriptions);
var i :Integer; //counter through all messages
begin
for i := 0 to Desc.Count - 1 do //for each message
TreeView.Items.AddChildObject(MsgRoot, //add it
Format('%d: %s',
[i, Desc.Descriptions[i].Text]),
Pointer(i));
end;
var Root :TTreeNode; //the root of all messages
i :Integer; //counter through all headings
begin
Root := TreeView.Items.Add(nil, 'All Messages'); //create the root
for i := 1 to Length(FDescriptions) - 1 do //for each heading
if assigned(FDescriptions[i]) then //if valid
FillMessages(TreeView.Items.AddChildObject(Root, //add heading and its
Format('%d: %s', //messages
[i,
FDescriptions[i].Title]),
Pointer(i)),
FDescriptions[i]);
Root.Expand(False); //show all headings
end;
{Set the state for each item in the TreeView whether filtered or not. }
procedure TFormMessageFilter.UpdateCheckBoxes;
//to translate from a boolean value to a filter state
const NewFilter: array[Boolean] of TMessageFilterStatus =
(mfsNotFiltered, mfsFiltered);
{Set the state for each message under the heading whether filtered or not.
~param Node the node of the first messages to update
~param Title the heading of the messages }
procedure CheckMessages(Node: TTreeNode; Title: String);
begin
while assigned(Node) do //for each message
begin //set check box state (image)
Node.ImageIndex := ord(NewFilter[FFilter.IsFiltered[Title,
TMessageNumber(Node.Data)]]);
Node.SelectedIndex := Node.ImageIndex;
Node := Node.getNextSibling; //next message
end;
end;
var Node :TTreeNode; //root node and node of headings
Title :String; //all headings of messages
begin
Node := TreeView.Items.GetFirstNode; //get the root node
Node.ImageIndex := ord(FFilter.DescFiltered[FDescriptions]); //set its state
Node.SelectedIndex := Node.ImageIndex;
Node := Node.getFirstChild; //get the first heading
while assigned(Node) do //for each heading
begin
Title := FDescriptions[TMessageID(Node.Data)].Title; //get the heading title
CheckMessages(Node.getFirstChild, Title); //update all messages under it
Node.ImageIndex := ord(FFilter.AllFiltered[Title]); //set state of heading
Node.SelectedIndex := Node.ImageIndex;
Node := Node.getNextSibling; //next heading
end;
end;
{Toggle the state of an item in the TreeView whether filtered or not.
~param Node the node whose check box should be toggled }
procedure TFormMessageFilter.ToggleCheckBox(Node: TTreeNode);
//to translate from a boolean value to a filter state
const NewFilter: array[Boolean] of TMessageFilterStatus =
(mfsNotFiltered, mfsFiltered);
var Title :String; //heading of the clicked node
begin
case Node.Level of //what level of the node?
0: //set filter state for all messages
FFilter.DescFiltered[FDescriptions] :=
NewFilter[FFilter.DescFiltered[FDescriptions] = mfsNotFiltered];
1: begin
Title := FDescriptions[TMessageID(Node.Data)].Title; //get heading
//set filter state for all messages under the heading
FFilter.AllFiltered[Title] := NewFilter[FFilter.AllFiltered[Title] =
mfsNotFiltered];
end;
2: begin //toggle filter state of the clicked message
Title := FDescriptions[TMessageID(Node.Parent.Data)].Title;
FFilter.IsFiltered[Title, TMessageNumber(Node.Data)] :=
not FFilter.IsFiltered[Title, TMessageNumber(Node.Data)];
end;
else
assert(False);
end;
UpdateCheckBoxes; //update filter state
TreeView.Invalidate; //and show it
end;
{Called when the form is about to be closed.
~param Sender the sender of the event, the form
~param Action out: if and how the form should be closed }
procedure TFormMessageFilter.FormClose(Sender: TObject; var Action: TCloseAction);
var Settings :TFormSettings; //to save the settings of the form
begin
//get object to save the settings in
Settings := TFormSettings(TFormSettings.GetSettings(ClassName));
if assigned(Settings) then
Settings.GetValuesFromForm(Self); //save current settings
end;
{Called when a new node of the tree view is selected.
~param Sender the sender of the event, ~[link TreeView]
~param Node the newly selected node }
procedure TFormMessageFilter.TreeViewChange(Sender: TObject; Node: TTreeNode);
var MessageID :TMessageID; //ID of the set of messages
MessageNumber :TMessageNumber; //number of message within the set
begin
MemoDescription.Text := ''; //no information so far
if Node.Level = 2 then //node of a message selected?
begin
MessageID := TMessageID(Node.Parent.Data); //get the indices
MessageNumber := TMessageNumber(Node.Data);
//show the information
MemoDescription.Lines.Append('Seriousness: ' +
MessageSeriousnesses[FDescriptions[MessageID].
Descriptions[MessageNumber].Seriousness]);
MemoDescription.Lines.Append(Format('Message IDs: %s (%d) - %d: ',
[FDescriptions[MessageID].Title,
MessageID,
MessageNumber]));
MemoDescription.Lines.Append('General Description:');
MemoDescription.Lines.Append(FDescriptions[MessageID].
Descriptions[MessageNumber].Text);
MemoDescription.Lines.Append('');
MemoDescription.Lines.Append('Help:');
MemoDescription.Lines.Append(FDescriptions[MessageID].
Descriptions[MessageNumber].HelpText);
MemoDescription.SelStart := 0;
MemoDescription.SelLength := 0;
end;
end;
{Called when the tree view is clicked.
~param Sender the sender of the event, ~[link TreeView]
~param Button the pressed mouse button
~param Shift state of special modifying keys
~param X,Y position of the mouse }
procedure TFormMessageFilter.TreeViewMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var Node :TTreeNode; //the clicked node
TextRect :TRect; //position of the text of the node
begin
if Button = mbLeft then //clicked with left button?
begin
Node := TreeView.GetNodeAt(X, Y); //get the clicked node
if assigned(Node) then //a node clicked?
begin
TextRect := Node. //get position of its text
{$IFNDEF LINUX}
DisplayRect(True);
{$ELSE}
TextRect;
{$ENDIF}
//icon/image/checkbox of the node clicked (directly next to the text) ?
if (X < TextRect.Left) and (X >= TextRect.Left - ImageList.Width) then
ToggleCheckBox(Node);
end;
end;
end;
{Called when a key is pressed while the tree view is focused.
~param Sender the sender of the event, ~[link TreeView]
~param Key the pressed key, #0 may be returned to indicate the event has
been handled }
procedure TFormMessageFilter.TreeViewKeyPress(Sender: TObject; var Key: Char);
begin
if (Key = ' ') and assigned(TreeView.Selected) then //space pressed?
begin
ToggleCheckBox(TreeView.Selected); //toggle check box
Key := #0; //message handled
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -