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