~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to ide/buildprojectdlg.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
 ***************************************************************************
 
3
 *                                                                         *
 
4
 *   This source is free software; you can redistribute it and/or modify   *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This code is distributed in the hope that it will be useful, but      *
 
10
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 
12
 *   General Public License for more details.                              *
 
13
 *                                                                         *
 
14
 *   A copy of the GNU General Public License is available on the World    *
 
15
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 
16
 *   obtain it by writing to the Free Software Foundation,                 *
 
17
 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 
18
 *                                                                         *
 
19
 ***************************************************************************
 
20
 
 
21
  Abstract:
 
22
    Dialog to clean up a project and its packages and to compile the project.
 
23
}
 
24
unit BuildProjectDlg;
 
25
 
 
26
{$mode objfpc}{$H+}
 
27
 
 
28
interface
 
29
 
 
30
uses
 
31
  Classes, SysUtils, Math, AVL_Tree, FileProcs, Forms, Controls, Graphics,
 
32
  Dialogs, ButtonPanel, ExtCtrls, StdCtrls, ComCtrls, Masks, LCLIntf,
 
33
  // codetools
 
34
  CodeToolManager, DirectoryCacher, CodeToolsStructs,
 
35
  // IDEIntf
 
36
  IDEDialogs, IDEImagesIntf,
 
37
  // IDE
 
38
  PackageDefs, PackageSystem, InputHistory, LazarusIDEStrConsts, Project,
 
39
  DialogProcs, IDEProcs;
 
40
 
 
41
type
 
42
  TBuildProjectDialogItem = class
 
43
  public
 
44
    IsDirectory: boolean;
 
45
    Filename: string;
 
46
  end;
 
47
 
 
48
  { TCleanBuildProjectDialog }
 
49
 
 
50
  TCleanBuildProjectDialog = class(TForm)
 
51
    ButtonPanel1: TButtonPanel;
 
52
    DeleteButton: TButton;
 
53
    PkgOutCheckBox: TCheckBox;
 
54
    PkgOutMaskComboBox: TComboBox;
 
55
    PkgSrcCheckBox: TCheckBox;
 
56
    PkgSrcMaskComboBox: TComboBox;
 
57
    PreviewGroupBox: TGroupBox;
 
58
    FilesTreeView: TTreeView;
 
59
    ProjOutCheckBox: TCheckBox;
 
60
    ProjOutMaskComboBox: TComboBox;
 
61
    ProjSrcCheckBox: TCheckBox;
 
62
    ProjSrcMaskComboBox: TComboBox;
 
63
    procedure ButtonPanel1OKButtonClick(Sender: TObject);
 
64
    procedure DeleteButtonClick(Sender: TObject);
 
65
    procedure FilesTreeViewMouseDown(Sender: TObject; Button: TMouseButton;
 
66
      Shift: TShiftState; X, Y: Integer);
 
67
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
 
68
    procedure FormCreate(Sender: TObject);
 
69
    procedure FormDestroy(Sender: TObject);
 
70
    procedure FormResize(Sender: TObject);
 
71
    procedure PkgOutCheckBoxChange(Sender: TObject);
 
72
    procedure PkgSrcCheckBoxChange(Sender: TObject);
 
73
    procedure ProjOutCheckBoxChange(Sender: TObject);
 
74
    procedure ProjOutMaskComboBoxChange(Sender: TObject);
 
75
    procedure ProjSrcCheckBoxChange(Sender: TObject);
 
76
  private
 
77
    ImageIndexDirectory: Integer;
 
78
    ImageIndexFile: Integer;
 
79
    FIdleConnected: boolean;
 
80
    procedure SetIdleConnected(const AValue: boolean);
 
81
    procedure OnIdle(Sender: TObject; var Done: Boolean);
 
82
  private
 
83
    FProject: TProject;
 
84
    FUpdateNeeded: boolean;
 
85
    procedure ClearFilesTreeView;
 
86
    procedure UpdateFilesTreeView(Immediately: boolean = false);
 
87
    procedure AddProjOutDirectory;
 
88
    procedure AddProjSrcDirectories;
 
89
    procedure AddPkgOutDirectories;
 
90
    procedure AddPkgSrcDirectory;
 
91
    procedure AddDirectory(aTVPath, aDirectory, aFileMask: string);
 
92
    procedure AddDirectories(aTVPath, aSearchPath, aFileMask: string);
 
93
    function GetAllFilesFromTree: TFilenameToStringTree;
 
94
    function DeleteFiles: TModalResult;
 
95
    property IdleConnected: boolean read FIdleConnected write SetIdleConnected;
 
96
  public
 
97
    procedure Init(AProject: TProject);
 
98
  end;
 
99
 
 
100
function ShowBuildProjectDialog(AProject: TProject): TModalResult;
 
101
 
 
102
implementation
 
103
 
 
104
function ShowBuildProjectDialog(AProject: TProject): TModalResult;
 
105
var
 
106
  CleanBuildProjectDialog: TCleanBuildProjectDialog;
 
107
begin
 
108
  CleanBuildProjectDialog:=TCleanBuildProjectDialog.Create(nil);
 
109
  try
 
110
    CleanBuildProjectDialog.Init(AProject);
 
111
    Result:=CleanBuildProjectDialog.ShowModal;
 
112
  finally
 
113
    CleanBuildProjectDialog.Free;
 
114
  end;
 
115
end;
 
116
 
 
117
{$R *.lfm}
 
118
 
 
119
{ TCleanBuildProjectDialog }
 
120
 
 
121
procedure TCleanBuildProjectDialog.FormCreate(Sender: TObject);
 
122
begin
 
123
  Caption:=lisCleanUpAndBuildProject;
 
124
 
 
125
  ProjOutCheckBox.Caption:=lisProjectOutputDirectory;
 
126
  ProjSrcCheckBox.Caption:=lisProjectSourceDirectories;
 
127
  PkgOutCheckBox.Caption:=lisPackageOutputDirectories;
 
128
  PkgSrcCheckBox.Caption:=lisPackageSourceDirectories;
 
129
  PreviewGroupBox.Caption:=lisTheseFilesWillBeDeleted;
 
130
 
 
131
  ButtonPanel1.OKButton.Caption:=lisCleanUpAndBuild;
 
132
  ButtonPanel1.HelpButton.Caption:=lisMenuHelp;
 
133
  ButtonPanel1.CancelButton.Caption:=lisCancel;
 
134
 
 
135
  DeleteButton.Caption:=lisDelete;
 
136
 
 
137
  FilesTreeView.Images:=IDEImages.Images_16;
 
138
  ImageIndexDirectory := IDEImages.LoadImage(16, 'pkg_files');
 
139
  ImageIndexFile := IDEImages.LoadImage(16, 'laz_delete');
 
140
 
 
141
  ButtonPanel1.OKButton.ModalResult:=mrNone;
 
142
end;
 
143
 
 
144
procedure TCleanBuildProjectDialog.FormDestroy(Sender: TObject);
 
145
begin
 
146
  ClearFilesTreeView;
 
147
  FProject:=nil;
 
148
  IdleConnected:=false;
 
149
end;
 
150
 
 
151
procedure TCleanBuildProjectDialog.FormClose(Sender: TObject;
 
152
  var CloseAction: TCloseAction);
 
153
 
 
154
  procedure StoreCombo(AComboBox: TComboBox);
 
155
  begin
 
156
    // store all masks into one history list
 
157
    ProjOutMaskComboBox.AddHistoryItem(AComboBox.Text,30,true,false);
 
158
  end;
 
159
 
 
160
begin
 
161
  FProject.CleanOutputFileMask:=ProjOutMaskComboBox.Text;
 
162
  FProject.CleanSourcesFileMask:=ProjSrcMaskComboBox.Text;
 
163
  InputHistories.CleanOutputFileMask:=PkgOutMaskComboBox.Text;
 
164
  InputHistories.CleanSourcesFileMask:=PkgSrcMaskComboBox.Text;
 
165
 
 
166
  // combine history lists
 
167
  StoreCombo(ProjOutMaskComboBox);
 
168
  StoreCombo(ProjSrcMaskComboBox);
 
169
  StoreCombo(PkgOutMaskComboBox);
 
170
  StoreCombo(PkgSrcMaskComboBox);
 
