From 7c2bb90b7b6451de9b120c79501d1a267612244b Mon Sep 17 00:00:00 2001 From: lazarus Date: Sat, 14 Sep 2002 07:05:15 +0000 Subject: [PATCH] MG: added uni dependencies git-svn-id: trunk@3339 - --- components/codetools/codetoolmanager.pas | 18 ++++++++++++++ components/codetools/finddeclarationtool.pas | 2 +- components/codetools/stdcodetools.pas | 25 ++++++++++++++++++++ ide/keymapping.pp | 7 ++++-- ide/lazarusidestrconsts.pas | 1 + ide/mainbar.pas | 7 ++++++ 6 files changed, 57 insertions(+), 3 deletions(-) diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index 4928613196..63a6b273c9 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -247,6 +247,8 @@ type const NewUnitName, NewUnitInFile: string): boolean; function RemoveUnitFromAllUsesSections(Code: TCodeBuffer; const AnUnitName: string): boolean; + function FindUsedUnits(Code: TCodeBuffer; var MainUsesSection, + ImplementationUsesSection: TStrings): boolean; // resources function FindLFMFileName(Code: TCodeBuffer): string; @@ -1140,6 +1142,22 @@ begin end; end; +function TCodeToolManager.FindUsedUnits(Code: TCodeBuffer; var MainUsesSection, + ImplementationUsesSection: TStrings): boolean; +begin + Result:=false; + {$IFDEF CTDEBUG} + writeln('TCodeToolManager.FindUsedUnits A ',Code.Filename); + {$ENDIF} + if not InitCurCodeTool(Code) then exit; + try + Result:=FCurCodeTool.FindUsedUnits(MainUsesSection, + ImplementationUsesSection); + except + on e: Exception do Result:=HandleException(e); + end; +end; + function TCodeToolManager.FindLFMFileName(Code: TCodeBuffer): string; var LinkIndex: integer; CurCode: TCodeBuffer; diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index e94286b361..8bfbe7f4db 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -2555,7 +2555,7 @@ begin if (fdfIgnoreUsedUnits in Params.Flags) then begin if CompareSrcIdentifiers(UnitNameAtom.StartPos,Params.Identifier) then begin - // the searched identifier was a uses unitname, but since the unit + // the searched identifier was a uses unitname, but because the unit // should not be opened, point to identifier in the uses section Result:=true; Params.SetResult(Self,UsesNode,UnitNameAtom.StartPos); diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 2599230277..3f0b2f3e5f 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -87,6 +87,8 @@ type SourceChangeCache: TSourceChangeCache): boolean; function RemoveUnitFromAllUsesSections(const UpperUnitName: string; SourceChangeCache: TSourceChangeCache): boolean; + function FindUsedUnits(var MainUsesSection, + ImplementationUsesSection: TStrings): boolean; // lazarus resources function FindNextIncludeInInitialization( @@ -517,6 +519,29 @@ begin end; end; +function TStandardCodeTool.FindUsedUnits(var MainUsesSection, + ImplementationUsesSection: TStrings): boolean; + + function UsesSectionToStrings(ANode: TCodeTreeNode): TStrings; + begin + Result:=TStringList.Create; + if ANode=nil then exit; + + end; + +var + MainUsesNode, ImplementatioUsesNode: TCodeTreeNode; +begin + // find the uses sections + BuildTree(false); + MainUsesNode:=FindMainUsesSection; + ImplementatioUsesNode:=FindImplementationUsesSection; + // create lists + MainUsesSection:=UsesSectionToStrings(MainUsesNode); + ImplementationUsesSection:=UsesSectionToStrings(ImplementatioUsesNode); + Result:=true; +end; + function TStandardCodeTool.FindNextIncludeInInitialization( var LinkIndex: integer): TCodeBuffer; // LinkIndex < 0 -> search first diff --git a/ide/keymapping.pp b/ide/keymapping.pp index 0bdafe7012..4dc5ad5da5 100644 --- a/ide/keymapping.pp +++ b/ide/keymapping.pp @@ -126,8 +126,9 @@ const ecToggleDebuggerOut = ecUserFirst + 308; ecViewUnits = ecUserFirst + 309; ecViewForms = ecUserFirst + 310; - ecToggleLocals = ecUserFirst + 311; - ecToggleCallStack = ecUserFirst + 312; + ecViewUnitDependencies = ecUserFirst + 311; + ecToggleLocals = ecUserFirst + 312; + ecToggleCallStack = ecUserFirst + 313; ecBuild = ecUserFirst + 400; ecRun = ecUserFirst + 401; @@ -564,6 +565,7 @@ begin ecToggleCallStack: Result := 'view call stack'; ecViewUnits: Result:= 'view units'; ecViewForms: Result:= 'view forms'; + ecViewUnitDependencies: Result:= 'view unit dependencies'; // codetools ecWordCompletion: Result:= 'word completion'; @@ -1382,6 +1384,7 @@ begin Add(C,'Toggle view Debugger Output',ecToggleDebuggerOut,VK_UNKNOWN,[],VK_UNKNOWN,[]); Add(C,'View Units',ecViewUnits,VK_F12,[ssCtrl],VK_UNKNOWN,[]); Add(C,'View Forms',ecViewForms,VK_F12,[ssShift],VK_UNKNOWN,[]); + Add(C,'View Unit Dependencies',ecViewUnitDependencies,VK_UNKNOWN,[],VK_UNKNOWN,[]); Add(C,'Focus to source editor',ecJumpToEditor,VK_UNKNOWN,[],VK_UNKNOWN,[]); Add(C,'Toggle between Unit and Form',ecToggleFormUnit,VK_F12,[],VK_UNKNOWN,[]); diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index a1fc8ad4e9..751f309233 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -156,6 +156,7 @@ resourcestring lisMenuViewCodeExplorer = 'Code Explorer'; lisMenuViewUnits = 'Units...'; lisMenuViewForms = 'Forms...'; + lisMenuViewUnitDependencies = 'Unit Dependencies ...'; lisMenuViewToggleFormUnit = 'Toggle form/unit view'; lisMenuViewMessages = 'Messages'; lisMenuDebugWindows = 'Debug windows'; diff --git a/ide/mainbar.pas b/ide/mainbar.pas index 0d61b8e8a9..ee0447dac6 100644 --- a/ide/mainbar.pas +++ b/ide/mainbar.pas @@ -195,6 +195,7 @@ type itmViewUnits : TMenuItem; itmViewCodeExplorer : TMenuItem; itmViewForms : TMenuItem; + itmViewUnitDependencies : TMenuItem; itmViewMessage : TMenuItem; itmViewDebugWindows: TMenuItem; itmViewWatches: TMenuItem; @@ -756,6 +757,11 @@ begin itmViewForms.Caption := lisMenuViewForms; mnuView.Add(itmViewForms); + itmViewUnitDependencies := TMenuItem.Create(Self); + itmViewUnitDependencies.Name:='itmViewUnitDependencies'; + itmViewUnitDependencies.Caption := lisMenuViewUnitDependencies; + mnuView.Add(itmViewUnitDependencies); + mnuView.Add(CreateMenuSeparator); itmViewToggleFormUnit := TMenuItem.Create(Self); @@ -1061,6 +1067,7 @@ begin itmViewProject.ShortCut:=CommandToShortCut(ecToggleProjectExpl); itmViewUnits.ShortCut:=CommandToShortCut(ecViewUnits); itmViewCodeExplorer.ShortCut:=CommandToShortCut(ecToggleCodeExpl); + itmViewUnitDependencies.ShortCut:=CommandToShortCut(ecViewUnitDependencies); itmViewForms.ShortCut:=CommandToShortCut(ecViewForms); itmViewToggleFormUnit.ShortCut:=CommandToShortCut(ecToggleFormUnit); itmViewMessage.ShortCut:=CommandToShortCut(ecToggleMessages);