IDE: unit deps: popup menu item for unused units

git-svn-id: trunk@41922 -
This commit is contained in:
mattias 2013-06-27 15:11:22 +00:00
parent a955cab41f
commit cdcaa4f43e
4 changed files with 152 additions and 89 deletions

View File

@ -72,6 +72,7 @@ resourcestring
lisOk = 'OK';
lisMenuOk = '&OK';
lisCancel = 'Cancel';
lisUnusedUnitsOf = 'Unused units of %s';
lisNo = 'No';
lisContinue = 'Continue';
lisBreak = 'Break';
@ -2169,6 +2170,7 @@ resourcestring
dlgCCOTestMissingPPU = 'Test: Checking missing fpc ppu ...';
dlgCCOTestCompilerDate = 'Test: Checking compiler date ...';
lisCCOErrorCaption = 'Error';
lisUnableToOpen = 'Unable to open "%s"';
lisCompilerDoesNotSupportTarget = 'Compiler "%s" does not support target %s-%s';
lisInvalidMode = 'Invalid mode %s';
lisTheProjectCompilerOptionsAndTheDirectivesInTheMain = 'The project '
@ -5129,7 +5131,6 @@ resourcestring
lisResult2 = 'Result:';
lisTheIdentifierIsAUnitPleaseUseTheFileSaveAsFunction = 'The identifier is '
+'a unit. Please use the File - Save as function to rename a unit.';
lisUnusedUnits = 'Unused units';
lisRemoveSelectedUnits = 'Remove selected units';
lisRemoveAllUnits = 'Remove all units';
lisCEShowCodeObserver = 'Show observerations about';
@ -5781,6 +5782,7 @@ resourcestring
lisUDSearchNextUnitOfThisPhrase = 'Search next unit of this phrase';
lisUDSearchPreviousUnitOfThisPhrase = 'Search previous unit of this phrase';
lisUDExpandAllNodes = 'Expand all nodes';
lisShowUnusedUnits = 'Show unused units ...';
lisUDCollapseAllNodes = 'Collapse all nodes';
lisUDFilter = '(Filter)';
lisUDSearch = '(Search)';

View File

@ -12,7 +12,7 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
LCLVersion = '1.1'
object MainPageControl: TPageControl
Left = 0
Height = 414
Height = 407
Top = 0
Width = 620
ActivePage = UnitsTabSheet
@ -21,26 +21,26 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
TabOrder = 0
object UnitsTabSheet: TTabSheet
Caption = 'UnitsTabSheet'
ClientHeight = 375
ClientWidth = 614
ClientHeight = 378
ClientWidth = 616
object ScopePanel: TPanel
Left = 0
Height = 47
Height = 59
Top = 0
Width = 614
Width = 616
Align = alTop
AutoSize = True
ClientHeight = 47
ClientWidth = 614
ClientHeight = 59
ClientWidth = 616
TabOrder = 0
object SearchCustomFilesCheckBox: TCheckBox
AnchorSideLeft.Control = ScopePanel
AnchorSideTop.Control = SearchCustomFilesComboBox
AnchorSideTop.Side = asrCenter
Left = 3
Height = 18
Height = 24
Top = 4
Width = 201
Width = 181
BorderSpacing.Around = 2
Caption = 'SearchCustomFilesCheckBox'
OnChange = SearchCustomFilesCheckBoxChange
@ -54,10 +54,10 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ScopePanel
AnchorSideRight.Side = asrBottom
Left = 543
Height = 20
Left = 562
Height = 27
Top = 3
Width = 70
Width = 53
Anchors = [akTop, akRight]
AutoSize = True
Caption = 'Browse'
@ -69,10 +69,10 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ScopePanel
AnchorSideRight.Control = SearchCustomFilesBrowseButton
Left = 206
Height = 21
Left = 186
Height = 27
Top = 3
Width = 335
Width = 374
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 2
ItemHeight = 0
@ -85,9 +85,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideTop.Control = SearchCustomFilesComboBox
AnchorSideTop.Side = asrBottom
Left = 3
Height = 18
Top = 26
Width = 153
Height = 24
Top = 32
Width = 141
BorderSpacing.Around = 2
Caption = 'SearchPkgsCheckBox'
OnChange = SearchPkgsCheckBoxChange
@ -98,10 +98,10 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = SearchPkgsCheckBox
AnchorSideTop.Side = asrCenter
Left = 173
Height = 18
Top = 26
Width = 167
Left = 161
Height = 24
Top = 32
Width = 156
BorderSpacing.Left = 15
BorderSpacing.Around = 2
Caption = 'SearchSrcEditCheckBox'
@ -113,22 +113,22 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
end
object AllUnitsGroupBox: TGroupBox
Left = 0
Height = 328
Top = 47
Height = 319
Top = 59
Width = 248
Align = alLeft
Caption = 'AllUnitsGroupBox'
ClientHeight = 306
ClientWidth = 240
ClientHeight = 302
ClientWidth = 244
TabOrder = 1
object AllUnitsShowGroupNodesSpeedButton: TSpeedButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = AllUnitsFilterEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = AllUnitsShowDirsSpeedButton
Left = 194
Left = 198
Height = 22
Top = 0
Top = 1
Width = 23
AllowAllUp = True
Anchors = [akTop, akRight]
@ -143,9 +143,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = AllUnitsGroupBox
AnchorSideRight.Side = asrBottom
Left = 217
Left = 221
Height = 22
Top = 0
Top = 1
Width = 23
AllowAllUp = True
Anchors = [akTop, akRight]
@ -159,9 +159,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideTop.Control = AllUnitsGroupBox
AnchorSideRight.Control = AllUnitsShowGroupNodesSpeedButton
Left = 0
Height = 22
Height = 25
Top = 0
Width = 194
Width = 198
Anchors = [akTop, akLeft, akRight]
OnChange = AllUnitsFilterEditChange
OnEnter = AllUnitsFilterEditEnter
@ -173,9 +173,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideTop.Control = AllUnitsSearchEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = AllUnitsSearchPrevSpeedButton
Left = 194
Left = 198
Height = 22
Top = 284
Top = 278
Width = 23
Anchors = [akTop, akRight]
OnClick = AllUnitsSearchNextSpeedButtonClick
@ -187,9 +187,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = AllUnitsGroupBox
AnchorSideRight.Side = asrBottom
Left = 217
Left = 221
Height = 22
Top = 284
Top = 278
Width = 23
Anchors = [akTop, akRight]
OnClick = AllUnitsSearchPrevSpeedButtonClick
@ -204,9 +204,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = AllUnitsSearchEdit
Left = 0
Height = 262
Top = 22
Width = 240
Height = 252
Top = 25
Width = 244
Anchors = [akTop, akLeft, akRight, akBottom]
DefaultItemHeight = 18
HotTrack = True
@ -230,9 +230,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideBottom.Control = AllUnitsGroupBox
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 22
Top = 284
Width = 194
Height = 25
Top = 277
Width = 198
Anchors = [akLeft, akRight, akBottom]
OnChange = AllUnitsSearchEditChange
OnEnter = AllUnitsSearchEditEnter
@ -243,27 +243,27 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
end
object UnitsSplitter: TSplitter
Left = 248
Height = 328
Top = 47
Height = 319
Top = 59
Width = 5
end
object SelectedUnitsGroupBox: TGroupBox
Left = 253
Height = 328
Top = 47
Width = 361
Height = 319
Top = 59
Width = 363
Align = alClient
Caption = 'SelectedUnitsGroupBox'
ClientHeight = 306
ClientWidth = 353
ClientHeight = 302
ClientWidth = 359
TabOrder = 3
object SelUnitsSearchNextSpeedButton: TSpeedButton
AnchorSideTop.Control = SelUnitsSearchEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = SelUnitsSearchPrevSpeedButton
Left = 307
Left = 313
Height = 22
Top = 284
Top = 278
Width = 23
Anchors = [akTop, akRight]
OnClick = SelUnitsSearchNextSpeedButtonClick
@ -275,9 +275,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = SelectedUnitsGroupBox
AnchorSideRight.Side = asrBottom
Left = 330
Left = 336
Height = 22
Top = 284
Top = 278
Width = 23
Anchors = [akTop, akRight]
OnClick = SelUnitsSearchPrevSpeedButtonClick
@ -290,9 +290,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideBottom.Control = SelectedUnitsGroupBox
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 22
Top = 284
Width = 307
Height = 25
Top = 277
Width = 313
Anchors = [akLeft, akRight, akBottom]
OnChange = SelUnitsSearchEditChange
OnEnter = SelUnitsSearchEditEnter
@ -307,9 +307,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = SelUnitsSearchEdit
Left = 0
Height = 284
Height = 277
Top = 0
Width = 353
Width = 359
Anchors = [akTop, akLeft, akRight, akBottom]
DefaultItemHeight = 18
HotTrack = True
@ -344,12 +344,12 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
end
object StatusPanel: TPanel
Left = 0
Height = 26
Top = 414
Height = 33
Top = 407
Width = 620
Align = alBottom
AutoSize = True
ClientHeight = 26
ClientHeight = 33
ClientWidth = 620
TabOrder = 1
object ProgressBar1: TProgressBar
@ -359,18 +359,18 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = RefreshButton
AnchorSideBottom.Side = asrBottom
Left = 77
Left = 69
Height = 20
Top = 3
Width = 425
Top = 6
Width = 451
Anchors = [akTop, akLeft, akRight]
TabOrder = 0
end
object RefreshButton: TButton
Left = 504
Height = 20
Left = 522
Height = 27
Top = 3
Width = 113
Width = 95
Align = alRight
AutoSize = True
BorderSpacing.Around = 2
@ -383,9 +383,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
AnchorSideTop.Control = RefreshButton
AnchorSideTop.Side = asrCenter
Left = 7
Height = 16
Top = 5
Width = 64
Height = 15
Top = 9
Width = 56
BorderSpacing.Left = 6
BorderSpacing.Right = 6
Caption = 'StatsLabel'
@ -400,6 +400,10 @@ object UnitDependenciesWindow: TUnitDependenciesWindow
Caption = 'UnitsTVCopyFilenameMenuItem'
OnClick = UnitsTVCopyFilenameMenuItemClick
end
object UnitsTVUnusedUnitsMenuItem: TMenuItem
Caption = 'UnitsTVUnusedUnitsMenuItem'
OnClick = UnitsTVUnusedUnitsMenuItemClick
end
object UnitsTVExpandAllMenuItem: TMenuItem
Caption = 'UnitsTVExpandAllMenuItem'
OnClick = UnitsTVExpandAllMenuItemClick

