IDE: fpdoc editor: auto repair xml

git-svn-id: trunk@28526 -
This commit is contained in:
mattias 2010-11-28 12:44:28 +00:00
parent afcd16b76c
commit 7d14b1c344
5 changed files with 35 additions and 17 deletions

View File

@ -33,7 +33,7 @@ interface
uses uses
Classes, SysUtils, FileProcs, contnrs, BasicCodeTools; Classes, SysUtils, FileProcs, contnrs, BasicCodeTools;
procedure FixFPDocFragment(var Fragment: string; Fix: boolean; procedure FixFPDocFragment(var Fragment: string; AllowTags, Fix: boolean;
out ErrorList: TObjectList; Verbose: boolean = false); out ErrorList: TObjectList; Verbose: boolean = false);
implementation implementation
@ -46,7 +46,7 @@ type
Msg: string; Msg: string;
end; end;
procedure FixFPDocFragment(var Fragment: string; Fix: boolean; procedure FixFPDocFragment(var Fragment: string; AllowTags, Fix: boolean;
out ErrorList: TObjectList; Verbose: boolean); out ErrorList: TObjectList; Verbose: boolean);
{ - Fix all tags to lowercase to reduce svn commits { - Fix all tags to lowercase to reduce svn commits
- auto close comments - auto close comments
@ -463,7 +463,10 @@ var
procedure ParseLowerThan; procedure ParseLowerThan;
begin begin
// comment, tag or 'lower than' // comment, tag or 'lower than'
if (p[1]='!') and (p[2]='-') and (p[3]='-') then begin if not AllowTags then begin
// invalid character => convert or skip
HandleSpecialChar;
end else if (p[1]='!') and (p[2]='-') and (p[3]='-') then begin
// comment // comment
ParseComment; ParseComment;
end else if p[1] in ['a'..'z','A'..'Z'] then begin end else if p[1] in ['a'..'z','A'..'Z'] then begin

View File

@ -7,6 +7,7 @@
<MainUnit Value="0"/> <MainUnit Value="0"/>
<ResourceType Value="res"/> <ResourceType Value="res"/>
</General> </General>
<LazDoc Paths="doc"/>
<i18n> <i18n>
<EnableI18N LFM="False"/> <EnableI18N LFM="False"/>
</i18n> </i18n>

View File

@ -102,7 +102,7 @@ begin
Result:=true; Result:=true;
try try
s:=Fragment; s:=Fragment;
FixFPDocFragment(s,true,ErrorList,Verbose); FixFPDocFragment(s,true,true,ErrorList,Verbose);
if s<>FixedFragment then begin if s<>FixedFragment then begin
Result:=false; Result:=false;
debugln(['failed: ',Title]); debugln(['failed: ',Title]);

View File

@ -31,7 +31,7 @@ interface
uses uses
// FCL // FCL
Classes, SysUtils, StrUtils, Classes, SysUtils, StrUtils, contnrs,
// LCL // LCL
LCLProc, LResources, StdCtrls, Buttons, ComCtrls, Controls, Dialogs, LCLProc, LResources, StdCtrls, Buttons, ComCtrls, Controls, Dialogs,
ExtCtrls, Forms, Graphics, LCLType, ExtCtrls, Forms, Graphics, LCLType,
@ -39,6 +39,7 @@ uses
SynEdit, SynEdit,
// codetools // codetools
BasicCodeTools, FileProcs, CodeAtom, CodeCache, CodeToolManager, BasicCodeTools, FileProcs, CodeAtom, CodeCache, CodeToolManager,
CTXMLFixFragment,
{$IFDEF NewXMLCfg} {$IFDEF NewXMLCfg}
Laz2_DOM, Laz2_XMLRead, Laz2_XMLWrite, Laz2_DOM, Laz2_XMLRead, Laz2_XMLWrite,
{$ELSE} {$ELSE}
@ -1259,29 +1260,38 @@ var
CurName:=Element.FPDocFile.Filename CurName:=Element.FPDocFile.Filename
else else
CurName:=Element.ElementName; CurName:=Element.ElementName;
MessageDlg('Write error', MessageDlg(lisCodeToolsDefsWriteError,
'Error writing "'+CurName+'"'#13 Format(lisFPDocErrorWriting, [CurName, #13, Msg]), mtError, [mbCancel],
+Msg,mtError,[mbCancel],0); 0);
end; end;
end; end;
function SetValue(Item: TFPDocItem): boolean; function SetValue(Item: TFPDocItem): boolean;
var var
NewValue: String; NewValue: String;
ErrorList: TObjectList;
begin begin
Result:=false; Result:=false;
NewValue:=Values[Item]; NewValue:=Values[Item];
ErrorList:=nil;
try try
CurDocFile.SetChildValue(TopNode,FPDocItemNames[Item],NewValue); try
Result:=true; FixFPDocFragment(NewValue,
except Item in [fpdiShort,fpdiDescription,fpdiErrors,fpdiSeeAlso],
on E: EXMLReadError do begin true,ErrorList);
DebugLn(['SetValue ',dbgs(E.LineCol),' Name=',FPDocItemNames[Item]]); CurDocFile.SetChildValue(TopNode,FPDocItemNames[Item],NewValue);
JumpToError(Item,E.LineCol); Result:=true;
MessageDlg('FPDoc syntax error', except
'There is a syntax error in the fpdoc element "'+FPDocItemNames[Item]+'":'#13#13 on E: EXMLReadError do begin
+E.Message,mtError,[mbOk],''); DebugLn(['SetValue ',dbgs(E.LineCol),' Name=',FPDocItemNames[Item]]);
JumpToError(Item,E.LineCol);
MessageDlg(lisFPDocFPDocSyntaxError,
Format(lisFPDocThereIsASyntaxErrorInTheFpdocElement, [FPDocItemNames
[Item], #13#13, E.Message]), mtError, [mbOk], '');
end;
end; end;
finally
FreeAndNil(ErrorList);
end; end;
end; end;

View File

@ -2890,6 +2890,10 @@ resourcestring
// codetools defines // codetools defines
lisCodeToolsDefsCodeToolsDefinesPreview = 'CodeTools Defines Preview'; lisCodeToolsDefsCodeToolsDefinesPreview = 'CodeTools Defines Preview';
lisCodeToolsDefsWriteError = 'Write error'; lisCodeToolsDefsWriteError = 'Write error';
lisFPDocErrorWriting = 'Error writing "%s"%s%s';
lisFPDocFPDocSyntaxError = 'FPDoc syntax error';
lisFPDocThereIsASyntaxErrorInTheFpdocElement = 'There is a syntax error in '
+'the fpdoc element "%s":%s%s';
lisUnableToWriteToFile2 = 'Unable to write to file "%s".'; lisUnableToWriteToFile2 = 'Unable to write to file "%s".';
lisUnableToWriteTheProjectSessionFileError = 'Unable to write the project ' lisUnableToWriteTheProjectSessionFileError = 'Unable to write the project '
+'session file%s"%s".%sError: %s'; +'session file%s"%s".%sError: %s';