seealso section is now saved and generated

example files limited to source directory

git-svn-id: trunk@7324 -
This commit is contained in:
jesus 2005-07-06 21:24:51 +00:00
parent bf09d62ab2
commit 5122960122
5 changed files with 131 additions and 40 deletions

View File

@ -34,6 +34,7 @@ Type
{ TCustomElementEditor }
TGetElementListEvent = Procedure (List : TStrings) of Object;
TGetInitialDirEvent = function: string of object;
{ TCustomElementEditor }
@ -43,9 +44,12 @@ Type
FGetElementList: TGetElementListEvent;
FSavedNode,
FModified : Boolean;
FTargetFileName: string;
FGetInitialDir: TGetInitialDirEvent;
Protected
Function GetCurrentSelection : String; virtual; abstract;
Procedure SetElement (Value : TDomElement); virtual;
Function GetInitialDir: String;
Public
Procedure Refresh; virtual; abstract;
Function TestSave(S : String) : Boolean; virtual; abstract;
@ -61,7 +65,9 @@ Type
Property CurrentSelection : String Read GetCurrentSelection;
Property Modified : Boolean Read FModified Write FModified;
Property SavedNode : Boolean Read FSavedNode Write FSavedNode;
Property TargetFileName: String read FTargetFileName write FTargetFileName;
Property OnGetElementList : TGetElementListEvent Read FGetElementList Write FGetElementList;
Property OnGetInitialDir: TGetInitialDirEvent read FGetInitialdir write FGetInitialDir;
end;
{ TElementEditor }
@ -133,6 +139,13 @@ begin
FElement:=Value;
end;
function TCustomElementEditor.GetInitialDir: String;
begin
result := '';
if Assigned(FGetInitialDir) then
result := FGetInitialdir();
end;
{ ---------------------------------------------------------------------
TElementEditor
---------------------------------------------------------------------}
@ -517,18 +530,17 @@ begin
Result:=GetNodeString('short',Trim(FShortEntry.Text));
Result:=Result+GetNodeString('descr',trim(FDescrMemo.Text));
Result:=Result+GetNodeString('errors',trim(FErrorsMemo.Text));
For I:=1 to FSeeAlso.Items.Count-1 do
begin
S:=Trim(FExamples.Items[i]);
If (S<>'') then
Result:=Result+'<link id="'+S+'"/>';
end;
For I:=1 to FExamples.Items.Count-1 do
begin
S:=Trim(FExamples.Items[i]);
If (S<>'') then
Result:=Result+'<example file="'+S+'"/>';
end;
S:='';
for I:=0 to FSeeAlso.Items.Count-1 do
if Trim(FSeeAlso.Items[i])<>'' then
S:=S+'<link id="'+Trim(FSeeAlso.Items[i])+'"/>';
Result:=Result+GetNodeString('seealso',S);
S:='';
for I:=0 to FExamples.Items.Count-1 do
if Trim(FExamples.Items[i])<>'' then
S:=S+'<example file="'+Trim(FExamples.Items[i])+'"/>';
Result:=Result+S;
//Result:=Result+GetNodeString('example',S);
end;
Function TElementEditor.Save : Boolean;
@ -709,10 +721,14 @@ begin
With TExampleForm.Create(Self) do
Try
ExampleName:='example.pp';
ExampleDir:= GetInitialDir;
If ShowModal=mrOK then
begin
FExamples.Items.Add(ExampleName);
Modified:=True;
if FExamples.Items.IndexOf(ExampleName)<0 then
begin
FExamples.Items.Add(ExampleName);
Modified:=True;
end;
end;
Finally
Free;
@ -787,8 +803,11 @@ begin
S:='';
If EditLink(S) then
begin
FSeeAlso.Items.Add(S);
Modified:=True;
if FSeeAlso.Items.IndexOf(S)<0 then
begin
FSeeAlso.Items.Add(S);
Modified:=True;
end;
end;
end;

View File

