File: projpackcommon.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (217 lines) | stat: -rw-r--r-- 6,246 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
unit ProjPackCommon;

{$mode objfpc}{$H+}
{.$INTERFACES CORBA}   // No reference counting for IProjPack. (does not work)

interface

uses
  Classes, SysUtils,
  // LazUtils
  LazTracer,
  // Codetools
  DefineTemplates, CodeToolManager,
  // IDE
  CompilerOptions, FileReferenceList;

type

  TProjPackDefineTemplates = class;

  { IProjPack }

  IProjPack = interface
    function GetIDAsString: string;
    function GetIDAsWord: string;
    function GetBaseCompilerOptions: TBaseCompilerOptions;
    function GetDefineTemplates: TProjPackDefineTemplates;
    function GetSourceDirectories: TFileReferenceList;
    function GetModified: boolean;
    //function GetOutputDirectory: string;  // Proj/Pack have different params.
    function NeedsDefineTemplates: boolean;
    procedure AddPackageDependency(const PackageName: string);
    //function FindDependencyByName(const PackageName: string): TPkgDependency;
    function RemoveNonExistingFiles(RemoveFromUsesSection: boolean = true): boolean;
    procedure SetModified(const AValue: boolean);

    property IDAsString: string read GetIDAsString;
    property IDAsWord: string read GetIDAsWord;
    property BaseCompilerOptions: TBaseCompilerOptions read GetBaseCompilerOptions;
    property DefineTemplates: TProjPackDefineTemplates read GetDefineTemplates;
    property SourceDirectories: TFileReferenceList read GetSourceDirectories;
  end;

  { TProjPackDefineTemplates }

  TProjPackDefineTemplatesFlag = (
    ptfIsPackageTemplate,
    ptfFlagsChanged,
    ptfIDChanged,
    ptfSourceDirsChanged,
    ptfOutputDirChanged,
    ptfCustomDefinesChanged
    );
  TProjPackDefineTemplatesFlags = set of TProjPackDefineTemplatesFlag;

  TProjPackDefineTemplates = class
  private
    FOwner: IProjPack;
  protected
    FActive: boolean;
    FSrcDirectories: TDefineTemplate;
    FSrcDirIf: TDefineTemplate;
    FFlags: TProjPackDefineTemplatesFlags;
    FMain: TDefineTemplate;
    FOutputDir: TDefineTemplate;
    FOutPutSrcPath: TDefineTemplate;
    FUpdateLock: integer;
    fLastSourceDirectories: TStringList;
    fLastOutputDirSrcPathIDAsString: string;
    fLastSourceDirsIDAsString: string;
    fLastSourceDirStamp: integer;
    FLastCustomOptions: string;
    fLastUnitPath: string;
    procedure SetActive(const AValue: boolean);
    procedure UpdateMain; virtual; abstract;
    procedure UpdateSrcDirIfDef; virtual; abstract;
    procedure UpdateSourceDirectories; virtual; abstract;
    procedure UpdateOutputDirectory; virtual; abstract;
    procedure UpdateDefinesForCustomDefines; virtual; abstract;
    procedure ClearFlags; virtual; abstract;
  public
    constructor Create(AOwner: IProjPack);
    destructor Destroy; override;
    procedure Clear;
    procedure BeginUpdate;
    procedure EndUpdate;
    procedure AllChanged; virtual; abstract;
    procedure IDChanged;
    procedure SourceDirectoriesChanged;// a source directory was added/deleted
    procedure CustomDefinesChanged;    // the defines of the source dirs changed
    procedure OutputDirectoryChanged;// the path or the defines of the output dir changed
  public
    property Owner: IProjPack read FOwner;
    property Main: TDefineTemplate read FMain;
    property SrcDirectories: TDefineTemplate read FSrcDirectories;
    property OutputDir: TDefineTemplate read FOutputDir;
    property OutPutSrcPath: TDefineTemplate read FOutPutSrcPath;
    property CustomDefines: TDefineTemplate read FSrcDirIf;
    property Active: boolean read FActive write SetActive;
  end;


implementation

constructor TProjPackDefineTemplates.Create(AOwner: IProjPack);
begin
  inherited Create;
  FOwner:=AOwner;
end;

destructor TProjPackDefineTemplates.Destroy;
begin
  Clear;
  fLastSourceDirectories.Free;
  inherited Destroy;
end;

procedure TProjPackDefineTemplates.Clear;
begin
  if FMain<>nil then begin
    if (CodeToolBoss<>nil) then
      CodeToolBoss.DefineTree.RemoveDefineTemplate(FMain);
    FMain:=nil;
    FSrcDirIf:=nil;
    FSrcDirectories:=nil;
    FOutputDir:=nil;
    FOutPutSrcPath:=nil;
    fLastOutputDirSrcPathIDAsString:='';
    FLastCustomOptions:='';
    fLastUnitPath:='';
    fLastSourceDirsIDAsString:='';
    if fLastSourceDirectories<>nil then
      fLastSourceDirectories.Clear;
    ClearFlags;
  end;
end;

procedure TProjPackDefineTemplates.BeginUpdate;
begin
  inc(FUpdateLock);
end;

procedure TProjPackDefineTemplates.EndUpdate;
begin
  if FUpdateLock=0 then RaiseGDBException('TProjPackDefineTemplates.EndUpdate');
  dec(FUpdateLock);
  if FUpdateLock=0 then begin
    if ptfIsPackageTemplate in FFlags then begin
      if ptfIDChanged in FFlags then IDChanged;
    end;
    if ptfFlagsChanged in FFlags then CustomDefinesChanged;
    if ptfSourceDirsChanged in FFlags then SourceDirectoriesChanged;
    if ptfOutputDirChanged in FFlags then OutputDirectoryChanged;
    if ptfCustomDefinesChanged in FFlags then CustomDefinesChanged;
  end;
end;

procedure TProjPackDefineTemplates.SetActive(const AValue: boolean);
begin
  if FActive=AValue then exit;
  FActive:=AValue;
  if FActive then
    AllChanged
  else
    Clear;
end;

procedure TProjPackDefineTemplates.IDChanged;
begin
  if FUpdateLock>0 then begin
    Include(FFlags,ptfIDChanged);
    exit;
  end;
  Exclude(FFlags,ptfIDChanged);
  UpdateMain;
  UpdateOutputDirectory;
  UpdateSourceDirectories;
  UpdateDefinesForCustomDefines;
end;

procedure TProjPackDefineTemplates.SourceDirectoriesChanged;
begin
  if FUpdateLock>0 then begin
    Include(FFlags,ptfSourceDirsChanged);
    exit;
  end;
  Exclude(FFlags,ptfSourceDirsChanged);
  UpdateSourceDirectories;
  CodeToolBoss.DefineTree.ClearCache;
end;

procedure TProjPackDefineTemplates.OutputDirectoryChanged;
begin
  if FUpdateLock>0 then begin
    Include(FFlags,ptfOutputDirChanged);
    exit;
  end;
  Exclude(FFlags,ptfOutputDirChanged);
  UpdateOutputDirectory;
  CodeToolBoss.DefineTree.ClearCache;
end;

procedure TProjPackDefineTemplates.CustomDefinesChanged;
begin
  if FUpdateLock>0 then begin
    Include(FFlags,ptfCustomDefinesChanged);
    exit;
  end;
  Exclude(FFlags,ptfCustomDefinesChanged);
  UpdateDefinesForCustomDefines; // maybe custom defines changed
  if ptfIsPackageTemplate in FFlags then
    CodeToolBoss.DefineTree.ClearCache;
end;


end.