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

View File

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

View File

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

View File

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