- stores edited data with unix line ending

- converts retrieved data from XML file to native line ending
- errors and short elements are now also supported
- some unnescesary updating is now prevented
From Darius

git-svn-id: trunk@7692 -
This commit is contained in:
vincents 2005-09-14 07:35:22 +00:00
parent c727146b87
commit fd1a7b2358
3 changed files with 166 additions and 43 deletions

View File

@ -1,5 +1,5 @@
object LazDocForm: TLazDocForm
ActiveControl = TabSheet1
ActiveControl = ErrorsTabSheet
Caption = 'LazDoc editor'
ClientHeight = 195
ClientWidth = 753
@ -12,15 +12,31 @@ object LazDocForm: TLazDocForm
Top = 506
Width = 753
object PageControl: TPageControl
ActivePage = TabSheet1
ActivePage = ErrorsTabSheet
Align = alClient
TabIndex = 0
TabIndex = 2
TabOrder = 0
TabPosition = tpBottom
Height = 195
Width = 753
object TabSheet1: TTabSheet
Caption = 'TabSheet1'
object ShortTabSheet: TTabSheet
Caption = 'ShortTabSheet'
ClientHeight = 169
ClientWidth = 745
Height = 169
Width = 745
object ShortEdit: TEdit
Align = alTop
BorderSpacing.OnChange = nil
OnChange = DescrMemoChange
TabOrder = 0
Text = 'ShortEdit'
Height = 23
Width = 745
end
end
object DescrTabSheet: TTabSheet
Caption = 'DescrTabSheet'
ClientHeight = 169
ClientWidth = 745
Height = 169
@ -32,6 +48,32 @@ object LazDocForm: TLazDocForm
Font.Height = -12
Font.Name = 'Courier New'
Font.Pitch = fpFixed
Lines.Strings = (
'DescrMemo'
)
OnChange = DescrMemoChange
TabOrder = 0
Height = 169
Width = 745
end
end
object ErrorsTabSheet: TTabSheet
Caption = 'ErrorsTabSheet'
ClientHeight = 169
ClientWidth = 745
Height = 169
Width = 745
object ErrorsMemo: TMemo
Align = alClient
BorderSpacing.OnChange = nil
Font.CharSet = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -12
Font.Name = 'Courier New'
Font.Pitch = fpFixed
Lines.Strings = (
'ErrorsMemo'
)
OnChange = DescrMemoChange
TabOrder = 0
Height = 169
@ -39,11 +81,4 @@ object LazDocForm: TLazDocForm
end
end
end
object OpenDialog1: TOpenDialog
Title = 'Open existing file'
FilterIndex = 0
Title = 'Open existing file'
left = 29
top = 720
end
end

View File

