On Sun, 26 Feb 2006 12:29:11 +0200 "Graeme Geldenhuys" <[EMAIL PROTECTED]> wrote:
> Hi, > > Is there any wiki site or other documentation for CodeTools? I started one: http://wiki.lazarus.freepascal.org/index.php/Codetools > I am > trying to convert some of the GExpert tools from Delphi to Lazarus. I > am looking at the Code Explorer in Lazarus as an example which is > helping... > > Question 1: > I need to retrieve a list of procedures and functions from the > current editor file. Code Explorer is based an a Treeview. The one I > am busy with is not, it will just populate a TListView with all > procedures and functions. Does CodeTools only return a treeview > structure of the current editor file, or is there another way of doing > this? The codetools create for every unit they parse a TCodeTree - a tree of TCodeTreeNode. This tree is rebuilt on every parsing. That's why the IDE calls CodeToolsBoss.Explore and creates a local copy of all items/info it needs for the code explorer. > Question 2: > Where does Code Explorer link into CodeTools to retrieve info from > the current editor file? > >From what I can see, it looks like the code in the Refresh method: > > // get the codetool with the updated codetree > ACodeTool:=nil; > if Assigned(OnGetCodeTree) then > OnGetCodeTree(Self,ACodeTool); > > > Is my assumption correct? Yes. OnGetCodeTree does basically this: // commit editor changes to codetools if not LazarusIDE.BeginCodeTools then exit; // get active source editor SrcEditor:=SourceEditorWindow.ActiveEditor; if SrcEditor=nil then exit; CodeBuffer:=SrcEditor.CodeToolsBuffer as TCodeBuffer; // parse source CodeToolsBoss.Explore(CodeBuffer,ACodeTool,false); // copy the tree if ACodeTool.Tree<>nil then ... See examples/idequickfix/quickfixexample.lpk for an example, how to work with the codetools. For example: If you only want the top level 'procedure' nodes of the implementation section of a unit, you can do this: ANode:=ACodeTool.FindImplementationNode; if ANode=nil then exit; ANode:=ANode.FirstChild; while ANode<>nil do begin if ANode.Desc=ctnProcedure then begin NodeText:=ACodeTool.ExtractProcHead(ANode,[]); // add ... end; ANode:=ANode.NextBrother; end; Mattias _________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives
