📄 umfgeneratemessages.pas
字号:
Message :TGeneratorMessage; //each message
Count :Integer; //number of unfiltered entries
begin
Filter := []; //no messages so far
if CheckBoxFatal.Checked then //fatal error messages wanted?
Include(Filter, msFatal);
if CheckBoxError.Checked then //error messages wanted?
Include(Filter, msError);
if CheckBoxWarning.Checked then //warning messages wanted?
Include(Filter, msWarning);
if CheckBoxHint.Checked then //hints wanted?
Include(Filter, msHint);
if CheckBoxInformational.Checked then //informational messages wanted?
Include(Filter, msInformational);
//get enough space for maxmimum number of messages
SetLength(MessageMap, State.GenerationMessages.Count);
Count := 0;
if Filter <> [] then //not all messages filtered?
//add messages of generator
for i := 0 to State.GenerationMessages.Count - 1 do //add messages
begin
Message := State.GenerationMessages[i];
//message not filtered?
if (State.GenerationMessageDescriptions[Message.MessageID][
Message.MessageNumber].Seriousness in Filter) and
not FFilter.IsFiltered[
State.GenerationMessageDescriptions[Message.MessageID].Title,
Message.MessageNumber] then
begin
MessageMap[Count] := i; //save the index
Inc(Count); //count the message
end;
end;
SetLength(MessageMap, Count); //use only the added messages
//set content of the list
FGrid.SetListContent(State.GenerationMessages,
State.GenerationMessageDescriptions,
MessageMap);
GridClick(nil); //show information of first message
end;
{Called when the button to filter the messages is chosen.
~param Sender the sender of the event, ~[link BitBtnFilter] }
procedure TMFGenerateMessages.BitBtnFilterClick(Sender: TObject);
begin
//edit the filter
if EditMessageFilter(State.GenerationMessageDescriptions, FFilter) then
ShowMessages; //update the shown messages with the new filter
end;
{Called when one of the check boxes to filter the messages is toggled.
~param Sender the sender of the event, ~[link CheckBoxFatal],
~[link CheckBoxError], ~[link CheckBoxWarning],
~[link CheckBoxHint], ~[link CheckBoxInformational] }
procedure TMFGenerateMessages.CheckBoxesClick(Sender: TObject);
begin
ShowMessages; //update the shown messages with the new filter
end;
{Called when the menu item to clear the sorting of the messages is chosen.
~param Sender the sender of the event, ~[link MenuItemClearSortingOrder] }
procedure TMFGenerateMessages.MenuItemClearSortingOrderClick(Sender: TObject);
begin
FGrid.SetSortOrder([]); //clear the sorting order of the messages
ShowMessages; //and add them in the original order
end;
{Called when the menu item to filter all messages with the same ID as the
current is chosen.
~param Sender the sender of the event, ~[link MenuItemFilterMessage] }
procedure TMFGenerateMessages.MenuItemFilterMessageClick(Sender: TObject);
var Message :TGeneratorMessage; //the selected message
begin
//a message selected in the grid?
if (FGrid.Row >= FGrid.GetFixedRows) and (FGrid.Row < FGrid.RowCount) then
begin
FGrid.ReadMessage(FGrid.Row, Message); //read the message
//filter the current message
FFilter.IsFiltered[State.GenerationMessageDescriptions[Message.MessageID].
Title,
Message.MessageNumber] := True;
ShowMessages; //update the shown messages with the new filter
end;
end;
{Called when the menu item to filter all messages of the same source as the
current is chosen.
~param Sender the sender of the event, ~[link MenuItemFilterMessagesOfSource] }
procedure TMFGenerateMessages.MenuItemFilterMessagesOfSourceClick(
Sender: TObject);
var Message :TGeneratorMessage; //the selected message
begin
//a message selected in the grid?
if (FGrid.Row >= FGrid.GetFixedRows) and (FGrid.Row < FGrid.RowCount) then
begin
FGrid.ReadMessage(FGrid.Row, Message); //read the message
with State.GenerationMessageDescriptions[Message.MessageID] do
begin
//make sure the filter contains all messages
FFilter.IsFiltered[Title, Count - 1] := True;
//filter all messages of the source of the current message
FFilter.AllFiltered[Title] := mfsFiltered;
ShowMessages; //update the shown messages with the new filter
end;
end;
end;
{Called when the menu item to show all messages (remove the filter) is chosen.
~param Sender the sender of the event, ~[link MenuItemShowAllMessages] }
procedure TMFGenerateMessages.MenuItemShowAllMessagesClick(Sender: TObject);
begin //show all messages of the last generation
FFilter.DescFiltered[State.GenerationMessageDescriptions] := mfsNotFiltered;
ShowMessages; //update the shown messages with the new filter
end;
{Called when the menu item to clear the filter completely is chosen.
~param Sender the sender of the event, ~[link MenuItemClearFilter] }
procedure TMFGenerateMessages.MenuItemClearFilterClick(Sender: TObject);
begin
FFilter.ClearFilter; //clear the filter
ShowMessages; //update the shown messages with the new filter
end;
{Called when one of the menu items to copy the selected messages is clicked.
~param Sender the sender of the event, either ~[link MenuItemCopySelectedSum]
or ~[link MenuItemCopySelectedTab] }
procedure TMFGenerateMessages.MenuItemCopySelectedClick(Sender: TObject);
var Range :TGMGridRect; //the selected messages
S :String; //the text of the messages
begin
if FGrid.RowCount - FGrid.GetFixedRows > 0 then //grid not empty?
begin
Range := FGrid.Selection; //get selection
S := GetMessages(Range.Top, Range.Bottom, //get selected messages
(Sender is TMenuItem) and
(TMenuItem(Sender).Parent = MenuItemSummaryLine));
if S <> '' then
Clipboard.AsText := S; //"copy" it
end;
end;
{Called when one of the menu items to copy the whole content is clicked.
~param Sender the sender of the event, either ~[link MenuItemCopyAllSum] or
~[link MenuItemCopyAllTab] }
procedure TMFGenerateMessages.MenuItemCopyAllClick(Sender: TObject);
var S :String; //the text of all message
begin
if FGrid.RowCount - FGrid.GetFixedRows > 0 then //grid not empty?
begin
S := GetMessages(FGrid.GetFixedRows, FGrid.RowCount - 1, //get messages
(Sender is TMenuItem) and
(TMenuItem(Sender).Parent = MenuItemSummaryLine));
if S <> '' then
Clipboard.AsText := S; //"copy" them
end;
end;
{Called when one of the menu items to save the content is clicked.
~param Sender the sender of the event, either ~[link MenuItemSaveToSum] or
~[link MenuItemSaveToTab] }
procedure TMFGenerateMessages.MenuItemSaveToClick(Sender: TObject);
var Dialog :TSaveDialog; //dialog to chose the file
Stream :TFileStream; //the file to save the messages to
S :String; //text of all messages
begin
if FGrid.RowCount - FGrid.GetFixedRows > 0 then //grid not empty?
begin
Dialog := TSaveDialog.Create(nil); //create a file save - dialog
try
Dialog.HelpContext := FGrid.HelpContext; //use the help context
Dialog.DefaultExt := 'TXT';
Dialog.Filter := 'Text-Files (*.txt)|*.txt|Log-Files (*.log)|*.log|all files (*)|*';
Dialog.InitialDir := GetCurrentDir;
Dialog.Options := [ofOverwritePrompt, ofHideReadOnly, ofPathMustExist,
ofEnableSizing, ofShowHelp];
Dialog.Title := 'Save Log of DelphiDoc';
if Dialog.Execute then //file to save to chosen?
begin
Stream := TFileStream.Create(Dialog.FileName, fmCreate); //open it
try //get messages
S := GetMessages(FGrid.GetFixedRows, FGrid.RowCount - 1,
(Sender is TMenuItem) and
(TMenuItem(Sender).Parent = MenuItemSummaryLine));
Stream.Write(S[1], Length(S)); //save the content
finally
Stream.Free; //close the file
end;
end;
finally
Dialog.Free; //free the dialog
end;
end;
end;
{Shows the information about the selected message.
~param Sender the sender of the event, the clicked ~[link Grid] }
procedure TMFGenerateMessages.GridClick(Sender: TObject);
var Message :TGeneratorMessage; //the selected message
Info :String; //information about it
Pos :String; //position of the message
begin
Memo.Text := ''; //no information so far
//valid message selected?
if (FGrid.Row >= FGrid.GetFixedRows) and (FGrid.Row < FGrid.RowCount) then
begin
FGrid.ReadMessage(FGrid.Row, Message); //read the message
with Message,
State.GenerationMessageDescriptions[MessageID],
Descriptions[MessageNumber] do
begin //show the information
Info := 'Seriousness: ' + MessageSeriousnesses[Seriousness] +
LineDelimiter;
Info := Info + Format('Message IDs: %s (%d) - %d: ',
[Title, MessageID, MessageNumber]) + LineDelimiter;
if assigned(Position.Identifier) then
begin
Pos := Position.Identifier.InFile.InternalFileName + '.';
if assigned(Position.Identifier.MemberOf) then
Pos := Pos + Position.Identifier.MemberOf.Name + '.';
Pos := Pos + Position.Identifier.Name;
end
else
if assigned(Position.TheFile) then
begin
Pos := Position.TheFile.InternalFileName;
if Position.Position.Row > 0 then
Pos := Pos + Format(':%d:%d', [Position.Position.Row,
Position.Position.Column]);
end
else
if (Position.UserDocPage <> '') or (Position.UserDocFile <> '') then
Pos := '~[userDoc ' + Position.UserDocPage + '.' +
ExtractFileName(Position.UserDocFile)
else
if (Position.GUIPageFile <> '') or (Position.GUIPageTopic <> '') then
Pos := Pos + '~gui ' + Position.GUIPageFile + '#' +
Position.GUIPageTopic
else
Pos := '';
if Pos <> '' then
Info := Info + 'Position: ' + Pos + LineDelimiter;
Info := Info + Message + LineDelimiter;
Info := Info + LineDelimiter;
Info := Info + 'General Description:' + LineDelimiter;
Info := Info + Text + LineDelimiter;
Info := Info + LineDelimiter;
Info := Info + 'Help:' + LineDelimiter;
Info := Info + HelpText;
Memo.Text := Info; //show the information
end;
end;
end;
{Shows the position of the selected message.
~param Sender the sender of the event, the clicked ~[link Grid] }
procedure TMFGenerateMessages.GridDblClick(Sender: TObject);
var Message :TGeneratorMessage; //the double clicked message
begin //valid message clicked?
if (FGrid.Row >= FGrid.GetFixedRows) and (FGrid.Row < FGrid.RowCount) then
begin
FGrid.ReadMessage(FGrid.Row, Message); //read the message
if Assigned(Message.Position.Identifier) or //in a sourc file?
Assigned(Message.Position.TheFile) then
//show the source code at the delcaration of the identifier/file in the
ShowSourceCode(Self, Message.Position.Identifier, //message
Message.Position.TheFile, Message.Position.Position,
Message.Position.TheFile, Message.Position.Position);
end;
end;
{Shows the position of the selected message when the enter key is pressed.
~param Sender the sender of the event, the clicked ~[link Grid]
~param Key the pressed key }
procedure TMFGenerateMessages.GridKeyPressed(Sender: TObject; var Key: Char);
begin
if Key = #13 then //enter key pressed?
begin
Key := #0; //ignore the key
GridDblClick(Sender); //show position of messages
end;
end;
{Sorts the grid by the selected column.
~param Sender the sender of the event, the clicked ~[link Grid]
~param ACol the clicked column title }
procedure TMFGenerateMessages.GridFixedClick(Sender: TObject; ACol: Integer);
begin
if ACol >= 0 then //valid column clicked?
FGrid.SortListBy(FGrid.Columns[ACol]); //sort by field shown in the column
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -