1{
2  Author: Jens Arm
3
4 ***************************************************************************
5 *                                                                         *
6 *   This source is free software; you can redistribute it and/or modify   *
7 *   it under the terms of the GNU General Public License as published by  *
8 *   the Free Software Foundation; either version 2 of the License, or     *
9 *   (at your option) any later version.                                   *
10 *                                                                         *
11 *   This code is distributed in the hope that it will be useful, but      *
12 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
14 *   General Public License for more details.                              *
15 *                                                                         *
16 *   A copy of the GNU General Public License is available on the World    *
17 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
18 *   obtain it by writing to the Free Software Foundation,                 *
19 *   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.   *
20 *                                                                         *
21 ***************************************************************************
22}
23unit UnitInfoDlg;
24
25{$mode objfpc}{$H+}
26
27interface
28
29uses
30  // LCL + FCL
31  SysUtils, LCLProc, Controls, StdCtrls, Forms, Buttons, ComCtrls,
32  // CodeTools
33  CodeToolsDefPreview, CodeToolManager, FileProcs,
34  // LazUtils
35  LazFileUtils,
36  // IDE
37  LazarusIDEStrConsts;
38
39type
40
41  { TUnitInfoDialog }
42
43  TUnitInfoDialog = class(TForm)
44    GotoIncludeDirectiveButton: TButton;
45    CodeToolsDefsButton: TButton;
46    ListValues: TListView;
47    OkButton: TBitBtn;
48    ClearIncludedBy: TButton;
49    UnitPathMemo: TMemo;
50    IncludePathMemo: TMemo;
51    SrcPathMemo: TMemo;
52    Notebook: TPageControl;
53    GeneralPage: TTabSheet;
54    UnitPathsPage: TTabSheet;
55    IncludePathsPage: TTabSheet;
56    CompleteUnitPathsPage: TTabSheet;
57    PathsGroupBox: TGroupBox;
58    procedure CodeToolsDefsButtonClick(Sender: TObject);
59    procedure FormCreate(Sender: TObject);
60    procedure clearIncludedByClick(Sender: TObject);
61  private
62    FFilePath: string;
63    function getIncludedBy: string;
64  end;
65
66function ShowUnitInfoDlg(const AnUnitName, AType: string;
67  IsPartOfProject: boolean; SizeInBytes, UnitSizeWithIncludeFiles, UnitSizeParsed,
68  LineCount, UnitLineCountWithIncludes, UnitLineCountParsed: integer;
69  const FilePath: string; const IncludedBy: string; out ClearIncludedBy: boolean;
70  const UnitPath, IncludePath, SrcPath: string): TModalResult;
71
72implementation
73
74{$R *.lfm}
75
76function ShowUnitInfoDlg(const AnUnitName, AType: string;
77  IsPartOfProject: boolean; SizeInBytes, UnitSizeWithIncludeFiles,
78  UnitSizeParsed, LineCount, UnitLineCountWithIncludes,
79  UnitLineCountParsed: integer; const FilePath: string;
80  const IncludedBy: string; out ClearIncludedBy: boolean; const UnitPath,
81  IncludePath, SrcPath: string): TModalResult;
82var Dlg: TUnitInfoDialog;
83  s: String;
84begin
85  ClearIncludedBy:=false;
86
87  Dlg:=TUnitInfoDialog.Create(nil);
88  with Dlg do begin
89    Caption:=Format(lisInformationAboutUnit, [AnUnitName]);
90
91    FFilePath:=FilePath;
92
93    ListValues.Items[0].SubItems[0]:=AnUnitName;
94    ListValues.Items[1].SubItems[0]:=AType;
95
96    if IsPartOfProject then s:=lisUIDyes else s:=lisUIDno;
97    ListValues.Items[2].SubItems[0]:=s;
98
99    s:=Format(lisUIDbytes, [IntToStr(SizeInBytes)]);
100    if UnitSizeWithIncludeFiles<>SizeInBytes then
101      s:=s+lisWithIncludes2+IntToStr(UnitSizeWithIncludeFiles);
102    if UnitSizeParsed<>UnitSizeWithIncludeFiles then
103      s:=s+lisParsed+IntToStr(UnitSizeParsed);
104    ListValues.Items[3].SubItems[0]:=s;
105
106    s:=IntToStr(LineCount);
107    if UnitLineCountWithIncludes<>LineCount then
108      s:=s+lisWithIncludes2+IntToStr(UnitLineCountWithIncludes);
109    if UnitLineCountParsed<>LineCount then
110      s:=s+lisParsed+IntToStr(UnitLineCountParsed);
111    ListValues.Items[4].SubItems[0]:=s;
112
113    ListValues.Items[5].SubItems[0]:=FilePath;
114    ListValues.Items[6].SubItems[0]:=IncludedBy;
115
116    UnitPathMemo.Lines.Delimiter := ';';
117    UnitPathMemo.Lines.StrictDelimiter := true;
118    UnitPathMemo.Lines.DelimitedText := MinimizeSearchPath(UnitPath);
119
120    IncludePathMemo.Lines.Delimiter := ';';
121    IncludePathMemo.Lines.StrictDelimiter := true;
122    IncludePathMemo.Lines.DelimitedText := MinimizeSearchPath(IncludePath);
123
124    SrcPathMemo.Lines.Delimiter := ';';
125    SrcPathMemo.Lines.StrictDelimiter := true;
126    SrcPathMemo.Lines.DelimitedText := MinimizeSearchPath(SrcPath);
127
128    GotoIncludeDirectiveButton.Visible:=IncludedBy<>'';
129  end;
130
131  Result:=Dlg.ShowModal;
132  ClearIncludedBy:=(Result in [mrOk,mrYes]) and (IncludedBy<>'')
133                   and (Dlg.getIncludedBy='');
134  Dlg.Free;
135end;
136
137{ TUnitInfoDialog }
138
139procedure TUnitInfoDialog.CodeToolsDefsButtonClick(Sender: TObject);
140begin
141  DebugLn(['TUnitInfoDialog.CodeToolsDefsButtonClick FFilePath=',FFilePath]);
142  ShowCodeToolsDefinesValuesDialog(CodeToolBoss.DefineTree, ExtractFilePath(FFilePath));
143end;
144
145procedure TUnitInfoDialog.FormCreate(Sender: TObject);
146begin
147  Notebook.Page[0].Caption := lisGeneral;
148  Notebook.Page[1].Caption := lisUnitPaths;
149  Notebook.Page[2].Caption := lisIncludePaths;
150  Notebook.Page[3].Caption := lisSourcePaths;
151  Notebook.PageIndex := 0;
152
153  with ListValues do
154  begin
155    with Items.Add do begin Caption:= lisUIDName; SubItems.Add(''); end;
156    with Items.Add do begin Caption:= lisUIDType; SubItems.Add(''); end;
157    with Items.Add do begin Caption:= lisUIDinProject; SubItems.Add(''); end;
158    with Items.Add do begin Caption:= lisUIDSize; SubItems.Add(''); end;
159    with Items.Add do begin Caption:= lisUIDLines; SubItems.Add(''); end;
160    with Items.Add do begin Caption:= lisToFPCPath; SubItems.Add(''); end;
161    with Items.Add do begin Caption:= lisUIDIncludedBy; SubItems.Add(''); end;
162  end;
163
164  ClearIncludedBy.Caption:=lisUIClearIncludedByReference;
165  CodeToolsDefsButton.Caption:=lisUIShowCodeToolsValues;
166  GotoIncludeDirectiveButton.Caption:=lisMenuGotoIncludeDirective;
167end;
168
169procedure TUnitInfoDialog.clearIncludedByClick(Sender: TObject);
170begin
171  ListValues.Items[6].SubItems[0]:='';
172end;
173
174function TUnitInfoDialog.getIncludedBy: string;
175begin
176  Result:=ListValues.Items[6].SubItems[0];
177end;
178
179end.
180