* Support for selecting an element using --element command-line option

git-svn-id: trunk@31806 -
This commit is contained in:
michael 2011-07-26 18:51:32 +00:00
parent 8b707e5d00
commit fe55286e6f
6 changed files with 139 additions and 32 deletions

View File

@ -175,7 +175,7 @@ type
procedure BuildReopenList;
Procedure AddTorecent(FN : String);
procedure FormLocalization;
Procedure OpenFile(FN : String);
Procedure OpenFile(FN : String; Const AStartNode : String = '');
Procedure SaveEditorAs(E : TEditorPage);
Procedure SaveEditor(E : TEditorPage);
Function CloseEditor(E : TEditorPage) : Boolean;
@ -600,14 +600,14 @@ begin
end;
end;
procedure TMainForm.OpenFile(FN: String);
procedure TMainForm.OpenFile(FN: String; Const AStartNode : String = '');
begin
if (FN<>'') then
begin
If FileExistsUTF8(FN) then
With CreatePage do
begin
LoadFromFile(UTF8ToSys(FN));
LoadFromFile(UTF8ToSys(FN),AStartNode);
AddToRecent(Fn);
end;
end;
@ -665,12 +665,22 @@ end;
procedure TMainForm.LoadCommandLine;
var
I : Integer;
N : string;
begin
I:=1;
While I<=ParamCount do
begin
If FileExistsUTF8(ParamStrUTF8(i)) then
OpenFile(ParamStrUTF8(I));
if (Copy(ParamStrUTF8(i),1,10)='--element=') then
begin
N:=ParamStrUTF8(i);
Delete(N,1,10);
end
else
begin
If FileExistsUTF8(ParamStrUTF8(i)) then
OpenFile(ParamStrUTF8(I),N);
N:='';
end;
Inc(I);
end;
end;

View File

@ -33,6 +33,7 @@
<RunParams>
<local>
<FormatVersion Value="1"/>
<CommandLineParams Value="--element=rtl.system.writeln /home/michael/docs/system.xml"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
@ -167,7 +168,7 @@
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="9"/>
<Version Value="10"/>
<Target>
<Filename Value="lazde"/>
</Target>

Binary file not shown.

View File

@ -222,7 +222,7 @@ ResourceString
SErrNoModuleForElement = 'No module found to insert element "%s"';
//SErrNoNodeForElement = 'No node found for element "%s"';
SErrUnknownDomElement = 'Unknwon DOM element as parent for selected element: "%s"';
SStartNodeNotFound = 'Start element "%d" could not be found';
//SSaveFileTitle = 'Enter filename to save to';
//SOpenFileTitle = 'Select file to open';

View File

@ -70,6 +70,9 @@ Type
FSplitter : TSplitter;
FFileNAme : String;
Procedure ElementSelected(Node : TDomElement) ;
function FindElement(const ElementName: String; Out PE,ME : TDomElement): TDomElement;
function FindElementNode(AParent: TDomElement; const ANodeName: String;
const AElementName: string): TDomElement;
Procedure TopicSelected(Node : TDomElement) ;
Procedure ModuleSelected(Node : TDomElement) ;
Procedure PackageSelected(Node : TDomElement) ;
@ -87,7 +90,7 @@ Type
Procedure SetModified(Value : Boolean);
Function GetModified : Boolean;
Function MakeBackup(FN : String) : Boolean;
Procedure DisplayDocument;
Procedure DisplayDocument(Const AStartNode : String = '');
Procedure ElementChanged(Sender: TObject);
protected
procedure SetParent(NewParent: TWinControl); override;
@ -95,7 +98,7 @@ Type
constructor Create(AOwner : TComponent); override;
Function FirstPackage : TDomElement;
Function FirstModule(APackage : TDomElement) : TDomElement;
Procedure LoadFromFile(FN : String);
Procedure LoadFromFile(FN : String; Const AStartNode : String = '');
Procedure LoadFromStream(S : TStream);
Procedure SaveToFile(FN : String);
Procedure SetFileName(FN : String);
@ -172,7 +175,7 @@ begin
Result:=FElement.CanInsertTag(TagType);
end;
Procedure TEditorPage.LoadFromFile(FN : String);
Procedure TEditorPage.LoadFromFile(FN : String; Const AStartNode : String = '');
Var
F : TFileStream;
@ -183,7 +186,7 @@ begin
Try
SetFileName(FN);
ReadXMLFile(FDocument,F);
DisplayDocument;
DisplayDocument(AStartNode);
finally
F.Free;
end;
@ -228,10 +231,94 @@ begin
Modified :=False;
end;
Procedure TEditorPage.DisplayDocument;
function TEditorPage.FindElementNode(AParent : TDomElement; Const ANodeName : String; Const AElementName : string) : TDomElement;
Var
N : TDomNode;
begin
Result:=Nil;
N:=AParent.FirstChild;
While (Result=Nil) and (N<>Nil) do
begin
if (N.NodeType=ELEMENT_NODE) and (N.NodeName=ANodeName) then
If (AElementName='') or (CompareText((N as TDomElement).AttribStrings['name'],AElementName)=0) then
Result:=N as TDomElement;
N:=N.NextSibling;
end;
end;
function TEditorPage.FindElement(Const ElementName : String; Out PE,ME : TDomElement) : TDomElement;
Function GetNextPart(Var N : String) : String;
Var
p : integer;
begin
P:=Pos('.',N);
if P=0 then
P:=Length(N)+1;
Result:=Copy(N,1,P-1);
Delete(N,1,P);
end;
Var
P : Integer;
PN,N : String;
begin
Result:=Nil;
PE:=Nil;
ME:=Nil;
N:=ElementName;
// Extract package name.
PN:=GetNextPart(N);
// Search package node
PE:=FindElementNode(FDocument.DocumentElement,'package',PN);
// if not found, assume first part is modulename in first package.
if (PE=Nil) then
begin
PE:=FindElementNode(FDocument.DocumentElement,'package',PN);
N:=ElementName;
end;
if (PE=Nil) then // No package node !
exit;
// Extract Module name
PN:=GetNextPart(N);
ME:=FindElementNode(PE,'module',PN);
// if not found, assume elementname is element in first module.
if (ME=Nil) then
begin
ME:=FindElementNode(PE,'module',PN);
N:=ElementName;
end;
if (ME=Nil) then // No module node !
exit;
Result:=FindElementNode(ME,'element',N);
end;
Procedure TEditorPage.DisplayDocument(Const AStartNode : String = '');
Var
PE,ME,EE : TDomElement;
begin
EE:=Nil;
if (AStartNode <> '') then
begin
EE:=FindElement(AStartNode,PE,ME);
If (EE=Nil) then
ShowMessage(Format(SStartNodeNotFound,[AStartNode]));
end;
FPackages.DescriptionNode:=FDocument.DocumentElement;
if (EE<>Nil) then
begin
FPackages.CurrentPackage:=PE;
FPackages.CurrentModule:=ME;
FPackages.CurrentElement:=EE;
end;
end;
procedure TEditorPage.ElementChanged(Sender: TObject);

View File

@ -296,6 +296,7 @@ begin
OnChange:=@ModuleChange;
OnChanging:=@ModuleChanging;
ReadOnly:=True;
HideSelection:=False;
end;
FSplitter:=TSplitter.Create(Self);
With FSplitter do
@ -329,6 +330,7 @@ begin
OnChange:=@ElementChange;
OnChanging:=@ElementChanging;
ReadOnly:=True;
HideSelection:=False;
end;
PEMenu:=TPopupMenu.Create(Self);
FERenameMenu:=NewMenuItem(SMenuRename,@MenuRenameClick);
@ -799,28 +801,33 @@ begin
// root node
TNode:=FModuleNode;
// process list of elements, create levels
For I:=0 to S.Count-1 do
begin
PNode:=Nil;
SNode:=TNode;
N:=S[i];
// look for a tentative new parents
While (SNode<>FModuleNode) and (PNode=Nil) do
FElementTree.Items.BeginUpdate;
try
For I:=0 to S.Count-1 do
begin
PN:=TDomElement(SNode.Data)['name']+'.';
L:=Length(PN);
If CompareText(Copy(N,1,L),PN)=0 then
PNode:=SNode;
SNode:=SNode.Parent;
PNode:=Nil;
SNode:=TNode;
N:=S[i];
// look for a tentative new parents
While (SNode<>FModuleNode) and (PNode=Nil) do
begin
PN:=TDomElement(SNode.Data)['name']+'.';
L:=Length(PN);
If CompareText(Copy(N,1,L),PN)=0 then
PNode:=SNode;
SNode:=SNode.Parent;
end;
If (PNode=Nil) then
PNode:=FModuleNode
else
System.Delete(N,1,L);
TNode:=FElementTree.Items.AddChild(PNode,N);
TNode.Data:=S.Objects[i];
UpdateNodeImage(TNode);
end;
If (PNode=Nil) then
PNode:=FModuleNode
else
System.Delete(N,1,L);
TNode:=FElementTree.Items.AddChild(PNode,N);
TNode.Data:=S.Objects[i];
UpdateNodeImage(TNode);
end;
finally
FElementTree.Items.EndUpdate;
end;
Finally
S.Free;
end;
@ -1007,6 +1014,7 @@ begin
SetCurrentModuleNode(FindModuleNodeInNode(Value,Nil))
else
ClearElements;
FCurrentModule:=Value
end;
end;
@ -1020,6 +1028,7 @@ begin
If Assigned(P) then
P.Expand(False);
FModuleTree.Selected:=N;
Application.ProcessMessages;
end;
Procedure TPackageEditor.SetCurrentTopic(T : TDomElement);