171
  InputHistories.HistoryLists.GetList(hlCleanBuildFileMask,true,
 
172
    rltFile).Assign(ProjOutMaskComboBox.Items);
 
173
end;
 
174
 
 
175
procedure TCleanBuildProjectDialog.ButtonPanel1OKButtonClick(Sender: TObject);
 
176
begin
 
177
  if DeleteFiles<>mrOk then exit;
 
178
  ModalResult:=mrOk;
 
179
end;
 
180
 
 
181
procedure TCleanBuildProjectDialog.DeleteButtonClick(Sender: TObject);
 
182
begin
 
183
  DeleteFiles;
 
184
end;
 
185
 
 
186
procedure TCleanBuildProjectDialog.FilesTreeViewMouseDown(Sender: TObject;
 
187
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
 
188
var
 
189
  Node: TTreeNode;
 
190
  Item: TBuildProjectDialogItem;
 
191
  Filename: String;
 
192
begin
 
193
  Node:=FilesTreeView.GetNodeAt(X,Y);
 
194
  if Node=nil then exit;
 
195
  if (Button=mbLeft) and (ssDouble in Shift) and (Node.Data<>nil) then begin
 
196
    Item:=TBuildProjectDialogItem(Node.Data);
 
197
    Filename:=Item.Filename;
 
198
    if Item.IsDirectory then exit;
 
199
    Filename:=ExtractFilePath(Filename);
 
200
    Filename:=ChompPathDelim(Filename);
 
201
    debugln(['TBuildProjectDialog.FilesTreeViewMouseDown Filename="',Filename,'"']);
 
202
    if FilenameIsAbsolute(Filename) then
 
203
      OpenURL('file://'+StringReplace(Filename,'\','/',[rfReplaceAll]));
 
204
  end;
 
205
end;
 
206
 
 
207
procedure TCleanBuildProjectDialog.FormResize(Sender: TObject);
 
208
var
 
209
  r: Integer;
 
210
begin
 
211
  r:=ProjOutCheckBox.Left
 
212
    +Max(Max(ProjOutCheckBox.Width,ProjSrcCheckBox.Width),
 
213
         Max(PkgOutCheckBox.Width,PkgSrcCheckBox.Width));
 
214
  ProjOutMaskComboBox.Left:=r+10;
 
215
end;
 
216
 
 
217
procedure TCleanBuildProjectDialog.PkgOutCheckBoxChange(Sender: TObject);
 
218
begin
 
219
  PkgOutMaskComboBox.Enabled:=PkgOutCheckBox.Checked;
 
220
  UpdateFilesTreeView;
 
221
end;
 
222
 
 
223
procedure TCleanBuildProjectDialog.PkgSrcCheckBoxChange(Sender: TObject);
 
224
begin
 
225
  PkgSrcMaskComboBox.Enabled:=PkgSrcCheckBox.Checked;
 
226
  UpdateFilesTreeView;
 
227
end;
 
228
 
 
229
procedure TCleanBuildProjectDialog.ProjOutCheckBoxChange(Sender: TObject);
 
230
begin
 
231
  ProjOutMaskComboBox.Enabled:=ProjOutCheckBox.Checked;
 
232
  UpdateFilesTreeView;
 
233
end;
 
234
 
 
235
procedure TCleanBuildProjectDialog.ProjOutMaskComboBoxChange(Sender: TObject);
 
236
begin
 
237
  UpdateFilesTreeView;
 
238
end;
 
239
 
 
240
procedure TCleanBuildProjectDialog.ProjSrcCheckBoxChange(Sender: TObject);
 
241
begin
 
242
  ProjSrcMaskComboBox.Enabled:=ProjSrcCheckBox.Checked;
 
243
  UpdateFilesTreeView;
 
244
end;
 
245
 
 
246
procedure TCleanBuildProjectDialog.SetIdleConnected(const AValue: boolean);
 
247
begin
 
248
  if FIdleConnected=AValue then exit;
 
249
  FIdleConnected:=AValue;
 
250
  if IdleConnected then
 
251
    Application.AddOnIdleHandler(@OnIdle)
 
252
  else
 
253
    Application.RemoveOnIdleHandler(@OnIdle);
 
254
end;
 
255
 
 
256
procedure TCleanBuildProjectDialog.OnIdle(Sender: TObject; var Done: Boolean);
 
257
begin
 
258
  if FProject=nil then exit;
 
259
  if not FUpdateNeeded then exit;
 
260
  IdleConnected:=false;
 
261
  UpdateFilesTreeView(true);
 
262
end;
 
263
 
 
264
procedure TCleanBuildProjectDialog.ClearFilesTreeView;
 
265
var
 
266
  Node: TTreeNode;
 
267
begin
 
268
  Node:=FilesTreeView.Items.GetFirstNode;
 
269
  while Node<>nil do begin
 
270
    if (Node.Data<>nil) then
 
271
      TObject(Node.Data).Free;
 
272
    Node:=Node.GetNext;
 
273
  end;
 
274
  FilesTreeView.Items.Clear;
 
275
end;
 
276
 
 
277
procedure TCleanBuildProjectDialog.UpdateFilesTreeView(Immediately: boolean);
 
278
 
 
279
  function CreateTVChildCounts(TVNode: TTreeNode): integer;
 
280
  var
 
281
    ChildNode: TTreeNode;
 
282
  begin
 
283
    Result:=0;
 
284
    if TVNode=nil then exit;
 
285
    ChildNode:=TVNode.GetFirstChild;
 
286
    while ChildNode<>nil do begin
 
287
      inc(Result,CreateTVChildCounts(ChildNode));
 
288
      ChildNode:=ChildNode.GetNextSibling;
 
289
    end;
 
290
    if (Result=0) and (TVNode.Count>0) then
 
291
      // has children, but no grand children => is a directory
 
292
      inc(Result,TVNode.Count);
 
293
    if Result>0 then
 
294
      TVNode.Text:=Format(lisCBPFiles, [TVNode.Text, IntToStr(Result)]);
 
295
  end;
 
296
 
 
297
var
 
298
  i: Integer;
 
299
  TVNode: TTreeNode;
 
300
begin
 
301
  if not Immediately then begin
 
302
    FUpdateNeeded:=true;
 
303
    IdleConnected:=true;
 
304
    exit;
 
305
  end;
 
306
  FUpdateNeeded:=false;
 
307
 
 
308
  FilesTreeView.BeginUpdate;
 
309
  ClearFilesTreeView;
 
310
  if FProject<>nil then begin
 
311
    if ProjOutCheckBox.Checked then AddProjOutDirectory;
 
312
    if ProjSrcCheckBox.Checked then AddProjSrcDirectories;
 
313
    if PkgOutCheckBox.Checked then AddPkgOutDirectories;
 
314
    if PkgSrcCheckBox.Checked then AddPkgSrcDirectory;
 
315
  end;
 
316
  for i:=0 to FilesTreeView.Items.TopLvlCount-1 do begin
 
317
    TVNode:=FilesTreeView.Items.TopLvlItems[i];
 
318
    CreateTVChildCounts(TVNode);
 
319
    TVNode.Expand(true);
 
320
  end;
 
321
  FilesTreeView.EndUpdate;
 
322
end;
 
323
 
 
324
procedure TCleanBuildProjectDialog.AddProjOutDirectory;
 
325
begin
 
326
  AddDirectory(lisProjectOutputDirectory,
 
327
    FProject.CompilerOptions.GetUnitOutputDirectory(false),
 
328
    ProjOutMaskComboBox.Text);
 
329
end;
 
330
 
 
331
procedure TCleanBuildProjectDialog.AddProjSrcDirectories;
 
332
begin
 
333
  AddDirectories(lisProjectOutputDirectory,
 
334
    FProject.SourceDirectories.CreateSearchPathFromAllFiles,
 
335
    ProjSrcMaskComboBox.Text);
 
336
end;
 
337
 
 
338
procedure TCleanBuildProjectDialog.AddPkgOutDirectories;
 
339
var
 
340
  List: TFPList;
 
341
  i: Integer;
 
342
  Pkg: TLazPackage;
 
343
begin
 
344
  List:=nil;
 
345
  try
 
346
    PackageGraph.GetAllRequiredPackages(FProject.FirstRequiredDependency,List);
 
347
    if List=nil then exit;
 
348
    for i:=0 to List.Count-1 do begin
 
349
      Pkg:=TLazPackage(List[i]);
 
350
      AddDirectory(Pkg.Name,Pkg.CompilerOptions.GetUnitOutputDirectory(false),
 
351
        PkgOutMaskComboBox.Text);
 
352
    end;
 
353
  finally
 
354
    List.Free;
 
355
  end;
 
356
end;
 
357
 
 
358
procedure TCleanBuildProjectDialog.AddPkgSrcDirectory;
 
359
var
 
360
  List: TFPList;
 
361
  i: Integer;
 
362
  Pkg: TLazPackage;
 
363
begin
 
364
  List:=nil;
 
365
  try
 
366
    PackageGraph.GetAllRequiredPackages(FProject.FirstRequiredDependency,List);
 
367
    if List=nil then exit;
 
368
    for i:=0 to List.Count-1 do begin
 
369
      Pkg:=TLazPackage(List[i]);
 
370
      AddDirectories(Pkg.Name,Pkg.SourceDirectories.CreateSearchPathFromAllFiles,
 
371
        PkgSrcMaskComboBox.Text);
 
372
    end;
 
373
  finally
 
374
    List.Free;
 
375
  end;
 
376
end;
 
377
 
 
378
procedure TCleanBuildProjectDialog.AddDirectory(aTVPath, aDirectory,
 
379
  aFileMask: string);
 
380
var
 
381
  Cache: TCTDirectoryCache;
 
382
  Files: TStrings;
 
383
  TVFiles: TStringList;
 
384
  MaskList: TMaskList;
 
385
  p: SizeInt;
 
386
  NodeText: String;
 
387
  TVNode: TTreeNode;
 
388
  ParentTVNode: TTreeNode;
 
389
  i: Integer;
 
390
  Item: TBuildProjectDialogItem;
 
391
begin
 
392
  //debugln(['TBuildProjectDialog.AddDirectory aTVPath="',aTVPath,'" aDirectory="',aDirectory,'" aFileMask="',aFileMask,'"']);
 
393
  aDirectory:=ChompPathDelim(aDirectory);
 
394
  if (aDirectory='') or (aFileMask='')
 
395
  or (not FilenameIsAbsolute(aDirectory))
 
396
  or (not DirPathExistsCached(aDirectory))
 
397
  then exit;
 
398
  // get directory listing from cache
 
399
  Cache:=CodeToolBoss.DirectoryCachePool.GetCache(aDirectory,true,false);
 
400
  if Cache=nil then exit;
 
401
  Files:=TStringList.Create;
 
402
  TVFiles:=TStringList.Create;
 
403
  MaskList:=TMaskList.Create(aFileMask,';');
 
404
  try
 
405
    if MaskList.Count=0 then exit;
 
406
    Cache.GetFiles(Files,false);
 
407
 
 
408
    //debugln(['TBuildProjectDialog.AddDirectory AllFiles="',Files.Text,'"']);
 
409
    // filter files
 
410
    for i:=0 to Files.Count-1 do
 
411
      if MaskList.Matches(Files[i]) then
 
412
        TVFiles.Add(Files[i]);
 
413
    //debugln(['TBuildProjectDialog.AddDirectory FilteredFiles="',TVFiles.Text,'"']);
 
414
    if TVFiles.Count=0 then exit;
 
415
 
 
416
    // create tree node for aTVPath
 
417
    ParentTVNode:=nil;
 
418
    p:=System.Pos('/',aTVPath);
 
419
    if p>0 then begin
 
420
      NodeText:=copy(aTVPath,1,p-1);
 
421
      aTVPath:=Copy(aTVPath,p+1,length(aTVPath));
 
422
    end else begin
 
423
      NodeText:=aTVPath;
 
424
    end;
 
425
    if ParentTVNode=nil then
 
426
      TVNode:=FilesTreeView.Items.FindTopLvlNode(NodeText)
 
427
    else
 
428
      TVNode:=ParentTVNode.FindNode(NodeText);
 
429
    if TVNode=nil then
 
430
      TVNode:=FilesTreeView.Items.AddChild(ParentTVNode,NodeText);
 
431
    TVNode.ImageIndex:=ImageIndexDirectory;
 
432
    TVNode.SelectedIndex:=ImageIndexDirectory;
 
433
    ParentTVNode:=TVNode;
 
434
 
 
435
    // create tree node for directory
 
436
    NodeText:=FProject.GetShortFilename(aDirectory,true);
 
437
    TVNode:=ParentTVNode.GetFirstChild;
 
438
    while (TVNode<>nil) and (CompareFilenames(TVNode.Text,NodeText)<0) do
 
439
      TVNode:=TVNode.GetNextSibling;
 
440
    if TVNode=nil then
 
441
      TVNode:=FilesTreeView.Items.AddChild(ParentTVNode,NodeText)
 
442
    else if (CompareFilenames(TVNode.Text,NodeText)<>0) then
 
443
      TVNode:=FilesTreeView.Items.Add(TVNode,NodeText);
 
444
    if TVNode.Data=nil then begin
 
445
      Item:=TBuildProjectDialogItem.Create;
 
446
      Item.IsDirectory:=true;
 
447
      Item.Filename:=aDirectory;
 
448
      TVNode.Data:=Item;
 
449
    end;
 
450
    TVNode.ImageIndex:=ImageIndexDirectory;
 
451
    TVNode.SelectedIndex:=ImageIndexDirectory;
 
452
    ParentTVNode:=TVNode;
 
453
 
 
454
    // add files
 
455
    aDirectory:=AppendPathDelim(aDirectory);
 
456
    for i:=0 to TVFiles.Count-1 do begin
 
457
      Item:=TBuildProjectDialogItem.Create;
 
458
      Item.Filename:=aDirectory+TVFiles[i];
 
459
      TVNode:=FilesTreeView.Items.AddChildObject(ParentTVNode,TVFiles[i],Item);
 
460
      TVNode.ImageIndex:=ImageIndexFile;
 
461
      TVNode.SelectedIndex:=ImageIndexFile;
 
462
    end;
 
463
  finally
 
464
    MaskList.Free;
 
465
    Files.Free;
 
466
    TVFiles.Free;
 
467
  end;
 
468
end;
 
469
 
 
470
procedure TCleanBuildProjectDialog.AddDirectories(aTVPath, aSearchPath,
 
471
  aFileMask: string);
 
472
var
 
473
  Directory: String;
 
474
  p: Integer;
 
475
begin
 
476
  p:=1;
 
477
  while p<=length(aSearchPath) do begin
 
478
    Directory:=TrimFilename(GetNextDelimitedItem(aSearchPath,';',p));
 
479
    if FilenameIsAbsolute(Directory) then
 
480
      AddDirectory(aTVPath,Directory,aFileMask);
 
481
  end;
 
482
end;
 
483
 
 
484
function TCleanBuildProjectDialog.GetAllFilesFromTree: TFilenameToStringTree;
 
485
var
 
486
  Node: TTreeNode;
 
487
  Item: TBuildProjectDialogItem;
 
488
begin
 
489
  Result:=TFilenameToStringTree.Create(false);
 
490
  Node:=FilesTreeView.Items.GetFirstNode;
 
491
  while Node<>nil do begin
 
492
    if (Node.Data<>nil) and (TObject(Node.Data) is TBuildProjectDialogItem) then
 
493
    begin
 
494
      Item:=TBuildProjectDialogItem(Node.Data);
 
495
      if not Item.IsDirectory then
 
496
        Result[Item.Filename]:='1';
 
497
    end;
 
498
    Node:=Node.GetNext;
 
499
  end;
 
500
end;
 
501
 
 
502
function TCleanBuildProjectDialog.DeleteFiles: TModalResult;
 
503
var
 
504
  Files: TFilenameToStringTree;
 
505
  Node: TAVLTreeNode;
 
506
  Item: PStringToStringTreeItem;
 
507
  MaskList: TMaskList;
 
508
  Filename: String;
 
509
  SourceFiles: TStringList;
 
510
  Quiet: Boolean;
 
511
begin
 
512
  Files:=GetAllFilesFromTree;
 
513
  MaskList:=TMaskList.Create('*.pas;*.pp;*.p;*.inc;*.lpr;*.lpi;*.lps;*.lpk',';');
 
514
  SourceFiles:=TStringList.Create;
 
515
  try
 
516
    // warn before deleting sources
 
517
    Node:=Files.Tree.FindLowest;
 
518
    while Node<>nil do begin
 
519
      Item:=PStringToStringTreeItem(Node.Data);
 
520
      Filename:=Item^.Name;
 
521
      if MaskList.Matches(ExtractFilename(Filename)) then
 
522
        SourceFiles.Add(Filename);
 
523
      Node:=Files.Tree.FindSuccessor(Node);
 
524
    end;
 
525
    if SourceFiles.Count>0 then begin
 
526
      Result:=IDEMessageDialog(lisCCOWarningCaption,
 
527
        Format(lisCBPReallyDeleteSourceFiles, [IntToStr(SourceFiles.Count), #13
 
528
          +#13, copy(SourceFiles.Text, 1, 1000)]), mtWarning, [mbYes, mbNo]);
 
529
      if Result<>mrYes then exit(mrCancel);
 
530
    end;
 
531
 
 
532
    // delete
 
533
    Node:=Files.Tree.FindLowest;
 
534
    Quiet:=false;
 
535
    while Node<>nil do begin
 
536
      Item:=PStringToStringTreeItem(Node.Data);
 
537
      Node:=Files.Tree.FindSuccessor(Node);
 
538
      Filename:=Item^.Name;
 
539
      //debugln(['TBuildProjectDialog.DeleteFiles ',Filename,' ',FileExistsUTF8(Filename)]);
 
540
      repeat
 
541
        if FileExistsUTF8(Filename) and (not DeleteFileUTF8(Filename))
 
542
        and (not Quiet) then begin
 
543
          Result:=IDEQuestionDialog(lisDeleteFileFailed,
 
544
            Format(lisPkgMangUnableToDeleteFile, ['"', Filename, '"']),
 
545
            mtError,
 
546
            [mrRetry, mrCancel, mrNo, lisCCOSkip, mrNoToAll, lisSkipErrors]);
 
547
          if Result=mrNoToAll then begin
 
548
            Quiet:=true;
 
549
            break;
 
550
          end;
 
551
          if Result=mrNo then break;
 
552
          if Result<>mrRetry then exit(mrCancel);
 
553
        end else break;
 
554
      until false;
 
555
    end;
 
556
 
 
557
    Result:=mrOk;
 
558
  finally
 
559
    InvalidateFileStateCache;
 
560
    UpdateFilesTreeView;
 
561
    SourceFiles.Free;
 
562
    MaskList.Free;
 
563
    Files.Free;
 
564
  end;
 
565
end;
 
566
 
 
567
procedure TCleanBuildProjectDialog.Init(AProject: TProject);
 
568
var
 
569
  List: THistoryList;
 
570
begin
 
571
  List:=InputHistories.HistoryLists.GetList(hlCleanBuildFileMask,true,rltFile);
 
572
  ProjOutMaskComboBox.Items.Assign(List);
 
573
  ProjOutMaskComboBox.Text:=AProject.CleanOutputFileMask;
 
574
  ProjSrcMaskComboBox.Items.Assign(List);
 
575
  ProjSrcMaskComboBox.Text:=AProject.CleanSourcesFileMask;
 
576
  PkgOutMaskComboBox.Items.Assign(List);
 
577
  PkgOutMaskComboBox.Text:=InputHistories.CleanOutputFileMask;
 
578
  PkgSrcMaskComboBox.Items.Assign(List);
 
579
  PkgSrcMaskComboBox.Text:=InputHistories.CleanSourcesFileMask;
 
580
 
 
581
  if AProject.CompilerOptions.UnitOutputDirectory='' then begin
 
582
    ProjOutCheckBox.Enabled:=false;
 
583
    ProjOutCheckBox.Checked:=false;
 
584
    ProjOutMaskComboBox.Enabled:=false;
 
585
  end;
 
586
 
 
587
  FProject:=AProject;
 
588
  UpdateFilesTreeView;
 
589
end;
 
590
 
 
591
end.
 
592