⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umfgeneratemessages.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 3 页
字号:
end;

{Saves the settings to the ini file.
~param Ini the ini file to save the settings to }
procedure TGenerateMessagesPageSettings.SaveToIni(Ini: TCustomIniFile);
var       Index           :TGMColumnShowed;  //counter through column types
          i               :Integer;          //counter through columns/fields
          S               :String;           //a value represented as a string
          option          :TGMGridOption;    //each possible option
begin
 //write state of the check boxes
 Ini.WriteBool(Name, 'ShowFatalErrors', msFatal in FSeriousnesses);
 Ini.WriteBool(Name, 'ShowErrors', msError in FSeriousnesses);
 Ini.WriteBool(Name, 'ShowWarnings', msWarning in FSeriousnesses);
 Ini.WriteBool(Name, 'ShowHints', msHint in FSeriousnesses);
 Ini.WriteBool(Name, 'ShowInformationals', msInformational in FSeriousnesses);

 FFilter.SaveToIni(Ini);                     //save the filter

 //write settings of the columns of the grid
 for Index := Low(Index) to High(Index) do
  Ini.WriteInteger(Name, Format('GridColWidth%d', [Ord(Index)]),
                         FGridColWidths[Index]);
 Ini.WriteInteger(Name, 'GridShownColumnCount', FGridColCount);
 for i := 0 to FGridColCount - 1 do
  Ini.WriteInteger(Name, Format('GridColumnType%d', [i]),
                         Ord(FGridColumnTypes[i]));

 S := '';
 for option := Low(option) to High(option) do
  if option in FGridOptions then
   S := S + '1'
  else
   S := S + '0';
 Ini.WriteString(Name, 'GridOptions', S);    //save its general options

 //and write settings for the rows
 Ini.WriteInteger(Name, 'GridRowHeight', FGridRowHeight);
 Ini.WriteInteger(Name, 'GridTitles', Ord(FGridShowTitle));

 //write the fields by which the messages are currently sorted
 S := '';
 for i := 0 to FSortCount - 1 do
  begin
   if i <> 0 then
    S := S + ',';
   if FSortOrder[i].Direction = -1 then
    S := S + '-';
   S := S + IntToStr(Ord(FSortOrder[i].Field));
  end;
 Ini.WriteString(Name, 'GridSortOrder', S);
end;

{Gets the settings from the page.
~param Page the page to read the values from }
procedure TGenerateMessagesPageSettings.ReadSettings(Page:
                                                          TMFGenerateMessages);
var       Index           :TGMColumnShowed;  //counter through column types
          i               :Integer;          //counter through columns
begin
 FSeriousnesses := [];                       //no messages so far
 if Page.CheckBoxFatal.Checked then          //fatal error messages wanted?
  Include(FSeriousnesses, msFatal);
 if Page.CheckBoxError.Checked then          //error messages wanted?
  Include(FSeriousnesses, msError);
 if Page.CheckBoxWarning.Checked then        //warning messages wanted?
  Include(FSeriousnesses, msWarning);
 if Page.CheckBoxHint.Checked then           //hints wanted?
  Include(FSeriousnesses, msHint);
 if Page.CheckBoxInformational.Checked then  //informational messages wanted?
  Include(FSeriousnesses, msInformational);

 //read options of the grid
 for Index := Low(Index) to High(Index) do
  FGridColWidths[Index] := Page.Grid.ColWidths[Index];
 FGridColCount := Page.Grid.ColCount;
 for i := 0 to FGridColCount - 1 do
  FGridColumnTypes[i] := Page.Grid.Columns[i];
 FGridOptions := Page.Grid.Options;
 FGridRowHeight := Page.Grid.RowHeight;
 FGridShowTitle := Page.Grid.ShowTitle;
 //get the sort order
 FSortCount := Page.Grid.GetSortOrder(FSortOrder);
end;









{Creates the components and the filter.
~param Parent the component to show the frame in, preferably a TPanel or a
              similar component
~param State  the state of the program }
constructor TMFGenerateMessages.Create(Parent: TWinControl; State: TJADDState);
var         Settings  :TGenerateMessagesPageSettings;  //to read ini settings
            i         :Integer;            //general counter
            MenuEntry :TMenuItem;          //each entry of the pop-up menu
            Index     :TGMColumnShowed;    //counter through column types
