mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-04 12:38:17 +02:00
IDE: codehelp: values are now read/stored with complete xml tree
git-svn-id: trunk@13881 -
This commit is contained in:
parent
8810e42aec
commit
bc4c1892bf
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<PathDelim Value="\"/>
|
<PathDelim Value="/"/>
|
||||||
<Version Value="6"/>
|
<Version Value="6"/>
|
||||||
<General>
|
<General>
|
||||||
<SessionStorage Value="InIDEConfig"/>
|
<SessionStorage Value="InIDEConfig"/>
|
||||||
<MainUnit Value="0"/>
|
<MainUnit Value="0"/>
|
||||||
<IconPath Value=".\"/>
|
<IconPath Value="./"/>
|
||||||
<TargetFileExt Value=""/>
|
<TargetFileExt Value=""/>
|
||||||
<UseXPManifest Value="True"/>
|
<UseXPManifest Value="True"/>
|
||||||
</General>
|
</General>
|
||||||
@ -21,7 +21,7 @@
|
|||||||
<RunParams>
|
<RunParams>
|
||||||
<local>
|
<local>
|
||||||
<FormatVersion Value="1"/>
|
<FormatVersion Value="1"/>
|
||||||
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
|
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||||
</local>
|
</local>
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<RequiredPackages Count="1">
|
<RequiredPackages Count="1">
|
||||||
@ -155,7 +155,6 @@
|
|||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="5"/>
|
<Version Value="5"/>
|
||||||
<PathDelim Value="\"/>
|
|
||||||
<Other>
|
<Other>
|
||||||
<ConfigFile>
|
<ConfigFile>
|
||||||
<StopAfterErrCount Value="10"/>
|
<StopAfterErrCount Value="10"/>
|
||||||
|
156
ide/codehelp.pas
156
ide/codehelp.pas
@ -226,6 +226,7 @@ function CompareLDSrc2DocSrcFilenames(Data1, Data2: Pointer): integer;
|
|||||||
function CompareAnsistringWithLDSrc2DocSrcFile(Key, Data: Pointer): integer;
|
function CompareAnsistringWithLDSrc2DocSrcFile(Key, Data: Pointer): integer;
|
||||||
|
|
||||||
function ToUnixLineEnding(const s: String): String;
|
function ToUnixLineEnding(const s: String): String;
|
||||||
|
function ToOSLineEnding(const s: String): String;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -254,6 +255,37 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function ToOSLineEnding(const s: String): String;
|
||||||
|
const
|
||||||
|
le: shortstring = LineEnding;
|
||||||
|
var
|
||||||
|
p: Integer;
|
||||||
|
begin
|
||||||
|
Result:=s;
|
||||||
|
p:=1;
|
||||||
|
while (p<=length(s)) do begin
|
||||||
|
if not (s[p] in [#10,#13]) then begin
|
||||||
|
inc(p);
|
||||||
|
end else begin
|
||||||
|
// line ending
|
||||||
|
if (p<length(s)) and (s[p+1] in [#10,#13]) and (s[p]<>s[p+1]) then begin
|
||||||
|
// double character line ending
|
||||||
|
if (length(le)<>2)
|
||||||
|
or (le[1]<>s[p]) or (le[2]<>s[p+1]) then begin
|
||||||
|
Result:=copy(Result,1,p-1)+le+copy(Result,p+2,length(Result));
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
// single char line ending #13 or #10
|
||||||
|
if (length(le)<>1)
|
||||||
|
or (le[1]<>s[p]) then begin
|
||||||
|
Result:=copy(Result,1,p-1)+le+copy(Result,p+2,length(Result));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
inc(p);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function CompareLazFPDocFilenames(Data1, Data2: Pointer): integer;
|
function CompareLazFPDocFilenames(Data1, Data2: Pointer): integer;
|
||||||
begin
|
begin
|
||||||
Result:=CompareFilenames(TLazFPDocFile(Data1).Filename,
|
Result:=CompareFilenames(TLazFPDocFile(Data1).Filename,
|
||||||
@ -353,18 +385,83 @@ end;
|
|||||||
|
|
||||||
function TLazFPDocFile.GetChildValuesAsString(Node: TDOMNode): String;
|
function TLazFPDocFile.GetChildValuesAsString(Node: TDOMNode): String;
|
||||||
var
|
var
|
||||||
Child: TDOMNode;
|
MemStream: TMemoryStream;
|
||||||
|
StartPos: Integer;
|
||||||
|
EndPos: Integer;
|
||||||
begin
|
begin
|
||||||
Result:='';
|
Result:='';
|
||||||
Child:=Node.FirstChild;
|
MemStream:=TMemoryStream.Create;
|
||||||
|
try
|
||||||
|
// write node with childs
|
||||||
|
WriteXML(Node,MemStream);
|
||||||
|
MemStream.Position:=0;
|
||||||
|
SetLength(Result,MemStream.Size);
|
||||||
|
if Result<>'' then
|
||||||
|
MemStream.Read(Result[1],length(Result));
|
||||||
|
// remove tag(s) for node, because Result should only contain the child values:
|
||||||
|
// <nodename/> or <nodename>...<nodename/>
|
||||||
|
// <nodename something=""/>
|
||||||
|
// plus line ends
|
||||||
|
StartPos:=1;
|
||||||
|
EndPos:=length(Result)+1;
|
||||||
|
// skip start tag
|
||||||
|
if (Result<>'') and (Result[StartPos]='<') then begin
|
||||||
|
inc(StartPos);
|
||||||
|
while (StartPos<=EndPos) do begin
|
||||||
|
if (Result[StartPos]='>') then begin
|
||||||
|
inc(StartPos);
|
||||||
|
break;
|
||||||
|
end else if Result[StartPos]='"' then begin
|
||||||
|
repeat
|
||||||
|
inc(StartPos);
|
||||||
|
until (StartPos>=EndPos) or (Result[StartPos]='"');
|
||||||
|
end;
|
||||||
|
inc(StartPos);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
// skip ending line ends
|
||||||
|
while (EndPos>StartPos) and (Result[EndPos-1] in [' ',#9,#10,#13]) do
|
||||||
|
dec(EndPos);
|
||||||
|
// skip end tag
|
||||||
|
if (EndPos>StartPos) and (Result[EndPos-1]='>') then begin
|
||||||
|
repeat
|
||||||
|
dec(EndPos);
|
||||||
|
if (EndPos=StartPos) then break;
|
||||||
|
if (Result[EndPos-1]='"') then begin
|
||||||
|
repeat
|
||||||
|
dec(EndPos);
|
||||||
|
until (EndPos=StartPos) or (Result[EndPos]='"');
|
||||||
|
end else if (Result[EndPos-1]='<') then begin
|
||||||
|
dec(EndPos);
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
until false;
|
||||||
|
end;
|
||||||
|
Result:=copy(Result,StartPos,EndPos-StartPos);
|
||||||
|
|
||||||
|
finally
|
||||||
|
MemStream.Free;
|
||||||
|
end;
|
||||||
|
DebugLn(['TLazFPDocFile.GetChildValuesAsString Node=',Node.NodeName,' Result=',Result]);
|
||||||
|
|
||||||
|
{Child:=Node.FirstChild;
|
||||||
|
//DebugLn(['TLazFPDocFile.GetChildValuesAsString Node=',Node.NodeName]);
|
||||||
while Child<>nil do begin
|
while Child<>nil do begin
|
||||||
//DebugLn(['TLazFPDocFile.GetChildValuesAsString ',dbgsName(Child)]);
|
//DebugLn(['TLazFPDocFile.GetChildValuesAsString ',dbgsName(Child),' ',Child.NodeName]);
|
||||||
if Child is TDOMText then begin
|
if Child is TDOMText then begin
|
||||||
//DebugLn(['TLazFPDocFile.GetChildValuesAsString Data="',TDOMText(Child).Data,'" Length=',TDOMText(Child).Length]);
|
//DebugLn(['TLazFPDocFile.GetChildValuesAsString Data="',TDOMText(Child).Data,'" Length=',TDOMText(Child).Length]);
|
||||||
Result:=Result+TDOMText(Child).Data;
|
Result:=Result+TDOMText(Child).Data;
|
||||||
|
end else if Child is TDOMElement then begin
|
||||||
|
if Child.FirstChild=nil then begin
|
||||||
|
Result:=Result+'<'+Child.NodeName+'/>';
|
||||||
|
end else begin
|
||||||
|
Result:=Result+'<'+Child.NodeName+'>'
|
||||||
|
+GetChildValuesAsString(Child)
|
||||||
|
+'</'+Child.NodeName+'>'
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
Child:=Child.NextSibling;
|
Child:=Child.NextSibling;
|
||||||
end;
|
end;}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLazFPDocFile.GetValuesFromNode(Node: TDOMNode): TFPDocElementValues;
|
function TLazFPDocFile.GetValuesFromNode(Node: TDOMNode): TFPDocElementValues;
|
||||||
@ -416,9 +513,24 @@ end;
|
|||||||
|
|
||||||
procedure TLazFPDocFile.SetChildValue(Node: TDOMNode; const ChildName: string;
|
procedure TLazFPDocFile.SetChildValue(Node: TDOMNode; const ChildName: string;
|
||||||
NewValue: string);
|
NewValue: string);
|
||||||
|
|
||||||
|
procedure ReadXMLFragmentFromString(AParentNode: TDOMNode; const s: string);
|
||||||
|
var
|
||||||
|
MemStream: TMemoryStream;
|
||||||
|
begin
|
||||||
|
if s='' then exit;
|
||||||
|
try
|
||||||
|
MemStream:=TMemoryStream.Create;
|
||||||
|
MemStream.Write(s[1],length(s));
|
||||||
|
MemStream.Position:=0;
|
||||||
|
ReadXMLFragment(AParentNode,MemStream);
|
||||||
|
finally
|
||||||
|
MemStream.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
Child: TDOMNode;
|
Child: TDOMNode;
|
||||||
TextNode: TDOMText;
|
|
||||||
begin
|
begin
|
||||||
Child:=Node.FindNode(ChildName);
|
Child:=Node.FindNode(ChildName);
|
||||||
NewValue:=ToUnixLineEnding(NewValue);
|
NewValue:=ToUnixLineEnding(NewValue);
|
||||||
@ -444,24 +556,30 @@ begin
|
|||||||
if NewValue<>'' then begin
|
if NewValue<>'' then begin
|
||||||
DebugLn(['TLazFPDocFile.SetChildValue Adding Name=',ChildName,' NewValue="',NewValue,'"']);
|
DebugLn(['TLazFPDocFile.SetChildValue Adding Name=',ChildName,' NewValue="',NewValue,'"']);
|
||||||
DocChanging;
|
DocChanging;
|
||||||
Child := Doc.CreateElement(ChildName);
|
try
|
||||||
Node.AppendChild(Child);
|
Child := Doc.CreateElement(ChildName);
|
||||||
TextNode := Doc.CreateTextNode(NewValue);
|
Node.AppendChild(Child);
|
||||||
Child.AppendChild(TextNode);
|
ReadXMLFragmentFromString(Child,NewValue);
|
||||||
DocChanged;
|
finally
|
||||||
|
DocChanged;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end else if GetChildValuesAsString(Child)<>NewValue then begin
|
end else if GetChildValuesAsString(Child)<>NewValue then begin
|
||||||
// change node
|
// change node
|
||||||
DocChanging;
|
DocChanging;
|
||||||
DebugLn(['TLazFPDocFile.CheckAndWriteNode Changing ',Node.NodeName,
|
try
|
||||||
' ChildName=',Child.NodeName,
|
DebugLn(['TLazFPDocFile.CheckAndWriteNode Changing ',Node.NodeName,
|
||||||
' OldValue=',GetChildValuesAsString(Child),
|
' ChildName=',Child.NodeName,
|
||||||
' NewValue="',NewValue,'"']);
|
' OldValue=',GetChildValuesAsString(Child),
|
||||||
while Child.LastChild<>nil do
|
' NewValue="',NewValue,'"']);
|
||||||
Child.RemoveChild(Child.LastChild);
|
// remove old content
|
||||||
TextNode := Doc.CreateTextNode(NewValue);
|
while Child.LastChild<>nil do
|
||||||
Child.AppendChild(TextNode);
|
Child.RemoveChild(Child.LastChild);
|
||||||
DocChanged;
|
// set new content
|
||||||
|
ReadXMLFragmentFromString(Child,NewValue);
|
||||||
|
finally
|
||||||
|
DocChanged;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user