From 4f26caa11dd643a009cf4cb8591ae617b5d53e68 Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 22 Mar 2011 12:51:41 +0000 Subject: [PATCH] IDE: codeexplorer: show source editor node in implementation git-svn-id: trunk@29981 - --- components/codetools/customcodetool.pas | 4 +- components/codetools/linkscanner.pas | 31 +++++++++----- ide/codeexplorer.pas | 57 ++++++++++++++++++++----- ide/lazarusidestrconsts.pas | 1 + 4 files changed, 70 insertions(+), 23 deletions(-) diff --git a/components/codetools/customcodetool.pas b/components/codetools/customcodetool.pas index 0d57d4c3ab..5a1565850c 100644 --- a/components/codetools/customcodetool.pas +++ b/components/codetools/customcodetool.pas @@ -2398,9 +2398,9 @@ function TCustomCodeTool.CaretToCleanPos(const Caret: TCodeXYPosition; out CleanPos: integer): integer; begin CleanPos:=0; - //DebugLn('TCustomCodeTool.CaretToCleanPos A ',Caret.Code.Filename,' ',Caret.Code.SourceLength); + //DebugLn(['TCustomCodeTool.CaretToCleanPos A ',Caret.Code.Filename,' ',Caret.Y,',',Caret.X,' ',Caret.Code.SourceLength]); Caret.Code.LineColToPosition(Caret.Y,Caret.X,CleanPos); - //DebugLn('TCustomCodeTool.CaretToCleanPos B ',CleanPos,',',Caret.Y,',',Caret.X); + //DebugLn(['TCustomCodeTool.CaretToCleanPos B ',CleanPos,',',Caret.Y,',',Caret.X,' ',dbgstr(copy(Caret.Code.Source,CleanPos-20,20)),'|',dbgstr(copy(Caret.Code.Source,CleanPos,20))]); if (CleanPos>=1) then Result:=Scanner.CursorToCleanPos(CleanPos,Caret.Code,CleanPos) else diff --git a/components/codetools/linkscanner.pas b/components/codetools/linkscanner.pas index 0ff08aa290..ea9df348e5 100644 --- a/components/codetools/linkscanner.pas +++ b/components/codetools/linkscanner.pas @@ -419,6 +419,7 @@ type function LinkIndexAtCursorPos(ACursorPos: integer; ACode: Pointer): integer; function LinkSize(Index: integer): integer; function LinkCleanedEndPos(Index: integer): integer; + function LinkSourceLog(Index: integer): TSourceLog; function FindFirstSiblingLink(LinkIndex: integer): integer; function FindParentLink(LinkIndex: integer): integer; function LinkIndexNearCursorPos(ACursorPos: integer; ACode: Pointer; @@ -794,6 +795,14 @@ begin Result:=FLinks[Index].CleanedPos+LinkSize(Index); end; +function TLinkScanner.LinkSourceLog(Index: integer): TSourceLog; +begin + if Assigned(OnGetSource) then + Result:=OnGetSource(Self,FLinks[Index].Code) + else + Result:=nil; +end; + function TLinkScanner.FindFirstSiblingLink(LinkIndex: integer): integer; { find link at the start of the code e.g. The resulting link SrcPos is always 1 @@ -3560,27 +3569,28 @@ function TLinkScanner.CursorToCleanPos(ACursorPos: integer; ACode: pointer; var i, j, SkippedCleanPos: integer; SkippedPos: boolean; + Link: PSourceLink; begin i:=0; SkippedPos:=false; SkippedCleanPos:=-1; ACleanPos:=0; while i search next end; // search next - i:=j-1; + i:=j; end else begin // in last link //DebugLn(['[TLinkScanner.CursorToCleanPos] E ACleanPos=',ACleanPos,' CleanedLen=',CleanedLen]); @@ -3608,8 +3619,8 @@ begin end; break; end; - end; - inc(i); + end else + inc(i); end; if SkippedPos then begin Result:=-1; diff --git a/ide/codeexplorer.pas b/ide/codeexplorer.pas index 3234925416..c92c77da02 100644 --- a/ide/codeexplorer.pas +++ b/ide/codeexplorer.pas @@ -147,6 +147,7 @@ type procedure IdleTimer1Timer(Sender: TObject); procedure JumpToMenuItemClick(Sender: TObject); procedure JumpToImplementationMenuItemClick(Sender: TObject); + procedure ShowSrcEditPosMenuItemClick(Sender: TObject); procedure MainNotebookPageChanged(Sender: TObject); procedure ModeSpeedButtonClick(Sender: TObject); procedure OptionsSpeedButtonClick(Sender: TObject); @@ -275,6 +276,7 @@ var CodeExplorerView: TCodeExplorerView = nil; CEJumpToIDEMenuCommand: TIDEMenuCommand; CEJumpToImplementationIDEMenuCommand: TIDEMenuCommand; + CEShowSrcEditPosIDEMenuCommand: TIDEMenuCommand; CERefreshIDEMenuCommand: TIDEMenuCommand; CERenameIDEMenuCommand: TIDEMenuCommand; @@ -294,7 +296,7 @@ type TViewNodeData = class public - CTNode: TCodeTreeNode; // only valid during update, other times it is nil + CTNode: TCodeTreeNode; // only valid during update, at other times it is nil Desc: TCodeTreeNodeDesc; SubDesc: TCodeTreeNodeSubDesc; StartPos, EndPos: integer; @@ -366,6 +368,8 @@ begin ); CEJumpToImplementationIDEMenuCommand:=RegisterIDEMenuCommand(Path, 'Jump to implementation', lisMenuJumpToImplementation); + CEShowSrcEditPosIDEMenuCommand:=RegisterIDEMenuCommand(Path, 'Show position of source editor', + lisShowPositionOfSourceEditor); CERefreshIDEMenuCommand:=RegisterIDEMenuCommand(Path, 'Refresh', dlgUnitDepRefresh); CERenameIDEMenuCommand:=RegisterIDEMenuCommand(Path, 'Rename', lisFRIRename); @@ -487,6 +491,7 @@ begin CEJumpToIDEMenuCommand.OnClick:=@JumpToMenuItemClick; CEJumpToImplementationIDEMenuCommand.OnClick:=@JumpToImplementationMenuItemClick; + CEShowSrcEditPosIDEMenuCommand.OnClick:=@ShowSrcEditPosMenuItemClick; CERefreshIDEMenuCommand.OnClick:=@RefreshMenuItemClick; CERenameIDEMenuCommand.OnClick:=@RenameMenuItemClick; @@ -576,6 +581,11 @@ begin JumpToSelection(true); end; +procedure TCodeExplorerView.ShowSrcEditPosMenuItemClick(Sender: TObject); +begin + SelectSourceEditorNode; +end; + procedure TCodeExplorerView.MainNotebookPageChanged(Sender: TObject); begin Refresh(true); @@ -654,7 +664,7 @@ begin end; CERenameIDEMenuCommand.Visible:=CanRename; CEJumpToImplementationIDEMenuCommand.Visible:=HasImplementation; - DebugLn(['TCodeExplorerView.TreePopupmenuPopup ',CERenameIDEMenuCommand.Visible]); + //DebugLn(['TCodeExplorerView.TreePopupmenuPopup ',CERenameIDEMenuCommand.Visible]); end; procedure TCodeExplorerView.OnUserInput(Sender: TObject; Msg: Cardinal); @@ -2101,9 +2111,13 @@ begin if CurrentPage=cepCode then begin if FLastCodeValid and (fLastCodeTool<>nil) then begin CodePos:=CodeXYPosition(X,Y,CodeBuf); + CodeBuf.LineColToPosition(Y,X,CleanPos); + //debugln(['TCodeExplorerView.SelectCodePosition Code ',ExtractFileName(CodeBuf.Filename),' y=',y,' x=',x,' CleanPos=',CleanPos,' ',dbgstr(copy(CodeBuf.Source,CleanPos-20,20)),'|',dbgstr(copy(CodeBuf.Source,CleanPos,20))]); if fLastCodeTool.CaretToCleanPos(CodePos,CleanPos)<>0 then exit; + //debugln(['TCodeExplorerView.SelectCodePosition CleanSrc ',ExtractFileName(CodeBuf.Filename),' y=',y,' x=',x,' Tool=',ExtractFileName(fLastCodeTool.MainFilename),' ',dbgstr(copy(fLastCodeTool.Src,CleanPos-20,20)),'|',dbgstr(copy(fLastCodeTool.Src,CleanPos,20))]); TVNode:=FindCodeTVNodeAtCleanPos(CleanPos); if TVNode=nil then exit; + //debugln(['TCodeExplorerView.SelectCodePosition ',TVNode.Text]); CodeTreeview.BeginUpdate; CodeTreeview.Options:=CodeTreeview.Options-[tvoAllowMultiselect]; if not TVNode.IsVisible then begin @@ -2115,6 +2129,7 @@ begin CodeTreeview.Selected:=TVNode; //debugln(['TCodeExplorerView.SelectCodePosition ',TVNode.Text]); end; + //debugln(['TCodeExplorerView.SelectCodePosition TVNode=',TVNode.Text,' Selected=',CodeTreeview.Selected=TVNode]); CodeTreeview.EndUpdate; Result:=true; end; @@ -2125,6 +2140,28 @@ function TCodeExplorerView.FindCodeTVNodeAtCleanPos(CleanPos: integer): TTreeNod // find TTreeNode in CodeTreeView containing the codetools clean position // if there are several nodes, the one with the shortest range (EndPos-StartPos) // is returned. +var + Best: TTreeNode; + BestStartPos, BestEndPos: integer; + + procedure Check(TVNode: TTreeNode; NodeData: TViewNodeData); + begin + if NodeData=nil then exit; + if (NodeData.StartPos>CleanPos) or (NodeData.EndPosnil) then begin + if (BestEndPos=CleanPos) and (NodeData.EndPos>CleanPos) then begin + // for example a,|b then b is better + end else if BestEndPos-BestStartPosnil do begin Node:=TTreeNode(AVLNode.Data); NodeData:=TViewNodeData(Node.Data); //debugln(['TCodeExplorerView.FindCodeTVNodeAtCleanPos Node ',NodeData.StartPos,'-',NodeData.EndPos,' ',Node.Text,' ',CleanPos]); - if NodeData.StartPos>CleanPos then exit; - if NodeData.EndPos>=CleanPos then begin - if (Result=nil) - or (NodeData.EndPos-NodeData.StartPos - < TViewNodeData(Result.Data).EndPos-TViewNodeData(Result.Data).StartPos) - then - Result:=Node; - end; + Check(Node,NodeData); + Check(Node,NodeData.ImplementationNode); AVLNode:=fCodeSortedForStartPos.FindSuccessor(AVLNode); end; + Result:=Best; end; procedure TCodeExplorerView.BuildCodeSortedForStartPos; diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index fc5ed8a73b..06e86f0199 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -5200,6 +5200,7 @@ resourcestring +'of class "%s"has created the error:%s"%s"'; lisShowSetupDialogForMostImportantSettings = 'Show setup dialog for most ' +'important settings'; + lisShowPositionOfSourceEditor = 'Show position of source editor'; implementation