mirror of
				https://gitlab.com/freepascal.org/lazarus/lazarus.git
				synced 2025-10-29 17:42:41 +01:00 
			
		
		
		
	* Support for selecting an element using --element command-line option
git-svn-id: trunk@31806 -
This commit is contained in:
		
							parent
							
								
									8b707e5d00
								
							
						
					
					
						commit
						fe55286e6f
					
				| @ -175,7 +175,7 @@ type | |||||||
|     procedure BuildReopenList; |     procedure BuildReopenList; | ||||||
|     Procedure AddTorecent(FN : String); |     Procedure AddTorecent(FN : String); | ||||||
|     procedure FormLocalization; |     procedure FormLocalization; | ||||||
|     Procedure OpenFile(FN : String); |     Procedure OpenFile(FN : String; Const AStartNode : String = ''); | ||||||
|     Procedure SaveEditorAs(E : TEditorPage); |     Procedure SaveEditorAs(E : TEditorPage); | ||||||
|     Procedure SaveEditor(E : TEditorPage); |     Procedure SaveEditor(E : TEditorPage); | ||||||
|     Function  CloseEditor(E : TEditorPage) : Boolean; |     Function  CloseEditor(E : TEditorPage) : Boolean; | ||||||
| @ -600,14 +600,14 @@ begin | |||||||
|   end; |   end; | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| procedure TMainForm.OpenFile(FN: String); | procedure TMainForm.OpenFile(FN: String; Const AStartNode : String = ''); | ||||||
| begin | begin | ||||||
|   if (FN<>'') then |   if (FN<>'') then | ||||||
|     begin |     begin | ||||||
|     If FileExistsUTF8(FN) then |     If FileExistsUTF8(FN) then | ||||||
|       With CreatePage do |       With CreatePage do | ||||||
|         begin |         begin | ||||||
|         LoadFromFile(UTF8ToSys(FN)); |         LoadFromFile(UTF8ToSys(FN),AStartNode); | ||||||
|         AddToRecent(Fn); |         AddToRecent(Fn); | ||||||
|         end; |         end; | ||||||
|     end; |     end; | ||||||
| @ -665,12 +665,22 @@ end; | |||||||
| procedure TMainForm.LoadCommandLine; | procedure TMainForm.LoadCommandLine; | ||||||
| var | var | ||||||
|   I : Integer; |   I : Integer; | ||||||
|  |   N : string; | ||||||
| begin | begin | ||||||
|   I:=1; |   I:=1; | ||||||
|   While I<=ParamCount do |   While I<=ParamCount do | ||||||
|     begin |     begin | ||||||
|     If FileExistsUTF8(ParamStrUTF8(i)) then |     if (Copy(ParamStrUTF8(i),1,10)='--element=') then | ||||||
|       OpenFile(ParamStrUTF8(I)); |       begin | ||||||
|  |       N:=ParamStrUTF8(i); | ||||||
|  |       Delete(N,1,10); | ||||||
|  |       end | ||||||
|  |     else | ||||||
|  |       begin | ||||||
|  |       If FileExistsUTF8(ParamStrUTF8(i)) then | ||||||
|  |         OpenFile(ParamStrUTF8(I),N); | ||||||
|  |       N:=''; | ||||||
|  |       end; | ||||||
|     Inc(I); |     Inc(I); | ||||||
|     end; |     end; | ||||||
| end; | end; | ||||||
|  | |||||||
| @ -33,6 +33,7 @@ | |||||||
|     <RunParams> |     <RunParams> | ||||||
|       <local> |       <local> | ||||||
|         <FormatVersion Value="1"/> |         <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)"/> |         <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> | ||||||
|       </local> |       </local> | ||||||
|     </RunParams> |     </RunParams> | ||||||
| @ -167,7 +168,7 @@ | |||||||
|     </Units> |     </Units> | ||||||
|   </ProjectOptions> |   </ProjectOptions> | ||||||
|   <CompilerOptions> |   <CompilerOptions> | ||||||
|     <Version Value="9"/> |     <Version Value="10"/> | ||||||
|     <Target> |     <Target> | ||||||
|       <Filename Value="lazde"/> |       <Filename Value="lazde"/> | ||||||
|     </Target> |     </Target> | ||||||
|  | |||||||
										
											Binary file not shown.
										
									
								
							| @ -222,7 +222,7 @@ ResourceString | |||||||
