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

📄 umfloadparseddata.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 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 UMFLoadParsedData;

{Contains a simple page with buttons to load already parsed data from a file or
 save the current data to a file. }

interface

uses Classes, Forms, Controls, StdCtrls, ExtCtrls, 
     UMainFormFrame,
     UJADDState,
     USaveParsed;

type
  {A simple page with buttons to load already parsed data from a file or save
   the current data to a file. }
  TMFLoadParsedData = class(TMainFormFrame)
    ButtonLoadData: TButton;
    ButtonSaveData: TButton;
    CheckBoxKeepCurrentData: TCheckBox;
    procedure ButtonLoadDataClick(Sender: TObject);
    procedure ButtonSaveDataClick(Sender: TObject);
  private
    //data has been loaded on this page?
    FDataLoaded: Boolean;

    //Shows the errors encountered while reading the parsed data to the user.
    procedure ShowReadErrors(Errors: TParsedDataReadErrors);
  protected
    //Called when the list of parsed file changes.
    procedure StateFileListChanged(State: TJADDState); override;
  public
    //Creates the components and allows dropping of files.
    constructor Create(Parent: TWinControl; State: TJADDState); override;


    //Called sometimes when the frame is to be replaced by another frame.
    procedure SelectNextFrame(var NewFrameClass: TMainFormFrameClass;
                              IsNext: Boolean); override;

    //Called when some files are dropped on the form.
    procedure FilesDropped(Files: TStrings); override;
  end;




implementation

{$R *.dfm}

uses SysUtils,
     Dialogs,
     General,
     UCommandParameters,
     UMFKeepSelectData;



{Creates the components and allows dropping of files.
~param Parent the component to show the frame in, preferably a TPanel or a
              similar component
~param State  the state of the program }
constructor TMFLoadParsedData.Create(Parent: TWinControl; State: TJADDState);
begin
 inherited Create(Parent, State);                  //create the page

 Include(FProperties, mffpAcceptsFileDrop);        //accepts dropped files
end;


{Shows the errors encountered while reading the parsed data to the user.
~param Errors the errors encountered while reading the parsed data }
procedure TMFLoadParsedData.ShowReadErrors(Errors: TParsedDataReadErrors);
var       Msg              :String;               //the message to show
          Error            :TParsedDataReadError; //each possible error
begin
 Msg := '';
 for Error := Low(Error) to High(Error) do        //add messages of all errors
  if Error in Errors then
   Msg := Msg + ParsedDataReadErrorMessages(.Error.) + LineDelimiter;

 if Msg <> '' then                                //some errors encountered?
  //show them
  MessageDlg('Errors occurred while reading the data:' + LineDelimiter + Msg,
             mtWarning, [mbOK], ButtonLoadData.HelpContext);
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 TMFLoadParsedData.SelectNextFrame(
                      var NewFrameClass: TMainFormFrameClass; IsNext: Boolean);
begin
 if IsNext and FDataLoaded then    //next page should be shown and data loaded?
  NewFrameClass := TMFKeepSelectData;  //skip the pages to parsed data
end;


{Called when some files are dropped on the form.
~param Files the list of the dropped files }
procedure TMFLoadParsedData.FilesDropped(Files: TStrings);
var       i                :Integer;        //counter through files
begin
 for i := 0 to Files.Count - 1 do           //for each selected file
  begin
   State.ReadDataFromFile(Files[i]);          //load the data
   FDataLoaded := True;                       //data has been loaded

   if i < Files.Count - 1 then                //not the last loaded file?
    State.KeepCurrentData;                      //keep the loaded data
  end;
end;



{Called when the list of parsed file changes.
~param State the state that has been changed }
procedure TMFLoadParsedData.StateFileListChanged(State: TJADDState);
begin
 ButtonSaveData.Enabled := State.CompletelyParsed;  //saving allowed?

 //current parsed data available and complete and not already kept?
 CheckBoxKeepCurrentData.Enabled := assigned(State.FileList) and
                                    State.CompletelyParsed and
                                    (State.CurrentDataKeptIndex = -1);
 //current parsed data already kept?
 CheckBoxKeepCurrentData.Checked := assigned(State.FileList) and
                                    State.CompletelyParsed and
                                    (State.CurrentDataKeptIndex <> -1);
end;














{Called when the button to load already parsed data is clicked.
~param Sender the sender of the event, ~[link ButtonLoadData] }
procedure TMFLoadParsedData.ButtonLoadDataClick(Sender: TObject);
begin
 with TOpenDialog.Create(nil) do          //create the file open - dialog
  try
    DefaultExt := DDDDefaultExtension;
    Filter := Format('DelphiDoc-Data (*.%s)|*.%s|all files (*)|*',
                     [DDDDefaultExtension, DDDDefaultExtension]);
    InitialDir := GetCurrentDir;
    Options := [ofHideReadOnly, ofFileMustExist, ofPathMustExist,
                ofEnableSizing, ofShowHelp];
    HelpContext := ButtonLoadData.HelpContext;
    Title := 'Load Parsed Data';
    if Execute then                       //show the dialog; file selected?
     begin
      //if data valid, not yet kept and should be kept
      if assigned(State.FileList) and State.CompletelyParsed and
         (State.CurrentDataKeptIndex = -1) and
         CheckBoxKeepCurrentData.Checked then
       State.KeepCurrentData;                 //keep the current parsed data

      ShowReadErrors(State.ReadDataFromFile(FileName));  //load the data
      FDataLoaded := True;                  //data has been loaded
     end;
  finally
   Free;                                  //free the dialog
  end;
end;

{Called when the button to save the current parsed data is clicked.
~param Sender the sender of the event, ~[link ButtonSaveData] }
procedure TMFLoadParsedData.ButtonSaveDataClick(Sender: TObject);
begin
 if Assigned(State.FileList) and
    (State.CompletelyParsed or
     (MessageDlg('No data has been parsed validly. If parsing was aborted, saving the incomplete data will probably result in a crash of the program and it won''t be able to load it again.' + LineDelimiter +
                 'Are you sure, you want to save the data?',
                 mtWarning, [mbYes, mbCancel],
                 ButtonSaveData.HelpContext) = mrYes)) then
  with TSaveDialog.Create(nil) do            //create the file save - dialog
   try
     DefaultExt := DDDDefaultExtension;
     Filter := Format('DelphiDoc-Data (*.%s)|*.%s|all files (*)|*',
                      [DDDDefaultExtension, DDDDefaultExtension]);
     InitialDir := GetCurrentDir;
     Options := [ofOverwritePrompt, ofHideReadOnly, ofPathMustExist,
                 ofEnableSizing, ofShowHelp];
     HelpContext := ButtonSaveData.HelpContext;
     Title := 'Save Parsed Data';
     if Execute then                         //show the dialog; file selected?
      State.WriteDataToFile(FileName);         //save the parsed data
   finally
    Free;                                    //free the dialog
   end;
end;

end.

⌨️ 快捷键说明

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