View File

@ -24,8 +24,8 @@
IDE Window showing dependencies of units and packages.
ToDo:
- every second: write parsed units
- resourcestrings
- show unit selected in TV on units graph
- show unused units dialog
}
unit UnitDependencies;
@ -40,8 +40,8 @@ uses
LazIDEIntf, ProjectIntf, IDEWindowIntf, PackageIntf, SrcEditorIntf,
IDEImagesIntf, IDECommands, IDEDialogs,
CodeToolManager, DefineTemplates, CodeToolsStructs,
CTUnitGraph, CTUnitGroupGraph, FileProcs,
LazarusIDEStrConsts;
CTUnitGraph, CTUnitGroupGraph, FileProcs, CodeCache,
LazarusIDEStrConsts, UnusedUnitsDlg;
const
GroupPrefixProject = '-Project-';
@ -113,6 +113,7 @@ type
StatsLabel: TLabel;
StatusPanel: TPanel;
Timer1: TTimer;
UnitsTVUnusedUnitsMenuItem: TMenuItem;
UnitsTVCopyFilenameMenuItem: TMenuItem;
UnitsTVCollapseAllMenuItem: TMenuItem;
UnitsTVExpandAllMenuItem: TMenuItem;
@ -175,6 +176,7 @@ type
procedure UnitsTVCopyFilenameMenuItemClick(Sender: TObject);
procedure UnitsTVExpandAllMenuItemClick(Sender: TObject);
procedure UnitsTVPopupMenuPopup(Sender: TObject);
procedure UnitsTVUnusedUnitsMenuItemClick(Sender: TObject);
private
FCurrentUnit: TUGUnit;
FIdleConnected: boolean;
@ -799,9 +801,37 @@ end;
procedure TUnitDependenciesWindow.UnitsTVPopupMenuPopup(Sender: TObject);
var
TV: TTreeView;
TVNode: TTreeNode;
UDNode: TUDNode;
begin
TV:=UnitsTVPopupMenu.PopupComponent as TTreeView;
UnitsTVExpandAllMenuItem.Visible:=TV=AllUnitsTreeView;
TVNode:=TV.Selected;
if (TVNode<>nil) and (TObject(TVNode.Data) is TUDNode) then begin
UDNode:=TUDNode(TVNode.Data);
UnitsTVUnusedUnitsMenuItem.Enabled:=UDNode.Typ=udnUnit;
end else
UnitsTVUnusedUnitsMenuItem.Enabled:=false;
end;
procedure TUnitDependenciesWindow.UnitsTVUnusedUnitsMenuItemClick(Sender: TObject
);
var
TV: TTreeView;
TVNode: TTreeNode;
UDNode: TUDNode;
Filename: String;
Code: TCodeBuffer;
begin
TV:=TTreeView(UnitsTVPopupMenu.PopupComponent);
if not (TV is TTreeView) then exit;
TVNode:=TV.Selected;
if (TVNode=nil) or not (TObject(TVNode.Data) is TUDNode) then exit;
UDNode:=TUDNode(TVNode.Data);
if UDNode.Typ<>udnUnit then exit;
Filename:=GetFilename(UDNode);
Code:=CodeToolBoss.LoadFile(Filename,true,false);
ShowUnusedUnitsDialog(Code);
end;
procedure TUnitDependenciesWindow.SetIdleConnected(AValue: boolean);
@ -1412,6 +1442,7 @@ begin
// popup menu
UnitsTVCopyFilenameMenuItem.Caption:=uemCopyFilename;
UnitsTVUnusedUnitsMenuItem.Caption:=lisShowUnusedUnits;
UnitsTVExpandAllMenuItem.Caption:=lisUDExpandAllNodes;
UnitsTVCollapseAllMenuItem.Caption:=lisUDCollapseAllNodes;

