diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-29 19:15:55 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-29 19:15:55 +0000 |
commit | 2464b59219ab51717fe2032fb0d0dcfe58a9f0e7 (patch) | |
tree | 033b2de8f286660d01a5b5215b70eecb9c0d9830 | |
parent | beca36cc9490d43fd36afcc04aadfe91121acaf7 (diff) | |
download | fpGUI-2464b59219ab51717fe2032fb0d0dcfe58a9f0e7.tar.xz |
* docedit: Started work on parsing a fpdoc description (xml) file.
-rw-r--r-- | examples/apps/docedit/frm_main.pas | 182 | ||||
-rw-r--r-- | examples/apps/docedit/tests/test1.xml | 8 | ||||
-rw-r--r-- | examples/apps/docedit/tests/test2.xml | 18 | ||||
-rw-r--r-- | examples/apps/docedit/tests/test3.xml | 24 |
4 files changed, 231 insertions, 1 deletions
diff --git a/examples/apps/docedit/frm_main.pas b/examples/apps/docedit/frm_main.pas index cd8fe01f..80791ad9 100644 --- a/examples/apps/docedit/frm_main.pas +++ b/examples/apps/docedit/frm_main.pas @@ -2,6 +2,10 @@ unit frm_main; {$mode objfpc}{$H+} +{ + NOTE: This is still work in progress!!!!!!! +} + interface uses @@ -12,12 +16,15 @@ uses gui_button, gui_edit, gui_label, - gui_menu; + gui_menu, + gui_memo, + dom, XMLWrite, XMLRead, contnrs; type TMainForm = class(TfpgForm) private btnQuit: TfpgButton; + FDescriptionNode: TDomNode; lblXMLFile: TfpgLabel; edXMLFile: TfpgEdit; btnOpen: TfpgButton; @@ -26,6 +33,13 @@ type miInsert: TfpgPopupMenu; miExtra: TfpgPopupMenu; miHelp: TfpgPopupMenu; + + FDoc: TXMLDocument; + FModified: Boolean; + CurrentModule: TDomElement; + FModuleTree: TObjectList; + FElementTree: TObjectList; + procedure btnQuitClicked(Sender: TObject); procedure btnOpenClicked(Sender: TObject); procedure InitializeComponents; @@ -34,8 +48,13 @@ type procedure miFileOpenClicked(Sender: TObject); procedure miFileSaveAsClicked(Sender: TObject); procedure miHelpAboutClicked(Sender: TObject); + procedure ProcessXMLFile(pFilename: string); + procedure Refresh; + procedure GetElementList(List: TStrings); public constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + property DescriptionNode: TDomNode read FDescriptionNode write FDescriptionNode; end; @@ -47,6 +66,35 @@ uses const cAppName = 'FPDoc Documentation Editor'; + + +type + TNodeTreeItem = class(TObjectList) + private + FNode: TDomElement; + public + constructor Create(ANode: TDomElement); virtual; + procedure CheckSubItems; + property Node: TDomElement Read FNode; + end; + + TModuleTreeItem = class(TNodeTreeItem); + TTopicTreeItem = class(TNodeTreeItem); + TPackageTreeItem = class(TNodeTreeItem); + +{ TNodeTreeItem } + +constructor TNodeTreeItem.Create(ANode: TDomElement); +begin + inherited Create(false); + FNode := ANode; +end; + +procedure TNodeTreeItem.CheckSubItems; +begin +// If (SubTree=Nil) then +// SubTree:=TFPgtkTree.Create; +end; { TMainForm } @@ -138,6 +186,7 @@ begin dlg.Filter := 'FPDoc Desc Files (*.xml)|*.xml|All Files (*)|*'; if dlg.RunOpenFile then edXMLFile.Text := dlg.FileName; + ProcessXMLFile(dlg.FileName); finally dlg.Free; end; @@ -167,6 +216,127 @@ begin ,'About'); end; +procedure TMainForm.ProcessXMLFile(pFilename: string); +var + dn: TDOMNode; + ls: TStringList; +begin + ReadXMLFile(FDoc, pFilename); + FDescriptionNode := FDoc.DocumentElement; + Refresh; + ls := TStringList.Create; + GetElementList(ls); + writeln('.......'); + writeln(ls.Text); + ls.Free; +end; + +procedure TMainForm.Refresh; + + procedure DoTopicNode(Node: TDomElement; Parent: TNodeTreeItem); + var + TTreeNode: TTopicTreeItem; + SubNode: TDomNode; + begin + TTreeNode := TTopicTreeItem.Create(TDomElement(Node)); +// TTreeNode.ConnectSelect(@SelectTopic,Node); +// TTreeNode.ConnectButtonPressEvent(@PopupTopicMenu,Nil); +// Parent.CheckSubItems; + Parent.Add(TTreeNode); +// TFPGtkTree(Parent.SubTree).Append(TTreeNode); +// TTreeNode.Show; + SubNode := Node.FirstChild; + while (SubNode <> nil) do + begin + if (SubNode.NodeType = ELEMENT_NODE) and (SubNode.NodeName = 'topic') then + DoTopicNode(SubNode as TDomElement, TTreeNode); + SubNode := SubNode.NextSibling; + end; + end; + +var + Node, SubNode, SSnode: TDomNode; + FTreeNode: TPackageTreeItem; + MTreeNode: TModuleTreeItem; + +begin + CurrentModule := nil; + +// FModuleTree.Tree.ClearItems(0,-1); + if Assigned(FDescriptionNode) then + begin + Node := FDescriptionNode.FirstChild; + while Assigned(Node) do + begin + if (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'package') then + begin + writeln('package: ', Node.Attributes.GetNamedItem('name').TextContent); + FTreeNode := TPackageTreeItem.Create(TDomElement(Node)); +// FTreeNode.ConnectSelect(@Selectpackage,Node); +// FTreeNode.ConnectButtonPressEvent(@PopupModuleMenu,Nil); + FModuleTree.Add(FTreeNode); +// FTreeNode.Show; + SubNode := Node.FirstChild; + while Assigned(SubNode) do + begin + if (SubNode.NodeType = ELEMENT_NODE) and (SubNode.NodeName = 'module') then + begin + writeln(' module: ', SubNode.Attributes.GetNamedItem('name').TextContent); + if not Assigned(CurrentModule) then + CurrentModule := TDomElement(SubNode); + MTreeNode := TModuleTreeItem.Create(TDomElement(SubNode)); +// MtreeNode.ConnectSelect(@SelectModule,SubNode); +// MTreeNode.ConnectButtonPressEvent(@PopupModuleMenu,Nil); +// FTreeNode.CheckSubtree; + FTreeNode.Add(MTreeNode); +// TFPGtkTree(FTreeNode.SubTree).Append(MTreeNode); + //MTreeNode.Show; + SSNode := SubNode.FirstChild; + while (SSNode <> nil) do + begin + if (SSNode.NodeType = ELEMENT_NODE) and (SSNode.NodeName = 'topic') then + begin + writeln(' topic: ', SSNode.Attributes.GetNamedItem('name').TextContent); + DoTopicNode(SSNode as TDomElement, MTreeNode); + end; + SSNode := SSNode.NextSibling; + end; + end + else if (SubNode.NodeType = ELEMENT_NODE) and (SubNode.NodeName = 'topic') then + begin + writeln(' topic: ', SubNode.Attributes.GetNamedItem('name').TextContent); + DoTopicNode(SubNode as TDomElement,FTreeNode); + end; + SubNode := SubNode.NextSibling; + end; + end; + Node := Node.NextSibling; + end; + end; +// CurrentModule := Nil; + FModified := False; +end; + +procedure TMainForm.GetElementList(List: TStrings); +var + N: TDOMNode; +begin + with List do + begin + Clear; + if Assigned(CurrentModule) then + begin + N := Currentmodule.FirstChild; + while (N <> Nil) do + begin + if (N is TDomElement) and (N.NodeName = 'element') then + Add(TDomElement(N)['name']); + N := N.NextSibling; + end; + end; + end; +end; + constructor TMainForm.Create(AOwner: TComponent); begin inherited Create(AOwner); @@ -177,6 +347,16 @@ begin Height := 402; InitializeComponents; + + FModuleTree := TObjectList.Create; + FElementTree := TObjectList.Create; +end; + +destructor TMainForm.Destroy; +begin + FModuleTree.Free; + FElementTree.Free; + inherited Destroy; end; end. diff --git a/examples/apps/docedit/tests/test1.xml b/examples/apps/docedit/tests/test1.xml new file mode 100644 index 00000000..7647a0c2 --- /dev/null +++ b/examples/apps/docedit/tests/test1.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="ISO8859-1"?> +<fpdoc-description> +<package name="fpc"> +<module name="Classes"> +</module> +</package> +</fpdoc-description> + diff --git a/examples/apps/docedit/tests/test2.xml b/examples/apps/docedit/tests/test2.xml new file mode 100644 index 00000000..071b524b --- /dev/null +++ b/examples/apps/docedit/tests/test2.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="ISO8859-1"?> +<fpdoc-description> + +<package name="fpc"> + +<module name="Classes"> + <topic name="UsingKeyboard"> + <short>Using the keyboard functions</short> + <descr> + To use the keyboard functions of the CRT unit, one... + </descr> + </topic> +</module> + +</package> + +</fpdoc-description> + diff --git a/examples/apps/docedit/tests/test3.xml b/examples/apps/docedit/tests/test3.xml new file mode 100644 index 00000000..737d80dd --- /dev/null +++ b/examples/apps/docedit/tests/test3.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="ISO8859-1"?> +<fpdoc-description> + +<package name="fpc"> + +<module name="Classes"> + <topic name="UsingKeyboard"> + <short>Using the keyboard functions</short> + <descr> + To use the keyboard functions of the CRT unit, one... + </descr> + </topic> + + <element name="TWindowPosition"> + <short></short> + <descr></descr> + <seealso></seealso> + </element> +</module> + +</package> + +</fpdoc-description> + |