/ide/codebrowser.pas
http://github.com/graemeg/lazarus · Pascal · 3356 lines · 2875 code · 280 blank · 201 comment · 398 complexity · e2cb45deae453ab5eab4e6f5b1f1ff4f MD5 · raw file
Large files are truncated click here to view the full file
- {
- ***************************************************************************
- * *
- * This source is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This code is distributed in the hope that it will be useful, but *
- * WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * General Public License for more details. *
- * *
- * A copy of the GNU General Public License is available on the World *
- * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
- * obtain it by writing to the Free Software Foundation, *
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- * *
- ***************************************************************************
- Author: Mattias Gaertner
- Abstract:
- Browser for packages, classes, methods, functions.
- Scope:
- Browse units of IDE, or a project or a package.
- Browse with required packages or without.
- Sort:
- Owner, unit, class, visibility, type (procedure, var, const, ...), identifier
- Notes:
- The codetools provides TCodeTree of every unit.
- ToDo:
- - pause
- - scan recently used packages
- - scan packages in global links
- }
- unit CodeBrowser;
- {$mode objfpc}{$H+}
- {off $DEFINE VerboseCodeBrowser}
- interface
- uses
- // RTL + FCL + LCL
- Classes, SysUtils, types, AVL_Tree,
- LCLProc, LResources, Forms, Controls, Graphics, Dialogs, Clipbrd, StdCtrls,
- ExtCtrls, ComCtrls, Buttons, Menus, HelpIntfs, LCLIntf,
- // CodeTools
- BasicCodeTools, DefineTemplates, CodeTree, CodeCache,
- CodeToolsStructs, CodeToolManager, PascalParserTool, LinkScanner, FileProcs,
- CodeIndex, StdCodeTools, SourceLog, CustomCodeTool,
- // LazUtils
- LazFileUtils, LazUtilities,
- // IDEIntf
- IDEWindowIntf, SrcEditorIntf, IDEMsgIntf, IDEDialogs, LazConfigStorage,
- IDEHelpIntf, PackageIntf, IDECommands, LazIDEIntf,
- IDEExternToolIntf,
- // IDE
- Project, DialogProcs, PackageSystem, PackageDefs, LazarusIDEStrConsts,
- IDEOptionDefs, etFPCMsgParser, BasePkgManager, EnvironmentOpts;
- type
- TCodeBrowserLevel = (
- cblPackages,
- cblUnits,
- cblIdentifiers
- );
-
- TCodeBrowserTextFilter = (
- cbtfBegins,
- cbtfContains
- );
-
- const
- CodeBrowserLevelNames: array[TCodeBrowserLevel] of string = (
- 'Packages',
- 'Units',
- 'Identifiers'
- );
-
- CodeBrowserTextFilterNames: array[TCodeBrowserTextFilter] of string = (
- 'Begins',
- 'Contains'
- );
- CodeBrowserIDEName = ' '+'Lazarus IDE';// Note: space is needed to avoid name clashing
- CodeBrowserProjectName = ' '+'Project';
- CodeBrowserHidden = ' ';
- CodeBrowserMaxTVIdentifiers = 5000; // the maximum amount of identifiers shown in the treeview
- type
- { TCodeBrowserViewOptions }
- TCodeBrowserViewOptions = class
- private
- FChangeStamp: integer;
- FModified: boolean;
- FScope: string;
- FLevels: TStrings;
- FShowEmptyNodes: boolean;
- FShowPrivate: boolean;
- FShowProtected: boolean;
- FStoreWithRequiredPackages: boolean;
- FWithRequiredPackages: boolean;
- FLevelFilterText: array[TCodeBrowserLevel] of string;
- FLevelFilterType: array[TCodeBrowserLevel] of TCodeBrowserTextFilter;
- function GetLevelFilterText(Level: TCodeBrowserLevel): string;
- function GetLevelFilterType(Level: TCodeBrowserLevel): TCodeBrowserTextFilter;
- procedure SetLevelFilterText(Level: TCodeBrowserLevel; const AValue: string);
- procedure SetLevelFilterType(Level: TCodeBrowserLevel;
- const AValue: TCodeBrowserTextFilter);
- procedure SetModified(const AValue: boolean);
- procedure SetScope(const AValue: string);
- procedure SetLevels(const AValue: TStrings);
- procedure SetShowEmptyNodes(const AValue: boolean);
- procedure SetShowPrivate(const AValue: boolean);
- procedure SetShowProtected(const AValue: boolean);
- procedure SetStoreWithRequiredPackages(const AValue: boolean);
- procedure SetWithRequiredPackages(const AValue: boolean);
- procedure IncreaseChangeStamp;
- public
- constructor Create;
- destructor Destroy; override;
- procedure Clear;
- procedure LoadFromConfig(ConfigStore: TConfigStorage; const Path: string);
- procedure SaveToConfig(ConfigStore: TConfigStorage; const Path: string);
- function HasLevel(Level: TCodeBrowserLevel): boolean;
- public
- property Scope: string read FScope write SetScope;
- property WithRequiredPackages: boolean read FWithRequiredPackages write SetWithRequiredPackages;
- property StoreWithRequiredPackages: boolean read FStoreWithRequiredPackages write SetStoreWithRequiredPackages;
- property Levels: TStrings read FLevels write SetLevels;
- property ShowPrivate: boolean read FShowPrivate write SetShowPrivate;
- property ShowProtected: boolean read FShowProtected write SetShowProtected;
- property ShowEmptyNodes: boolean read FShowEmptyNodes write SetShowEmptyNodes;
- property LevelFilterText[Level: TCodeBrowserLevel]: string read GetLevelFilterText write SetLevelFilterText;
- property LevelFilterType[Level: TCodeBrowserLevel]: TCodeBrowserTextFilter read GetLevelFilterType write SetLevelFilterType;
- property Modified: boolean read FModified write SetModified;
- property ChangeStamp: integer read FChangeStamp;
- end;
- TCodeBrowserWorkStage = (
- cbwsGetScopeOptions,
- cbwsGatherPackages,
- cbwsFreeUnusedPackages,
- cbwsAddNewPackages,
- cbwsGatherFiles,
- cbwsGatherOutdatedFiles,
- cbwsUpdateUnits,
- cbwsGetViewOptions,
- cbwsUpdateTreeView,
- cbwsFinished
- );
-
- TExpandableNodeType = (
- entPackage,
- entUnit,
- entClass
- );
-
- TCopyNodeType = (
- cntIdentifier,
- cntDescription
- );
- { TCodeBrowserView }
- TCodeBrowserView = class(TForm)
- AllClassesSeparatorMenuItem: TMenuItem;
- AllPackagesSeparatorMenuItem: TMenuItem;
- AllUnitsSeparatorMenuItem: TMenuItem;
- BrowseTreeView: TTreeView;
- UseIdentifierInCurUnitMenuItem: TMenuItem;
- UseUnitInCurUnitMenuItem: TMenuItem;
- RescanButton: TButton;
- IdleTimer1: TIdleTimer;
- UsePkgInProjectMenuItem: TMenuItem;
- UsePkgInCurUnitMenuItem: TMenuItem;
- UseSeparatorMenuItem: TMenuItem;
- ShowEmptyNodesCheckBox: TCheckBox;
- CollapseAllClassesMenuItem: TMenuItem;
- CollapseAllPackagesMenuItem: TMenuItem;
- CollapseAllUnitsMenuItem: TMenuItem;
- CopyDescriptionMenuItem: TMenuItem;
- CopyIdentifierMenuItem: TMenuItem;
- CopySeparatorMenuItem: TMenuItem;
- ExpandAllClassesMenuItem: TMenuItem;
- ExpandAllPackagesMenuItem: TMenuItem;
- ExpandAllUnitsMenuItem: TMenuItem;
- ExportMenuItem: TMenuItem;
- IdentifierFilterBeginsSpeedButton: TSpeedButton;
- IdentifierFilterContainsSpeedButton: TSpeedButton;
- IdentifierFilterEdit: TEdit;
- ImageList1: TImageList;
- LevelsGroupBox: TGroupBox;
- OpenMenuItem: TMenuItem;
- OptionsGroupBox: TGroupBox;
- PackageFilterBeginsSpeedButton: TSpeedButton;
- PackageFilterContainsSpeedButton: TSpeedButton;
- PackageFilterEdit: TEdit;
- PopupMenu1: TPopupMenu;
- ProgressBar1: TProgressBar;
- ScopeComboBox: TComboBox;
- ScopeGroupBox: TGroupBox;
- ScopeWithRequiredPackagesCheckBox: TCheckBox;
- ShowIdentifiersCheckBox: TCheckBox;
- ShowPackagesCheckBox: TCheckBox;
- ShowPrivateCheckBox: TCheckBox;
- ShowProtectedCheckBox: TCheckBox;
- ShowUnitsCheckBox: TCheckBox;
- StatusBar1: TStatusBar;
- UnitFilterBeginsSpeedButton: TSpeedButton;
- UnitFilterContainsSpeedButton: TSpeedButton;
- UnitFilterEdit: TEdit;
- procedure BrowseTreeViewMouseMove(Sender: TObject; {%H-}Shift: TShiftState; {%H-}X,
- {%H-}Y: Integer);
- procedure FormDeactivate(Sender: TObject);
- procedure UseIdentifierInCurUnitMenuItemClick(Sender: TObject);
- procedure UsePkgInCurUnitMenuItemClick(Sender: TObject);
- procedure UsePkgInProjectMenuItemClick(Sender: TObject);
- procedure UseUnitInCurUnitMenuItemClick(Sender: TObject);
- procedure BrowseTreeViewMouseDown(Sender: TOBject; {%H-}Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure BrowseTreeViewShowHint(Sender: TObject; HintInfo: PHintInfo);
- procedure CollapseAllPackagesMenuItemClick(Sender: TObject);
- procedure CollapseAllUnitsMenuItemClick(Sender: TObject);
- procedure CollapseAllClassesMenuItemClick(Sender: TObject);
- procedure CopyDescriptionMenuItemClick(Sender: TObject);
- procedure CopyIdentifierMenuItemClick(Sender: TObject);
- procedure ExpandAllClassesMenuItemClick(Sender: TObject);
- procedure ExpandAllPackagesMenuItemClick(Sender: TObject);
- procedure ExpandAllUnitsMenuItemClick(Sender: TObject);
- procedure ExportMenuItemClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure IdleTimer1Timer(Sender: TObject);
- procedure PackageFilterEditChange(Sender: TObject);
- procedure PackageFilterEditEditingDone(Sender: TObject);
- procedure PopupMenu1Popup(Sender: TObject);
- procedure RescanButtonClick(Sender: TObject);
- procedure ScopeComboBoxChange(Sender: TObject);
- procedure ScopeWithRequiredPackagesCheckBoxChange(Sender: TObject);
- procedure OnIdle(Sender: TObject; var Done: Boolean);
- procedure OpenMenuItemClick(Sender: TObject);
- procedure ShowIdentifiersCheckBoxChange(Sender: TObject);
- procedure ShowPackagesCheckBoxChange(Sender: TObject);
- procedure ShowPrivateCheckBoxChange(Sender: TObject);
- procedure ShowUnitsCheckBoxChange(Sender: TObject);
- private
- FHintManager: THintWindowManager;
- FIDEDescription: string;
- FIdleConnected: boolean;
- FOptions: TCodeBrowserViewOptions;
- FOptionsChangeStamp: integer;
- FProjectDescription: string;
- FParserRoot: TCodeBrowserUnitList;
- FScannedBytes: PtrInt;
- FScannedIdentifiers: PtrInt;
- FScannedLines: PtrInt;
- FScannedPackages: integer;
- FScannedUnits: integer;
- FUpdateNeeded: boolean;
- FViewRoot: TCodeBrowserUnitList;
- FVisibleIdentifiers: PtrInt;
- FVisiblePackages: integer;
- FVisibleUnits: integer;
- FWorkingParserRoot: TCodeBrowserUnitList;
- fUpdateCount: integer;
- fStage: TCodeBrowserWorkStage;
- fOutdatedFiles: TAVLTree;// tree of TCodeBrowserUnit
- fLastStatusBarUpdate: TDateTime;
- ImgIDDefault: integer;
- ImgIDProgramCode: Integer;
- ImgIDUnitCode: Integer;
- ImgIDInterfaceSection: Integer;
- ImgIDImplementation: Integer;
- ImgIDInitialization: Integer;
- ImgIDFinalization: Integer;
- ImgIDTypeSection: Integer;
- ImgIDType: Integer;
- ImgIDVarSection: Integer;
- ImgIDVariable: Integer;
- ImgIDConstSection: Integer;
- ImgIDConst: Integer;
- ImgIDClass: Integer;
- ImgIDProc: Integer;
- ImgIDProperty: Integer;
- ImgIDPackage: Integer;
- ImgIDProject: Integer;
- procedure LoadOptions;
- procedure LoadLevelsGroupBox;
- procedure LoadFilterGroupbox;
- procedure FillScopeComboBox;
- procedure SetIdleConnected(AValue: boolean);
- procedure SetScannedBytes(const AValue: PtrInt);
- procedure SetScannedIdentifiers(const AValue: PtrInt);
- procedure SetScannedLines(const AValue: PtrInt);
- procedure SetScannedPackages(const AValue: integer);
- procedure SetScannedUnits(const AValue: integer);
- procedure SetUpdateNeeded(const AValue: boolean);
- procedure SetVisibleIdentifiers(const AValue: PtrInt);
- procedure SetVisiblePackages(const AValue: integer);
- procedure SetVisibleUnits(const AValue: integer);
- procedure Work(var Done: Boolean);
- procedure WorkGetScopeOptions;
- procedure WorkGatherPackages;
- procedure WorkFreeUnusedPackages;
- procedure WorkAddNewUnitLists;
- procedure WorkGatherFileLists;
- procedure WorkUpdateFileList(List: TCodeBrowserUnitList);
- procedure WorkGatherOutdatedFiles;
- procedure WorkUpdateUnits;
- procedure WorkUpdateUnit(AnUnit: TCodeBrowserUnit);
- procedure WorkGetViewOptions;
- procedure WorkUpdateTreeView;
- procedure FreeUnitList(List: TCodeBrowserUnitList);
- procedure UpdateStatusBar(Lazy: boolean);
- procedure RemoveUnit(AnUnit: TCodeBrowserUnit);
- function CountIdentifiers(Tool: TCodeTool): integer;
- procedure UpdateTreeView;
- procedure ClearTreeView;
- procedure InitTreeView;
- function ListOwnerToText(const ListOwner: string): string;
- procedure InitImageList;
- function GetNodeImage(CodeNode: TObject): integer;
- function GetTVNodeHint(TVNode: TTreeNode): string;
- function GetCodeHelp(TVNode: TTreeNode; out BaseURL, HTMLHint: string): boolean;
- procedure ExpandCollapseAllNodesInTreeView(NodeType: TExpandableNodeType;
- Expand: boolean);
- procedure CopyNode(TVNode: TTreeNode; NodeType: TCopyNodeType);
- function GetCodeTool(AnUnit: TCodeBrowserUnit): TStandardCodeTool;
- procedure GetNodeIdentifier(Tool: TStandardCodeTool;
- CTNode: TCodeTreeNode; out Identifier: string);
- procedure GetNodeDescription(Tool: TStandardCodeTool;
- CTNode: TCodeTreeNode; Identifier: string; out Description: string);
- function GetSelectedUnit: TCodeBrowserUnit;
- function GetSelectedPackage: TLazPackage;
- function GetCurUnitInSrcEditor(out FileOwner: TObject;
- out UnitCode: TCodeBuffer): boolean;
- function GetCurPackageInSrcEditor: TLazPackage;
- procedure OpenTVNode(TVNode: TTreeNode);
- procedure UseUnitInSrcEditor(InsertIdentifier: boolean);
- procedure CloseHintWindow;
- public
- procedure BeginUpdate;
- procedure EndUpdate;
- function ExportTree: TModalResult;
- function ExportTreeAsText(Filename: string): TModalResult;
- function GetScopeToCurUnitOwner(UseFCLAsDefault: boolean): string;
- function SetScopeToCurUnitOwner(UseFCLAsDefault,
- WithRequiredPackages: boolean): boolean;
- procedure SetFilterToSimpleIdentifier(Identifier: string);
- procedure InvalidateStage(AStage: TCodeBrowserWorkStage);
- public
- property ParserRoot: TCodeBrowserUnitList read FParserRoot;
- property WorkingParserRoot: TCodeBrowserUnitList read FWorkingParserRoot;
- property ViewRoot: TCodeBrowserUnitList read FViewRoot;
- property Options: TCodeBrowserViewOptions read FOptions;
- property IDEDescription: string read FIDEDescription;
- property ProjectDescription: string read FProjectDescription;
- property ScannedPackages: integer read FScannedPackages write SetScannedPackages;
- property ScannedUnits: integer read FScannedUnits write SetScannedUnits;
- property ScannedLines: PtrInt read FScannedLines write SetScannedLines;
- property ScannedBytes: PtrInt read FScannedBytes write SetScannedBytes;
- property ScannedIdentifiers: PtrInt read FScannedIdentifiers write SetScannedIdentifiers;
- property VisiblePackages: integer read FVisiblePackages write SetVisiblePackages;
- property VisibleUnits: integer read FVisibleUnits write SetVisibleUnits;
- property VisibleIdentifiers: PtrInt read FVisibleIdentifiers write SetVisibleIdentifiers;
- property UpdateNeeded: boolean read FUpdateNeeded write SetUpdateNeeded;
- property IdleConnected: boolean read FIdleConnected write SetIdleConnected;
- end;
- type
- { TQuickFixIdentifierNotFound_Search }
- TQuickFixIdentifierNotFound_Search = class(TMsgQuickFix)
- public
- function IsApplicable(Msg: TMessageLine; out Identifier: string): boolean;
- procedure CreateMenuItems(Fixes: TMsgQuickFixes); override;
- procedure QuickFix({%H-}Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
- end;
- var
- CodeBrowserView: TCodeBrowserView = nil;
-
- function StringToCodeBrowserTextFilter(const s: string): TCodeBrowserTextFilter;
- procedure InitCodeBrowserQuickFixItems;
- procedure CreateCodeBrowser(DisableAutoSizing: boolean);
- procedure ShowCodeBrowser(const Identifier: string);
- implementation
- {$R *.lfm}
- const
- ProgressGetScopeStart=0;
- ProgressGetScopeSize=10;
- ProgressGatherPackagesStart=ProgressGetScopeStart+ProgressGetScopeSize;
- ProgressGatherPackagesSize=30;
- ProgressFreeUnusedPkgStart=ProgressGatherPackagesStart+ProgressGatherPackagesSize;
- ProgressFreeUnusedPkgSize=100;
- ProgressAddNewUnitListsStart=ProgressFreeUnusedPkgStart+ProgressFreeUnusedPkgSize;
- ProgressAddNewUnitListsSize=300;
- ProgressGatherFileListsStart=ProgressAddNewUnitListsStart+ProgressAddNewUnitListsSize;
- ProgressGatherFileListsSize=300;
- ProgressGatherOutdatedFilesStart=ProgressGatherFileListsStart+ProgressGatherFileListsSize;
- ProgressGatherOutdatedFilesSize=300;
- ProgressUpdateUnitsStart=ProgressGatherOutdatedFilesStart+ProgressGatherOutdatedFilesSize;
- ProgressUpdateUnitsSize=3000;
- ProgressGetViewOptionsStart=ProgressUpdateUnitsStart+ProgressUpdateUnitsSize;
- ProgressGetViewOptionsSize=10;
- ProgressUpdateTreeViewStart=ProgressGetViewOptionsStart+ProgressGetViewOptionsSize;
- ProgressUpdateTreeViewSize=1000;
- ProgressTotal=ProgressUpdateTreeViewStart+ProgressUpdateTreeViewSize;
- const
- ProcDescFlags = [phpWithStart,phpWithParameterNames,
- phpWithVarModifiers,phpWithResultType,phpWithoutSemicolon];
- ProcIdentifierFlags = [phpWithoutClassKeyword,phpWithParameterNames,
- phpWithoutSemicolon];
- PropDescFlags = [phpWithoutClassKeyword,phpWithParameterNames,
- phpWithVarModifiers,phpWithResultType];
- function StringToCodeBrowserTextFilter(const s: string): TCodeBrowserTextFilter;
- begin
- for Result:=Low(TCodeBrowserTextFilter) to High(TCodeBrowserTextFilter) do
- if SysUtils.CompareText(CodeBrowserTextFilterNames[Result],s)=0 then exit;
- Result:=cbtfBegins;
- end;
- procedure InitCodeBrowserQuickFixItems;
- begin
- RegisterIDEMsgQuickFix(TQuickFixIdentifierNotFound_Search.Create);
- end;
- procedure CreateCodeBrowser(DisableAutoSizing: boolean);
- begin
- if CodeBrowserView=nil then
- IDEWindowCreators.CreateForm(CodeBrowserView,TCodeBrowserView,
- DisableAutoSizing,LazarusIDE.OwningComponent)
- else if DisableAutoSizing then
- CodeBrowserView.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('CreateCodeBrowser'){$ENDIF};
- end;
- procedure ShowCodeBrowser(const Identifier: string);
- begin
- IDEWindowCreators.ShowForm(NonModalIDEWindowNames[nmiwCodeBrowser],true);
- CodeBrowserView.SetScopeToCurUnitOwner(true,true);
- CodeBrowserView.SetFilterToSimpleIdentifier(Identifier);
- end;
- { TCodeBrowserView }
- procedure TCodeBrowserView.FormCreate(Sender: TObject);
- begin
- FHintManager:=THintWindowManager.Create;
- FOptions:=TCodeBrowserViewOptions.Create;
-
- FIDEDescription:=lisLazarusIDE;
- FProjectDescription:=dlgProject;
- Name:=NonModalIDEWindowNames[nmiwCodeBrowser];
- Caption:=lisCodeBrowser;
- ScopeGroupBox.Caption:=dlgSearchScope;
- ScopeWithRequiredPackagesCheckBox.Caption:=lisWithRequiredPackages;
- RescanButton.Caption:=lisRescan;
- LevelsGroupBox.Caption:=lisLevels;
- ShowPackagesCheckBox.Caption:=lisShowPackages;
- ShowUnitsCheckBox.Caption:=lisShowUnits;
- ShowIdentifiersCheckBox.Caption:=lisShowIdentifiers;
- OptionsGroupBox.Caption:=lisFilter;
- ShowPrivateCheckBox.Caption:=lisPrivate;
- ShowProtectedCheckBox.Caption:=lisProtected;
- ShowEmptyNodesCheckBox.Caption:=lisShowEmptyUnitsPackages;
- ExpandAllPackagesMenuItem.Caption:=lisExpandAllPackages;
- CollapseAllPackagesMenuItem.Caption:=lisCollapseAllPackages;
- ExpandAllUnitsMenuItem.Caption:=lisExpandAllUnits;
- CollapseAllUnitsMenuItem.Caption:=lisCollapseAllUnits;
- ExpandAllClassesMenuItem.Caption:=lisExpandAllClasses;
- CollapseAllClassesMenuItem.Caption:=lisCollapseAllClasses;
- ExportMenuItem.Caption:=lisDlgExport;
- OpenMenuItem.Caption:=lisOpen;
- // UsePkgInProjectMenuItem.Caption: see PopupMenu1Popup
- // UsePkgInCurUnitMenuItem.Caption: see PopupMenu1Popup
- // UseUnitInCurUnitMenuItem.Caption: see PopupMenu1Popup
- PackageFilterBeginsSpeedButton.Caption:=lisBegins;
- PackageFilterBeginsSpeedButton.Hint:=lisPackageNameBeginsWith;
- PackageFilterContainsSpeedButton.Caption:=lisContains;
- PackageFilterContainsSpeedButton.Hint:=lisPackageNameContains;
- UnitFilterBeginsSpeedButton.Caption:=lisBegins;
- UnitFilterBeginsSpeedButton.Hint:=lisUnitNameBeginsWith;
- UnitFilterContainsSpeedButton.Caption:=lisContains;
- UnitFilterContainsSpeedButton.Hint:=lisUnitNameContains;
- IdentifierFilterBeginsSpeedButton.Caption:=lisBegins;
- IdentifierFilterBeginsSpeedButton.Hint:=lisIdentifierBeginsWith;
- IdentifierFilterContainsSpeedButton.Caption:=lisContains;
- IdentifierFilterContainsSpeedButton.Hint:=lisIdentifierContains;
-
- ProgressBar1.Max:=ProgressTotal;
- InitImageList;
- LoadOptions;
- FillScopeComboBox;
- ScopeComboBox.ItemIndex:=0;
- IdleConnected:=true;
- end;
- procedure TCodeBrowserView.FormDestroy(Sender: TObject);
- begin
- IdleConnected:=false;
- ClearTreeView;
- FreeAndNil(fOutdatedFiles);
- FreeAndNil(FViewRoot);
- FreeAndNil(FParserRoot);
- FreeAndNil(FWorkingParserRoot);
- FreeAndNil(FOptions);
- FreeAndNil(FHintManager);
- IdleConnected:=false;
- end;
- procedure TCodeBrowserView.IdleTimer1Timer(Sender: TObject);
- begin
- InvalidateStage(cbwsGetViewOptions);
- IdleTimer1.Enabled:=false;
- end;
- procedure TCodeBrowserView.PackageFilterEditChange(Sender: TObject);
- begin
- IdleTimer1.Enabled:=true;
- end;
- procedure TCodeBrowserView.PackageFilterEditEditingDone(Sender: TObject);
- begin
- InvalidateStage(cbwsGetViewOptions);
- end;
- procedure TCodeBrowserView.PopupMenu1Popup(Sender: TObject);
- var
- TVNode: TTreeNode;
- Node: TObject;
- Identifier: String;
- UnitList: TCodeBrowserUnitList;
- EnableUsePkgInProject: Boolean;
- APackage: TLazPackage;
- EnableUsePkgInCurUnit: Boolean;
- TargetPackage: TLazPackage;
- EnableUseUnitInCurUnit: Boolean;
- CurUnit: TCodeBrowserUnit;
- SrcEditUnitOwner: TObject;
- SrcEditUnitCode: TCodeBuffer;
- CurUnitName: String;
- SrcEditUnitName: String;
- CBNode: TCodeBrowserNode;
- EnableUseIdentifierInCurUnit: Boolean;
- SrcEdit: TSourceEditorInterface;
- begin
- ExpandAllPackagesMenuItem.Visible:=Options.HasLevel(cblPackages);
- CollapseAllPackagesMenuItem.Visible:=ExpandAllPackagesMenuItem.Visible;
- AllPackagesSeparatorMenuItem.Visible:=ExpandAllPackagesMenuItem.Visible;
-
- ExpandAllUnitsMenuItem.Visible:=Options.HasLevel(cblUnits);
- CollapseAllUnitsMenuItem.Visible:=ExpandAllUnitsMenuItem.Visible;
- AllUnitsSeparatorMenuItem.Visible:=ExpandAllUnitsMenuItem.Visible;
- ExpandAllClassesMenuItem.Visible:=Options.HasLevel(cblIdentifiers);
- CollapseAllClassesMenuItem.Visible:=ExpandAllClassesMenuItem.Visible;
- AllClassesSeparatorMenuItem.Visible:=ExpandAllClassesMenuItem.Visible;
- TVNode:=BrowseTreeView.Selected;
- Node:=nil;
- if TVNode<>nil then
- Node:=TObject(TVNode.Data);
- EnableUsePkgInProject:=false;
- EnableUsePkgInCurUnit:=false;
- EnableUseUnitInCurUnit:=false;
- EnableUseIdentifierInCurUnit:=false;
- if Node<>nil then begin
- Identifier:='';
- APackage:=nil;
- UnitList:=nil;
- CurUnit:=nil;
- TargetPackage:=nil;
- if Node is TCodeBrowserNode then begin
- Identifier:=TCodeBrowserNode(Node).Identifier;
- CBNode:=TCodeBrowserNode(Node);
- CurUnit:=CBNode.CBUnit;
- if CurUnit<>nil then
- UnitList:=CurUnit.UnitList;
- end else if Node is TCodeBrowserUnit then begin
- CurUnit:=TCodeBrowserUnit(Node);
- UnitList:=CurUnit.UnitList;
- end else if Node is TCodeBrowserUnitList then begin
- UnitList:=TCodeBrowserUnitList(Node);
- end;
- if UnitList<>nil then begin
- if UnitList.Owner=CodeBrowserProjectName then begin
- // project
- end else if UnitList.Owner=CodeBrowserIDEName then begin
- // IDE
- end else if UnitList.Owner=CodeBrowserHidden then begin
- // nothing
- end else begin
- // package
- APackage:=PackageGraph.FindPackageWithName(UnitList.Owner,nil);
- if APackage<>nil then begin
- // check if package can be added to project
- if Project1.FindDependencyByName(APackage.Name)=nil then begin
- EnableUsePkgInProject:=true;
- UsePkgInProjectMenuItem.Caption:=Format(lisUsePackageInProject, [
- APackage.Name]);
- end;
- // check if package can be added to package of src editor unit
- TargetPackage:=GetCurPackageInSrcEditor;
- if (TargetPackage<>nil)
- and (SysUtils.CompareText(TargetPackage.Name,APackage.Name)<>0)
- and (TargetPackage.FindDependencyByName(APackage.Name)=nil) then begin
- EnableUsePkgInCurUnit:=true;
- UsePkgInCurUnitMenuItem.Caption:=Format(
- lisUsePackageInPackage, [APackage.Name,
- TargetPackage.Name]);
- end;
- // check if unit can be added to project/package
- GetCurUnitInSrcEditor(SrcEditUnitOwner,SrcEditUnitCode);
- if (CurUnit<>nil) and (SrcEditUnitOwner<>nil) then begin
- CurUnitName:=ExtractFileNameOnly(CurUnit.Filename);
- SrcEditUnitName:=ExtractFileNameOnly(SrcEditUnitCode.Filename);
- if SysUtils.CompareText(CurUnitName,SrcEditUnitName)<>0 then begin
- EnableUseUnitInCurUnit:=true;
- UseUnitInCurUnitMenuItem.Caption:=
- Format(lisUseUnitInUnit, [CurUnitName, SrcEditUnitName]);
- if (Node is TCodeBrowserNode) and (Identifier<>'') then begin
- EnableUseIdentifierInCurUnit:=true;
- SrcEdit:=SourceEditorManagerIntf.ActiveEditor;
- UseIdentifierInCurUnitMenuItem.Caption:=
- Format(lisUseIdentifierInAt, [Identifier, ExtractFilename(
- SrcEdit.FileName), dbgs(SrcEdit.CursorScreenXY)]);
- end;
- end;
- end;
- end;
- end;
- end;
- OpenMenuItem.Visible:=true;
- CopyDescriptionMenuItem.Caption:=lisCopyDescription;
- CopyIdentifierMenuItem.Caption:=Format(lisCopyIdentifier, [Identifier]);
- CopyDescriptionMenuItem.Visible:=true;
- CopyIdentifierMenuItem.Visible:=Identifier<>'';
- CopySeparatorMenuItem.Visible:=true;
- UseUnitInCurUnitMenuItem.Enabled:=EnableUseUnitInCurUnit;
- UseUnitInCurUnitMenuItem.Visible:=true;
- if not EnableUseUnitInCurUnit then
- UseUnitInCurUnitMenuItem.Caption:=lisPkgMangUseUnit;
- UseIdentifierInCurUnitMenuItem.Enabled:=EnableUseIdentifierInCurUnit;
- UseIdentifierInCurUnitMenuItem.Visible:=true;
- if not EnableUseIdentifierInCurUnit then
- UseIdentifierInCurUnitMenuItem.Caption:=lisUseIdentifier;
- UsePkgInProjectMenuItem.Enabled:=EnableUsePkgInProject;
- UsePkgInProjectMenuItem.Visible:=true;
- if not EnableUsePkgInProject then
- UsePkgInProjectMenuItem.Caption:=lisUsePackageInProject2;
- UsePkgInCurUnitMenuItem.Enabled:=EnableUsePkgInCurUnit;
- UsePkgInCurUnitMenuItem.Visible:=true;
- if not EnableUsePkgInCurUnit then
- UsePkgInCurUnitMenuItem.Caption:=lisUsePackageInPackage2;
- end else begin
- OpenMenuItem.Visible:=false;
- CopyDescriptionMenuItem.Visible:=false;
- CopyIdentifierMenuItem.Visible:=false;
- CopySeparatorMenuItem.Visible:=false;
- UseUnitInCurUnitMenuItem.Visible:=false;
- UseIdentifierInCurUnitMenuItem.Visible:=false;
- UsePkgInProjectMenuItem.Visible:=false;
- UsePkgInCurUnitMenuItem.Visible:=false;
- UseSeparatorMenuItem.Visible:=false;
- end;
- end;
- procedure TCodeBrowserView.RescanButtonClick(Sender: TObject);
- begin
- UpdateNeeded:=true;
- InvalidateStage(cbwsGetScopeOptions);
- end;
- procedure TCodeBrowserView.ScopeComboBoxChange(Sender: TObject);
- begin
- InvalidateStage(cbwsGetScopeOptions);
- end;
- procedure TCodeBrowserView.ScopeWithRequiredPackagesCheckBoxChange(Sender: TObject);
- begin
- InvalidateStage(cbwsGetScopeOptions);
- end;
- procedure TCodeBrowserView.OnIdle(Sender: TObject; var Done: Boolean);
- begin
- if (Screen.GetCurrentModalForm<>nil) then exit;
- Work(Done);
- end;
- procedure TCodeBrowserView.OpenMenuItemClick(Sender: TObject);
- begin
- OpenTVNode(BrowseTreeView.Selected);
- end;
- procedure TCodeBrowserView.ShowIdentifiersCheckBoxChange(Sender: TObject);
- begin
- InvalidateStage(cbwsGetViewOptions);
- end;
- procedure TCodeBrowserView.ShowPackagesCheckBoxChange(Sender: TObject);
- begin
- //DebugLn(['TCodeBrowserView.ShowPackagesCheckBoxChange ']);
- InvalidateStage(cbwsGetViewOptions);
- end;
- procedure TCodeBrowserView.ShowPrivateCheckBoxChange(Sender: TObject);
- begin
- InvalidateStage(cbwsGetViewOptions);
- end;
- procedure TCodeBrowserView.ShowUnitsCheckBoxChange(Sender: TObject);
- begin
- InvalidateStage(cbwsGetViewOptions);
- end;
- procedure TCodeBrowserView.LoadOptions;
- begin
- BeginUpdate;
- ScopeWithRequiredPackagesCheckBox.Checked:=Options.WithRequiredPackages;
- ScopeComboBox.Text:=Options.Scope;
- LoadLevelsGroupBox;
- LoadFilterGroupbox;
- EndUpdate;
- end;
- procedure TCodeBrowserView.LoadLevelsGroupBox;
- begin
- ShowPackagesCheckBox.Checked:=Options.HasLevel(cblPackages);
- ShowUnitsCheckBox.Checked:=Options.HasLevel(cblUnits);
- ShowIdentifiersCheckBox.Checked:=Options.HasLevel(cblIdentifiers);
- end;
- procedure TCodeBrowserView.LoadFilterGroupbox;
- begin
- ShowPrivateCheckBox.Checked:=Options.ShowPrivate;
- ShowProtectedCheckBox.Checked:=Options.ShowProtected;
- ShowEmptyNodesCheckBox.Checked:=Options.ShowEmptyNodes;
- PackageFilterEdit.Text:=Options.LevelFilterText[cblPackages];
- case Options.LevelFilterType[cblPackages] of
- cbtfBegins: PackageFilterBeginsSpeedButton.Down:=true;
- cbtfContains: PackageFilterContainsSpeedButton.Down:=true;
- end;
- UnitFilterEdit.Text:=Options.LevelFilterText[cblUnits];
- case Options.LevelFilterType[cblUnits] of
- cbtfBegins: UnitFilterBeginsSpeedButton.Down:=true;
- cbtfContains: UnitFilterContainsSpeedButton.Down:=true;
- end;
- IdentifierFilterEdit.Text:=Options.LevelFilterText[cblIdentifiers];
- case Options.LevelFilterType[cblIdentifiers] of
- cbtfBegins: IdentifierFilterBeginsSpeedButton.Down:=true;
- cbtfContains: IdentifierFilterContainsSpeedButton.Down:=true;
- end;
- end;
- procedure TCodeBrowserView.FillScopeComboBox;
- var
- sl: TStringList;
- i: Integer;
- begin
- if ScopeComboBox.Items.Count=0 then begin
- sl:=TStringList.Create;
- try
- if PackageGraph<>nil then begin
- for i:=0 to PackageGraph.Count-1 do
- sl.Add(PackageGraph.Packages[i].Name);
- end;
- sl.Sort;
- sl.Insert(0,IDEDescription);
- sl.Insert(1,ProjectDescription);
- ScopeComboBox.Items.Assign(sl);
- finally
- sl.Free;
- end;
- end;
- end;
- procedure TCodeBrowserView.SetIdleConnected(AValue: boolean);
- begin
- if csDestroying in ComponentState then AValue:=false;
- if FIdleConnected=AValue then Exit;
- FIdleConnected:=AValue;
- if IdleConnected then
- Application.AddOnIdleHandler(@OnIdle)
- else
- Application.RemoveOnIdleHandler(@OnIdle);
- end;
- procedure TCodeBrowserView.InitImageList;
- begin
- ImgIDDefault := Imagelist1.AddResourceName(HInstance, 'ce_default');
- ImgIDProgramCode := Imagelist1.AddResourceName(HInstance, 'ce_program');
- ImgIDUnitCode := Imagelist1.AddResourceName(HInstance, 'ce_unit');
- ImgIDInterfaceSection := Imagelist1.AddResourceName(HInstance, 'ce_interface');
- ImgIDImplementation := Imagelist1.AddResourceName(HInstance, 'ce_implementation');
- ImgIDInitialization := Imagelist1.AddResourceName(HInstance, 'ce_initialization');
- ImgIDFinalization := Imagelist1.AddResourceName(HInstance, 'ce_finalization');
- ImgIDTypeSection := Imagelist1.AddResourceName(HInstance, 'ce_type');
- ImgIDType := Imagelist1.AddResourceName(HInstance, 'ce_type');
- ImgIDVarSection := Imagelist1.AddResourceName(HInstance, 'ce_variable');
- ImgIDVariable := Imagelist1.AddResourceName(HInstance, 'ce_variable');
- ImgIDConstSection := Imagelist1.AddResourceName(HInstance, 'ce_const');
- ImgIDConst := Imagelist1.AddResourceName(HInstance, 'ce_const');
- ImgIDClass := Imagelist1.AddResourceName(HInstance, 'ce_class');
- ImgIDProc := Imagelist1.AddResourceName(HInstance, 'ce_procedure');
- ImgIDProperty := Imagelist1.AddResourceName(HInstance, 'ce_property');
- ImgIDPackage := Imagelist1.AddResourceName(HInstance, 'item_package');
- ImgIDProject := Imagelist1.AddResourceName(HInstance, 'item_project');
- end;
- procedure TCodeBrowserView.SetScannedBytes(const AValue: PtrInt);
- begin
- if FScannedBytes=AValue then exit;
- FScannedBytes:=AValue;
- end;
- procedure TCodeBrowserView.SetScannedIdentifiers(const AValue: PtrInt);
- begin
- if FScannedIdentifiers=AValue then exit;
- FScannedIdentifiers:=AValue;
- end;
- procedure TCodeBrowserView.SetScannedLines(const AValue: PtrInt);
- begin
- if FScannedLines=AValue then exit;
- FScannedLines:=AValue;
- end;
- procedure TCodeBrowserView.SetScannedPackages(const AValue: integer);
- begin
- if FScannedPackages=AValue then exit;
- FScannedPackages:=AValue;
- end;
- procedure TCodeBrowserView.SetScannedUnits(const AValue: integer);
- begin
- if FScannedUnits=AValue then exit;
- FScannedUnits:=AValue;
- end;
- procedure TCodeBrowserView.SetUpdateNeeded(const AValue: boolean);
- procedure InvalidateFileList(StartList: TCodeBrowserUnitList);
- var
- APackage: TCodeBrowserUnitList;
- Node: TAVLTreeNode;
- begin
- if StartList=nil then exit;
- StartList.UnitsValid:=false;
- if (StartList.UnitLists=nil) then exit;
- Node:=StartList.UnitLists.FindLowest;
- while Node<>nil do begin
- APackage:=TCodeBrowserUnitList(Node.Data);
- InvalidateFileList(APackage);
- Node:=StartList.UnitLists.FindSuccessor(Node);
- end;
- end;
- begin
- if FUpdateNeeded=AValue then exit;
- FUpdateNeeded:=AValue;
- if FUpdateNeeded then begin
- InvalidateFileList(FParserRoot);
- InvalidateFileList(FWorkingParserRoot);
- InvalidateStage(cbwsGetScopeOptions);
- end;
- end;
- procedure TCodeBrowserView.SetVisibleIdentifiers(const AValue: PtrInt);
- begin
- if FVisibleIdentifiers=AValue then exit;
- FVisibleIdentifiers:=AValue;
- end;
- procedure TCodeBrowserView.SetVisiblePackages(const AValue: integer);
- begin
- if FVisiblePackages=AValue then exit;
- FVisiblePackages:=AValue;
- end;
- procedure TCodeBrowserView.SetVisibleUnits(const AValue: integer);
- begin
- if FVisibleUnits=AValue then exit;
- FVisibleUnits:=AValue;
- end;
- procedure TCodeBrowserView.UseUnitInSrcEditor(InsertIdentifier: boolean);
- var
- // temporary data, that can be freed on next idle
- SelectedUnit: TCodeBrowserUnit;
- TVNode: TTreeNode;
- Node: TObject;
- IdentifierNode: TCodeBrowserNode;
- // normal vars
- SelectedUnitName: String;
- SelectedCode: TCodeBuffer;
- List: TFPList;
- SelectedOwner: TObject;
- APackage: TLazPackage;
- TargetCode: TCodeBuffer;
- TargetOwner: TObject;
- SrcEdit: TSourceEditorInterface;
- Code: TCodeBuffer;
- CodeMarker: TSourceLogMarker;
- Identifier: String;
- SelectedUnitFilename: String;
- IdentStart: integer;
- IdentEnd: integer;
- InsertStartPos: TPoint;
- InsertEndPos: TPoint;
- begin
- TVNode:=BrowseTreeView.Selected;
- if TVNode=nil then exit;
- Node:=TObject(TVNode.Data);
- IdentifierNode:=nil;
- SelectedUnit:=nil;
- if Node is TCodeBrowserNode then begin
- IdentifierNode:=TCodeBrowserNode(Node);
- Identifier:=IdentifierNode.Identifier;
- SelectedUnit:=IdentifierNode.CBUnit;
- end else if Node is TCodeBrowserUnit then begin
- SelectedUnit:=TCodeBrowserUnit(Node);
- end else
- exit;
- if (SelectedUnit=nil) then exit;
- SelectedUnitFilename:=SelectedUnit.Filename;
- if InsertIdentifier then begin
- if (IdentifierNode=nil) or (Identifier='') then exit;
- end;
- if SelectedUnit.UnitList=nil then begin
- DebugLn(['TCodeBrowserView.UseUnitInSrcEditor not implemented: '
- +'SelectedUnit.UnitList=nil']);
- IDEMessageDialog('Implement me',
- 'TCodeBrowserView.UseUnitInSrcEditor not implemented: '
- +'SelectedUnit.UnitList=nil',
- mtInformation, [mbOk]);
- exit;
- end;
- SelectedOwner:=nil;
- if SelectedUnit.UnitList.Owner=CodeBrowserProjectName then begin
- // project
- SelectedOwner:=Project1;
- end else if SelectedUnit.UnitList.Owner=CodeBrowserIDEName then begin
- // IDE can not be added as dependency
- DebugLn(['TCodeBrowserView.UseUnitInSrcEditor IDE can not be '
- +'added as dependency']);
- exit;
- end else if SelectedUnit.UnitList.Owner=CodeBrowserHidden then begin
- // nothing
- DebugLn(['TCodeBrowserView.UseUnitInSrcEditor hidden unitlist']
- );
- exit;
- end else begin
- // package
- APackage:=PackageGraph.FindPackageWithName(SelectedUnit.UnitList.Owner,nil);
- if APackage=nil then begin
- DebugLn(['TCodeBrowserView.UseUnitInSrcEditor package not '
- +'found: ', SelectedUnit.UnitList.Owner]);
- exit;
- end;
- SelectedOwner:=APackage;
- end;
- // get target unit
- if not GetCurUnitInSrcEditor(TargetOwner, TargetCode) then exit;
- if (not (TargetOwner is TProject))
- and (not (TargetOwner is TLazPackage)) then begin
- DebugLn(['TCodeBrowserView.UseUnitInSrcEditor not implemented: '
- +'TargetOwner=', DbgSName(TargetOwner)]);
- IDEMessageDialog('Implement me',
- 'TCodeBrowserView.UseUnitInSrcEditor not implemented: '
- +'TargetOwner='+DbgSName(TargetOwner),
- mtInformation, [mbOk]);
- exit;
- end;
- if (SelectedOwner is TProject) and (TargetOwner<>SelectedOwner) then begin
- // unit of project can not be used by other packages/projects
- IDEMessageDialog(lisImpossible,
- lisAProjectUnitCanNotBeUsedByOtherPackagesProjects,
- mtError, [mbCancel]);
- exit;
- end;
- // safety first: clear the references, they will become invalid on next idle
- SelectedUnit:=nil;
- IdentifierNode:=nil;
- Node:=nil;
- TVNode:=nil;
- List:=TFPList.Create;
- CodeMarker:=nil;
- try
- SrcEdit:=SourceEditorManagerIntf.ActiveEditor;
- if SrcEdit=nil then exit;
- InsertStartPos:=SrcEdit.CursorTextXY;
- Code:=TCodeBuffer(SrcEdit.CodeToolsBuffer);
- CodeMarker:=Code.AddMarkerXY(InsertStartPos.Y,InsertStartPos.X,Self);
- List.Add(TargetOwner);
- if (SelectedOwner is TLazPackage) then begin
- // add package to TargetOwner
- APackage:=TLazPackage(SelectedOwner);
- if PkgBoss.AddDependencyToOwners(List, APackage)<>mrOk then begin
- DebugLn(['TCodeBrowserView.UseUnitInSrcEditor PkgBoss.'
- +'AddDependencyToOwners failed']);
- exit;
- end;
- end;
- // get nice unit name
- LazarusIDE.SaveSourceEditorChangesToCodeCache(nil);
- SelectedCode:=CodeToolBoss.LoadFile(SelectedUnitFilename, true, false);
- if SelectedCode=nil then begin
- debugln(['TCodeBrowserView.UseUnitInSrcEditor failed to load SelectedUnitFilename=',SelectedUnitFilename]);
- exit;
- end;
- SelectedUnitName:=CodeToolBoss.GetSourceName(SelectedCode, false);
- // add unit to uses section
- if not CodeToolBoss.AddUnitToMainUsesSection(TargetCode, SelectedUnitName,'') then
- begin
- DebugLn(['TCodeBrowserView.UseUnitInSrcEditor CodeToolBoss.'
- +'AddUnitToMainUsesSection failed: TargetCode=', TargetCode.Filename,
- ' SelectedUnitName=', SelectedUnitName]);
- LazarusIDE.DoJumpToCodeToolBossError;
- end;
- // insert identifier
- if InsertIdentifier then begin
- if CodeMarker.Deleted then begin
- DebugLn(['TCodeBrowserView.UseUnitInSrcEditor insert place was deleted']);
- exit;
- end;
- GetIdentStartEndAtPosition(Code.Source,CodeMarker.NewPosition,
- IdentStart,IdentEnd);
- Code.AbsoluteToLineCol(IdentStart,InsertStartPos.Y,InsertStartPos.X);
- InsertEndPos:=InsertStartPos;
- inc(InsertEndPos.X,IdentEnd-IdentStart);
- SrcEdit.ReplaceText(InsertStartPos,InsertEndPos,Identifier);
- end;
- finally
- List.Free;
- CodeMarker.Free;
- end;
- end;
- procedure TCodeBrowserView.Work(var Done: Boolean);
- // do some work
- // This is called during OnIdle, so progress in small steps
- var
- OldStage: TCodeBrowserWorkStage;
- begin
- OldStage:=fStage;
- case fStage of
- cbwsGetScopeOptions: WorkGetScopeOptions;
- cbwsGatherPackages: WorkGatherPackages;
- cbwsFreeUnusedPackages: WorkFreeUnusedPackages;
- cbwsAddNewPackages: WorkAddNewUnitLists;
- cbwsGatherFiles: WorkGatherFileLists;
- cbwsGatherOutdatedFiles: WorkGatherOutdatedFiles;
- cbwsUpdateUnits: WorkUpdateUnits;
- cbwsGetViewOptions: WorkGetViewOptions;
- cbwsUpdateTreeView: WorkUpdateTreeView;
- else
- FOptionsChangeStamp:=Options.ChangeStamp;
- UpdateNeeded:=false;
- Done:=true;
- ProgressBar1.Position:=ProgressTotal;
- ProgressBar1.Visible:=false;
- exit;
- end;
- if ord(OldStage)<ord(cbwsFinished) then begin
- Done:=false;
- ProgressBar1.Visible:=true;
- UpdateStatusBar(fStage<cbwsFinished);
- end;
- //if fStage=cbwsFinished then CodeToolBoss.WriteMemoryStats;
- end;
- procedure TCodeBrowserView.WorkGetScopeOptions;
- var
- CurChangStamp: LongInt;
- begin
- DebugLn(['TCodeBrowserView.WorkGetScopeOptions START']);
- IdleTimer1.Enabled:=false;
- ProgressBar1.Position:=ProgressGetScopeStart;
- CurChangStamp:=Options.ChangeStamp;
- Options.WithRequiredPackages:=ScopeWithRequiredPackagesCheckBox.Checked;
- Options.Scope:=ScopeComboBox.Text;
- // this stage finished -> next stage
- if UpdateNeeded or (Options.ChangeStamp<>CurChangStamp) then
- fStage:=cbwsGatherPackages
- else
- fStage:=cbwsGetViewOptions;
- ProgressBar1.Position:=ProgressGetScopeStart+ProgressGetScopeSize;
- end;
- procedure TCodeBrowserView.WorkGatherPackages;
- procedure AddPackage(APackage: TLazPackage);
- begin
- TCodeBrowserUnitList.Create(APackage.Name,FWorkingParserRoot);
- end;
-
- procedure AddPackages(FirstDependency: TPkgDependency);
- var
- List: TFPList;
- i: Integer;
- begin
- List:=nil;
- try
- PackageGraph.GetAllRequiredPackages(nil,FirstDependency,List);
- if (List=nil) then exit;
- for i:=0 to List.Count-1 do begin
- if TObject(List[i]) is TLazPackage then
- AddPackage(TLazPackage(List[i]));
- end;
- finally
- List.Free;
- end;
- end;
- var
- APackage: TLazPackage;
- RootOwner: string;
- i: Integer;
- begin
- // clean up
- if fOutdatedFiles<>nil then fOutdatedFiles.Clear;
- // find ParserRoot
- RootOwner:='';
- if Options.Scope=IDEDescription then begin
- RootOwner:=CodeBrowserIDEName;
- end else if Options.Scope=ProjectDescription then begin
- RootOwner:=CodeBrowserProjectName;
- end else begin
- APackage:=PackageGraph.FindPackageWithName(Options.Scope,nil);
- if APackage<>nil then
- RootOwner:=APackage.Name;
- end;
- DebugLn(['TCodeBrowserView.WorkGatherPackages RootOwner="',RootOwner,'"']);
- FreeAndNil(FWorkingParserRoot);
- FWorkingParserRoot:=TCodeBrowserUnitList.Create(RootOwner,nil);
-
- // find required packages
- if Options.WithRequiredPackages then begin
- if SysUtils.CompareText(FWorkingParserRoot.Owner,CodeBrowserIDEName)=0 then begin
- for i:=0 to PackageGraph.Count-1 do
- AddPackage(PackageGraph[i]);
- end else if SysUtils.CompareText(FWorkingParserRoot.Owner,CodeBrowserProjectName)=0
- then begin
- AddPackages(Project1.FirstRequiredDependency);
- end else if FWorkingParserRoot.Owner<>'' then begin
- APackage:=PackageGraph.FindPackageWithName(FWorkingParserRoot.Owner,nil);
- if APackage<>nil then
- AddPackages(APackage.FirstRequiredDependency);
- end;
- end;
-
- // update ParserRoot item (children will be updated on next Idle)
- if FParserRoot=nil then begin
- FParserRoot:=TCodeBrowserUnitList.Create(FWorkingParserRoot.Owner,nil);
- inc(FScannedPackages);
- end else begin
- FParserRoot.Owner:=FWorkingParserRoot.Owner;
- end;
-
- // this stage finished -> next stage
- fStage:=cbwsFreeUnusedPackages;
- ProgressBar1.Position:=ProgressGatherPackagesStart+ProgressGatherPackagesSize;
- end;
- procedure TCodeBrowserView.WorkFreeUnusedPackages;
- function FindUnusedUnitList: TCodeBrowserUnitList;
- var
- Node: TAVLTreeNode;
- UnusedPackage: TCodeBrowserUnitList;
- PackageName: String;
- begin
- // find an unused package (a package in ParserRoot but not in WorkingParserRoot)
- Result:=nil;
- if (FParserRoot=nil) or (FParserRoot.UnitLists=nil) then exit;
- Node:=FParserRoot.UnitLists.FindLowest;
- while Node<>nil do begin
- UnusedPackage:=TCodeBrowserUnitList(Node.Data);
- PackageName:=UnusedPackage.Owner;
- if (FWorkingParserRoot=nil)
- or (FWorkingParserRoot.UnitLists=nil)
- or (FWorkingParserRoot.UnitLists.FindKey(Pointer(PackageName),
- @CompareAnsiStringWithUnitListOwner)=nil)
- then begin
- Result:=UnusedPackage;
- exit;
- end;
- Node:=FParserRoot.UnitLists.FindSuccessor(Node);
- end;
- end;
-
- var
- UnusedPackage: TCodeBrowserUnitList;
- begin
- DebugLn(['TCodeBrowserView.WorkFreeUnusedPackages START']);
- // find an unused package
- UnusedPackage:=FindUnusedUnitList;
- if UnusedPackage=nil then begin
- // this stage finished -> next stage
- fStage:=cbwsAddNewPackages;
- ProgressBar1.Position:=ProgressFreeUnusedPkgStart+ProgressFreeUnusedPkgSize;
- exit;
- end;
- // free the unused package
- FreeUnitList(UnusedPackage);
- end;
- procedure TCodeBrowserView.WorkAddNewUnitLists;
- var
- Node: TAVLTreeNode;
- List: TCodeBrowserUnitList;
- begin
- ProgressBar1.Position:=ProgressAddNewUnitListsStart;
- if (FWorkingParserRoot<>nil) and (FWorkingParserRoot.UnitLists<>nil)
- and (FParserRoot<>nil) then begin
- Node:=FWorkingParserRoot.UnitLists.FindLowest;
- while Node<>nil do begin
- List:=TCodeBrowserUnitList(Node.Data);
- if FParserRoot.FindUnitList(List.Owner)=nil then begin
- // new unit list
- TCodeBrowserUnitList.Create(List.Owner,FParserRoot);
- inc(FScannedPackages);
- end;
- Node:=FWorkingParserRoot.UnitLists.FindSuccessor(Node);
- end;
- end;
-
- // this stage finished -> next stage
- fStage:=cbwsGatherFiles;
- ProgressBar1.Position:=ProgressAddNewUnitListsStart+ProgressAddNewUnitListsSize;
- end;
- procedure TCodeBrowserView.WorkGatherFileLists;
- function ListFilesAreValid(List: TCodeBrowserUnitList): boolean;
- begin
- Result:=List.UnitsValid;
- end;
- function FindListWithInvalidFileList(StartList: TCodeBrowserUnitList
- ): TCodeBrowserUnitList;
- var
- APackage: TCodeBrowserUnitList;
- Node: TAVLTreeNode;
- begin
- Result:=nil;
- if StartList=nil then exit;
- if not ListFilesAreValid(StartList) then begin
- Result:=StartList;
- exit;
- end;
- if (StartList.UnitLists=nil) then exit;
- Node:=StartList.UnitLists.FindLowest;
- while Node<>nil do begin
- APackage:=TCodeBrowserUnitList(Node.Data);
- Result:=FindListWithInvalidFileList(APackage);
- if Result<>nil then exit;
- Node:=StartList.UnitLists.FindSuccessor(Node);
- end;
- end;
- var
- List: TCodeBrowserUnitList;
- begin
- DebugLn(['TCodeBrowserView.WorkGatherFiles START']);
- // find a unit list which needs update
- List:=FindListWithInvalidFileList(FParserRoot);
- if List=nil then begin
- // this stage finished -> next stage
- fStage:=cbwsGatherOutdatedFiles;
- ProgressBar1.Position:=ProgressGatherFileListsStart+ProgressGatherFileListsSize;
- exit;
- end;
-
- WorkUpdateFileList(List);
- end;
- procedure TCodeBrowserView.WorkUpdateFileList(List: TCodeBrowserUnitList);
- var
- NewFileList: TAVLTree;
- procedure AddFile(const Filename: string; ClearIncludedByInfo: boolean);
- begin
- //DebugLn(['AddFile Filename="',Filename,'"']);
- if Filename='' then exit;
- if System.Pos('$',Filename)>0 then begin
- DebugLn(['WARNING: TCodeBrowserView.WorkUpdateFiles Macros in filename ',Filename]);
- exit;
- end;
- if NewFileList.FindKey(Pointer(Filename),@CompareAnsiStringWithUnitFilename)<>nil
- then exit;
- //DebugLn(['TCodeBrowserView.WorkUpdateFiles AddFile ',Filename]);
- NewFileList.Add(TCodeBrowserUnit.Create(Filename));
- if ClearIncludedByInfo then begin
- CodeToolBoss.SourceCache.ClearIncludedByEntry(Filename);
- end;
- end;
-
- procedure AddFilesOfProject(AProject: TProject);
- var
- AnUnitInfo: TUnitInfo;
- begin
- if AProject=nil then exit;
- AnUnitInfo:=AProject.FirstPartOfProject;
- //DebugLn(['AddFilesOfProject ',AnUnitInfo<>nil]);
- while AnUnitInfo<>nil do begin
- //DebugLn(['AddFilesOfProject ',AnUnitInfo.Filename]);
- if FilenameIsPascalUnit(AnUnitInfo.Filename)
- or (AnUnitInfo=aProject.MainUnitInfo) then
- AddFile(AnUnitInfo.Filename,false);
- AnUnitInfo:=AnUnitInfo.NextPartOfProject;
- end;
- end;
-
- procedure AddFilesOfPackageFCL;
- var
- LazDir: String;
- UnitSetID: string;
- UnitSetChanged: Boolean;
- UnitSet: TFPCUnitSetCache;
- Filename: String;
- ConfigCache: TFPCTargetConfigCache;
- Node: TAVLTreeNode;
- Item: PStringToStringTreeItem;
- begin
- // use unitset of the lazarus source directory
- LazDir:=AppendPathDelim(EnvironmentOptions.GetParsedLazarusDirectory);
- if (LazDir='') or (not FilenameIsAbsolute(LazDir)) then exit;
- UnitSetID:=CodeToolBoss.GetUnitSetIDForDirectory(LazDir);
- if UnitSetID='' then exit;
- UnitSetChanged:=false;
- UnitSet:=CodeToolBoss.FPCDefinesCache.FindUnitSetWithID(UnitSetID,
- UnitSetChanged,false);
- if UnitSet=nil then exit;
- ConfigCache:=UnitSet.GetConfigCache(false);
- if (ConfigCache=nil) or (ConfigCache.Units=nil) then exit;
- Node:=ConfigCache.Units.Tree.FindLowest;
- while Node<>nil do begin
- Item:=PStringToStringTreeItem(Node.Data);
- Filename:=Item^.Value;
- if (CompareFileExt(Filename,'ppu',false)=0) then begin
- // search source in fpc sources
- Filename:=UnitSet.GetUnitSrcFile(ExtractFileNameOnly(Filename));
- end;
- if FilenameIsPascalUnit(Filename) then
- AddFile(Filename,false);
- Node:=ConfigCache.Units.Tree.F…