View File

@ -32,10 +32,9 @@ unit UnusedUnitsDlg;
interface
uses
Classes, LCLProc, Forms, Controls, ComCtrls, StdCtrls, ExtCtrls, Buttons,
SrcEditorIntf, LazIDEIntf, IDEImagesIntf,
CodeCache, CodeToolManager,
LazarusIDEStrConsts;
Classes, sysutils, LCLProc, Forms, Controls, ComCtrls, StdCtrls, ExtCtrls,
Buttons, Dialogs, SrcEditorIntf, LazIDEIntf, IDEImagesIntf, IDEDialogs,
CodeCache, CodeToolManager, LazarusIDEStrConsts;
type
@ -53,11 +52,13 @@ type
procedure RemoveSelectedBitBtnClick(Sender: TObject);
procedure UnitsTreeViewSelectionChanged(Sender: TObject);
private
FCode: TCodeBuffer;
FUnits: TStrings;
ImgIDInterface: LongInt;
ImgIDImplementation: LongInt;
ImgIDInitialization: LongInt;
ImgIDNone: LongInt;
procedure SetCode(AValue: TCodeBuffer);
procedure SetUnits(const AValue: TStrings);
procedure RebuildUnitsTreeView;
procedure UpdateButtons;
@ -65,10 +66,12 @@ type
function GetSelectedUnits: TStrings;
function GetAllUnits: TStrings;
property Units: TStrings read FUnits write SetUnits;
property Code: TCodeBuffer read FCode write SetCode;
end;
function ShowUnusedUnitsDialog: TModalResult;
function ShowUnusedUnitsDialog(Code: TCodeBuffer): TModalResult;
implementation
@ -76,22 +79,29 @@ implementation
function ShowUnusedUnitsDialog: TModalResult;
var
UnusedUnitsDialog: TUnusedUnitsDialog;
SrcEdit: TSourceEditorInterface;
Code: TCodeBuffer;
Units: TStringList;
RemoveUnits: TStrings;
i: Integer;
DlgResult: TModalResult;
begin
Result:=mrOk;
if not LazarusIDE.BeginCodeTools then exit;
// get cursor position
SrcEdit:=SourceEditorManagerIntf.ActiveEditor;
if SrcEdit=nil then exit;
Code:=TCodeBuffer(SrcEdit.CodeToolsBuffer);
if Code=nil then exit;
Result:=ShowUnusedUnitsDialog(Code);
end;
function ShowUnusedUnitsDialog(Code: TCodeBuffer): TModalResult;
var
UnusedUnitsDialog: TUnusedUnitsDialog;
Units: TStringList;
RemoveUnits: TStrings;
i: Integer;
DlgResult: TModalResult;
SrcEdit: TSourceEditorInterface;
begin
Result:=mrOk;
if Code=nil then exit;
if not LazarusIDE.BeginCodeTools then exit;
UnusedUnitsDialog:=nil;
RemoveUnits:=nil;
@ -106,6 +116,7 @@ begin
UnusedUnitsDialog:=TUnusedUnitsDialog.Create(nil);
UnusedUnitsDialog.Units:=Units;
UnusedUnitsDialog.Code:=Code;
DlgResult:=UnusedUnitsDialog.ShowModal;
if DlgResult=mrOk then
RemoveUnits:=UnusedUnitsDialog.GetSelectedUnits
@ -114,6 +125,15 @@ begin
else
RemoveUnits:=nil;
if (RemoveUnits<>nil) and (RemoveUnits.Count>0) then begin
LazarusIDE.DoOpenEditorFile(Code.Filename,-1,-1,[]);
SrcEdit:=SourceEditorManagerIntf.SourceEditorIntfWithFilename(Code.Filename);
if SrcEdit=nil then begin
IDEMessageDialog(lisCCOErrorCaption,
Format(lisUnableToOpen, [Code.Filename]),
mtError,[mbCancel]);
exit(mrCancel);
end;
SrcEdit.BeginUndoBlock{$IFDEF SynUndoDebugBeginEnd}('ShowUnusedUnitsDialog'){$ENDIF};
try
for i:=0 to RemoveUnits.Count-1 do begin
@ -139,8 +159,6 @@ end;
procedure TUnusedUnitsDialog.FormCreate(Sender: TObject);
begin
Caption:=lisUnusedUnits;
RemoveSelectedBitBtn.Caption:=lisRemoveSelectedUnits;
RemoveAllBitBtn.Caption:=lisRemoveAllUnits;
CancelBitBtn.Caption:=lisCancel;
@ -179,6 +197,14 @@ begin
RebuildUnitsTreeView;
end;
procedure TUnusedUnitsDialog.SetCode(AValue: TCodeBuffer);
begin
if FCode=AValue then Exit;
FCode:=AValue;
if FCode<>nil then
Caption:=Format(lisUnusedUnitsOf, [ExtractFilename(Code.Filename)]);
end;
procedure TUnusedUnitsDialog.RebuildUnitsTreeView;
var
i: Integer;