@ -1,19 +1,29 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TLazDocForm','FORMDATA',[
'TPF0'#11'TLazDocForm'#10'LazDocForm'#13'ActiveControl'#7#9'TabSheet1'#7'Capt'
+'ion'#6#13'LazDoc editor'#12'ClientHeight'#3#195#0#11'ClientWidth'#3#241#2#8
+'OnCreate'#7#10'FormCreate'#13'PixelsPerInch'#2'`'#18'HorzScrollBar.Page'#3
+#240#2#18'VertScrollBar.Page'#3#194#0#4'Left'#3#245#0#6'Height'#3#195#0#3'To'
+'p'#3#250#1#5'Width'#3#241#2#0#12'TPageControl'#11'PageControl'#10'ActivePag'
+'e'#7#9'TabSheet1'#5'Align'#7#8'alClient'#8'TabIndex'#2#0#8'TabOrder'#2#0#11
+'TabPosition'#7#8'tpBottom'#6'Height'#3#195#0#5'Width'#3#241#2#0#9'TTabSheet'
+#9'TabSheet1'#7'Caption'#6#9'TabSheet1'#12'ClientHeight'#3#169#0#11'ClientWi'
+'dth'#3#233#2#6'Height'#3#169#0#5'Width'#3#233#2#0#5'TMemo'#9'DescrMemo'#5'A'
+'lign'#7#8'alClient'#12'Font.CharSet'#7#12'ANSI_CHARSET'#10'Font.Color'#7#7
+'clBlack'#11'Font.Height'#2#244#9'Font.Name'#6#11'Courier New'#10'Font.Pitch'
+#7#7'fpFixed'#8'OnChange'#7#15'DescrMemoChange'#8'TabOrder'#2#0#6'Height'#3
+#169#0#5'Width'#3#233#2#0#0#0#0#11'TOpenDialog'#11'OpenDialog1'#5'Title'#6#18
+'Open existing file'#11'FilterIndex'#2#0#5'Title'#6#18'Open existing file'#4
+'left'#2#29#3'top'#3#208#2#0#0#0
'TPF0'#11'TLazDocForm'#10'LazDocForm'#13'ActiveControl'#7#14'ErrorsTabSheet'#7
+'Caption'#6#13'LazDoc editor'#12'ClientHeight'#3#195#0#11'ClientWidth'#3#241
+#2#8'OnCreate'#7#10'FormCreate'#13'PixelsPerInch'#2'`'#18'HorzScrollBar.Page'
+#3#240#2#18'VertScrollBar.Page'#3#194#0#4'Left'#3#245#0#6'Height'#3#195#0#3
+'Top'#3#250#1#5'Width'#3#241#2#0#12'TPageControl'#11'PageControl'#10'ActiveP'
+'age'#7#14'ErrorsTabSheet'#5'Align'#7#8'alClient'#8'TabIndex'#2#2#8'TabOrder'
+#2#0#11'TabPosition'#7#8'tpBottom'#6'Height'#3#195#0#5'Width'#3#241#2#0#9'TT'
+'abSheet'#13'ShortTabSheet'#7'Caption'#6#13'ShortTabSheet'#12'ClientHeight'#3
+#169#0#11'ClientWidth'#3#233#2#6'Height'#3#169#0#5'Width'#3#233#2#0#5'TEdit'
+#9'ShortEdit'#5'Align'#7#5'alTop'#22'BorderSpacing.OnChange'#13#8'OnChange'#7
+#15'DescrMemoChange'#8'TabOrder'#2#0#4'Text'#6#9'ShortEdit'#6'Height'#2#23#5
+'Width'#3#233#2#0#0#0#9'TTabSheet'#13'DescrTabSheet'#7'Caption'#6#13'DescrTa'
+'bSheet'#12'ClientHeight'#3#169#0#11'ClientWidth'#3#233#2#6'Height'#3#169#0#5
+'Width'#3#233#2#0#5'TMemo'#9'DescrMemo'#5'Align'#7#8'alClient'#12'Font.CharS'
+'et'#7#12'ANSI_CHARSET'#10'Font.Color'#7#7'clBlack'#11'Font.Height'#2#244#9
+'Font.Name'#6#11'Courier New'#10'Font.Pitch'#7#7'fpFixed'#13'Lines.Strings'#1
+#6#9'DescrMemo'#0#8'OnChange'#7#15'DescrMemoChange'#8'TabOrder'#2#0#6'Height'
+#3#169#0#5'Width'#3#233#2#0#0#0#9'TTabSheet'#14'ErrorsTabSheet'#7'Caption'#6
+#14'ErrorsTabSheet'#12'ClientHeight'#3#169#0#11'ClientWidth'#3#233#2#6'Heigh'
+'t'#3#169#0#5'Width'#3#233#2#0#5'TMemo'#10'ErrorsMemo'#5'Align'#7#8'alClient'
+#22'BorderSpacing.OnChange'#13#12'Font.CharSet'#7#12'ANSI_CHARSET'#10'Font.C'
+'olor'#7#7'clBlack'#11'Font.Height'#2#244#9'Font.Name'#6#11'Courier New'#10
+'Font.Pitch'#7#7'fpFixed'#13'Lines.Strings'#1#6#10'ErrorsMemo'#0#8'OnChange'
+#7#15'DescrMemoChange'#8'TabOrder'#2#0#6'Height'#3#169#0#5'Width'#3#233#2#0#0
+#0#0#0
]);

View File

