IDE: lazdoc: added utility function to find dom nodes

git-svn-id: trunk@12913 -
This commit is contained in:
mattias 2007-11-18 11:21:42 +00:00
parent bc6dd44a80
commit ec8cae645e
2 changed files with 82 additions and 3 deletions

View File

@ -32,7 +32,7 @@ interface
uses
Classes, SysUtils, LCLProc, FileUtil,
CodeToolManager, CodeCache, FileProcs, AvgLvlTree,
CodeTree, CodeToolManager, CodeCache, FileProcs, AvgLvlTree,
Laz_DOM, Laz_XMLRead, Laz_XMLWrite,
MacroIntf, PackageIntf, LazHelpIntf, ProjectIntf, LazIDEIntf,
IDEProcs, PackageDefs, EnvironmentOpts;
@ -47,6 +47,9 @@ type
ChangeStep: integer;// the CodeBuffer.ChangeStep value, when Doc was build
CodeBuffer: TCodeBuffer;
destructor Destroy; override;
function GetModuleNode: TDOMNode;
function GetFirstElement: TDOMNode;
function GetElementWithName(const ElementName: string): TDOMNode;
end;
TLazDocChangeEvent =
@ -82,6 +85,7 @@ type
Context: TPascalHelpContextList): string;
function GetFPDocFilenameForSource(SrcFilename: string;
ResolveIncludeFiles: Boolean): string;
function CodeNodeToElementName(Tool: TCodeTool; CodeNode: TCodeTreeNode): string;
public
// Event lists
procedure RemoveAllHandlersOfObject(AnObject: TObject);
@ -121,6 +125,49 @@ begin
inherited Destroy;
end;
function TLazFPDocFile.GetModuleNode: TDOMNode;
begin
Result:=nil;
if Doc=nil then exit;
// get first node
Result := Doc.FindNode('fpdoc-descriptions');
if Result=nil then exit;
// proceed to package
Result := Result.FirstChild;
if Result=nil then exit;
// proceed to module
Result := Result.FirstChild;
while (Result<>nil) and (Result.NodeName <> 'module') do
Result := Result.NextSibling;
end;
function TLazFPDocFile.GetFirstElement: TDOMNode;
begin
//get first module node
Result := GetModuleNode;
if Result=nil then exit;
//proceed to element
Result := Result.FirstChild;
while Result.NodeName <> 'element' do
Result := Result.NextSibling;
end;
function TLazFPDocFile.GetElementWithName(const ElementName: string): TDOMNode;
begin
Result:=GetFirstElement;
while Result<>nil do begin
if (Result is TDomElement)
and (CompareText(TDomElement(Result).GetAttribute('name'),ElementName)=0)
then
exit;
Result:=Result.NextSibling;
end;
end;
procedure TLazDocManager.AddHandler(HandlerType: TLazDocManagerHandler;
const AMethod: TMethod; AsLast: boolean);
begin
@ -346,8 +393,40 @@ begin
Result:=SearchFileInPath(FPDocName,'',SearchPath,';',ctsfcAllCase);
end;
procedure TLazDocManager.FreeDocs;
function TLazDocManager.CodeNodeToElementName(Tool: TCodeTool;
CodeNode: TCodeTreeNode): string;
var
NodeName: String;
begin
Result:='';
while CodeNode<>nil do begin
case CodeNode.Desc of
ctnVarDefinition, ctnConstDefinition, ctnTypeDefinition, ctnGenericType:
NodeName:=Tool.ExtractDefinitionName(CodeNode);
ctnProperty:
NodeName:=Tool.ExtractPropName(CodeNode,false);
ctnProcedure:
NodeName:=Tool.ExtractProcName(CodeNode,[]);
else NodeName:='';
end;
if NodeName<>'' then begin
if Result<>'' then
Result:='.'+Result;
Result:=NodeName+Result;
end;
CodeNode:=CodeNode.Parent;
end;
end;
procedure TLazDocManager.FreeDocs;
var
AVLNode: TAvgLvlTreeNode;
begin
AVLNode:=FDocs.FindLowest;
while AVLNode<>nil do begin
CallDocChangeEvents(ldmhDocChanging,TLazFPDocFile(AVLNode.Data));
AVLNode:=FDocs.FindSuccessor(AVLNode);
end;
FDocs.FreeAndClear;
end;

View File

@ -212,7 +212,7 @@ begin
GetMem(FormatList,SizeOf(TClipboardFormat)*FCount);
for i:=0 to FCount-1 do
FormatList[i]:=FData[i].FormatID;
//DebugLn('[TClipboard.GetOwnerShip] A ',ClipboardTypeName[ClipboardType],' Allocated=',FAllocated);
//DebugLn(['[TClipboard.GetOwnerShip] A ',ClipboardTypeName[ClipboardType],' Allocated=',FAllocated]);
FAllocated:=true;
if not ClipboardGetOwnerShip(ClipboardType,@InternalOnRequest,FCount,
FormatList)