PageRenderTime 169ms CodeModel.GetById 40ms app.highlight 118ms RepoModel.GetById 1ms app.codeStats 0ms

/ideintf/projectintf.pas

http://github.com/graemeg/lazarus
Pascal | 1643 lines | 1350 code | 206 blank | 87 comment | 62 complexity | 050ea32a1b06db9c727e7f4194f2bb09 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1{
   2 *****************************************************************************
   3 *                                                                           *
   4 *  See the file COPYING.modifiedLGPL.txt, included in this distribution,    *
   5 *  for details about the copyright.                                         *
   6 *                                                                           *
   7 *  This program is distributed in the hope that it will be useful,          *
   8 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
   9 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
  10 *                                                                           *
  11 *****************************************************************************
  12
  13  Author: Mattias Gaertner
  14
  15  Abstract:
  16    IDE interface to the IDE projects.
  17}
  18unit ProjectIntf;
  19
  20{$mode objfpc}{$H+}
  21
  22interface
  23
  24uses
  25  Classes, SysUtils, LCLProc, FileUtil, Controls, Forms, AvgLvlTree,
  26  NewItemIntf, ObjInspStrConsts;
  27
  28const
  29  FileDescGroupName = 'File';
  30  FileDescNamePascalUnit = 'Unit';
  31  FileDescNameLCLForm = 'Form';
  32  FileDescNameDatamodule = 'Datamodule';
  33  FileDescNameFrame = 'Frame';
  34  FileDescNameText = 'Text';
  35
  36  InheritedItemsGroupName = 'Inherited Items';
  37  FileDescNameLCLInheritedComponent = 'Inherited Component';
  38
  39  ProjDescGroupName = 'Project';
  40  ProjDescNameApplication = 'Application';
  41  ProjDescNameProgram = 'Program';
  42  ProjDescNameConsoleApplication = 'Console application';
  43  ProjDescNameLibrary = 'Library';
  44  ProjDescNameCustomProgram = 'Custom Program';
  45  ProjDescNameEmpty = 'Empty';
  46
  47type
  48  TCOCNodeType = (
  49    cocntNone,
  50    cocntIf,
  51    cocntIfdef,
  52    cocntIfNdef,
  53    cocntElseIf,
  54    cocntElse,
  55    cocntAddValue,
  56    cocntSetValue
  57  );
  58  TCOCNodeTypes = set of TCOCNodeType;
  59  TCOCValueType = (
  60    cocvtNone,
  61    cocvtResult,
  62    cocvtUnitPath,
  63    cocvtSrcPath,
  64    cocvtIncludePath,
  65    cocvtObjectPath,
  66    cocvtLibraryPath,
  67    cocvtDebugPath,
  68    cocvtLinkerOptions,
  69    cocvtCustomOptions
  70    );
  71  TCOCValueTypes = set of TCOCValueType;
  72
  73const
  74  COCNodeTypeNames: array[TCOCNodeType] of string = (
  75    'None',
  76    'If',
  77    'Ifdef',
  78    'IfNdef',
  79    'ElseIf',
  80    'Else',
  81    'AddValue',
  82    'SetValue'
  83    );
  84  COCValueTypeNames: array[TCOCValueType] of string = (
  85    'None',
  86    'Result',
  87    'UnitPath',
  88    'SrcPath',
  89    'IncludePath',
  90    'ObjectPath',
  91    'LibraryPath',
  92    'DebugPath',
  93    'LinkerOptions',
  94    'CustomOptions'
  95    );
  96
  97type
  98  TLazCompOptConditionals = class;
  99
 100  { TCompOptCondNode - a node in the conditional tree of the compiler options
 101    of a project or package }
 102
 103  TCompOptCondNode = class
 104  private
 105    fChilds: TFPList; // list of TCompOptCondNode
 106    fClearing: boolean;
 107    FNodeType: TCOCNodeType;
 108    FOwner: TLazCompOptConditionals;
 109    FParent: TCompOptCondNode;
 110    FValue: string;
 111    FValueType: TCOCValueType;
 112    function GetChilds(Index: integer): TCompOptCondNode;
 113    function GetCount: integer;
 114    function GetIndex: integer;
 115    procedure SetIndex(const AValue: integer);
 116    procedure SetNodeType(const AValue: TCOCNodeType);
 117    procedure SetValue(const AValue: string);
 118    procedure SetValueType(const AValue: TCOCValueType);
 119    procedure Changed;
 120  public
 121    constructor Create(TheOwner: TLazCompOptConditionals);
 122    destructor Destroy; override;
 123    procedure ClearNodes;
 124    procedure AddLast(Child: TCompOptCondNode);
 125    procedure Insert(Index: integer; Child: TCompOptCondNode);
 126    procedure Move(OldIndex, NewIndex: integer);
 127    procedure Move(NewParent: TCompOptCondNode; NewIndex: integer);
 128    procedure Delete(Index: integer);
 129    procedure Assign(Source: TCompOptCondNode);
 130    property NodeType: TCOCNodeType read FNodeType write SetNodeType;
 131    property ValueType: TCOCValueType read FValueType write SetValueType;
 132    property Value: string read FValue write SetValue;
 133    property Owner: TLazCompOptConditionals read FOwner;
 134    property Parent: TCompOptCondNode read FParent;
 135    property Count: integer read GetCount;
 136    property Childs[Index: integer]: TCompOptCondNode read GetChilds; default;
 137    property Index: integer read GetIndex write SetIndex;
 138  end;
 139
 140  { TLazCompOptConditionals
 141    - conditional compiler options
 142    - additions dependending  }
 143
 144  TLazCompOptConditionals = class
 145  private
 146    FRoot: TCompOptCondNode;
 147  public
 148    constructor Create;
 149    destructor Destroy; override;
 150    procedure InvalidateValues; virtual; abstract;
 151    procedure Assign(Source: TLazCompOptConditionals); virtual; abstract;
 152    property Root: TCompOptCondNode read FRoot write FRoot;
 153  end;
 154
 155  { TLazBuildProperty }
 156
 157  TLazBuildProperty = class
 158  protected
 159    FDefaultValue: TLazCompOptConditionals;
 160    FIdentifier: string;
 161    FDescription: string;
 162    FValueDescriptions: TStrings;
 163    FValues: TStrings;
 164    procedure SetIdentifier(const AValue: string); virtual; abstract;
 165    procedure SetDescription(const AValue: string); virtual; abstract;
 166    procedure SetValueDescriptions(const AValue: TStrings); virtual; abstract;
 167    procedure SetValues(const AValue: TStrings); virtual; abstract;
 168  public
 169    procedure Assign(Source: TLazBuildProperty); virtual; abstract;
 170    procedure SetDefaultValue(const AValue: string); virtual; abstract;
 171    property Identifier: string read FIdentifier write SetIdentifier;
 172    property Description: string read FDescription write SetDescription;
 173    property Values: TStrings read FValues write SetValues;
 174    property ValueDescriptions: TStrings read FValueDescriptions write SetValueDescriptions;
 175    property DefaultValue: TLazCompOptConditionals read FDefaultValue;
 176  end;
 177
 178  { TLazBuildProperties }
 179
 180  TLazBuildProperties = class
 181  private
 182    FOwner: TObject;
 183  protected
 184    function GetItems(Index: integer): TLazBuildProperty; virtual; abstract;
 185  public
 186    constructor Create(TheOwner: TObject); virtual;
 187    function Add(Identifier: string): TLazBuildProperty; virtual; abstract;
 188    procedure Delete(Index: integer); virtual; abstract;
 189    procedure Move(OldIndex, NewIndex: integer); virtual; abstract;
 190    function IndexOfIdentifier(Identifier: string): integer; virtual; abstract;
 191    function ModeWithIdentifier(Identifier: string): TLazBuildProperty; virtual; abstract;
 192    function Count: integer; virtual; abstract;
 193    procedure Clear; virtual; abstract;
 194    property Items[Index: integer]: TLazBuildProperty read GetItems; default;
 195    property Owner: TObject read FOwner;
 196  end;
 197
 198  { TLazCompilerOptions }
 199
 200  TCompilationExecutableType = (
 201    cetProgram,
 202    cetLibrary
 203    );
 204
 205  TCompileReason = (
 206    crCompile,  // normal build current project/package
 207    crBuild,    // build all
 208    crRun       // quick build before run
 209    );
 210  TCompileReasons = set of TCompileReason;
 211const
 212  crAll = [crCompile, crBuild, crRun];
 213
 214type
 215  { TLazCompilerOptions }
 216
 217  TLazCompilerOptions = class(TPersistent)
 218  private
 219    FOnModified: TNotifyEvent;
 220    fOwner: TObject;
 221  protected
 222    FModified: boolean;
 223
 224    // Paths:
 225    fIncludePaths: String;
 226    fLibraryPaths: String;
 227    fUnitPaths: String;
 228    FObjectPath: string;
 229    FSrcPath: string;
 230    fUnitOutputDir: string;
 231    fDebugPath: string;
 232
 233    // conditionals / build modes
 234    FConditionals: TLazCompOptConditionals;
 235    fBuildProperties: TLazBuildProperties;
 236    fLCLWidgetType: string;
 237
 238    // Parsing:
 239    // assembler style
 240    fAssemblerStyle: Integer;
 241
 242    // syntax options
 243    FSyntaxMode: string;
 244    fCStyleOp: Boolean;
 245    fIncludeAssertionCode: Boolean;
 246    fAllowLabel: Boolean;
 247    fUseAnsiStr: Boolean;
 248    fCPPInline: Boolean;
 249    fCMacros: Boolean;
 250    fInitConst: Boolean;
 251    fStaticKeyword: Boolean;
 252
 253    // Code generation:
 254    fSmartLinkUnit: Boolean;
 255    fIOChecks: Boolean;
 256    fRangeChecks: Boolean;
 257    fOverflowChecks: Boolean;
 258    fStackChecks: Boolean;
 259    FEmulatedFloatOpcodes: boolean;
 260    fHeapSize: LongInt;
 261    fVerifyObjMethodCall: boolean;
 262    FSmallerCode: boolean;
 263    fTargetProc: string;
 264    fTargetCPU: string;
 265    fVarsInReg: Boolean;
 266    fUncertainOpt: Boolean;
 267    fOptLevel: Integer;
 268    fTargetOS: String;
 269
 270    // Linking:
 271    fGenDebugInfo: Boolean;
 272    fUseLineInfoUnit: Boolean;
 273    FGenerateDwarf: Boolean;
 274    fUseHeaptrc: Boolean;
 275    fUseValgrind: Boolean;
 276    fGenGProfCode: Boolean;
 277    fStripSymbols: Boolean;
 278    fLinkSmart: Boolean;
 279    fPassLinkerOpt: Boolean;
 280    fLinkerOptions: String;
 281    FWin32GraphicApp: boolean;
 282    FExecutableType: TCompilationExecutableType;
 283    FUseExternalDbgSyms : Boolean;
 284
 285    // Messages:
 286    fShowErrors: Boolean;
 287    fShowWarn: Boolean;
 288    fShowNotes: Boolean;
 289    fShowHints: Boolean;
 290    fShowGenInfo: Boolean;
 291    fShowLineNum: Boolean;
 292    fShowAll: Boolean;
 293    fShowAllProcsOnError: Boolean;
 294    fShowDebugInfo: Boolean;
 295    fShowUsedFiles: Boolean;
 296    fShowTriedFiles: Boolean;
 297    fShowDefMacros: Boolean;
 298    fShowCompProc: Boolean;
 299    fShowCond: Boolean;
 300    fShowExecInfo: Boolean;
 301    fShowNothing: Boolean;
 302    fShowSummary: Boolean;
 303    fShowHintsForUnusedUnitsInMainSrc: Boolean;
 304    fShowHintsForSenderNotUsed: Boolean;
 305    fWriteFPCLogo: Boolean;
 306    fStopAfterErrCount: integer;
 307
 308    // Other:
 309    fDontUseConfigFile: Boolean;
 310    fCustomConfigFile: Boolean;
 311    fConfigFilePath: String;
 312    fCustomOptions: string;
 313  protected
 314    procedure SetBaseDirectory(const AValue: string); virtual; abstract;
 315    procedure SetCompilerPath(const AValue: String); virtual; abstract;
 316    procedure SetCustomOptions(const AValue: string); virtual; abstract;
 317    procedure SetIncludePaths(const AValue: String); virtual; abstract;
 318    procedure SetLibraryPaths(const AValue: String); virtual; abstract;
 319    procedure SetLinkerOptions(const AValue: String); virtual; abstract;
 320    procedure SetUnitPaths(const AValue: String); virtual; abstract;
 321    procedure SetUnitOutputDir(const AValue: string); virtual; abstract;
 322    procedure SetObjectPath(const AValue: string); virtual; abstract;
 323    procedure SetSrcPath(const AValue: string); virtual; abstract;
 324    procedure SetDebugPath(const AValue: string); virtual; abstract;
 325    procedure SetTargetCPU(const AValue: string); virtual; abstract;
 326    procedure SetTargetProc(const AValue: string); virtual; abstract;
 327    procedure SetTargetOS(const AValue: string); virtual; abstract;
 328    procedure SetModified(const AValue: boolean); virtual; abstract;
 329  public
 330    constructor Create(const TheOwner: TObject); virtual;
 331  public
 332    property Owner: TObject read fOwner write fOwner;
 333    property Modified: boolean read FModified write SetModified;
 334    property OnModified: TNotifyEvent read FOnModified write FOnModified;
 335
 336    // search paths:
 337    property IncludePath: String read fIncludePaths write SetIncludePaths;
 338    property Libraries: String read fLibraryPaths write SetLibraryPaths;
 339    property OtherUnitFiles: String read fUnitPaths write SetUnitPaths;
 340    property ObjectPath: string read FObjectPath write SetObjectPath;
 341    property SrcPath: string read FSrcPath write SetSrcPath;
 342    property DebugPath: string read FDebugPath write SetDebugPath;
 343    property UnitOutputDirectory: string read fUnitOutputDir write SetUnitOutputDir;
 344
 345    // conditional / build modes
 346    property Conditionals: TLazCompOptConditionals read FConditionals;
 347    property BuildProperties: TLazBuildProperties read fBuildProperties;
 348    // Beware: eventually LCLWidgetType will be replaced by a more generic solution
 349    property LCLWidgetType: string read fLCLWidgetType write fLCLWidgetType;
 350
 351    // parsing:
 352    property SyntaxMode: string read FSyntaxMode write FSyntaxMode;
 353    property AssemblerStyle: Integer read fAssemblerStyle write fAssemblerStyle;
 354    property CStyleOperators: Boolean read fCStyleOp write fCStyleOp;
 355    property IncludeAssertionCode: Boolean
 356                         read fIncludeAssertionCode write fIncludeAssertionCode;
 357    property AllowLabel: Boolean read fAllowLabel write fAllowLabel;
 358    property UseAnsiStrings: Boolean read fUseAnsiStr write fUseAnsiStr;
 359    property CPPInline: Boolean read fCPPInline write fCPPInline;
 360    property CStyleMacros: Boolean read fCMacros write fCMacros;
 361    property InitConstructor: Boolean read fInitConst write fInitConst;
 362    property StaticKeyword: Boolean read fStaticKeyword write fStaticKeyword;
 363
 364    // code generation:
 365    property IOChecks: Boolean read fIOChecks write fIOChecks;
 366    property RangeChecks: Boolean read fRangeChecks write fRangeChecks;
 367    property OverflowChecks: Boolean read fOverflowChecks write fOverflowChecks;
 368    property StackChecks: Boolean read fStackChecks write fStackChecks;
 369    property SmartLinkUnit: Boolean read fSmartLinkUnit write fSmartLinkUnit;
 370    property EmulatedFloatOpcodes: boolean read FEmulatedFloatOpcodes
 371                                           write FEmulatedFloatOpcodes;
 372    property HeapSize: Integer read fHeapSize write fHeapSize;
 373    property VerifyObjMethodCall: boolean read FVerifyObjMethodCall
 374                                          write FVerifyObjMethodCall;
 375    property SmallerCode: boolean read FSmallerCode write FSmallerCode;
 376    property TargetCPU: string read fTargetCPU write SetTargetCPU; // general type
 377    property TargetProcessor: String read fTargetProc write SetTargetProc; // specific
 378    property TargetOS: string read fTargetOS write SetTargetOS;
 379    property VariablesInRegisters: Boolean read fVarsInReg write fVarsInReg;
 380    property UncertainOptimizations: Boolean read fUncertainOpt write fUncertainOpt;
 381    property OptimizationLevel: Integer read fOptLevel write fOptLevel;
 382
 383    // linking:
 384    property GenerateDebugInfo: Boolean read fGenDebugInfo write fGenDebugInfo;
 385    property UseLineInfoUnit: Boolean read fUseLineInfoUnit write fUseLineInfoUnit;
 386    property GenerateDwarf: Boolean read FGenerateDwarf write FGenerateDwarf;
 387    property UseHeaptrc: Boolean read fUseHeaptrc write fUseHeaptrc;
 388    property UseValgrind: Boolean read fUseValgrind write fUseValgrind;
 389    property GenGProfCode: Boolean read fGenGProfCode write fGenGProfCode;
 390    property StripSymbols: Boolean read fStripSymbols write fStripSymbols;
 391    property LinkSmart: Boolean read fLinkSmart write fLinkSmart;
 392    property PassLinkerOptions: Boolean read fPassLinkerOpt write fPassLinkerOpt;
 393    property LinkerOptions: String read fLinkerOptions write SetLinkerOptions;
 394    property Win32GraphicApp: boolean read FWin32GraphicApp write FWin32GraphicApp;
 395    property ExecutableType: TCompilationExecutableType
 396                                     read FExecutableType write FExecutableType;
 397    property UseExternalDbgSyms: Boolean read FUseExternalDbgSyms write FUseExternalDbgSyms;
 398
 399    // messages:
 400    property ShowErrors: Boolean read fShowErrors write fShowErrors;
 401    property ShowWarn: Boolean read fShowWarn write fShowWarn;
 402    property ShowNotes: Boolean read fShowNotes write fShowNotes;
 403    property ShowHints: Boolean read fShowHints write fShowHints;
 404    property ShowGenInfo: Boolean read fShowGenInfo write fShowGenInfo;
 405    property ShowLineNum: Boolean read fShowLineNum write fShowLineNum;
 406    property ShowAll: Boolean read fShowAll write fShowAll;
 407    property ShowAllProcsOnError: Boolean
 408      read fShowAllProcsOnError write fShowAllProcsOnError;
 409    property ShowDebugInfo: Boolean read fShowDebugInfo write fShowDebugInfo;
 410    property ShowUsedFiles: Boolean read fShowUsedFiles write fShowUsedFiles;
 411    property ShowTriedFiles: Boolean read fShowTriedFiles write fShowTriedFiles;
 412    property ShowDefMacros: Boolean read fShowDefMacros write fShowDefMacros;
 413    property ShowCompProc: Boolean read fShowCompProc write fShowCompProc;
 414    property ShowCond: Boolean read fShowCond write fShowCond;
 415    property ShowExecInfo: Boolean read fShowExecInfo write fShowExecInfo;
 416    property ShowNothing: Boolean read fShowNothing write fShowNothing;
 417    property ShowSummary: Boolean read FShowSummary write FShowSummary;
 418    property ShowHintsForUnusedUnitsInMainSrc: Boolean
 419      read fShowHintsForUnusedUnitsInMainSrc write fShowHintsForUnusedUnitsInMainSrc;
 420    property ShowHintsForSenderNotUsed: Boolean
 421      read fShowHintsForSenderNotUsed write fShowHintsForSenderNotUsed;
 422    property WriteFPCLogo: Boolean read fWriteFPCLogo write fWriteFPCLogo;
 423    property StopAfterErrCount: integer
 424      read fStopAfterErrCount write fStopAfterErrCount;
 425
 426    // other
 427    property DontUseConfigFile: Boolean read fDontUseConfigFile
 428                                        write fDontUseConfigFile;
 429    property CustomConfigFile: Boolean read fCustomConfigFile
 430                                       write fCustomConfigFile;
 431    property ConfigFilePath: String read fConfigFilePath write fConfigFilePath;
 432    property CustomOptions: string read fCustomOptions write SetCustomOptions;
 433  end;
 434
 435
 436  { TLazProjectFile }
 437
 438  TLazProjectFile = class(TPersistent)
 439  private
 440    FCustomData: TStringToStringTree;
 441    FCustomSessionData: TStringToStringTree;
 442    FIsPartOfProject: boolean;
 443  protected
 444    function GetFilename: string; virtual; abstract;
 445    procedure SetFilename(const AValue: string); virtual; abstract;
 446    procedure SetIsPartOfProject(const AValue: boolean); virtual;
 447  public
 448    constructor Create;
 449    destructor Destroy; override;
 450    procedure SetSourceText(const SourceText: string); virtual; abstract;
 451    function GetSourceText: string; virtual; abstract;
 452    procedure ClearModifieds; virtual; abstract;
 453  public
 454    property IsPartOfProject: boolean read FIsPartOfProject
 455                                      write SetIsPartOfProject;
 456    property Filename: string read GetFilename write SetFilename;
 457    property CustomData: TStringToStringTree read FCustomData;
 458    property CustomSessionData: TStringToStringTree read FCustomSessionData;
 459  end;
 460  TLazProjectFileClass = class of TLazProjectFile;
 461
 462
 463  { TProjectFileDescriptor
 464
 465    ResourceClass: When the IDE creates a new unit of this type the IDE will
 466                   create a direct descendant from this class.
 467                   You should also register this class, so that, when the IDE
 468                   opens a unit with such a type
 469                   (i.e. 'TMyResouceClass1 = class(TMyResouceClass)')
 470                   it creates the correct class type. Just call somewhere once
 471                   RegisterClass(ResourceClass);
 472                   }
 473
 474  TProjectFileDescriptor = class(TPersistent)
 475  private
 476    FAddToProject: boolean;
 477    FDefaultFileExt: string;
 478    FDefaultFilename: string;
 479    FDefaultResFileExt: string;
 480    FDefaultResourceName: string;
 481    FDefaultSourceName: string;
 482    FIsComponent: boolean;
 483    FIsPascalUnit: boolean;
 484    FName: string;
 485    FReferenceCount: integer;
 486    FResourceClass: TPersistentClass;
 487    FRequiredPackages: string;
 488    FUseCreateFormStatements: boolean;
 489    FVisibleInNewDialog: boolean;
 490  protected
 491    procedure SetDefaultFilename(const AValue: string); virtual;
 492    procedure SetDefaultFileExt(const AValue: string); virtual;
 493    procedure SetDefaultSourceName(const AValue: string); virtual;
 494    procedure SetDefaultResFileExt(const AValue: string); virtual;
 495    procedure SetName(const AValue: string); virtual;
 496    procedure SetResourceClass(const AValue: TPersistentClass); virtual;
 497    procedure SetRequiredPackages(const AValue: string); virtual;
 498  public
 499    constructor Create; virtual;
 500    function GetLocalizedName: string; virtual;
 501    function GetLocalizedDescription: string; virtual;
 502    function GetResourceSource(const ResourceName: string): string; virtual;
 503    procedure Release;
 504    procedure Reference;
 505    function CreateSource(const Filename, SourceName,
 506                          ResourceName: string): string; virtual;
 507    procedure UpdateDefaultPascalFileExtension(const DefPasExt: string); virtual;
 508  public
 509    property Name: string read FName write SetName;
 510    property DefaultFilename: string read FDefaultFilename write SetDefaultFilename;
 511    property DefaultFileExt: string read FDefaultFileExt write SetDefaultFileExt;
 512    property DefaultSourceName: string read FDefaultSourceName write SetDefaultSourceName;
 513    property DefaultResFileExt: string read FDefaultResFileExt write SetDefaultResFileExt;
 514    property DefaultResourceName: string read FDefaultResourceName write FDefaultResourceName;
 515    property ResourceClass: TPersistentClass read FResourceClass write SetResourceClass;
 516    property RequiredPackages: string read FRequiredPackages write SetRequiredPackages; // package names separated by semicolon
 517    property IsComponent: boolean read FIsComponent;
 518    property UseCreateFormStatements: boolean read FUseCreateFormStatements write FUseCreateFormStatements;
 519    property VisibleInNewDialog: boolean read FVisibleInNewDialog write FVisibleInNewDialog;
 520    property IsPascalUnit: boolean read FIsPascalUnit write FIsPascalUnit;
 521    property AddToProject: boolean read FAddToProject write FAddToProject;// only if there is choice
 522  end;
 523  TProjectFileDescriptorClass = class of TProjectFileDescriptor;
 524
 525
 526  { TNewItemProjectFile - a new item for project file descriptors }
 527
 528  TNewItemProjectFile = class(TNewIDEItemTemplate)
 529  private
 530    FDescriptor: TProjectFileDescriptor;
 531  public
 532    function LocalizedName: string; override;
 533    function Description: string; override;
 534    procedure Assign(Source: TPersistent); override;
 535  public
 536    property Descriptor: TProjectFileDescriptor read FDescriptor write FDescriptor;
 537  end;
 538
 539
 540  { TFileDescPascalUnit }
 541
 542  TFileDescPascalUnit = class(TProjectFileDescriptor)
 543  public
 544    constructor Create; override;
 545    function CreateSource(const Filename, SourceName,
 546                          ResourceName: string): string; override;
 547    function GetLocalizedName: string; override;
 548    function GetLocalizedDescription: string; override;
 549    function GetInterfaceUsesSection: string; virtual;
 550    function GetInterfaceSource(const Filename, SourceName,
 551                                ResourceName: string): string; virtual;
 552    function GetImplementationSource(const Filename, SourceName,
 553                                     ResourceName: string): string; virtual;
 554  end;
 555
 556
 557  { TFileDescPascalUnitWithResource }
 558
 559  TFileDescPascalUnitWithResource = class(TFileDescPascalUnit)
 560  private
 561    FDeclareClassVariable: Boolean;
 562  public
 563    constructor Create; override;
 564
 565    function GetInterfaceUsesSection: string; override;
 566    function GetInterfaceSource(const Filename, SourceName,
 567                                ResourceName: string): string; override;
 568    function GetImplementationSource(const Filename, SourceName,
 569                                     ResourceName: string): string; override;
 570
 571    property DeclareClassVariable: Boolean read FDeclareClassVariable write FDeclareClassVariable;
 572  end;
 573
 574
 575  { TProjectFileDescriptors }
 576
 577  TProjectFileDescriptors = class(TPersistent)
 578  protected
 579    function GetItems(Index: integer): TProjectFileDescriptor; virtual; abstract;
 580  public
 581    function Count: integer; virtual; abstract;
 582    function GetUniqueName(const Name: string): string; virtual; abstract;
 583    function IndexOf(const Name: string): integer; virtual; abstract;
 584    function IndexOf(FileDescriptor: TProjectFileDescriptor): integer; virtual; abstract;
 585    function FindByName(const Name: string): TProjectFileDescriptor; virtual; abstract;
 586    procedure RegisterFileDescriptor(FileDescriptor: TProjectFileDescriptor); virtual; abstract;
 587    procedure UnregisterFileDescriptor(FileDescriptor: TProjectFileDescriptor); virtual; abstract;
 588  public
 589    property Items[Index: integer]: TProjectFileDescriptor read GetItems; default;
 590  end;
 591
 592
 593var
 594  ProjectFileDescriptors: TProjectFileDescriptors; // will be set by the IDE
 595
 596function FileDescriptorUnit: TProjectFileDescriptor;
 597function FileDescriptorForm: TProjectFileDescriptor;
 598function FileDescriptorDatamodule: TProjectFileDescriptor;
 599function FileDescriptorText: TProjectFileDescriptor;
 600
 601
 602type
 603  TLazProject = class;
 604
 605  { TProjectDescriptor - Template for initializing new projects }
 606
 607  TProjectFlag = (
 608    pfSaveClosedUnits,     // save info about closed files (not part of project)
 609    pfSaveOnlyProjectUnits, // save no info about foreign files (not part of project)
 610    pfMainUnitIsPascalSource,// main unit is pascal, even it does not end in .pas/.pp
 611    pfMainUnitHasUsesSectionForAllUnits,// add/remove pascal units to main uses section
 612    pfMainUnitHasCreateFormStatements,// add/remove Application.CreateForm statements
 613    pfMainUnitHasTitleStatement,// add/remove Application.Title:= statements
 614    pfRunnable, // project can be run
 615    pfAlwaysBuild, // skip IDE's smart check if compilation is needed and always compile
 616    pfLRSFilesInOutputDirectory // put .lrs files in output directory
 617    );
 618  TProjectFlags = set of TProjectFlag;
 619
 620  TProjectSessionStorage = (
 621    pssInProjectInfo, // save session info in .lpi file
 622    pssInProjectDir, // save session info in .lps file in project directory
 623    pssInIDEConfig, // save session info in IDE config directory
 624    pssNone         // do not save any session info
 625    );
 626  TProjectSessionStorages = set of TProjectSessionStorage;
 627
 628  { TProjectDescriptor
 629    - to show an option dialog to the user override the DoInitDescriptor
 630    - to initialize project compiler settings and paths override InitProject
 631    - to create files on creation override CreateStartFiles
 632  }
 633
 634  TProjectDescriptor = class(TPersistent)
 635  private
 636    FDefaultExt: string;
 637    FFlags: TProjectFlags;
 638    FName: string;
 639    FReferenceCount: integer;
 640    FVisibleInNewDialog: boolean;
 641  protected
 642    procedure SetName(const AValue: string); virtual;
 643    procedure SetFlags(const AValue: TProjectFlags); virtual;
 644    function DoInitDescriptor: TModalResult; virtual;// put here option dialogs
 645  public
 646    constructor Create; virtual;
 647    function GetLocalizedName: string; virtual;
 648    function GetLocalizedDescription: string; virtual;
 649    procedure Release;
 650    procedure Reference;
 651    function InitDescriptor: TModalResult;
 652    function InitProject(AProject: TLazProject): TModalResult; virtual;
 653    function CreateStartFiles(AProject: TLazProject): TModalResult; virtual;
 654  public
 655    property Name: string read FName write SetName;
 656    property VisibleInNewDialog: boolean read FVisibleInNewDialog
 657                                         write FVisibleInNewDialog;
 658    property Flags: TProjectFlags read FFlags write SetFlags;
 659    property DefaultExt: string read FDefaultExt write FDefaultExt;
 660  end;
 661  TProjectDescriptorClass = class of TProjectDescriptor;
 662
 663
 664  { TNewItemProject - a new item for project descriptors }
 665
 666  TNewItemProject = class(TNewIDEItemTemplate)
 667  private
 668    FDescriptor: TProjectDescriptor;
 669  public
 670    function LocalizedName: string; override;
 671    function Description: string; override;
 672    procedure Assign(Source: TPersistent); override;
 673  public
 674    property Descriptor: TProjectDescriptor read FDescriptor write FDescriptor;
 675  end;
 676
 677  { TLazProject - interface class to a Lazarus project }
 678
 679  TProjectFileSearchFlag = (
 680    pfsfResolveFileLinks,
 681    pfsfOnlyEditorFiles,
 682    pfsfOnlyVirtualFiles,
 683    pfsfOnlyProjectFiles
 684    );
 685  TProjectFileSearchFlags = set of TProjectFileSearchFlag;
 686
 687  TProjectExecutableType = (
 688    petNone,
 689    petProgram,
 690    petLibrary,
 691    petPackage,
 692    petUnit
 693    );
 694
 695  TLazProject = class(TPersistent)
 696  private
 697    FCustomData: TStringToStringTree;
 698    FCustomSessionData: TStringToStringTree;
 699    FExecutableType: TProjectExecutableType;
 700    FLazCompilerOptions: TLazCompilerOptions;
 701    fModified: boolean;
 702    FProjectSessionFile: string;
 703    FSessionModified: boolean;
 704    FTitle: String;
 705    FSessionStorage: TProjectSessionStorage;
 706    FLazDocPaths: string;
 707    procedure SetLazDocPaths(const AValue: string);
 708  protected
 709    FFlags: TProjectFlags;
 710    procedure SetLazCompilerOptions(const AValue: TLazCompilerOptions);
 711    function GetMainFile: TLazProjectFile; virtual; abstract;
 712    function GetMainFileID: Integer; virtual; abstract;
 713    procedure SetMainFileID(const AValue: Integer); virtual; abstract;
 714    function GetFiles(Index: integer): TLazProjectFile; virtual; abstract;
 715    procedure SetTitle(const AValue: String); virtual;
 716    procedure SetFlags(const AValue: TProjectFlags); virtual;
 717    function GetProjectInfoFile: string; virtual; abstract;
 718    procedure SetProjectInfoFile(const NewFilename: string); virtual; abstract;
 719    procedure SetProjectSessionFile(const AValue: string); virtual;
 720    procedure SetSessionStorage(const AValue: TProjectSessionStorage); virtual;
 721    procedure SetModified(const AValue: boolean); virtual;
 722    procedure SetSessionModified(const AValue: boolean); virtual;
 723    procedure SetExecutableType(const AValue: TProjectExecutableType); virtual;
 724  public
 725    constructor Create(ProjectDescription: TProjectDescriptor); virtual;
 726    destructor Destroy; override;
 727    function CreateProjectFile(const Filename: string
 728                               ): TLazProjectFile; virtual; abstract;
 729    procedure AddFile(ProjectFile: TLazProjectFile;
 730                      AddToProjectUsesClause: boolean); virtual; abstract;
 731    procedure RemoveUnit(Index: integer; RemoveFromUsesSection: boolean = true); virtual; abstract;
 732    function GetFileCount: integer; virtual; abstract;
 733    procedure AddSrcPath(const SrcPathAddition: string); virtual; abstract;
 734    procedure AddPackageDependency(const PackageName: string); virtual; abstract;
 735    function ShortDescription: string;
 736    procedure ClearModifieds(ClearUnits: boolean);
 737    function FindFile(const AFilename: string;
 738                      SearchFlags: TProjectFileSearchFlags): TLazProjectFile; virtual; abstract;
 739    procedure UpdateExecutableType; virtual; abstract;
 740    procedure ShortenFilename(var AFilename: string); virtual; abstract;
 741    procedure LongenFilename(var AFilename: string); virtual; abstract;
 742  public
 743    property MainFileID: Integer read GetMainFileID write SetMainFileID;
 744    property Files[Index: integer]: TLazProjectFile read GetFiles;
 745    property FileCount: integer read GetFileCount;
 746    property MainFile: TLazProjectFile read GetMainFile;
 747    property Title: String read FTitle write SetTitle;
 748    property Flags: TProjectFlags read FFlags write SetFlags;
 749    property ExecutableType: TProjectExecutableType read FExecutableType
 750                 write SetExecutableType;// read from MainFile, not saved to lpi
 751    property LazCompilerOptions: TLazCompilerOptions read FLazCompilerOptions
 752                                                     write SetLazCompilerOptions;
 753    property ProjectInfoFile: string
 754                               read GetProjectInfoFile write SetProjectInfoFile;
 755    property ProjectSessionFile: string
 756                           read FProjectSessionFile write SetProjectSessionFile;
 757    property SessionStorage: TProjectSessionStorage read FSessionStorage
 758                                                    write SetSessionStorage;
 759    property Modified: boolean read fModified
 760                       write SetModified; // project data (not units, session),
 761                                          // units have their own Modified
 762    property SessionModified: boolean read FSessionModified
 763                       write SetSessionModified;
 764                       // project session data (not units, data),
 765                       // units have their own SessionModified
 766    property LazDocPaths: string read FLazDocPaths write SetLazDocPaths;
 767    property CustomData: TStringToStringTree read FCustomData;
 768    property CustomSessionData: TStringToStringTree read FCustomSessionData;
 769  end;
 770
 771  TLazProjectClass = class of TLazProject;
 772
 773
 774  { TProjectDescriptors }
 775
 776  TProjectDescriptors = class(TPersistent)
 777  protected
 778    function GetItems(Index: integer): TProjectDescriptor; virtual; abstract;
 779  public
 780    function Count: integer; virtual; abstract;
 781    function GetUniqueName(const Name: string): string; virtual; abstract;
 782    function IndexOf(const Name: string): integer; virtual; abstract;
 783    function IndexOf(Descriptor: TProjectDescriptor): integer; virtual; abstract;
 784    function FindByName(const Name: string): TProjectDescriptor; virtual; abstract;
 785    procedure RegisterDescriptor(Descriptor: TProjectDescriptor); virtual; abstract;
 786    procedure UnregisterDescriptor(Descriptor: TProjectDescriptor); virtual; abstract;
 787  public
 788    property Items[Index: integer]: TProjectDescriptor read GetItems; default;
 789  end;
 790  TProjectDescriptorsClass = class of TProjectDescriptors;
 791
 792var
 793  ProjectDescriptors: TProjectDescriptors; // will be set by the IDE
 794
 795function ProjectDescriptorApplication: TProjectDescriptor;
 796function ProjectDescriptorProgram: TProjectDescriptor;
 797function ProjectDescriptorConsoleApplication: TProjectDescriptor;
 798function ProjectDescriptorLibrary: TProjectDescriptor;
 799function ProjectDescriptorCustomProgram: TProjectDescriptor;
 800function ProjectDescriptorEmptyProject: TProjectDescriptor;
 801
 802const
 803  DefaultProjectFlags = [pfSaveClosedUnits,
 804                         pfMainUnitIsPascalSource,
 805                         pfMainUnitHasUsesSectionForAllUnits,
 806                         pfMainUnitHasCreateFormStatements,
 807                         pfMainUnitHasTitleStatement,
 808                         pfRunnable,
 809                         pfAlwaysBuild,
 810                         pfLRSFilesInOutputDirectory];
 811  ProjectFlagNames : array[TProjectFlag] of string = (
 812      'SaveClosedFiles',
 813      'SaveOnlyProjectUnits',
 814      'MainUnitIsPascalSource',
 815      'MainUnitHasUsesSectionForAllUnits',
 816      'MainUnitHasCreateFormStatements',
 817      'MainUnitHasTitleStatement',
 818      'Runnable',
 819      'AlwaysBuild',
 820      'LRSInOutputDirectory'
 821    );
 822
 823  ProjectSessionStorageNames: array[TProjectSessionStorage] of string = (
 824    'InProjectInfo',
 825    'InProjectDir',
 826    'InIDEConfig',
 827    'None'
 828    );
 829
 830  CompilationExecutableTypeNames: array[TCompilationExecutableType] of string =(
 831    'Program',
 832    'Library'
 833    );
 834
 835
 836function ProjectFlagsToStr(Flags: TProjectFlags): string;
 837function StrToProjectSessionStorage(const s: string): TProjectSessionStorage;
 838function CompilationExecutableTypeNameToType(const s: string
 839                                             ): TCompilationExecutableType;
 840function COCNodeTypeNameToType(const s: string): TCOCNodeType;
 841function COCNodeTypeLocalizedName(const nt: TCOCNodeType): string;
 842function COCValueTypeNameToType(const s: string): TCOCValueType;
 843function COCValueTypeLocalizedName(const vt: TCOCValueType): string;
 844
 845procedure RegisterProjectFileDescriptor(FileDesc: TProjectFileDescriptor);
 846procedure RegisterProjectDescriptor(ProjDesc: TProjectDescriptor);
 847procedure RegisterProjectFileDescriptor(FileDesc: TProjectFileDescriptor;
 848                       const ACategory : String;
 849                       DefaultCreateFlag: TNewIDEItemFlag = niifCopy;
 850                       const AllowedCreateFlags: TNewIDEItemFlags = [niifCopy]);
 851procedure RegisterProjectDescriptor(ProjDesc: TProjectDescriptor;
 852                       const ACategory : String;
 853                       DefaultCreateFlag: TNewIDEItemFlag = niifCopy;
 854                       const AllowedCreateFlags: TNewIDEItemFlags = [niifCopy]);
 855
 856
 857implementation
 858
 859function COCNodeTypeNameToType(const s: string): TCOCNodeType;
 860begin
 861  for Result:=Low(TCOCNodeType) to High(TCOCNodeType) do
 862    if SysUtils.CompareText(s,COCNodeTypeNames[Result])=0 then exit;
 863  Result:=cocntNone;
 864end;
 865
 866function COCNodeTypeLocalizedName(const nt: TCOCNodeType): string;
 867begin
 868  case nt of
 869  cocntNone:   Result:=sccsILEdtNone;
 870  cocntIf:     Result:=liisIf;
 871  cocntIfdef:  Result:=liisIfDef;
 872  cocntIfNdef: Result:=liisIfNDef;
 873  cocntElseIf: Result:=liisElseIf;
 874  cocntElse:   Result:=liisElse;
 875  cocntAddValue: Result:=liisAddValue;
 876  cocntSetValue: Result:=liisSetValue;
 877  else         Result:='?';
 878  end;
 879end;
 880
 881function COCValueTypeNameToType(const s: string): TCOCValueType;
 882begin
 883  for Result:=Low(TCOCValueType) to High(TCOCValueType) do
 884    if SysUtils.CompareText(s,COCValueTypeNames[Result])=0 then exit;
 885  Result:=cocvtNone;
 886end;
 887
 888function COCValueTypeLocalizedName(const vt: TCOCValueType): string;
 889begin
 890  case vt of
 891  cocvtNone:          Result:='None';
 892  cocvtResult:        Result:='Result';
 893  cocvtUnitPath:      Result:='Unit search path';
 894  cocvtSrcPath:       Result:='Unit source search path';
 895  cocvtIncludePath:   Result:='Include search path';
 896  cocvtObjectPath:    Result:='Object search path';
 897  cocvtLibraryPath:   Result:='Library search path';
 898  cocvtDebugPath:     Result:='Debug search path';
 899  cocvtLinkerOptions: Result:='Linker options';
 900  cocvtCustomOptions: Result:='Custom options';
 901  else                Result:='?';
 902  end;
 903end;
 904
 905procedure RegisterProjectFileDescriptor(FileDesc: TProjectFileDescriptor);
 906begin
 907  RegisterProjectFileDescriptor(FileDesc,FileDescGroupName);
 908end;
 909
 910procedure RegisterProjectFileDescriptor(FileDesc: TProjectFileDescriptor;
 911  const ACategory : String;
 912  DefaultCreateFlag: TNewIDEItemFlag; const AllowedCreateFlags: TNewIDEItemFlags);
 913var
 914  NewItemFile: TNewItemProjectFile;
 915begin
 916  ProjectFileDescriptors.RegisterFileDescriptor(FileDesc);
 917  if FileDesc.VisibleInNewDialog then begin
 918    NewItemFile:=TNewItemProjectFile.Create(FileDesc.Name,
 919                                          DefaultCreateFlag,AllowedCreateFlags);
 920    NewItemFile.Descriptor:=FileDesc;
 921    RegisterNewDialogItem(ACategory,NewItemFile);
 922  end;
 923end;
 924
 925procedure RegisterProjectDescriptor(ProjDesc: TProjectDescriptor);
 926begin
 927  RegisterProjectDescriptor(ProjDesc,ProjDescGroupName);
 928end;
 929
 930procedure RegisterProjectDescriptor(ProjDesc: TProjectDescriptor;
 931  const ACategory : String;
 932  DefaultCreateFlag: TNewIDEItemFlag; const AllowedCreateFlags: TNewIDEItemFlags);
 933var
 934  NewItemProject: TNewItemProject;
 935begin
 936  ProjectDescriptors.RegisterDescriptor(ProjDesc);
 937  if ProjDesc.VisibleInNewDialog then begin
 938    NewItemProject:=TNewItemProject.Create(ProjDesc.Name,
 939                                          DefaultCreateFlag,AllowedCreateFlags);
 940    NewItemProject.Descriptor:=ProjDesc;
 941    RegisterNewDialogItem(ACategory,NewItemProject);
 942  end;
 943end;
 944
 945function FileDescriptorUnit: TProjectFileDescriptor;
 946begin
 947  Result:=ProjectFileDescriptors.FindByName(FileDescNamePascalUnit);
 948end;
 949
 950function FileDescriptorForm: TProjectFileDescriptor;
 951begin
 952  Result:=ProjectFileDescriptors.FindByName(FileDescNameLCLForm);
 953end;
 954
 955function FileDescriptorDatamodule: TProjectFileDescriptor;
 956begin
 957  Result:=ProjectFileDescriptors.FindByName(FileDescNameDatamodule);
 958end;
 959
 960function FileDescriptorText: TProjectFileDescriptor;
 961begin
 962  Result:=ProjectFileDescriptors.FindByName(FileDescNameText);
 963end;
 964
 965function ProjectDescriptorApplication: TProjectDescriptor;
 966begin
 967  Result:=ProjectDescriptors.FindByName(ProjDescNameApplication);
 968end;
 969
 970function ProjectDescriptorProgram: TProjectDescriptor;
 971begin
 972  Result:=ProjectDescriptors.FindByName(ProjDescNameProgram);
 973end;
 974
 975function ProjectDescriptorConsoleApplication: TProjectDescriptor;
 976begin
 977  Result:=ProjectDescriptors.FindByName(ProjDescNameConsoleApplication);
 978end;
 979
 980function ProjectDescriptorLibrary: TProjectDescriptor;
 981begin
 982  Result:=ProjectDescriptors.FindByName(ProjDescNameLibrary);
 983end;
 984
 985function ProjectDescriptorCustomProgram: TProjectDescriptor;
 986begin
 987  Result:=ProjectDescriptors.FindByName(ProjDescNameCustomProgram);
 988end;
 989
 990function ProjectDescriptorEmptyProject: TProjectDescriptor;
 991begin
 992  Result:=ProjectDescriptors.FindByName(ProjDescNameEmpty);
 993end;
 994
 995function ProjectFlagsToStr(Flags: TProjectFlags): string;
 996var f: TProjectFlag;
 997begin
 998  Result:='';
 999  for f:=Low(TProjectFlag) to High(TProjectFlag) do begin
1000    if f in Flags then begin
1001      if Result='' then Result:=Result+',';
1002      Result:=Result+ProjectFlagNames[f];
1003    end;
1004  end;
1005end;
1006
1007function StrToProjectSessionStorage(const s: string): TProjectSessionStorage;
1008begin
1009  for Result:=Low(TProjectSessionStorage) to High(TProjectSessionStorage) do
1010    if CompareText(s,ProjectSessionStorageNames[Result])=0 then exit;
1011  Result:=pssInProjectInfo;
1012end;
1013
1014function CompilationExecutableTypeNameToType(const s: string
1015  ): TCompilationExecutableType;
1016begin
1017  for Result:=Low(TCompilationExecutableType) to High(TCompilationExecutableType)
1018  do if CompareText(s,CompilationExecutableTypeNames[Result])=0 then exit;
1019  Result:=cetProgram;
1020end;
1021
1022{ TCompOptCondNode }
1023
1024procedure TCompOptCondNode.SetNodeType(const AValue: TCOCNodeType);
1025begin
1026  if FNodeType=AValue then exit;
1027  FNodeType:=AValue;
1028  Changed;
1029end;
1030
1031function TCompOptCondNode.GetChilds(Index: integer): TCompOptCondNode;
1032begin
1033  Result:=TCompOptCondNode(fChilds[Index]);
1034end;
1035
1036function TCompOptCondNode.GetCount: integer;
1037begin
1038  Result:=fChilds.Count;
1039end;
1040
1041function TCompOptCondNode.GetIndex: integer;
1042begin
1043  if Parent=nil then
1044    Result:=-1
1045  else
1046    Result:=Parent.fChilds.IndexOf(Self);
1047end;
1048
1049procedure TCompOptCondNode.SetIndex(const AValue: integer);
1050var
1051  OldIndex: LongInt;
1052begin
1053  OldIndex:=GetIndex;
1054  if OldIndex=AValue then exit;
1055  Parent.Move(OldIndex,AValue);
1056end;
1057
1058procedure TCompOptCondNode.SetValue(const AValue: string);
1059begin
1060  if FValue=AValue then exit;
1061  FValue:=AValue;
1062  Changed;
1063end;
1064
1065procedure TCompOptCondNode.SetValueType(const AValue: TCOCValueType);
1066begin
1067  if FValueType=AValue then exit;
1068  FValueType:=AValue;
1069  Changed;
1070end;
1071
1072procedure TCompOptCondNode.Changed;
1073begin
1074  if (FOwner<>nil) and (not fClearing) then FOwner.InvalidateValues;
1075end;
1076
1077constructor TCompOptCondNode.Create(TheOwner: TLazCompOptConditionals);
1078begin
1079  FOwner:=TheOwner;
1080  fChilds:=TFPList.Create;
1081end;
1082
1083destructor TCompOptCondNode.Destroy;
1084begin
1085  fClearing:=true;
1086  ClearNodes;
1087  if FParent<>nil then begin
1088    FParent.fChilds.Remove(Self);
1089    FParent.Changed;
1090    FParent:=nil;
1091  end;
1092  FreeAndNil(fChilds);
1093  inherited Destroy;
1094end;
1095
1096procedure TCompOptCondNode.ClearNodes;
1097var
1098  i: Integer;
1099  OldClearing: Boolean;
1100begin
1101  if fChilds.Count=0 then exit;
1102  OldClearing:=fClearing;
1103  fClearing:=true;
1104  for i:=fChilds.Count-1 downto 0 do
1105    TObject(fChilds[i]).Free;
1106  fChilds.Clear;
1107  fClearing:=OldClearing;
1108  Changed;
1109end;
1110
1111procedure TCompOptCondNode.AddLast(Child: TCompOptCondNode);
1112begin
1113  Insert(Count,Child);
1114end;
1115
1116procedure TCompOptCondNode.Insert(Index: integer; Child: TCompOptCondNode);
1117begin
1118  fChilds.Insert(Index,Child);
1119  Child.FParent:=Self;
1120  Changed;
1121end;
1122
1123procedure TCompOptCondNode.Move(OldIndex, NewIndex: integer);
1124begin
1125  if OldIndex=NewIndex then exit;
1126  fChilds.Move(OldIndex,NewIndex);
1127  Changed;
1128end;
1129
1130procedure TCompOptCondNode.Move(NewParent: TCompOptCondNode; NewIndex: integer
1131  );
1132begin
1133  if (NewParent=Parent) and (NewIndex=Index) then exit;
1134  if FParent<>nil then begin
1135    FParent.fChilds.Remove(Self);
1136    FParent.Changed;
1137  end;
1138  FParent:=NewParent;
1139  if FParent<>nil then begin
1140    if (NewIndex<0) or (NewIndex>FParent.Count) then
1141      NewIndex:=FParent.Count;
1142    FParent.fChilds.Insert(NewIndex,Self);
1143    FParent.Changed;
1144  end;
1145end;
1146
1147procedure TCompOptCondNode.Delete(Index: integer);
1148begin
1149  Childs[Index].Free;
1150end;
1151
1152procedure TCompOptCondNode.Assign(Source: TCompOptCondNode);
1153var
1154  i: Integer;
1155  Child: TCompOptCondNode;
1156begin
1157  ClearNodes;
1158  NodeType:=Source.NodeType;
1159  ValueType:=Source.ValueType;
1160  Value:=Source.Value;
1161  for i:=0 to Source.Count-1 do begin
1162    Child:=TCompOptCondNode.Create(Owner);
1163    AddLast(Child);
1164    Child.Assign(Source.Childs[i]);
1165  end;
1166end;
1167
1168{ TProjectFileDescriptor }
1169
1170procedure TProjectFileDescriptor.SetResourceClass(
1171  const AValue: TPersistentClass);
1172begin
1173  if FResourceClass=AValue then exit;
1174  FResourceClass:=AValue;
1175  FIsComponent:=(FResourceClass<>nil)
1176                and (FResourceClass.InheritsFrom(TComponent));
1177  if FResourceClass=nil then
1178    FDefaultResourceName:=''
1179  else begin
1180    FDefaultResourceName:=
1181      copy(FResourceClass.ClassName,2,length(FResourceClass.ClassName)-1)+'1';
1182  end;
1183end;
1184
1185procedure TProjectFileDescriptor.SetDefaultFileExt(const AValue: string);
1186begin
1187  if FDefaultFileExt=AValue then exit;
1188  FDefaultFileExt:=AValue;
1189end;
1190
1191procedure TProjectFileDescriptor.SetDefaultResFileExt(const AValue: string);
1192begin
1193  if FDefaultResFileExt=AValue then exit;
1194  FDefaultResFileExt:=AValue;
1195end;
1196
1197procedure TProjectFileDescriptor.SetDefaultSourceName(const AValue: string);
1198begin
1199  if FDefaultSourceName=AValue then exit;
1200  FDefaultSourceName:=AValue;
1201end;
1202
1203procedure TProjectFileDescriptor.SetRequiredPackages(const AValue: string);
1204begin
1205  if FRequiredPackages=AValue then exit;
1206  FRequiredPackages:=AValue;
1207end;
1208
1209procedure TProjectFileDescriptor.SetDefaultFilename(const AValue: string);
1210begin
1211  if FDefaultFilename=AValue then exit;
1212  FDefaultFilename:=AValue;
1213  DefaultFileExt:=ExtractFileExt(FDefaultFilename);
1214  FIsPascalUnit:=FilenameIsPascalUnit(DefaultFileExt);
1215end;
1216
1217procedure TProjectFileDescriptor.SetName(const AValue: string);
1218begin
1219  if FName=AValue then exit;
1220  FName:=AValue;
1221end;
1222
1223constructor TProjectFileDescriptor.Create;
1224begin
1225  FReferenceCount:=1;
1226  DefaultResFileExt:='.lrs';
1227  AddToProject:=true;
1228  VisibleInNewDialog:=true;
1229end;
1230
1231function TProjectFileDescriptor.GetLocalizedName: string;
1232begin
1233  Result:=Name;
1234end;
1235
1236function TProjectFileDescriptor.GetLocalizedDescription: string;
1237begin
1238  Result:=GetLocalizedName;
1239end;
1240
1241function TProjectFileDescriptor.GetResourceSource(const ResourceName: string): string;
1242// This function can override the automatic creation of the .lfm file source.
1243begin
1244  Result:=''; // if empty, the IDE will create the source automatically
1245end;
1246
1247procedure TProjectFileDescriptor.Release;
1248begin
1249  //debugln('TProjectFileDescriptor.Release A ',Name,' ',dbgs(FReferenceCount));
1250  if FReferenceCount=0 then
1251    raise Exception.Create('');
1252  dec(FReferenceCount);
1253  if FReferenceCount=0 then Free;
1254end;
1255
1256procedure TProjectFileDescriptor.Reference;
1257begin
1258  inc(FReferenceCount);
1259end;
1260
1261function TProjectFileDescriptor.CreateSource(const Filename, SourceName,
1262  ResourceName: string): string;
1263begin
1264  Result:='';
1265end;
1266
1267procedure TProjectFileDescriptor.UpdateDefaultPascalFileExtension(
1268  const DefPasExt: string);
1269begin
1270  if DefPasExt='' then exit;
1271  if FilenameIsPascalUnit(DefaultFileExt) then
1272    DefaultFileExt:=DefPasExt;
1273  if FilenameIsPascalUnit(DefaultFilename) then
1274    DefaultFilename:=ChangeFileExt(DefaultFilename,DefPasExt);
1275end;
1276
1277{ TFileDescPascalUnit }
1278
1279constructor TFileDescPascalUnit.Create;
1280begin
1281  inherited Create;
1282  Name:=FileDescNamePascalUnit;
1283  DefaultFilename:='unit.pas';
1284  DefaultSourceName:='Unit1';
1285  IsPascalUnit:=true;
1286end;
1287
1288function TFileDescPascalUnit.CreateSource(const Filename, SourceName,
1289  ResourceName: string): string;
1290var
1291  LE: string;
1292begin
1293  LE:=LineEnding;
1294  Result:=
1295     'unit '+SourceName+';'+LE
1296    +LE
1297    +'{$mode objfpc}{$H+}'+LE
1298    +LE
1299    +'interface'+LE
1300    +LE
1301    +'uses'+LE
1302    +'  '+GetInterfaceUsesSection+';'+LE
1303    +LE
1304    +GetInterfaceSource(Filename,SourceName,ResourceName)
1305    +'implementation'+LE
1306    +LE
1307    +GetImplementationSource(Filename,SourceName,ResourceName)
1308    +'end.'+LE
1309    +LE;
1310end;
1311
1312function TFileDescPascalUnit.GetLocalizedName: string;
1313begin
1314  Result:='Unit';
1315end;
1316
1317function TFileDescPascalUnit.GetLocalizedDescription: string;
1318begin
1319  Result:=oisCreateANewPascalUnit;
1320end;
1321
1322function TFileDescPascalUnit.GetInterfaceUsesSection: string;
1323begin
1324  Result:='Classes, SysUtils';
1325end;
1326
1327function TFileDescPascalUnit.GetInterfaceSource(const Filename, SourceName,
1328  ResourceName: string): string;
1329begin
1330  Result:='';
1331end;
1332
1333function TFileDescPascalUnit.GetImplementationSource(const Filename,
1334  SourceName, ResourceName: string): string;
1335begin
1336  Result:='';
1337end;
1338
1339{ TFileDescPascalUnitWithResource }
1340
1341constructor TFileDescPascalUnitWithResource.Create;
1342begin
1343  inherited Create;
1344  FDeclareClassVariable := True;
1345end;
1346
1347function TFileDescPascalUnitWithResource.GetInterfaceUsesSection: string;
1348begin
1349  Result:=inherited GetInterfaceUsesSection;
1350  Result:=Result+', FileUtil, LResources';
1351end;
1352
1353function TFileDescPascalUnitWithResource.GetInterfaceSource(const Filename,
1354  SourceName, ResourceName: string): string;
1355var
1356  LE: string;
1357begin
1358  LE:=LineEnding;
1359  Result:=
1360     'type'+LE
1361    +'  T'+ResourceName+' = class('+ResourceClass.ClassName+')'+LE
1362    +'  private'+LE
1363    +'    { private declarations }'+LE
1364    +'  public'+LE
1365    +'    { public declarations }'+LE
1366    +'  end;'+LE
1367    +LE;
1368
1369  if DeclareClassVariable then
1370    Result := Result +
1371     'var'+LE
1372    +'  '+ResourceName+': T'+ResourceName+';'+LE
1373    +LE;
1374end;
1375
1376function TFileDescPascalUnitWithResource.GetImplementationSource(
1377  const Filename, SourceName, ResourceName: string): string;
1378var
1379  ResourceFilename: String;
1380  LE: String;
1381begin
1382  ResourceFilename:=TrimFilename(ExtractFilenameOnly(Filename)+DefaultResFileExt);
1383  LE:=LineEnding;
1384  Result:='initialization'+LE
1385    +'  {$I '+ResourceFilename+'}'+LE
1386    +LE
1387end;
1388
1389{ TProjectDescriptor }
1390
1391procedure TProjectDescriptor.SetFlags(const AValue: TProjectFlags);
1392begin
1393  FFlags:=AValue;
1394end;
1395
1396function TProjectDescriptor.DoInitDescriptor: TModalResult;
1397begin
1398  Result:=mrOk;
1399end;
1400
1401procedure TProjectDescriptor.SetName(const AValue: string);
1402begin
1403  if FName=AValue then exit;
1404  FName:=AValue;
1405end;
1406
1407constructor TProjectDescriptor.Create;
1408begin
1409  FReferenceCount:=1;
1410  FFlags:=DefaultProjectFlags;
1411  fVisibleInNewDialog:=true;
1412  FDefaultExt:='.pas';
1413end;
1414
1415function TProjectDescriptor.GetLocalizedName: string;
1416begin
1417  Result:=Name;
1418end;
1419
1420function TProjectDescriptor.GetLocalizedDescription: string;
1421begin
1422  Result:=GetLocalizedName;
1423end;
1424
1425procedure TProjectDescriptor.Release;
1426begin
1427  //debugln('TProjectDescriptor.Release A ',Name,' ',dbgs(FReferenceCount));
1428  if FReferenceCount=0 then
1429    raise Exception.Create('');
1430  dec(FReferenceCount);
1431  if FReferenceCount=0 then Free;
1432end;
1433
1434procedure TProjectDescriptor.Reference;
1435begin
1436  inc(FReferenceCount);
1437end;
1438
1439function TProjectDescriptor.InitDescriptor: TModalResult;
1440begin
1441  Result:=DoInitDescriptor;
1442end;
1443
1444function TProjectDescriptor.InitProject(AProject: TLazProject): TModalResult;
1445begin
1446  AProject.Title:='project1';
1447  AProject.Flags:=Flags;
1448  Result:=mrOk;
1449end;
1450
1451function TProjectDescriptor.CreateStartFiles(AProject: TLazProject
1452  ): TModalResu

Large files files are truncated, but you can click here to view the full file