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

📄 ueditdefines.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{  JADD - Just Another DelphiDoc: Documentation from Delphi Source Code

Copyright (C) 2003-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 UEditDefines;

{Contains some functions to work with compiler options, especially defines, of
 before the parsing of the pascal data. Also a dialog, ~[link TFormDefines],
 for the user to change them is available. }

interface

uses
  Windows, SysUtils, Classes,
{$IFNDEF LINUX}
  Graphics, Controls, Forms, StdCtrls, ExtCtrls, ComCtrls, CheckLst, Buttons,
  Dialogs,
  Messages,
{$ELSE}
  Qt, QForms, QButtons, QTypes, QControls, QStdCtrls, QExtCtrls, QComCtrls,
  QCheckLst, QDialogs,
{$ENDIF}
  UBaseIdents;


type
  {A dialog for the user to change the compiler options before the parsing of
   the pascal data. }
  TFormDefines = class(TForm)
    BitBtnOK: TBitBtn;
    PageControl: TPageControl;
    TabSheetBefore: TTabSheet;
    TabSheetMoreSettings: TTabSheet;
    TabSheetAfter: TTabSheet;
    LabelCompilerOptionsPre: TLabel;
    CheckListBoxPre: TCheckListBox;
    GroupBoxCompilerSymbols: TGroupBox;
    RadioGroupVersion: TRadioGroup;
    CheckBoxConsole: TCheckBox;
    CheckBoxPIC: TCheckBox;
    CheckBoxDotNET: TCheckBox;
    CheckBoxGPL: TCheckBox;
    CheckBoxAuto: TCheckBox;
    EditPreDefs: TEdit;
    LabelUnitAliases: TLabel;
    EditUnitAliases: TEdit;
    BitBtnLoadFromCFG: TBitBtn;
    LabelConstants: TLabel;
    MemoConstants: TMemo;
    LabelAdditionalSearchPaths: TLabel;
    ListBoxSearchPath: TListBox;
    ButtonAdd: TButton;
    ButtonRemove: TButton;
    ButtonClear: TButton;
    LabelPostCompilerOptions: TLabel;
    CheckListBoxPost: TCheckListBox;
    LabelPostDefine: TLabel;
    EditPostDefs: TEdit;
    LabelPostUndefine: TLabel;
    EditPostUnDefs: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure PageControlChange(Sender: TObject);
    procedure RadioGroupVersionClick(Sender: TObject);
    procedure CheckBoxClick(Sender: TObject);
    procedure EditPreDefsChange(Sender: TObject);
    procedure BitBtnLoadFromCFGClick(Sender: TObject);
    procedure ButtonAddClick(Sender: TObject);
    procedure ButtonRemoveClick(Sender: TObject);
    procedure ButtonClearClick(Sender: TObject);
    procedure ListBoxSearchPathKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    FDefines: TDefineOptions;      //the compiler defines to edit

{$IFNDEF LINUX}

    //Adds the dropped directories to the list of search paths.
    procedure FileDropped(var Msg: TWMDropFiles); message WM_DropFiles;

{$ENDIF}


    //Shows the compiler options in ~[link FDefines] on the form.
    procedure ShowData;
    //Saves the set compiler options from the form to ~[link FDefines].
    procedure SaveData;
    { private declarations }
  public
    //Creates the form.
    constructor Create(Defines: TDefineOptions); reintroduce;

    //Returns the edited defines.
    function GetDefines: TDefineOptions;
    { public declarations }
  end;







  

//Shows a dialog to the user to edit the compiler options.
procedure EditDefines(Defines: TDefineOptions); overload;


implementation

{$R *.dfm}


uses
{$IFNDEF LINUX}
     ShellAPI,
{$ENDIF}
{$IFDEF VER120}
     FileCtrl,
{$ENDIF}
     UFilePaths,
     UPascalConsts,
     UExtIdents, UCodeParser,
     UJADDState,
     GeneralVCL,
     USettingsKeeper;



{Shows a dialog to the user to edit the compiler options.
~param Defines the compiler options to edit }
procedure EditDefines(Defines: TDefineOptions); overload;
var       Form       :TFormDefines;  //the dialog to edit the compiler options
begin
 Form := TFormDefines.Create(Defines); //create the dialog
 try
   Form.ShowModal;                     //show the dialog
 finally
  Form.Free;                           //free the form
 end;
end;






















{Creates the form.
~param Defines the compiler options to edit }
constructor TFormDefines.Create(Defines: TDefineOptions);
var         c           :Char;        //all compiler options characters
            S           :String;      //text for the compiler options
            i           :Integer;     //counter through mapping: short <-> long
begin
 inherited Create(nil);               //create the form
 FDefines := Defines;                 //save the compiler options to edit

 for c := 'A' to 'Z' do               //fill check boxes
  begin                                 //with the compiler options
   S := c;                                //short (single character) and long
   for i := low(ShortCompilerOptions) to high(ShortCompilerOptions) do
    if ShortCompilerOptions[i] = c then
     S := S + ', ' + LongCompilerOptions[i];
   CheckListBoxPre.Items.Append(S);
  end;
 CheckListBoxPost.Items := CheckListBoxPre.Items;

 ShowData;                            //show the compiler options

 //make sure the first page is shown
 PageControl.ActivePage := TabSheetBefore;

 TFormSettings.SaveBasicFormValues(Self); //read the basic form values
end;



{Returns the edited defines.
~result the edited defines }
function TFormDefines.GetDefines: TDefineOptions;
begin
 Result := FDefines;
end;









{$IFNDEF LINUX}

{Called when the user drops some files on the form. Adds the dropped
 directories to the list of search paths.
~param Msg the window message of the dropping of some files }
procedure TFormDefines.FileDropped(var Msg: TWMDropFiles);

 {Adds all directories to the list of search paths.
 ~param Dirs list of dropped directories (and files) }
 procedure AddDirectories(Dirs: TStrings);
 var       i             :Integer;        //counter through the list
           Dir           :String;         //each directory
 begin
  for i := 0 to Dirs.Count - 1 do         //for each files/directory
   begin
    Dir := Dirs[i];                         //get it
    if DirectoryExists(Dir) then            //is a directory (not file)?
     begin
      Dir := Dir + PathDelimiter;
      Dir := ExtractShortPathName(ExpandFileName(Dir)); //get unique path
      ListBoxSearchPath.Items.Add(Dir);                 //add the directory
     end;
   end;
 end;

var       Files       :TStringList;   //list for the dropped files
          i           :Integer;       //counter through the dropped files
          Size        :UINT;          //length of the names of the files
          FileName    :String;        //names of the dropped files
begin
 try
   Files := TStringList.Create;       //create list for the dropped files
   try
     //for all dropped files
     for i := 0 to DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0) - 1 do
      begin
       Size := DragQueryFile(Msg.Drop, i, nil, 0);
       SetLength(FileName, Size);
       if (Size = DragQueryFile(Msg.Drop, i,    //get name of dropped file
                                PChar(FileName), Size + 1)) then
        Files.Append(FileName);                   //and add it to the list
      end;

     if Files.Count > 0 then       //some files dropped?
      AddDirectories(Files);         //add the directories

   finally
    Files.Free;                    //free list of files
   end
 finally
  DragFinish(Msg.Drop);            //finish the dropping
  Msg.Result := 0;                 //dropping of files has been handled
 end;