begin
 inherited Create(Parent, State);          //create the frame


 //create and initialize the grid to show the messages
 FGrid := TGMGrid.Create(Self);
 FGrid.Parent := PanelEditor;
 FGrid.Name := 'FGrid';                    //only to add it to the GUI log file
 FGrid.Left := 10;
 FGrid.Top := 59;
 FGrid.Width := PanelEditor.Width - 2 * FGrid.Left;
 FGrid.Height := Memo.Top - FGrid.Top;
 FGrid.Hint := 'The messages generated while generating the ' +
               'documentation. Double clicking will show the identifier ' +
               'or file at which the message was generated if possible.';
 FGrid.HelpContext := 14802;
 FGrid.Anchors := [akLeft, akTop, akRight, akBottom];
 FGrid.TabOrder := 0;

 FGrid.Options := [goRowSelect, goMoveCursorOnCol, goFillFixedRow,
                   goScrollBarThumb, goQuickSearch];
 FGrid.ShowTitle := stText;

 FGrid.Columns[0] := gmfwMessageNumberSeriousness;
 FGrid.Columns[1] := gmfwMessageID;
 FGrid.Columns[2] := gmfwMessageNumber;
 FGrid.Columns[3] := gmfwPositionAll;
 FGrid.Columns[4] := gmfwMessageText;
 FGrid.ColCount := 5;

 FGrid.ColWidths[gmfwMessageNumberSeriousness] := 50;
 FGrid.ColWidths[gmfwMessageID] := 12;
 FGrid.ColWidths[gmfwMessageNumber] := 15;
 FGrid.ColWidths[gmfwPositionAll] := 180;
 FGrid.ColWidths[gmfwMessageText] := 480;

 FGrid.OnClick := GridClick;
 FGrid.OnDblClick := GridDblClick;
 FGrid.OnKeyPress := GridKeyPressed;
 FGrid.OnFixedClick := GridFixedClick;
 FGrid.OnFixedDblClick := GridFixedClick;

// FGrid.BorderStyle := bsSingle;
// FGrid.Ctl3D := False;

 FGrid.CreatePopupMenu;
 FGrid.PopUpMenu.HelpContext := FGrid.HelpContext;

 //move all menu items to the pop-up menu of the grid
 for i := 0 to PopupMenu.Items.Count - 1 do
  begin
   MenuEntry := PopupMenu.Items[0];
   PopupMenu.Items.Delete(0);
   FGrid.PopUpMenu.Items.Add(MenuEntry);
  end;

 FGrid.ImageList := ImageListCaptions;
// FGrid.ImageIndexDown := 0;
// FGrid.ImageIndexUp := 1;





 //get object to load the settings from
 Settings := TGenerateMessagesPageSettings(TGenerateMessagesPageSettings.
                                                       GetSettings(ClassName));
 if not Assigned(Settings) then        //no object initialized?
  begin                                  //create a new object
   Settings := TGenerateMessagesPageSettings.Create(ClassName);
   Settings.ReadSettings(Self);          //initialize with the default values
   Settings.Initialize;                  //and read from the ini file
  end;
 //initialize page with read values
 FFilter := Settings.Filter;
 CheckBoxFatal.Checked := msFatal in Settings.Seriousnesses;
 CheckBoxError.Checked := msError in Settings.Seriousnesses;
 CheckBoxWarning.Checked := msWarning in Settings.Seriousnesses;
 CheckBoxHint.Checked := msHint in Settings.Seriousnesses;
 CheckBoxInformational.Checked := msInformational in Settings.Seriousnesses;


 //read options of the grid
 for Index := Low(Index) to High(Index) do
  FGrid.ColWidths[Index] := Settings.GridColWidths[Index];
 FGrid.ColCount := Settings.GridColCount;
 for i := 0 to Settings.GridColCount - 1 do
  FGrid.Columns[i] := Settings.GridColumnTypes[i];
 FGrid.Options := Settings.GridOptions;
 FGrid.RowHeight := Settings.GridRowHeight;
 FGrid.ShowTitle := Settings.GridShowTitle;
 FGrid.SetSortOrder(Slice(Settings.GridSortOrder, Settings.GridSortCount));

 FGrid.TopRow := FGrid.GetFixedRows;
end;