@ -54,21 +54,26 @@ type
TFPDocNode = record
Short: String;
Descr: String;
Errors: String;
end;
{ TLazDocForm }
TLazDocForm = class(TForm)
DescrMemo: TMemo;
OpenDialog1: TOpenDialog;
ShortEdit: TEdit;
ErrorsMemo: TMemo;
PageControl: TPageControl;
TabSheet1: TTabSheet;
DescrTabSheet: TTabSheet;
ErrorsTabSheet: TTabSheet;
ShortTabSheet: TTabSheet;
procedure DescrMemoChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
FDocFileName: String;
FCurrentElement: String;
FLastElement: String;
procedure SetDocFileName(Value: String);
function NodeByName(ElementName: String): TDOMNode;
function GetFirstChildValue(n: TDOMNode): String;
@ -119,7 +124,9 @@ begin
ReadXMLFile(doc, FDocFileName);
//clear all element editors/viewers
ShortEdit.Clear;
DescrMemo.Clear;
ErrorsMemo.Clear;
SetCaption;
@ -133,12 +140,19 @@ end;
procedure TLazDocForm.FormCreate(Sender: TObject);
begin
Caption := MAINFORMCAPTION;
with PageControl do
begin
Page[0].Caption := 'Description';
Page[0].Caption := 'Short';
Page[1].Caption := 'Description';
Page[2].Caption := 'Errors';
PageIndex := 0;
end;
//clear all element editors/viewers
ShortEdit.Clear;
DescrMemo.Clear;
ErrorsMemo.Clear;
end;
function TLazDocForm.NodeByName(ElementName: String): TDOMNode;
@ -147,6 +161,15 @@ var
begin
Result := Nil;
if not Assigned(doc) then
begin
{$ifdef dbgLazDoc}
DebugLn('TLazDocForm.NodeByName: document is not set');
{$endif}
Exit;
end;
//get first node
n := doc.FindNode('fpdoc-descriptions');
@ -219,12 +242,9 @@ begin
if S = 'descr' then
Result.Descr := GetFirstChildValue(Node);
//else if S='errors' then
//FErrorsNode:=Node.NodeValue
//else if S='seealso' then
//FSeeAlsoNode:=Node.NodeValue
//else if S='example' then
//FExampleNodes.Add(n);
if S='errors' then
Result.Errors := GetFirstChildValue(Node);
end;
Node := Node.NextSibling;
end;
@ -240,7 +260,7 @@ begin
ypos := startpos.y;
result := '';
while (src[ypos][xpos] <> '(') and (src[ypos][xpos] <> ';') do
while (src[ypos][xpos] <> '(') and (src[ypos][xpos] <> ';') and (src[ypos][xpos] <> ':') do
begin
Result := Result + src[ypos][xpos];
Inc(xpos);
@ -303,6 +323,7 @@ procedure TLazDocForm.UpdateLazDoc(source: TStrings; pos: TPoint);
var
dn: TFPDocNode;
n: TDOMNode;
EnabledState: boolean;
begin
if not Assigned(doc) then
begin
@ -317,20 +338,50 @@ begin
SetCaption;
//do not continue if FCurrentElement=FLastElement
//or FCurrentElement is empty (J. Reyes)
if (FCurrentElement = FLastElement) or (FCurrentElement = '') then
Exit;
FLastElement := FCurrentElement;
n := NodeByName(FCurrentElement);
DescrMemo.Enabled := Assigned(n);
EnabledState := Assigned(n);
ShortEdit.Enabled := True;
DescrMemo.Enabled := True;
ErrorsMemo.Enabled := True;
//detach the update method, because changing the text already
//commits to XML. Fix later, hack now ;)
ShortEdit.OnChange := nil;
DescrMemo.OnChange := nil;
ErrorsMemo.OnChange := nil;
if Assigned(n) then
begin
dn := ElementFromNode(n);
DescrMemo.Lines.Text := dn.Descr;
ShortEdit.Text := dn.Short;
DescrMemo.Lines.Text := ConvertLineEndings(dn.Descr);
ErrorsMemo.Lines.Text := ConvertLineEndings(dn.Errors);
end
else
begin
ShortEdit.Text := NODOCUMENTATION;
DescrMemo.Lines.Text := NODOCUMENTATION;
ErrorsMemo.Lines.Text := NODOCUMENTATION;
end;
//attach the update method again
ShortEdit.OnChange := @DescrMemoChange;
DescrMemo.OnChange := @DescrMemoChange;
ErrorsMemo.OnChange := @DescrMemoChange;
ShortEdit.Enabled := EnabledState;
DescrMemo.Enabled := EnabledState;
ErrorsMemo.Enabled := EnabledState;
end;
procedure TLazDocForm.DescrMemoChange(Sender: TObject);
@ -351,16 +402,43 @@ begin
begin
S := n.NodeName;
if S = 'descr' then
if S = 'short' then
begin
if not Assigned(n.FirstChild) then
begin
child := doc.CreateTextNode(DescrMemo.Text);
child := doc.CreateTextNode(ShortEdit.Text);
n.AppendChild(child);
end
else
n.FirstChild.NodeValue := DescrMemo.Text;
n.FirstChild.NodeValue := ShortEdit.Text;
end;
if S = 'descr' then
begin
DescrMemo.Lines.Delimiter := #10;
if not Assigned(n.FirstChild) then
begin
child := doc.CreateTextNode(DescrMemo.Lines.DelimitedText);
n.AppendChild(child);
end
else
n.FirstChild.NodeValue := DescrMemo.Lines.DelimitedText;
end;
if S = 'errors' then
begin
ErrorsMemo.Lines.Delimiter := #10;
if not Assigned(n.FirstChild) then
begin
child := doc.CreateTextNode(ErrorsMemo.Lines.DelimitedText);
n.AppendChild(child);
end
else
n.FirstChild.NodeValue :=ErrorsMemo.Lines.DelimitedText;
end;
end;
n := n.NextSibling;
end;