@ -2,14 +2,16 @@ object ExampleForm: TExampleForm
Caption = 'Example file'
ClientHeight = 85
ClientWidth = 404
PixelsPerInch = 90
OnCloseQuery = ExampleFormCloseQuery
PixelsPerInch = 75
HorzScrollBar.Page = 403
VertScrollBar.Page = 84
Left = 437
Left = 387
Height = 85
Top = 311
Width = 404
object LEFileName: TLabel
BorderSpacing.OnChange = nil
Caption = '&Filename'
FocusControl = EFileName
Layout = tlCenter
@ -23,6 +25,7 @@ object ExampleForm: TExampleForm
end
object BOK: TButton
Anchors = [akTop, akRight]
BorderSpacing.OnChange = nil
Caption = '&OK'
Default = True
ModalResult = 1
@ -34,6 +37,7 @@ object ExampleForm: TExampleForm
end
object BCancel: TButton
Anchors = [akTop, akRight]
BorderSpacing.OnChange = nil
Cancel = True
Caption = '&Cancel'
ModalResult = 2
@ -45,12 +49,14 @@ object ExampleForm: TExampleForm
end
object EFileName: TFileNameEdit
DialogTitle = 'Select an example file'
Filter = 'Pascal files |*.pp|Pascal files|*.pas'
Filter = 'Pascal files|*.pp;*.pas|All files|*.*'
ButtonWidth = 23
NumGlyphs = 1
Anchors = [akTop, akLeft, akRight]
BorderSpacing.OnChange = nil
TabOrder = 2
Anchors = [akTop, akLeft, akRight]
BorderSpacing.OnChange = nil
TabOrder = 2
Left = 80
Height = 23

View File

@ -1,19 +1,24 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TExampleForm','FORMDATA',[
'TPF0'#12'TExampleForm'#11'ExampleForm'#7'Caption'#6#12'Example file'#12'Clie'
+'ntHeight'#2'U'#11'ClientWidth'#3#148#1#13'PixelsPerInch'#2'Z'#18'HorzScroll'
+'Bar.Page'#3#147#1#18'VertScrollBar.Page'#2'T'#4'Left'#3#181#1#6'Height'#2'U'
+#3'Top'#3'7'#1#5'Width'#3#148#1#0#6'TLabel'#10'LEFileName'#7'Caption'#6#9'&F'
+'ilename'#12'FocusControl'#7#9'EFileName'#6'Layout'#7#8'tlCenter'#11'ParentC'
+'olor'#9#21'AnchorSideTop.Control'#7#9'EFileName'#18'AnchorSideTop.Side'#7#9
+'ntHeight'#2'U'#11'ClientWidth'#3#148#1#12'OnCloseQuery'#7#21'ExampleFormClo'
+'seQuery'#13'PixelsPerInch'#2'K'#18'HorzScrollBar.Page'#3#147#1#18'VertScrol'
+'lBar.Page'#2'T'#4'Left'#3#131#1#6'Height'#2'U'#3'Top'#3'7'#1#5'Width'#3#148
+#1#0#6'TLabel'#10'LEFileName'#22'BorderSpacing.OnChange'#13#7'Caption'#6#9'&'
+'Filename'#12'FocusControl'#7#9'EFileName'#6'Layout'#7#8'tlCenter'#11'Parent'
+'Color'#9#21'AnchorSideTop.Control'#7#9'EFileName'#18'AnchorSideTop.Side'#7#9
+'asrCenter'#4'Left'#2#12#6'Height'#2#12#3'Top'#2#21#5'Width'#2'<'#0#0#7'TBut'
+'ton'#3'BOK'#7'Anchors'#11#5'akTop'#7'akRight'#0#7'Caption'#6#3'&OK'#7'Defau'
+'lt'#9#11'ModalResult'#2#1#8'TabOrder'#2#0#4'Left'#3'8'#1#6'Height'#2#26#3'T'
+'op'#2#14#5'Width'#2'O'#0#0#7'TButton'#7'BCancel'#7'Anchors'#11#5'akTop'#7'a'
+'kRight'#0#6'Cancel'#9#7'Caption'#6#7'&Cancel'#11'ModalResult'#2#2#8'TabOrde'
+'r'#2#1#4'Left'#3'8'#1#6'Height'#2#26#3'Top'#2'0'#5'Width'#2'O'#0#0#13'TFile'
+'NameEdit'#9'EFileName'#11'DialogTitle'#6#22'Select an example file'#6'Filte'
+'r'#6'%Pascal files |*.pp|Pascal files|*.pas'#11'ButtonWidth'#2#23#9'NumGlyp'
+'hs'#2#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'TabOrder'#2#2#7'Anc'
+'hors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'TabOrder'#2#2#4'Left'#2'P'#6'Hei'
+'ght'#2#23#3'Top'#2#16#5'Width'#3#196#0#0#0#0
+'ton'#3'BOK'#7'Anchors'#11#5'akTop'#7'akRight'#0#22'BorderSpacing.OnChange'
+#13#7'Caption'#6#3'&OK'#7'Default'#9#11'ModalResult'#2#1#8'TabOrder'#2#0#4'L'
+'eft'#3'8'#1#6'Height'#2#26#3'Top'#2#14#5'Width'#2'O'#0#0#7'TButton'#7'BCanc'
+'el'#7'Anchors'#11#5'akTop'#7'akRight'#0#22'BorderSpacing.OnChange'#13#6'Can'
+'cel'#9#7'Caption'#6#7'&Cancel'#11'ModalResult'#2#2#8'TabOrder'#2#1#4'Left'#3
+'8'#1#6'Height'#2#26#3'Top'#2'0'#5'Width'#2'O'#0#0#13'TFileNameEdit'#9'EFile'
+'Name'#11'DialogTitle'#6#22'Select an example file'#6'Filter'#6'%Pascal file'
+'s|*.pp;*.pas|All files|*.*'#11'ButtonWidth'#2#23#9'NumGlyphs'#2#1#7'Anchors'
+#11#5'akTop'#6'akLeft'#7'akRight'#0#22'BorderSpacing.OnChange'#13#8'TabOrder'
+#2#2#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#22'BorderSpacing.OnChange'
+#13#8'TabOrder'#2#2#4'Left'#2'P'#6'Height'#2#23#3'Top'#2#16#5'Width'#3#196#0
+#0#0#0
]);

View File

@ -39,13 +39,18 @@ type
BCancel: TButton;
EFileName: TFileNameEdit;
LEFileName: TLabel;
procedure ExampleFormCloseQuery(Sender: TObject; var CanClose: boolean);
private
function GetExampleDir: String;
function GetExampleName: String;
procedure SetExampleDir(const AValue: String);
procedure SetExampleName(const AValue: String);
function CheckFilePath(const AValue: String): boolean;
{ private declarations }
public
{ public declarations }
Property ExampleName : String Read GetExampleName Write SetExampleName;
Property ExampleDir: String read GetExampleDir write SetExampleDir;
end;
var
@ -58,9 +63,32 @@ implementation
{ TExampleForm }
procedure TExampleForm.ExampleFormCloseQuery(Sender: TObject;
var CanClose: boolean);
var
S: String;
begin
if ModalResult = mrOk then begin
S := ExtractFilePath(EFilename.Text);
CanClose := CheckFilePath(S);
end;
end;
function TExampleForm.GetExampleDir: String;
begin
Result := EFileName.InitialDir;
end;
function TExampleForm.GetExampleName: String;
begin
Result:=EFileName.FileName
Result:=EFilename.Text; //EFileName.FileName;
if ExampleDir<>'' then
Result := ExtractRelativePath(ExampleDir, Result);
end;
procedure TExampleForm.SetExampleDir(const AValue: String);
begin
EFileName.InitialDir := AValue;
end;
procedure TExampleForm.SetExampleName(const AValue: String);
@ -68,6 +96,26 @@ begin
EFileName.FileName:=AValue;
end;
function TExampleForm.CheckFilePath(const AValue: String): boolean;
begin
Result := True;
// Check Empty Path and filename
if (Length(ExtractFilePath(AValue))=0) and FileExists(ExampleDir+AValue) then
exit;
// Check partial file path within ExampleDir
if FileExists(ExampleDir + AValue) then
exit;
// it might be a full path
if FileExists(AValue) and (Pos(ExampleDir, AValue)<>0) then
exit;
Result := false;
ShowMessage('Invalid file or path');
end;
initialization
{$I frmexample.lrs}

View File

@ -99,6 +99,7 @@ Type
Procedure NewTopic(ATopicName : String);
Procedure NewElement(AElementName : String);
Procedure GetElementList(List : TStrings);
function GetInitialDir: String;
Procedure ClearDocument;
Function CanInsertTag(TagType : TTagType) : Boolean;
Property FileName : String Read FFileName;
@ -137,6 +138,7 @@ begin
FElement.Parent:=Self;
Felement.Align:=AlClient;
FElement.OnGetElementList:=@GetELementList;
FElement.OnGetInitialDir:=@GetInitialDir;
end;
@ -206,15 +208,19 @@ end;
Procedure TEditorPage.SaveToFile(FN : String);
begin
If FElement.Modified then
FElement.Save;
If (not FileExists(FN)) or MakeBackup(FN) then
begin
WriteXMLFile(FDocument,FN);
Modified:=False;
if (FN<>FFileName) then
SetFileName(FN);
end;
If FElement.Modified then
FElement.Save;
WriteXMLFile(FDocument,FN);
Modified:=False;
end;
end;
Procedure TEditorPage.DisplayDocument;
@ -494,4 +500,11 @@ begin
end;
end;
function TEditorPage.GetInitialDir: String;
begin
result := '';
if FileExists(FFileName) then
Result := ExtractFilePath(FFileName);
end;
end.