IDE: fpdoc editor: fixed unitialized function results when fpdoc xml has no module

git-svn-id: trunk@36252 -
This commit is contained in:
mattias 2012-03-23 09:18:03 +00:00
parent 7723f075ae
commit 829b02a095

View File

@ -94,13 +94,17 @@ type
private private
fUpdateLock: integer; fUpdateLock: integer;
FFlags: TLazFPDocFileFlags; FFlags: TLazFPDocFileFlags;
FDocChangeStamp: int64;
FDocSaveChangeStamp: int64;
function GetDocModified: boolean;
procedure SetDocModified(AValue: boolean);
public public
Filename: string;// the fpdoc xml filename Filename: string;// the fpdoc xml filename
Doc: TXMLdocument;// IMPORTANT: if you change this, call DocChanging and DocChanged to notify the references Doc: TXMLdocument;// IMPORTANT: if you change this, call DocChanging and DocChanged to notify the references
DocErrorMsg: string; // if xml is broken, Doc could not be created DocErrorMsg: string; // if xml is broken, Doc could not be created
DocModified: boolean;
CodeBufferChangeStep: integer;// the CodeBuffer.ChangeStep value, when Doc was built CodeBufferChangeStep: integer;// the CodeBuffer.ChangeStep value, when Doc was built
CodeBuffer: TCodeBuffer; CodeBuffer: TCodeBuffer;
constructor Create;
destructor Destroy; override; destructor Destroy; override;
function GetPackageNode: TDOMNode; // the lazarus project or package function GetPackageNode: TDOMNode; // the lazarus project or package
function GetPackageName: string; function GetPackageName: string;
@ -117,6 +121,8 @@ type
function GetValuesFromNode(Node: TDOMNode): TFPDocElementValues; function GetValuesFromNode(Node: TDOMNode): TFPDocElementValues;
function GetValueFromNode(Node: TDOMNode; Item: TFPDocItem): string; function GetValueFromNode(Node: TDOMNode; Item: TFPDocItem): string;
procedure SetChildValue(Node: TDOMNode; const ChildName: string; NewValue: string); procedure SetChildValue(Node: TDOMNode; const ChildName: string; NewValue: string);
property DocModified: boolean read GetDocModified write SetDocModified;
property DocChangeStamp: int64 read FDocChangeStamp;
procedure DocChanging; procedure DocChanging;
procedure DocChanged; procedure DocChanged;
procedure BeginUpdate; procedure BeginUpdate;
@ -570,6 +576,25 @@ end;
{ TLazFPDocFile } { TLazFPDocFile }
function TLazFPDocFile.GetDocModified: boolean;
begin
Result:=FDocSaveChangeStamp<>FDocChangeStamp;
end;
procedure TLazFPDocFile.SetDocModified(AValue: boolean);
begin
if AValue then
CTIncreaseChangeStamp64(FDocChangeStamp)
else
FDocSaveChangeStamp:=FDocChangeStamp;
end;
constructor TLazFPDocFile.Create;
begin
FDocChangeStamp:=CTInvalidChangeStamp64;
FDocSaveChangeStamp:=CTInvalidChangeStamp64;
end;
destructor TLazFPDocFile.Destroy; destructor TLazFPDocFile.Destroy;
begin begin
FreeAndNil(Doc); FreeAndNil(Doc);
@ -628,42 +653,42 @@ end;
function TLazFPDocFile.GetModuleTopicCount: Integer; function TLazFPDocFile.GetModuleTopicCount: Integer;
var var
n: TDOMNode; Node: TDOMNode;
begin begin
Result := 0; Result := 0;
n := GetModuleNode; Node := GetModuleNode;
if n = nil then exit; if Node = nil then exit;
n := n.FirstChild; Node := Node.FirstChild;
while (n <> nil) do begin while (Node <> nil) do begin
if (n.NodeName = 'topic') then inc(result); if (Node.NodeName = 'topic') then inc(result);
n := n.NextSibling; Node := Node.NextSibling;
end; end;
end; end;
function TLazFPDocFile.GetModuleTopicName(Index: Integer): String; function TLazFPDocFile.GetModuleTopicName(Index: Integer): String;
var var
n: TDOMNode; Node: TDOMNode;
begin begin
Result := ''; Result := '';
n := GetModuleNode; Node := GetModuleNode;
if n = nil then exit; if Node = nil then exit;
n := n.FirstChild; Node := Node.FirstChild;
while (n <> nil) and (Index >= 0) do begin while (Node <> nil) and (Index >= 0) do begin
if (n.NodeName = 'topic') and (n is TDomElement) then begin if (Node.NodeName = 'topic') and (Node is TDomElement) then begin
if Index = 0 then begin if Index = 0 then begin
Result := TDomElement(n).GetAttribute('name'); Result := TDomElement(Node).GetAttribute('name');
exit; exit;
end; end;
dec(Index); dec(Index);
end; end;
n := n.NextSibling; Node := Node.NextSibling;
end; end;
end; end;
function TLazFPDocFile.GetModuleTopic(Name: String): TDOMNode; function TLazFPDocFile.GetModuleTopic(Name: String): TDOMNode;
begin begin
Result := GetModuleNode; Result := GetModuleNode;
if Result = nil then exit; if Result = nil then exit(nil);
Result := Result.FirstChild; Result := Result.FirstChild;
while (Result <> nil) do begin while (Result <> nil) do begin
if (Result.NodeName = 'topic') and (Result is TDomElement) and if (Result.NodeName = 'topic') and (Result is TDomElement) and
@ -679,13 +704,16 @@ var
ModuleNode: TDOMNode; ModuleNode: TDOMNode;
begin begin
ModuleNode := GetModuleNode; ModuleNode := GetModuleNode;
if ModuleNode = nil then exit; if ModuleNode = nil then exit(nil);
Result:=Doc.CreateElement('topic');
DocChanging; DocChanging;
TDOMElement(Result).SetAttribute('name', Name); try
ModuleNode.AppendChild(Result); Result:=Doc.CreateElement('topic');
DocChanged; TDOMElement(Result).SetAttribute('name', Name);
ModuleNode.AppendChild(Result);
finally
DocChanged;
end;
end; end;
function TLazFPDocFile.GetFirstElement: TDOMNode; function TLazFPDocFile.GetFirstElement: TDOMNode;
@ -716,10 +744,9 @@ begin
end; end;
// check module name // check module name
if (ModuleNode is TDomElement) if (ModuleNode is TDomElement)
and (SysUtils.CompareText(TDomElement(ModuleNode).GetAttribute('name'),ElementName)=0) and (CompareTextIgnoringSpace(TDomElement(ModuleNode).GetAttribute('name'),ElementName,false)=0)
then begin then begin
Result:=ModuleNode; exit(ModuleNode);
exit;
end; end;
// check elements // check elements
Result:=GetFirstElement; Result:=GetFirstElement;
@ -728,18 +755,21 @@ begin
//DebugLn(['TLazFPDocFile.GetElementWithName ',dbgsName(Result)]); //DebugLn(['TLazFPDocFile.GetElementWithName ',dbgsName(Result)]);
//if Result is TDomElement then DebugLn(['TLazFPDocFile.GetElementWithName ',TDomElement(Result).GetAttribute('name')]); //if Result is TDomElement then DebugLn(['TLazFPDocFile.GetElementWithName ',TDomElement(Result).GetAttribute('name')]);
if (Result is TDomElement) if (Result is TDomElement)
and (SysUtils.CompareText(TDomElement(Result).GetAttribute('name'),ElementName)=0) and (CompareTextIgnoringSpace(TDomElement(Result).GetAttribute('name'),ElementName,false)=0)
then then
exit; exit;
Result:=Result.NextSibling; Result:=Result.NextSibling;
end; end;
if (Result=nil) and CreateIfNotExists then begin if (Result=nil) and CreateIfNotExists then begin
DebugLn(['TLazFPDocFile.GetElementWithName creating ',ElementName]); DebugLn(['TLazFPDocFile.GetElementWithName creating ',ElementName]);
Result:=Doc.CreateElement('element');
DocChanging; DocChanging;
TDOMElement(Result).SetAttribute('name',ElementName); try
ModuleNode.AppendChild(Result); Result:=Doc.CreateElement('element');
DocChanged; TDOMElement(Result).SetAttribute('name',ElementName);
ModuleNode.AppendChild(Result);
finally
DocChanged;
end;
end; end;
end; end;
@ -1012,21 +1042,22 @@ end;
procedure TLazFPDocFile.DocChanging; procedure TLazFPDocFile.DocChanging;
begin begin
if (ldffDocChangingCalled in FFlags) then exit;
DocModified:=true; DocModified:=true;
if (fUpdateLock>0) then begin Include(FFlags,ldffDocChangingCalled);
if (ldffDocChangingCalled in FFlags) then exit;
Include(FFlags,ldffDocChangingCalled);
end;
CodeHelpBoss.CallDocChangeEvents(chmhDocChanging,Self); CodeHelpBoss.CallDocChangeEvents(chmhDocChanging,Self);
end; end;
procedure TLazFPDocFile.DocChanged; procedure TLazFPDocFile.DocChanged;
begin begin
if not (ldffDocChangingCalled in FFlags) then
raise Exception.Create('TLazFPDocFile.DocChanged missing call to DocChanging');
if (fUpdateLock>0) then begin if (fUpdateLock>0) then begin
Include(FFlags,ldffDocChangedNeedsCalling); Include(FFlags,ldffDocChangedNeedsCalling);
exit; exit;
end; end;
Exclude(FFlags,ldffDocChangedNeedsCalling); Exclude(FFlags,ldffDocChangedNeedsCalling);
Exclude(FFlags,ldffDocChangingCalled);
CodeHelpBoss.CallDocChangeEvents(chmhDocChanged,Self); CodeHelpBoss.CallDocChangeEvents(chmhDocChanged,Self);
end; end;
@ -1040,7 +1071,6 @@ begin
dec(fUpdateLock); dec(fUpdateLock);
if fUpdateLock<0 then RaiseGDBException('TLazFPDocFile.EndUpdate'); if fUpdateLock<0 then RaiseGDBException('TLazFPDocFile.EndUpdate');
if fUpdateLock=0 then begin if fUpdateLock=0 then begin
Exclude(FFlags,ldffDocChangingCalled);
if ldffDocChangedNeedsCalling in FFlags then if ldffDocChangedNeedsCalling in FFlags then
DocChanged; DocChanged;
end; end;