|   SErrNoModuleForElement = 'No module found to insert element "%s"'; |   SErrNoModuleForElement = 'No module found to insert element "%s"'; | ||||||
|   //SErrNoNodeForElement   = 'No node found for element "%s"'; |   //SErrNoNodeForElement   = 'No node found for element "%s"'; | ||||||
|   SErrUnknownDomElement  = 'Unknwon DOM element as parent for selected 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'; |   //SSaveFileTitle = 'Enter filename to save to'; | ||||||
|   //SOpenFileTitle = 'Select file to open'; |   //SOpenFileTitle = 'Select file to open'; | ||||||
|  | |||||||
| @ -70,6 +70,9 @@ Type | |||||||
|     FSplitter : TSplitter; |     FSplitter : TSplitter; | ||||||
|     FFileNAme : String; |     FFileNAme : String; | ||||||
|     Procedure ElementSelected(Node : TDomElement) ; |     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 TopicSelected(Node : TDomElement) ; | ||||||
|     Procedure ModuleSelected(Node : TDomElement) ; |     Procedure ModuleSelected(Node : TDomElement) ; | ||||||
|     Procedure PackageSelected(Node : TDomElement) ; |     Procedure PackageSelected(Node : TDomElement) ; | ||||||
| @ -87,7 +90,7 @@ Type | |||||||
|     Procedure SetModified(Value : Boolean); |     Procedure SetModified(Value : Boolean); | ||||||
|     Function  GetModified : Boolean; |     Function  GetModified : Boolean; | ||||||
|     Function MakeBackup(FN : String) : Boolean; |     Function MakeBackup(FN : String) : Boolean; | ||||||
|     Procedure DisplayDocument; |     Procedure DisplayDocument(Const AStartNode : String = ''); | ||||||
|     Procedure ElementChanged(Sender: TObject); |     Procedure ElementChanged(Sender: TObject); | ||||||
|   protected |   protected | ||||||
|     procedure SetParent(NewParent: TWinControl); override; |     procedure SetParent(NewParent: TWinControl); override; | ||||||
| @ -95,7 +98,7 @@ Type | |||||||
|     constructor Create(AOwner : TComponent); override; |     constructor Create(AOwner : TComponent); override; | ||||||
|     Function  FirstPackage : TDomElement; |     Function  FirstPackage : TDomElement; | ||||||
|     Function  FirstModule(APackage : TDomElement) : TDomElement; |     Function  FirstModule(APackage : TDomElement) : TDomElement; | ||||||
|     Procedure LoadFromFile(FN : String); |     Procedure LoadFromFile(FN : String; Const AStartNode : String = ''); | ||||||
|     Procedure LoadFromStream(S : TStream); |     Procedure LoadFromStream(S : TStream); | ||||||
|     Procedure SaveToFile(FN : String); |     Procedure SaveToFile(FN : String); | ||||||
|     Procedure SetFileName(FN : String); |     Procedure SetFileName(FN : String); | ||||||
| @ -172,7 +175,7 @@ begin | |||||||
|   Result:=FElement.CanInsertTag(TagType); |   Result:=FElement.CanInsertTag(TagType); | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| Procedure TEditorPage.LoadFromFile(FN : String); | Procedure TEditorPage.LoadFromFile(FN : String; Const AStartNode : String = ''); | ||||||
| 
 | 
 | ||||||
| Var | Var | ||||||
|   F : TFileStream; |   F : TFileStream; | ||||||
| @ -183,7 +186,7 @@ begin | |||||||
|   Try |   Try | ||||||
|     SetFileName(FN); |     SetFileName(FN); | ||||||
|     ReadXMLFile(FDocument,F); |     ReadXMLFile(FDocument,F); | ||||||
|     DisplayDocument; |     DisplayDocument(AStartNode); | ||||||
|   finally |   finally | ||||||
|     F.Free; |     F.Free; | ||||||
|   end; |   end; | ||||||
| @ -228,10 +231,94 @@ begin | |||||||
|   Modified :=False; |   Modified :=False; | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| Procedure TEditorPage.DisplayDocument; | function TEditorPage.FindElementNode(AParent : TDomElement; Const ANodeName : String; Const AElementName : string) : TDomElement; | ||||||
|  | 
 | ||||||
|  | Var | ||||||
|  |   N : TDomNode; | ||||||
| 
 | 
 | ||||||