end;

{$ENDIF}





          //internal compiler versions of the Delphi/Kylix verions mapped to
          //the list in ~[link TFormDefines.RadioGroupVersion]
const     VersionNumbers: array[0..11] of Byte =
                    (80, 90, 100, 120, 130, 140, 140, 150, 160, 170, 180, 185);
          //the indices indicating a kylix version in ~[link
          KylixVersions = [6];               //TFormDefines.RadioGroupVersion]
          //index for version using .NET
          DotNetVersion = 8;
          //index for version ablto to use .NET
          DotNetPossibleVersions = [9, 10, 11];
          //index for unknown version: don't change any defines
          UnknownVersion = 12;

{Shows the compiler options in ~[link FDefines] on the form. }
procedure TFormDefines.ShowData;
          //mapping from values to change the compiler options to the check box
const     TranslatePostOption: array[TPostOption] of TCheckBoxState =
                                          (cbUnchecked, cbChecked, cbGrayed);
var       c           :Char;        //counter through all compiler options
          i           :Integer;     //index of the Delphi/Kylix version
          ConstFormat :TTextFormat; //format for declaration of constants
begin
 for c := 'A' to 'Z' do             //show values of all compiler options
  CheckListBoxPre.Checked[ord(c) - ord('A')] := FDefines.PreOptions[c];
 for c := 'A' to 'Z' do             //show values of all compiler options
  CheckListBoxPost.State[ord(c) - ord('A')] := TranslatePostOption[
                                                      FDefines.PostOptions[c]];

 EditPreDefs.OnChange := nil;
 EditPreDefs.Text := FDefines.PreDefines.CommaText;       //show all symbols
 EditPreDefs.OnChange := EditPreDefsChange;

 EditPostDefs.Text := FDefines.PostDefines.CommaText;
 EditPostUnDefs.Text := FDefines.PostUnDefines.CommaText;

 CheckBoxAuto.Checked := FDefines.AutoParse;

 //show this special defines
 CheckBoxConsole.Checked := FDefines.PreDefines.IndexOf('CONSOLE') <> -1;
 CheckBoxPIC.Checked := FDefines.PreDefines.IndexOf('PIC') <> -1;

 CheckBoxDotNET.OnClick := nil;
 CheckBoxDotNET.Checked := FDefines.PreDefines.IndexOf('CLR') <> -1;
 CheckBoxDotNET.OnClick := CheckBoxClick;

 CheckBoxGPL.Checked := FDefines.PreDefines.IndexOf('DECLARE_GPL') <> -1;



 //calculate the version of the Delphi/Kylix
 i := high(VersionNumbers);
 while (i >= low(VersionNumbers)) and
       (FDefines.PreDefines.IndexOf(Format('VER%u',
                                           [VersionNumbers[i]])) = -1) do
  dec(i);
 if i >= low(VersionNumbers) then
  begin
   if (i > low(VersionNumbers)) and (i in KylixVersions) and
      (FDefines.PreDefines.IndexOf('LINUX') = -1) then       //is a Kylix?
    dec(i);                                                    //adjust version
   RadioGroupVersion.OnClick := nil;
   RadioGroupVersion.ItemIndex := i;                         //show version
   RadioGroupVersion.OnClick := RadioGroupVersionClick;
  end;


 //in Kylix, PIC possible?
 CheckBoxPIC.Enabled := FDefines.PreDefines.IndexOf('LINUX') <> -1;
 //allow .NET?
 CheckBoxDotNET.Enabled := RadioGroupVersion.ItemIndex in
                           [UnknownVersion] + DotNetPossibleVersions;

 MemoConstants.Lines.Clear;         //clear old declaration of constants
 ConstFormat := TTextFormat.Create; //create object to get their declaration
 try                                //add all constants
   for i := FDefines.ConditionalCompilingConstants.Count - 1 downto 0 do
    MemoConstants.Lines.Insert(0, FDefines.ConditionalCompilingConstants[i].
                                       GetDescriptionString(ConstFormat, nil) +
                                  ';');
 finally
  ConstFormat.Free;                 //free object to get declarations
 end;

⌨️ 快捷键说明

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