{Save the settings and frees the page. }
destructor TMFGenerateMessages.Destroy;
var        Settings  :TGenerateMessagesPageSettings; //to write ini settings
begin
 //get object to save the settings in
 Settings := TGenerateMessagesPageSettings(TGenerateMessagesPageSettings.
                                                       GetSettings(ClassName));
 if assigned(Settings) then
  Settings.ReadSettings(Self);                         //save current settings

 inherited Destroy;                                  //free the page
end;




{Called sometimes when the frame is to be replaced by another frame. This
 method is ~[em not] always called before the frame is being replaced (and
 freed).
~param NewFrameClass the class of the frame that should replace this one
~param IsNext        if the next frame should be shown (instead of the previous
                     one) in some kind of an order }
procedure TMFGenerateMessages.SelectNextFrame(
                      var NewFrameClass: TMainFormFrameClass; IsNext: Boolean);
begin
 //if the previous page should be shown and the status text is empty
 if not IsNext and (State.Generate.GetGenerateStatusText = '') then
  NewFrameClass := TMFGenerate;            //skip that page
end;




{Called when the generator changes.
~param State the state that has been changed }
procedure TMFGenerateMessages.StateGeneratorChanged(State: TJADDState);
begin
 ShowMessages;                          //show the messages
end;




{Gets the selected range of messages as a string.
~param First         the first line of the range of messages to retrieve in
                     text form
~param Last          the last message of the range of messages
~param AsSummaryLine whether the messages should be returnes as a single
                     summary line each instead of the currently selected
                     columns in the grid
~result the string representation of the messages }
function TMFGenerateMessages.GetMessages(First, Last: Integer;
                                         AsSummaryLine: Boolean): String;

 {Returns the caption of a message to be added to the list.
 ~param Index the index of the message
 ~result the summary line of the message }
 function SummaryLine(Index: Integer): String;
 var      Message    :TGeneratorMessage; //message to get the summary line of
          HasPos     :Boolean;       //whether position of the message is known
 begin
  FGrid.ReadMessage(Index, Message); //read the message

  Result := MessageSeriousnesses[State.GenerationMessageDescriptions[
                       Message.MessageID][Message.MessageNumber].Seriousness] +
            Format(': %d:%d: ', [Message.MessageID, Message.MessageNumber]);

  HasPos := True;                         //assume position of message is known
  if assigned(Message.Position.Identifier) then
   begin
    Result := Result +
              Message.Position.Identifier.InFile.InternalFileName + '.';
    if assigned(Message.Position.Identifier.MemberOf) then
     Result := Result + Message.Position.Identifier.MemberOf.Name + '.';
    Result := Result + Message.Position.Identifier.Name;
   end
  else
   if assigned(Message.Position.TheFile) then
    begin
     Result := Result + Message.Position.TheFile.InternalFileName;
     if Message.Position.Position.Row > 0 then
      Result := Result +
                Format(':%d:%d',
                       [Message.Position.Position.Row,
                        Message.Position.Position.Column]);
    end
   else
    if (Message.Position.UserDocPage <> '') or
       (Message.Position.UserDocFile <> '') then
     Result := Result + '~[userDoc ' + Message.Position.UserDocPage + '.' +
                        ExtractFileName(Message.Position.UserDocFile)
    else
     if (Message.Position.GUIPageFile <> '') or
        (Message.Position.GUIPageTopic <> '') then
      Result := Result + '~gui ' + Message.Position.GUIPageFile +
                         '#' + Message.Position.GUIPageTopic
     else
      HasPos := False;                          //no position for message known

  if HasPos then
   Result := Result + ': ';

  Result := Result + Message.Message;
 end;

var      i                  :Integer;      //counter through messages
begin
 Result := '';                             //no messages added so far

 for i := First to Last do                 //for each message?
  begin
   if i <> First then                        //not the first
    Result := Result + LineDelimiter;          //add a separator

    if AsSummaryLine then                    //add the message
     Result := Result + SummaryLine(i)
    else
     Result := Result + FGrid.GetTabulatedRowText(i);
  end;
end;


{Shows the messages filtered and sorted as specified in the GUI. }
procedure TMFGenerateMessages.ShowMessages;
          //kinds of shown messages
var       Filter             :TMessageSeriousnesses;
          //the map from the index in the visible list to the messages
          MessageMap         :array of Integer;
          i                  :Integer;           //counter through all messages

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -