mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 13:00:31 +02:00
IDE: codebrowser: implemented use identifier in unit
git-svn-id: trunk@21530 -
This commit is contained in:
parent
eb1302950c
commit
1a98815a5b
@ -74,7 +74,7 @@ object CodeBrowserView: TCodeBrowserView
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 53
|
||||
Top = 202
|
||||
Top = 187
|
||||
Width = 611
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
@ -133,8 +133,8 @@ object CodeBrowserView: TCodeBrowserView
|
||||
AnchorSideTop.Control = OptionsGroupBox
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 261
|
||||
Top = 261
|
||||
Height = 276
|
||||
Top = 246
|
||||
Width = 623
|
||||
Align = alBottom
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
@ -164,14 +164,14 @@ object CodeBrowserView: TCodeBrowserView
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 124
|
||||
Height = 109
|
||||
Top = 72
|
||||
Width = 611
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'LevelsGroupBox'
|
||||
ClientHeight = 105
|
||||
ClientHeight = 90
|
||||
ClientWidth = 607
|
||||
TabOrder = 3
|
||||
object PackageFilterBeginsSpeedButton: TSpeedButton
|
||||
@ -407,17 +407,21 @@ object CodeBrowserView: TCodeBrowserView
|
||||
object CopySeparatorMenuItem: TMenuItem
|
||||
Caption = '-'
|
||||
end
|
||||
object AddUnitToCurUnitMenuItem: TMenuItem
|
||||
Caption = 'AddUnitToCurUnitMenuItem'
|
||||
OnClick = AddUnitToCurUnitMenuItemClick
|
||||
object UseUnitInCurUnitMenuItem: TMenuItem
|
||||
Caption = 'UseUnitInCurUnitMenuItem'
|
||||
OnClick = UseUnitInCurUnitMenuItemClick
|
||||
end
|
||||
object AddPkgToProjectMenuItem: TMenuItem
|
||||
Caption = 'AddPkgToProjectMenuItem'
|
||||
OnClick = AddPkgToProjectMenuItemClick
|
||||
object UseIdentifierInCurUnitMenuItem: TMenuItem
|
||||
Caption = 'UseIdentifierInCurUnitMenuItem'
|
||||
OnClick = UseIdentifierInCurUnitMenuItemClick
|
||||
end
|
||||
object AddPkgToCurUnitMenuItem: TMenuItem
|
||||
Caption = 'AddPkgToCurUnitMenuItem'
|
||||
OnClick = AddPkgToCurUnitMenuItemClick
|
||||
object UsePkgInProjectMenuItem: TMenuItem
|
||||
Caption = 'UsePkgInProjectMenuItem'
|
||||
OnClick = UsePkgInProjectMenuItemClick
|
||||
end
|
||||
object UsePkgInCurUnitMenuItem: TMenuItem
|
||||
Caption = 'UsePkgInCurUnitMenuItem'
|
||||
OnClick = UsePkgInCurUnitMenuItemClick
|
||||
end
|
||||
object UseSeparatorMenuItem: TMenuItem
|
||||
Caption = '-'
|
||||
|
@ -26,7 +26,7 @@ LazarusResources.Add('TCodeBrowserView','FORMDATA',[
|
||||
+'onsGroupBox'#22'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorSideTop.Control'
|
||||
+#7#14'LevelsGroupBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#23'AnchorSideRig'
|
||||
+'ht.Control'#7#5'Owner'#20'AnchorSideRight.Side'#7#9'asrBottom'#21'AnchorSid'
|
||||
+'eBottom.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2'5'#3'Top'#3#202#0#5'Wi'
|
||||
+'eBottom.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2'5'#3'Top'#3#187#0#5'Wi'
|
||||
+'dth'#3'c'#2#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'AutoSize'#9#18
|
||||
+'BorderSpacing.Left'#2#6#17'BorderSpacing.Top'#2#6#19'BorderSpacing.Right'#2
|
||||
+#6#7'Caption'#6#15'OptionsGroupBox'#29'ChildSizing.EnlargeHorizontal'#7#24'c'
|
||||
@ -49,8 +49,8 @@ LazarusResources.Add('TCodeBrowserView','FORMDATA',[
|
||||
+'g.Around'#2#6#7'Caption'#6#22'ShowEmptyNodesCheckBox'#13'OnEditingDone'#7#25
|
||||
+'ShowPrivateCheckBoxChange'#8'TabOrder'#2#2#0#0#0#9'TTreeView'#14'BrowseTree'
|
||||
+'View'#21'AnchorSideTop.Control'#7#15'OptionsGroupBox'#18'AnchorSideTop.Side'
|
||||
+#7#9'asrBottom'#4'Left'#2#0#6'Height'#3#5#1#3'Top'#3#5#1#5'Width'#3'o'#2#5'A'
|
||||
+'lign'#7#8'alBottom'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'
|
||||
+#7#9'asrBottom'#4'Left'#2#0#6'Height'#3#20#1#3'Top'#3#246#0#5'Width'#3'o'#2#5
|
||||
+'Align'#7#8'alBottom'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'
|
||||
+#0#17'BorderSpacing.Top'#2#6#17'DefaultItemHeight'#2#19#6'Images'#7#10'Image'
|
||||
+'List1'#14'ParentShowHint'#8#9'PopupMenu'#7#10'PopupMenu1'#8'ReadOnly'#9#8'S'
|
||||
+'howHint'#9#8'TabOrder'#2#2#11'OnMouseDown'#7#23'BrowseTreeViewMouseDown'#10
|
||||
@ -61,9 +61,9 @@ LazarusResources.Add('TCodeBrowserView','FORMDATA',[
|
||||
+'anels'#14#0#0#0#9'TGroupBox'#14'LevelsGroupBox'#22'AnchorSideLeft.Control'#7
|
||||
+#5'Owner'#21'AnchorSideTop.Control'#7#13'ScopeGroupBox'#18'AnchorSideTop.Sid'
|
||||
+'e'#7#9'asrBottom'#23'AnchorSideRight.Control'#7#5'Owner'#20'AnchorSideRight'
|
||||
+'.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2'|'#3'Top'#2'H'#5'Width'#3'c'#2
|
||||
+'.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2'm'#3'Top'#2'H'#5'Width'#3'c'#2
|
||||
+#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'AutoSize'#9#20'BorderSpacin'
|
||||
+'g.Around'#2#6#7'Caption'#6#14'LevelsGroupBox'#12'ClientHeight'#2'i'#11'Clie'
|
||||
+'g.Around'#2#6#7'Caption'#6#14'LevelsGroupBox'#12'ClientHeight'#2'Z'#11'Clie'
|
||||
+'ntWidth'#3'_'#2#8'TabOrder'#2#3#0#12'TSpeedButton'#30'PackageFilterBeginsSp'
|
||||
,'eedButton'#22'AnchorSideLeft.Control'#7#17'PackageFilterEdit'#19'AnchorSide'
|
||||
+'Left.Side'#7#9'asrBottom'#21'AnchorSideTop.Control'#7#17'PackageFilterEdit'
|
||||
@ -151,12 +151,14 @@ LazarusResources.Add('TCodeBrowserView','FORMDATA',[
|
||||
+'tem'#7'OnClick'#7#28'CopyDescriptionMenuItemClick'#0#0#9'TMenuItem'#22'Copy'
|
||||
+'IdentifierMenuItem'#7'Caption'#6#22'CopyIdentifierMenuItem'#7'OnClick'#7#27
|
||||
+'CopyIdentifierMenuItemClick'#0#0#9'TMenuItem'#21'CopySeparatorMenuItem'#7'C'
|
||||
+'aption'#6#1'-'#0#0#9'TMenuItem'#24'AddUnitToCurUnitMenuItem'#7'Caption'#6#24
|
||||
+'AddUnitToCurUnitMenuItem'#7'OnClick'#7#29'AddUnitToCurUnitMenuItemClick'#0#0
|
||||
+#9'TMenuItem'#23'AddPkgToProjectMenuItem'#7'Caption'#6#23'AddPkgToProjectMen'
|
||||
+'uItem'#7'OnClick'#7#28'AddPkgToProjectMenuItemClick'#0#0#9'TMenuItem'#23'Ad'
|
||||
+'dPkgToCurUnitMenuItem'#7'Caption'#6#23'AddPkgToCurUnitMenuItem'#7'OnClick'#7
|
||||
+#28'AddPkgToCurUnitMenuItemClick'#0#0#9'TMenuItem'#20'UseSeparatorMenuItem'#7
|
||||
+'aption'#6#1'-'#0#0#9'TMenuItem'#24'UseUnitInCurUnitMenuItem'#7'Caption'#6#24
|
||||
+'UseUnitInCurUnitMenuItem'#7'OnClick'#7#29'UseUnitInCurUnitMenuItemClick'#0#0
|
||||
+#9'TMenuItem'#30'UseIdentifierInCurUnitMenuItem'#7'Caption'#6#30'UseIdentifi'
|
||||
+'erInCurUnitMenuItem'#7'OnClick'#7'#UseIdentifierInCurUnitMenuItemClick'#0#0
|
||||
+#9'TMenuItem'#23'UsePkgInProjectMenuItem'#7'Caption'#6#23'UsePkgInProjectMen'
|
||||
+'uItem'#7'OnClick'#7#28'UsePkgInProjectMenuItemClick'#0#0#9'TMenuItem'#23'Us'
|
||||
+'ePkgInCurUnitMenuItem'#7'Caption'#6#23'UsePkgInCurUnitMenuItem'#7'OnClick'#7
|
||||
+#28'UsePkgInCurUnitMenuItemClick'#0#0#9'TMenuItem'#20'UseSeparatorMenuItem'#7
|
||||
+'Caption'#6#1'-'#0#0#9'TMenuItem'#25'ExpandAllPackagesMenuItem'#7'Caption'#6
|
||||
+#25'ExpandAllPackagesMenuItem'#7'OnClick'#7#30'ExpandAllPackagesMenuItemClic'
|
||||
+'k'#0#0#9'TMenuItem'#27'CollapseAllPackagesMenuItem'#7'Caption'#6#27'Collaps'
|
||||
|
@ -32,8 +32,7 @@
|
||||
The codetools provides TCodeTree of every unit.
|
||||
|
||||
ToDo:
|
||||
- add package+unit+identifier to editor caret
|
||||
- show first results after parsing every package
|
||||
- pause
|
||||
- scan recently used packages
|
||||
- scan packages in global links
|
||||
}
|
||||
@ -44,12 +43,13 @@ unit CodeBrowser;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
Clipbrd, LCLIntf, AVL_Tree, StdCtrls, ExtCtrls, ComCtrls, Buttons, Menus,
|
||||
Classes, SysUtils, types, LCLProc, LResources, Forms, Controls, Graphics,
|
||||
Dialogs, Clipbrd, LCLIntf, AVL_Tree, StdCtrls, ExtCtrls, ComCtrls, Buttons,
|
||||
Menus,
|
||||
// codetools
|
||||
CodeAtom, BasicCodeTools, DefineTemplates, CodeTree, CodeCache,
|
||||
CodeToolManager, PascalParserTool, LinkScanner, FileProcs, CodeIndex,
|
||||
StdCodeTools,
|
||||
StdCodeTools, SourceLog,
|
||||
// IDEIntf
|
||||
SrcEditorIntf, IDEDialogs, LazConfigStorage, Project, PackageIntf,
|
||||
IDECommands, LazIDEIntf, DialogProcs,
|
||||
@ -172,11 +172,12 @@ type
|
||||
AllPackagesSeparatorMenuItem: TMenuItem;
|
||||
AllUnitsSeparatorMenuItem: TMenuItem;
|
||||
BrowseTreeView: TTreeView;
|
||||
AddUnitToCurUnitMenuItem: TMenuItem;
|
||||
UseIdentifierInCurUnitMenuItem: TMenuItem;
|
||||
UseUnitInCurUnitMenuItem: TMenuItem;
|
||||
RescanButton: TButton;
|
||||
IdleTimer1: TIdleTimer;
|
||||
AddPkgToProjectMenuItem: TMenuItem;
|
||||
AddPkgToCurUnitMenuItem: TMenuItem;
|
||||
UsePkgInProjectMenuItem: TMenuItem;
|
||||
UsePkgInCurUnitMenuItem: TMenuItem;
|
||||
UseSeparatorMenuItem: TMenuItem;
|
||||
ShowEmptyNodesCheckBox: TCheckBox;
|
||||
CollapseAllClassesMenuItem: TMenuItem;
|
||||
@ -213,9 +214,10 @@ type
|
||||
UnitFilterBeginsSpeedButton: TSpeedButton;
|
||||
UnitFilterContainsSpeedButton: TSpeedButton;
|
||||
UnitFilterEdit: TEdit;
|
||||
procedure AddPkgToCurUnitMenuItemClick(Sender: TObject);
|
||||
procedure AddPkgToProjectMenuItemClick(Sender: TObject);
|
||||
procedure AddUnitToCurUnitMenuItemClick(Sender: TObject);
|
||||
procedure UseIdentifierInCurUnitMenuItemClick(Sender: TObject);
|
||||
procedure UsePkgInCurUnitMenuItemClick(Sender: TObject);
|
||||
procedure UsePkgInProjectMenuItemClick(Sender: TObject);
|
||||
procedure UseUnitInCurUnitMenuItemClick(Sender: TObject);
|
||||
procedure BrowseTreeViewMouseDown(Sender: TOBject; Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer);
|
||||
procedure BrowseTreeViewShowHint(Sender: TObject; HintInfo: PHintInfo);
|
||||
@ -329,6 +331,7 @@ type
|
||||
out UnitCode: TCodeBuffer): boolean;
|
||||
function GetCurPackageInSrcEditor: TLazPackage;
|
||||
procedure OpenTVNode(TVNode: TTreeNode);
|
||||
procedure UseUnitInSrcEditor(InsertIdentifier: boolean);
|
||||
public
|
||||
procedure BeginUpdate;
|
||||
procedure EndUpdate;
|
||||
@ -421,9 +424,9 @@ begin
|
||||
CollapseAllClassesMenuItem.Caption:=lisCollapseAllClasses;
|
||||
ExportMenuItem.Caption:=lisExport;
|
||||
OpenMenuItem.Caption:=lisHintOpen;
|
||||
// AddPkgToProjectMenuItem.Caption: see PopupMenu1Popup
|
||||
// AddPkgToCurUnitMenuItem.Caption: see PopupMenu1Popup
|
||||
// AddUnitToCurUnitMenuItem.Caption: see PopupMenu1Popup
|
||||
// UsePkgInProjectMenuItem.Caption: see PopupMenu1Popup
|
||||
// UsePkgInCurUnitMenuItem.Caption: see PopupMenu1Popup
|
||||
// UseUnitInCurUnitMenuItem.Caption: see PopupMenu1Popup
|
||||
|
||||
PackageFilterBeginsSpeedButton.Caption:=lisBegins;
|
||||
PackageFilterBeginsSpeedButton.Hint:=lisPackageNameBeginsWith;
|
||||
@ -479,16 +482,19 @@ var
|
||||
Node: TObject;
|
||||
Identifier: String;
|
||||
UnitList: TCodeBrowserUnitList;
|
||||
EnableAddPkgToProject: Boolean;
|
||||
EnableUsePkgInProject: Boolean;
|
||||
APackage: TLazPackage;
|
||||
EnableAddPkgToCurUnit: Boolean;
|
||||
EnableUsePkgInCurUnit: Boolean;
|
||||
TargetPackage: TLazPackage;
|
||||
EnableUnitToCurUnit: Boolean;
|
||||
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;
|
||||
@ -506,19 +512,23 @@ begin
|
||||
Node:=nil;
|
||||
if TVNode<>nil then
|
||||
Node:=TObject(TVNode.Data);
|
||||
EnableAddPkgToProject:=false;
|
||||
EnableAddPkgToCurUnit:=false;
|
||||
EnableUnitToCurUnit:=false;
|
||||
EnableUsePkgInProject:=false;
|
||||
EnableUsePkgInCurUnit:=false;
|
||||
EnableUseUnitInCurUnit:=false;
|
||||
EnableUseIdentifierInCurUnit:=false;
|
||||
if Node<>nil then begin
|
||||
if Node is TCodeBrowserNode then
|
||||
Identifier:=TCodeBrowserNode(Node).Identifier
|
||||
else
|
||||
Identifier:='';
|
||||
Identifier:='';
|
||||
APackage:=nil;
|
||||
UnitList:=nil;
|
||||
CurUnit:=nil;
|
||||
TargetPackage:=nil;
|
||||
if Node is TCodeBrowserUnit then begin
|
||||
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
|
||||
@ -537,8 +547,8 @@ begin
|
||||
if APackage<>nil then begin
|
||||
// check if package can be added to project
|
||||
if Project1.FindDependencyByName(APackage.Name)=nil then begin
|
||||
EnableAddPkgToProject:=true;
|
||||
AddPkgToProjectMenuItem.Caption:=Format(lisUsePackageInProject, [
|
||||
EnableUsePkgInProject:=true;
|
||||
UsePkgInProjectMenuItem.Caption:=Format(lisUsePackageInProject, [
|
||||
APackage.Name]);
|
||||
end;
|
||||
// check if package can be added to package of src editor unit
|
||||
@ -546,8 +556,8 @@ begin
|
||||
if (TargetPackage<>nil)
|
||||
and (SysUtils.CompareText(TargetPackage.Name,APackage.Name)<>0)
|
||||
and (TargetPackage.FindDependencyByName(APackage.Name)=nil) then begin
|
||||
EnableAddPkgToCurUnit:=true;
|
||||
AddPkgToCurUnitMenuItem.Caption:=Format(
|
||||
EnableUsePkgInCurUnit:=true;
|
||||
UsePkgInCurUnitMenuItem.Caption:=Format(
|
||||
lisUsePackageInPackage, [APackage.Name,
|
||||
TargetPackage.Name]);
|
||||
end;
|
||||
@ -557,9 +567,16 @@ begin
|
||||
CurUnitName:=ExtractFileNameOnly(CurUnit.Filename);
|
||||
SrcEditUnitName:=ExtractFileNameOnly(SrcEditUnitCode.Filename);
|
||||
if SysUtils.CompareText(CurUnitName,SrcEditUnitName)<>0 then begin
|
||||
EnableUnitToCurUnit:=true;
|
||||
AddUnitToCurUnitMenuItem.Caption:=
|
||||
EnableUseUnitInCurUnit:=true;
|
||||
UseUnitInCurUnitMenuItem.Caption:=
|
||||
Format(lisUseUnitInUnit, [CurUnitName, SrcEditUnitName]);
|
||||
if (Node is TCodeBrowserNode) and (Identifier<>'') then begin
|
||||
EnableUseIdentifierInCurUnit:=true;
|
||||
SrcEdit:=SourceEditorWindow.ActiveEditor;
|
||||
UseIdentifierInCurUnitMenuItem.Caption:=
|
||||
Format(lisUseIdentifierInAt, [Identifier, ExtractFilename(
|
||||
SrcEdit.FileName), dbgs(SrcEdit.CursorScreenXY)]);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -572,26 +589,35 @@ begin
|
||||
CopyDescriptionMenuItem.Visible:=true;
|
||||
CopyIdentifierMenuItem.Visible:=Identifier<>'';
|
||||
CopySeparatorMenuItem.Visible:=true;
|
||||
AddUnitToCurUnitMenuItem.Enabled:=EnableUnitToCurUnit;
|
||||
AddUnitToCurUnitMenuItem.Visible:=true;
|
||||
if not EnableUnitToCurUnit then
|
||||
AddUnitToCurUnitMenuItem.Caption:=lisPkgMangUseUnit;
|
||||
AddPkgToProjectMenuItem.Enabled:=EnableAddPkgToProject;
|
||||
AddPkgToProjectMenuItem.Visible:=true;
|
||||
if not EnableAddPkgToProject then
|
||||
AddPkgToProjectMenuItem.Caption:=lisUsePackageInProject2;
|
||||
AddPkgToCurUnitMenuItem.Enabled:=EnableAddPkgToCurUnit;
|
||||
AddPkgToCurUnitMenuItem.Visible:=true;
|
||||
if not EnableAddPkgToCurUnit then
|
||||
AddPkgToCurUnitMenuItem.Caption:=lisUsePackageInPackage2;
|
||||
|
||||
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;
|
||||
AddUnitToCurUnitMenuItem.Visible:=false;
|
||||
AddPkgToProjectMenuItem.Visible:=false;
|
||||
AddPkgToCurUnitMenuItem.Visible:=false;
|
||||
UseUnitInCurUnitMenuItem.Visible:=false;
|
||||
UseIdentifierInCurUnitMenuItem.Visible:=false;
|
||||
UsePkgInProjectMenuItem.Visible:=false;
|
||||
UsePkgInCurUnitMenuItem.Visible:=false;
|
||||
UseSeparatorMenuItem.Visible:=false;
|
||||
end;
|
||||
end;
|
||||
@ -812,6 +838,164 @@ begin
|
||||
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;
|
||||
InsertPos: TPoint;
|
||||
Code: TCodeBuffer;
|
||||
CodeMarker: TSourceLogMarker;
|
||||
Identifier: String;
|
||||
SelectedUnitFilename: String;
|
||||
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']);
|
||||
MessageDlg('Implement me',
|
||||
'TCodeBrowserView.UseUnitInSrcEditor not implemented: '
|
||||
+'SelectedUnit.UnitList=nil',
|
||||
mtInformation, [mbOk], 0);
|
||||
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.FindAPackageWithName(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)]);
|
||||
MessageDlg('Implement me',
|
||||
'TCodeBrowserView.UseUnitInSrcEditor not implemented: '
|
||||
+'TargetOwner='+DbgSName(TargetOwner),
|
||||
mtInformation, [mbOk], 0);
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (SelectedOwner is TProject) and (TargetOwner<>SelectedOwner) then begin
|
||||
// unit of project can not be used by other packages/projects
|
||||
MessageDlg('Impossible',
|
||||
'unit of project can not be used by other packages/projects',
|
||||
mtError, [mbCancel], 0);
|
||||
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:=SourceEditorWindow.ActiveEditor;
|
||||
if SrcEdit=nil then exit;
|
||||
InsertPos:=SrcEdit.CursorTextXY;
|
||||
Code:=TCodeBuffer(SrcEdit.CodeToolsBuffer);
|
||||
CodeMarker:=Code.AddMarkerXY(InsertPos.Y,InsertPos.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
|
||||
if not LazarusIDE.SaveSourceEditorChangesToCodeCache(-1) then begin
|
||||
DebugLn(['TCodeBrowserView.UseUnitInSrcEditor LazarusIDE.'
|
||||
+'SaveSourceEditorChangesToCodeCache failed']);
|
||||
exit;
|
||||
end;
|
||||
SelectedCode:=CodeToolBoss.LoadFile(SelectedUnitFilename, true, false);
|
||||
if SelectedCode=nil then exit;
|
||||
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;
|
||||
Code.AbsoluteToLineCol(CodeMarker.NewPosition,InsertPos.Y,InsertPos.X);
|
||||
SrcEdit.ReplaceText(InsertPos,InsertPos,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
|
||||
@ -2553,7 +2737,7 @@ begin
|
||||
OpenTVNode(BrowseTreeView.GetNodeAt(X,Y));
|
||||
end;
|
||||
|
||||
procedure TCodeBrowserView.AddPkgToProjectMenuItemClick(Sender: TObject);
|
||||
procedure TCodeBrowserView.UsePkgInProjectMenuItemClick(Sender: TObject);
|
||||
var
|
||||
APackage: TLazPackage;
|
||||
begin
|
||||
@ -2562,100 +2746,12 @@ begin
|
||||
PkgBoss.AddProjectDependency(Project1,APackage);
|
||||
end;
|
||||
|
||||
procedure TCodeBrowserView.AddUnitToCurUnitMenuItemClick(Sender: TObject);
|
||||
var
|
||||
SelectedUnit: TCodeBrowserUnit;
|
||||
TargetOwner: TObject;
|
||||
TargetCode: TCodeBuffer;
|
||||
APackage: TLazPackage;
|
||||
SelectedOwner: TObject;
|
||||
List: TFPList;
|
||||
SelectedCode: TCodeBuffer;
|
||||
SelectedUnitName: String;
|
||||
procedure TCodeBrowserView.UseUnitInCurUnitMenuItemClick(Sender: TObject);
|
||||
begin
|
||||
SelectedUnit:=GetSelectedUnit;
|
||||
if (SelectedUnit=nil) then exit;
|
||||
if SelectedUnit.UnitList=nil then begin
|
||||
DebugLn(['TCodeBrowserView.AddUnitToCurUnitMenuItemClick not implemented: SelectedUnit.UnitList=nil']);
|
||||
MessageDlg('Implement me',
|
||||
'TCodeBrowserView.AddUnitToCurUnitMenuItemClick not implemented: SelectedUnit.UnitList=nil',
|
||||
mtInformation,[mbOk],0);
|
||||
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.AddUnitToCurUnitMenuItemClick IDE can not be added as dependency']);
|
||||
exit;
|
||||
end else if SelectedUnit.UnitList.Owner=CodeBrowserHidden then begin
|
||||
// nothing
|
||||
DebugLn(['TCodeBrowserView.AddUnitToCurUnitMenuItemClick hidden unitlist']);
|
||||
exit;
|
||||
end else begin
|
||||
// package
|
||||
APackage:=PackageGraph.FindAPackageWithName(SelectedUnit.UnitList.Owner,nil);
|
||||
if APackage=nil then begin
|
||||
DebugLn(['TCodeBrowserView.AddUnitToCurUnitMenuItemClick 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.AddUnitToCurUnitMenuItemClick not implemented: TargetOwner=',DbgSName(TargetOwner)]);
|
||||
MessageDlg('Implement me',
|
||||
'TCodeBrowserView.AddUnitToCurUnitMenuItemClick not implemented: TargetOwner='+DbgSName(TargetOwner),
|
||||
mtInformation,[mbOk],0);
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (SelectedOwner is TProject) and (TargetOwner<>SelectedOwner) then begin
|
||||
// unit of project can not be used by other packages/projects
|
||||
MessageDlg('Impossible',
|
||||
'unit of project can not be used by other packages/projects',
|
||||
mtError,[mbCancel],0);
|
||||
exit;
|
||||
end;
|
||||
|
||||
List:=TFPList.Create;
|
||||
try
|
||||
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.AddUnitToCurUnitMenuItemClick PkgBoss.AddDependencyToOwners failed']);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
// get nice unit name
|
||||
if not LazarusIDE.SaveSourceEditorChangesToCodeCache(-1) then begin
|
||||
DebugLn(['TCodeBrowserView.AddUnitToCurUnitMenuItemClick LazarusIDE.SaveSourceEditorChangesToCodeCache failed']);
|
||||
exit;
|
||||
end;
|
||||
SelectedCode:=CodeToolBoss.LoadFile(SelectedUnit.Filename,true,false);
|
||||
if SelectedCode=nil then exit;
|
||||
SelectedUnitName:=CodeToolBoss.GetSourceName(SelectedCode,false);
|
||||
|
||||
// add unit to uses section
|
||||
if not CodeToolBoss.AddUnitToMainUsesSection(TargetCode,SelectedUnitName,'')
|
||||
then begin
|
||||
DebugLn(['TCodeBrowserView.AddUnitToCurUnitMenuItemClick CodeToolBoss.AddUnitToMainUsesSection failed: TargetCode=',TargetCode.Filename,' SelectedUnitName=',SelectedUnitName]);
|
||||
LazarusIDE.DoJumpToCodeToolBossError;
|
||||
end;
|
||||
finally
|
||||
List.Free;
|
||||
end;
|
||||
UseUnitInSrcEditor(false);
|
||||
end;
|
||||
|
||||
procedure TCodeBrowserView.AddPkgToCurUnitMenuItemClick(Sender: TObject);
|
||||
procedure TCodeBrowserView.UsePkgInCurUnitMenuItemClick(Sender: TObject);
|
||||
var
|
||||
APackage: TLazPackage;
|
||||
TargetPackage: TLazPackage;
|
||||
@ -2676,6 +2772,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCodeBrowserView.UseIdentifierInCurUnitMenuItemClick(Sender: TObject);
|
||||
begin
|
||||
UseUnitInSrcEditor(true);
|
||||
end;
|
||||
|
||||
{ TCodeBrowserViewOptions }
|
||||
|
||||
procedure TCodeBrowserViewOptions.SetModified(const AValue: boolean);
|
||||
|
@ -1850,6 +1850,7 @@ resourcestring
|
||||
lisEMDRemoveMethods = 'Remove methods';
|
||||
lisRoot = 'Root';
|
||||
lisCopyDescription = 'Copy description to clipboard';
|
||||
lisUseIdentifierInAt = 'Use identifier %s in %s at %s';
|
||||
lisCopyIdentifier = 'Copy %s%s%s to clipboard';
|
||||
lisExpandAllPackages = 'Expand all packages';
|
||||
lisCollapseAllPackages = 'Collapse all packages';
|
||||
@ -4469,6 +4470,7 @@ resourcestring
|
||||
lisRescan = 'Rescan';
|
||||
lisUseUnitInUnit = 'Use unit %s in unit %s';
|
||||
lisUsePackageInProject2 = 'Use package in project';
|
||||
lisUseIdentifier = 'Use identifier';
|
||||
lisUsePackageInPackage2 = 'Use package in package';
|
||||
|
||||
implementation
|
||||
|
Loading…
Reference in New Issue
Block a user