📄 umfparsemessages.pas
字号:
{ JADD - Just Another DelphiDoc: Documentation from Delphi Source Code
Copyright (C) 2002-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 UMFParseMessages;
{Contains a page to show the messages generated while parsing, they can be
filtered by their kind. If a message is selected further information is shown
and if possible the position of the error in the source code. }
interface
uses Classes, Forms, Controls, StdCtrls, ExtCtrls,
UMainFormFrame,
UJADDState, Menus;
type
{A page to show the messages generated while parsing, they can be filtered by
their kind. If a message is selected further information is shown and if
possible the position of the error in the source code. }
TMFParseMessages = class(TMainFormFrame)
ListBox: TListBox;
Memo: TMemo;
CheckBoxError: TCheckBox;
CheckBoxWarning: TCheckBox;
CheckBoxHint: TCheckBox;
CheckBoxShowPositions: TCheckBox;
PopupMenu: TPopupMenu;
MenuItemCopySelected: TMenuItem;
MenuItemCopyAll: TMenuItem;
MenuItemSaveTo: TMenuItem;
procedure ListBoxClick(Sender: TObject);
procedure ListBoxDblClick(Sender: TObject);
procedure CheckBoxesClick(Sender: TObject);
procedure MenuItemCopySelectedClick(Sender: TObject);
procedure MenuItemCopyAllClick(Sender: TObject);
procedure MenuItemSaveToClick(Sender: TObject);
private
//Shows the messages filtered as specified in the GUI.
procedure ShowMessages;
protected
//Called when the list of parsed file changes.
procedure StateFileListChanged(State: TJADDState); override;
public
//Creates the components and reads their settings.
constructor Create(Parent: TWinControl; State: TJADDState); override;
//Unregisters the event handlers and saves settings.
destructor Destroy; override;
end;
implementation
{$R *.dfm}
uses SysUtils, IniFiles,
GeneralVCL, USettingsKeeper,
UTokenParser;
type
{Loads and saves the settings of the pages to select classes to generate
documentation. }
TParseMessagesPageSettings = class(TAbstractSettings)
private
//the kinds of shown messages
FFilter: TParseMessageKinds;
//whether the positions of the messages should be shown in the list
FShowPositions: Boolean;
protected
public
//Loads the settings from the ini file.
procedure LoadFromIni(Ini: TCustomIniFile); override;
//Saves the settings to the ini file.
procedure SaveToIni(Ini: TCustomIniFile); override;
//Gets the settings from the page.
procedure ReadValues(Page: TMFParseMessages);
property Filter: TParseMessageKinds read FFilter;
property ShowPositions: Boolean read FShowPositions;
end;
{Loads the settings from the ini file.
~param Ini the ini file to load the settings from }
procedure TParseMessagesPageSettings.LoadFromIni(Ini: TCustomIniFile);
var Filter :TParseMessageKinds; //the kinds of shown messages
begin
Filter := []; //no messages so far
//error messages wanted?
if Ini.ReadBool(Name, 'ShowErrors', pmkError in FFilter) then
Include(Filter, pmkError);
//warning messages wanted?
if Ini.ReadBool(Name, 'ShowWarnings', pmkWarning in FFilter) then
Include(Filter, pmkWarning);
if Ini.ReadBool(Name, 'ShowHints', pmkHint in FFilter) then //hints wanted?
Include(Filter, pmkHint);
FFilter := Filter;
//read state of the check box
FShowPositions := Ini.ReadBool(Name, 'ShowPositions', FShowPositions);
end;
{Saves the settings to the ini file.
~param Ini the ini file to save the settings to }
procedure TParseMessagesPageSettings.SaveToIni(Ini: TCustomIniFile);
begin
//write state of the check boxes
Ini.WriteBool(Name, 'ShowErrors', pmkError in FFilter);
Ini.WriteBool(Name, 'ShowWarnings', pmkWarning in FFilter);
Ini.WriteBool(Name, 'ShowHints', pmkHint in FFilter);
Ini.WriteBool(Name, 'ShowPositions', FShowPositions);
end;
{Gets the settings from the page.
~param Page the page to read the values from }
procedure TParseMessagesPageSettings.ReadValues(Page: TMFParseMessages);
begin
FFilter := []; //no messages so far
if Page.CheckBoxError.Checked then //error messages wanted?
Include(FFilter, pmkError);
if Page.CheckBoxWarning.Checked then //warning messages wanted?
Include(FFilter, pmkWarning);
if Page.CheckBoxHint.Checked then //hints wanted?
Include(FFilter, pmkHint);
//get state of the check box
FShowPositions := Page.CheckBoxShowPositions.Checked;
end;
{Creates the components and reads their settings.
~param Parent the component to show the frame in, preferably a TPanel or a
similar component
~param State the state of the program }
constructor TMFParseMessages.Create(Parent: TWinControl; State: TJADDState);
var Settings :TParseMessagesPageSettings; //to read ini settings
begin
inherited Create(Parent, State); //create frame
//get object to load the settings from
Settings := TParseMessagesPageSettings(TParseMessagesPageSettings.
GetSettings(ClassName));
if not Assigned(Settings) then //no object initialized?
begin //create a new object
Settings := TParseMessagesPageSettings.Create(ClassName);
Settings.ReadValues(Self); //initialize with the default values
Settings.Initialize; //and read from the ini file
end;
//initialize page with read values
CheckBoxError.Checked := pmkError in Settings.Filter;
CheckBoxWarning.Checked := pmkWarning in Settings.Filter;
CheckBoxHint.Checked := pmkHint in Settings.Filter;
CheckBoxShowPositions.Checked := Settings.ShowPositions;
end;
{Unregisters the event handlers and saves settings. }
destructor TMFParseMessages.Destroy;
var Settings :TParseMessagesPageSettings; //to write ini settings
begin
//get object to save the settings in
Settings := TParseMessagesPageSettings(TParseMessagesPageSettings.
GetSettings(ClassName));
if assigned(Settings) then
Settings.ReadValues(Self); //save current settings
inherited Destroy; //free the page
end;
{Called when the list of parsed file changes.
~param State the state that has been changed }
procedure TMFParseMessages.StateFileListChanged(State: TJADDState);
begin
ShowMessages; //show the messages
end;
{Shows the messages filtered as specified in the GUI. }
procedure TMFParseMessages.ShowMessages;
var Filter :TParseMessageKinds; //kinds of shown messages
ShowPosition :Boolean; //position of error should be shown?
i :Integer; //counter through the messages
Text :String; //the text to show for the message
begin
ListBox.Items.BeginUpdate;
try
ListBox.Clear; //clear the messages
ShowPosition := CheckBoxShowPositions.Checked; //positions should be shown?
Filter := []; //no messages so far
if CheckBoxError.Checked then //error messages wanted?
Include(Filter, pmkError);
if CheckBoxWarning.Checked then //warning messages wanted?
Include(Filter, pmkWarning);
if CheckBoxHint.Checked then //hints wanted?
Include(Filter, pmkHint);
if Filter <> [] then //not all messages filtered?
for i := 0 to State.ParserMessages.Count - 1 do //for each message
with State.ParserMessages[i] do
if MessageKind in Filter then //should be shown?
begin
Text := Message;
if MessageType <> etNone then
Text := ExceptTypeName[MessageType] + ': ' + Text;
if ShowPosition and assigned(EffectiveFile) then
Text := Format('%s:%d:%d: ',
[EffectiveFile.InternalFileName,
ErrorPosition.Row, ErrorPosition.Column]) + Text;
if MessageKind = pmkError then
Text := 'ERROR: ' + Text;
ListBox.Items.AddObject(Text, TObject(i)); //show the messages
end;
finally
ListBox.Items.EndUpdate;
end;
end;
{Called when a message is selected in the list box.
~param Sender the sender of the event, ~[link ListBox] }
procedure TMFParseMessages.ListBoxClick(Sender: TObject);
//the texts to show for the different kinds of messages
const KindName: array[TParseMessageKind] of String =
('ERROR', 'Warning', 'Hint');
begin
Memo.Text := ''; //no information so far
if (ListBox.ItemIndex >= 0) and //valid message selected?
(ListBox.ItemIndex < State.ParserMessages.Count) then
with State.ParserMessages[Integer(ListBox.Items.Objects[ //get the message
ListBox.ItemIndex])] do
begin
Memo.Lines.Append('Kind: ' + KindName[MessageKind]); //add information
Memo.Lines.Append('Type: ' + ExceptTypeName[MessageType]);
if assigned(TheFile) then
Memo.Lines.Append(Format('Position: %s in line %d column %d',
[TheFile.InternalFileName,
ErrorPosition.Row, ErrorPosition.Column]));
if assigned(EffectiveFile) and
((TheFile <> EffectiveFile) or
(ErrorPosition.Row <> EffectiveErrorPosition.Row) or
(ErrorPosition.Column <> EffectiveErrorPosition.Column)) then
Memo.Lines.Append(Format('Effective Position: %s in line %d column %d',
[EffectiveFile.InternalFileName,
EffectiveErrorPosition.Row,
EffectiveErrorPosition.Column]));
Memo.Lines.Append(Message); //add its text
Memo.SelStart := 0;
Memo.SelLength := 0;
end;
end;
{Called when a message is double clicked in the list box.
~param Sender the sender of the event, ~[link ListBox] }
procedure TMFParseMessages.ListBoxDblClick(Sender: TObject);
begin
if (ListBox.ItemIndex >= 0) and //valid message selected?
(ListBox.ItemIndex < State.ParserMessages.Count) then
with State.ParserMessages[Integer(ListBox.Items.Objects[ //get the message
ListBox.ItemIndex])] do
begin
assert(assigned(TheFile) = assigned(EffectiveFile));
if assigned(ShowSourceCode) and assigned(TheFile) then //has a position?
ShowSourceCode(Self, nil, TheFile, ErrorPosition, //show it
EffectiveFile, EffectiveErrorPosition)
end;
end;
{Called when of the check boxes to filter the messages is changed.
~param Sender the sender of the event, ~[link CheckBoxError],
~[link CheckBoxWarning] or ~[link CheckBoxHint] }
procedure TMFParseMessages.CheckBoxesClick(Sender: TObject);
begin
ShowMessages; //update the shown messages with the new filter
end;
{Called when the menu item to copy the selected items is clicked.
~param Sender the sender of the event, ~[link MenuItemCopySelected] }
procedure TMFParseMessages.MenuItemCopySelectedClick(Sender: TObject);
begin
SelectedListBoxItemsToClipboard(ListBox);
end;
{Called when the menu item to copy the whole content is clicked.
~param Sender the sender of the event, ~[link MenuItemCopyAll] }
procedure TMFParseMessages.MenuItemCopyAllClick(Sender: TObject);
begin
ListBoxItemsToClipboard(ListBox);
end;
{Called when the menu item to save the content is clicked.
~param Sender the sender of the event, ~[link MenuItemSaveTo] }
procedure TMFParseMessages.MenuItemSaveToClick(Sender: TObject);
begin
ListBoxItemsToFile(ListBox, MenuItemSaveTo.HelpContext);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -