From 88dafd00304e983ad69567272aee4ff9ef4e730a Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 6 Aug 2008 09:24:39 +0000 Subject: [PATCH] IDE: fpdoc editor: implemented saving example filename git-svn-id: trunk@15968 - --- ide/codehelp.pas | 41 +++++++++++++++++++++++++++-------------- ide/fpdoceditwindow.pas | 2 +- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/ide/codehelp.pas b/ide/codehelp.pas index 027af25e0d..fcdffaee5b 100644 --- a/ide/codehelp.pas +++ b/ide/codehelp.pas @@ -608,7 +608,6 @@ procedure TLazFPDocFile.SetChildValue(Node: TDOMNode; const ChildName: string; var Child: TDOMNode; - OldNode: TDOMNode; FileAttribute, LinkAttribute: TDOMAttr; begin NewValue:=ToUnixLineEnding(NewValue); @@ -637,21 +636,30 @@ begin // update sub node Child:=Node.FindNode(ChildName); if ChildName = FPDocItemNames[fpdiExample] then begin - OldNode:=nil; - if Child<>nil then - OldNode:=Child.Attributes.GetNamedItem('file'); + // update sub node example, attribute file NewValue:=FilenameToURLPath(NewValue); - if (NewValue<>'') - or (not (OldNode is TDOMAttr)) - or (TDOMAttr(OldNode).Value<>NewValue) then begin + FileAttribute:=nil; + if Child is TDomElement then + FileAttribute:=TDomElement(Child).GetAttributeNode('file'); + if ((NewValue='') and (FileAttribute<>nil)) + or ((NewValue<>'') and ((FileAttribute=nil) or (FileAttribute.NodeValue<>NewValue))) + then begin + // delete, add or change attribute 'file' DebugLn(['TLazFPDocFile.SetChildValue Changing example file Name=',ChildName,' NewValue="',NewValue,'"']); - // add, change or delete example file DocChanging; try - FileAttribute := Doc.CreateAttribute('file'); - FileAttribute.Value := NewValue; - OldNode:=Node.Attributes.SetNamedItem(FileAttribute); - OldNode.Free; + if NewValue='' then begin + // remove old content + while Child.LastChild<>nil do + Child.RemoveChild(Child.LastChild); + Node.RemoveChild(Child); + end else begin + if Child=nil then begin + Child := Doc.CreateElement(ChildName); + Node.AppendChild(Child); + end; + TDomElement(Child).SetAttribute('file',NewValue); + end; finally DocChanged; end; @@ -681,8 +689,13 @@ begin // remove old content while Child.LastChild<>nil do Child.RemoveChild(Child.LastChild); - // set new content - ReadXMLFragmentFromString(Child,NewValue); + if NewValue='' then begin + // remove entire child + Node.RemoveChild(Child); + end else begin + // set new content + ReadXMLFragmentFromString(Child,NewValue); + end; finally DocChanged; end; diff --git a/ide/fpdoceditwindow.pas b/ide/fpdoceditwindow.pas index 99f7aea261..17e51007b6 100644 --- a/ide/fpdoceditwindow.pas +++ b/ide/fpdoceditwindow.pas @@ -1043,7 +1043,7 @@ begin CurDocFile.SetChildValue(TopNode,'errors',Values[fpdiErrors]); // ToDo: //CurDocFile.SetChildValue(TopNode,'seealso',Values[fpdiSeeAlso]); - //CurDocFile.SetChildValue(TopNode,'example',Values[fpdiExample]); + CurDocFile.SetChildValue(TopNode,'example',Values[fpdiExample]); finally CurDocFile.EndUpdate; fChain.MakeValid;