| begin | 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; |   FPackages.DescriptionNode:=FDocument.DocumentElement; | ||||||
|  |   if (EE<>Nil) then | ||||||
|  |     begin | ||||||
|  |     FPackages.CurrentPackage:=PE; | ||||||
|  |     FPackages.CurrentModule:=ME; | ||||||
|  |     FPackages.CurrentElement:=EE; | ||||||
|  |     end; | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| procedure TEditorPage.ElementChanged(Sender: TObject); | procedure TEditorPage.ElementChanged(Sender: TObject); | ||||||
|  | |||||||
| @ -296,6 +296,7 @@ begin | |||||||
|     OnChange:=@ModuleChange; |     OnChange:=@ModuleChange; | ||||||
|     OnChanging:=@ModuleChanging; |     OnChanging:=@ModuleChanging; | ||||||
|     ReadOnly:=True; |     ReadOnly:=True; | ||||||
|  |     HideSelection:=False; | ||||||
|     end; |     end; | ||||||
|   FSplitter:=TSplitter.Create(Self); |   FSplitter:=TSplitter.Create(Self); | ||||||
|   With FSplitter do |   With FSplitter do | ||||||
| @ -329,6 +330,7 @@ begin | |||||||
|     OnChange:=@ElementChange; |     OnChange:=@ElementChange; | ||||||
|     OnChanging:=@ElementChanging; |     OnChanging:=@ElementChanging; | ||||||
|     ReadOnly:=True; |     ReadOnly:=True; | ||||||
|  |     HideSelection:=False; | ||||||
|     end; |     end; | ||||||
|   PEMenu:=TPopupMenu.Create(Self); |   PEMenu:=TPopupMenu.Create(Self); | ||||||
|   FERenameMenu:=NewMenuItem(SMenuRename,@MenuRenameClick); |   FERenameMenu:=NewMenuItem(SMenuRename,@MenuRenameClick); | ||||||
| @ -799,28 +801,33 @@ begin | |||||||
|       // root node |       // root node | ||||||
|       TNode:=FModuleNode; |       TNode:=FModuleNode; | ||||||
|       // process list of elements, create levels |       // process list of elements, create levels | ||||||
|       For I:=0 to S.Count-1 do |       FElementTree.Items.BeginUpdate; | ||||||
|         begin |       try | ||||||
|         PNode:=Nil; |         For I:=0 to S.Count-1 do | ||||||
|         SNode:=TNode; |  | ||||||
|         N:=S[i]; |  | ||||||
|         // look for a tentative new parents |  | ||||||
|         While (SNode<>FModuleNode) and (PNode=Nil) do |  | ||||||
|           begin |           begin | ||||||
|           PN:=TDomElement(SNode.Data)['name']+'.'; |           PNode:=Nil; | ||||||
|           L:=Length(PN); |           SNode:=TNode; | ||||||
|           If CompareText(Copy(N,1,L),PN)=0 then |           N:=S[i]; | ||||||
|             PNode:=SNode; |           // look for a tentative new parents | ||||||
|           SNode:=SNode.Parent; |           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; |           end; | ||||||
|         If (PNode=Nil) then |       finally | ||||||
|           PNode:=FModuleNode |         FElementTree.Items.EndUpdate; | ||||||
|         else |       end; | ||||||
|           System.Delete(N,1,L); |  | ||||||
|         TNode:=FElementTree.Items.AddChild(PNode,N); |  | ||||||
|         TNode.Data:=S.Objects[i]; |  | ||||||
|         UpdateNodeImage(TNode); |  | ||||||
|         end; |  | ||||||
|       Finally |       Finally | ||||||
|         S.Free; |         S.Free; | ||||||
|       end; |       end; | ||||||
| @ -1007,6 +1014,7 @@ begin | |||||||
|       SetCurrentModuleNode(FindModuleNodeInNode(Value,Nil)) |       SetCurrentModuleNode(FindModuleNodeInNode(Value,Nil)) | ||||||
|     else |     else | ||||||
|       ClearElements; |       ClearElements; | ||||||
|  |     FCurrentModule:=Value | ||||||
|     end; |     end; | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| @ -1020,6 +1028,7 @@ begin | |||||||
|   If Assigned(P) then |   If Assigned(P) then | ||||||
|     P.Expand(False); |     P.Expand(False); | ||||||
|   FModuleTree.Selected:=N; |   FModuleTree.Selected:=N; | ||||||
|  |   Application.ProcessMessages; | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| Procedure TPackageEditor.SetCurrentTopic(T : TDomElement); | Procedure TPackageEditor.SetCurrentTopic(T : TDomElement); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 michael
						michael