Changeset 47
- Timestamp:
- Mar 4, 2012, 3:38:44 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/UCompiler.pas
r46 r47 35 35 Targets: TListTarget; 36 36 SourceFiles: TListString; 37 TargetFiles: TListString; 37 38 constructor Create; 38 39 destructor Destroy; override; … … 66 67 Targets := TListTarget.Create; 67 68 SourceFiles := TListString.Create; 69 TargetFiles := TListString.Create; 68 70 69 71 RegisterTargets(Self); … … 87 89 ErrorMessages.Free; 88 90 SourceFiles.Free; 91 TargetFiles.Free; 89 92 end; 90 93 -
trunk/Demos/Console/Console.tppr
r15 r47 2 2 <Project> 3 3 <Files> 4 <File Type="File" Name="Console.pas" /> 5 <File Type="File" Name="System.pas" /> 4 <File> 5 <FileName>Console.pas</FileName> 6 </File> 7 <File> 8 <FileName>System.pas</FileName> 9 </File> 6 10 </Files> 7 11 </Project> -
trunk/Demos/Generics/Generics.tppr
r23 r47 1 1 <?xml version="1.0"?> 2 <Project Name="Generics"> 3 <Folder Name="Generics"> 4 <File Name="Generics.pas"/> 5 <File Name="System.pas"/> 6 <File Name="List.pas"/> 7 </Folder> 2 <Project> 3 <Name>Generics</Name> 4 <Files> 5 <File> 6 <FileName>Generics.pas</FileName> 7 </File> 8 <File> 9 <FileName>System.pas</FileName> 10 </File> 11 <File> 12 <FileName>List.pas</FileName> 13 </File> 14 </Files> 8 15 </Project> -
trunk/Demos/Structure/Project.tppr
r15 r47 2 2 <Project> 3 3 <Files> 4 <File Type="File" Name="Project.pas" /> 5 <File Type="File" Name="System.pas" /> 4 <File> 5 <FileName>Project.pas</FileName> 6 </File> 7 <File> 8 <FileName>System.pas</FileName> 9 </File> 6 10 </Files> 7 11 </Project> -
trunk/IDE/Forms/UFormMain.pas
r46 r47 232 232 else Compiler.Analyzer.OnDebugLog := nil; 233 233 234 if Project. Items.Count > 0 then235 with TProjectFile(Project. Items[0]) do begin234 if Project.Files.Count > 0 then 235 with TProjectFile(Project.Files[0]) do begin 236 236 Compiler.SourceFiles.Clear; 237 Project. DumpFileList(Compiler.SourceFiles);238 Compiler.TargetFolder := Project.RootDir;237 Project.Files.DumpFileList(Compiler.SourceFiles); 238 Compiler.TargetFolder := ExtractFileDir(Project.FileName); 239 239 Compiler.Compile; 240 240 end; 241 FormProject.TreeViewProjectChange(Self, FormProject.TreeViewProject.Selected);241 //FormProject.TreeViewProjectChange(Self, FormProject.TreeViewProject.Selected); 242 242 FormMessages.Reload; 243 243 end; … … 283 283 F: TFileStream; 284 284 begin 285 FileName := Project.GetDir(True) + Name + '.pas';285 FileName := ExtractFileDir(Project.FileName) + Name + '.pas'; 286 286 if FileExists(FileName) then 287 287 try … … 302 302 begin 303 303 Title := ApplicationInfo.Name; 304 if Project. Name <> '' then Title := Project.Name + ' - ' + Title;304 if Project.FileName <> '' then Title := Project.FileName + ' - ' + Title; 305 305 if Project.Modified then Title := Title + ' *'; 306 306 Caption := Title; … … 557 557 558 558 procedure TFormMain.AProjectNewExecute(Sender: TObject); 559 var 560 NewFile: TProjectFile; 559 561 begin 560 562 AProjectClose.Execute; 561 563 Project.Active := True; 562 Project.Name := SNewProject; 564 Project.FileName := SNewProject; 565 Project.Files.AddFile('Unit1.pas'); 563 566 UpdateInterface; 564 567 end; -
trunk/IDE/Forms/UFormMessages.pas
r46 r47 70 70 if Assigned(ListView1.Selected) then 71 71 with TErrorMessage(ListView1.Selected.Data) do begin 72 ProjectFile := Project. SearchFile(FileName);72 ProjectFile := Project.Files.SearchFile(FileName); 73 73 if Assigned(ProjectFile) then 74 74 SynEditSource.Lines.Assign(ProjectFile.Source); -
trunk/IDE/Forms/UFormProject.pas
r45 r47 15 15 procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode); 16 16 private 17 procedure UpdateProject Group(Node: TTreeNode; Group: TProjectGroup);17 procedure UpdateProjectFiles(Node: TTreeNode; Files: TProjectFileList); 18 18 public 19 19 procedure UpdateProjectTree; … … 38 38 with FormMain, FormSourceCode do 39 39 if Assigned(Node) then begin 40 if TProject Node(Node.Data) is TProjectFile then begin40 if TProjectFile(Node.Data) is TProjectFile then begin 41 41 ProjectFile := TProjectFile(Node.Data); 42 42 SynEditSource.Lines.Assign(TProjectFile(Node.Data).Source); … … 75 75 Clear; 76 76 if Project.Active then begin 77 NewNode := AddChild(nil, Project.Name);78 UpdateProject Group(NewNode, Project);77 NewNode := AddChild(nil, ExtractFileNameOnly(Project.FileName)); 78 UpdateProjectFiles(NewNode, Project.Files); 79 79 NewNode.Expand(True); 80 80 end; … … 92 92 end; 93 93 94 procedure TFormProject.UpdateProject Group(Node: TTreeNode; Group: TProjectGroup);94 procedure TFormProject.UpdateProjectFiles(Node: TTreeNode; Files: TProjectFileList); 95 95 var 96 96 I: Integer; 97 97 NewNode: TTreeNode; 98 FileName: string; 99 NamePart: string; 100 SelNode: TTreeNode; 101 SubNode: TTreeNode; 98 102 begin 99 with FormMain do 100 for I := 0 to Group.Items.Count - 1 do begin 101 NewNode := TreeViewProject.Items.AddChild(Node, 102 TProjectNode(Group.Items[I]).Name); 103 NewNode.Data := Pointer(Group.Items[I]); 104 if TProjectNode(Group.Items[I]) is TProjectGroup then 105 UpdateProjectGroup(NewNode, TProjectGroup(Group.Items[I])); 103 for I := 0 to Files.Count - 1 do begin 104 FileName := TProjectFile(Files[I]).FileName; 105 SelNode := Node; 106 while Pos(DirectorySeparator, FileName) > 0 do begin 107 NamePart := Copy(FileName, 1, Pos(DirectorySeparator, FileName) - 1); 108 Delete(FileName, 1, Length(NamePart) + 1); 109 SubNode := SelNode.FindNode(NamePart); 110 if Assigned(SubNode) then SelNode := SubNode 111 else begin 112 SelNode := TreeViewProject.Items.AddChild(SelNode, NamePart); 113 end; 114 end; 115 NewNode := TreeViewProject.Items.AddChild(SelNode, FileName); 116 NewNode.Data := Pointer(Files[I]); 106 117 end; 107 118 end; 108 119 109 110 111 120 end. 112 121 -
trunk/IDE/UProject.pas
r39 r47 1 1 unit UProject; 2 2 3 {$mode objfpc}{$H+} 4 {$MACRO ON} 3 {$mode Delphi}{$H+} 5 4 6 5 interface … … 14 13 15 14 type 16 17 { TProjectNode } 18 19 TProjectNode = class 15 TProject = class; 16 17 TProjectPackage = class 18 Name: string; 19 end; 20 21 { TProjectPackageList } 22 23 TProjectPackageList = class(TListObject) 24 Parent: TProject; 25 procedure Load; 26 procedure Save; 27 procedure SaveToXMLNode(Node: TDOMNode); 28 procedure LoadFromXMLNode(Node: TDOMNode); 29 end; 30 31 TProjectBuildConfig = class 32 Name: string; 33 end; 34 35 TProjectBuildConfigList = class(TListObject) 36 end; 37 38 { TProjectFile } 39 40 TProjectFile = class 20 41 private 21 42 FModified: Boolean; 22 43 procedure SetModified(const AValue: Boolean); 23 44 public 24 Parent: TProjectNode; 25 Name: string; 26 ProducedFileName: string; 27 procedure SaveToXMLNode(Node: TDOMNode); virtual; 28 procedure LoadFromXMLNode(Node: TDOMNode); virtual; 29 procedure Load; virtual; 30 procedure Save; virtual; 31 function GetDir(IncludeRoot: Boolean = False): string; virtual; 32 property Modified: Boolean read FModified write SetModified; 33 end; 34 35 36 // TListProjectNode = TGObjectList<Integer, TProjectNode> 37 TListProjectNode = class(TListObject); 38 39 { TProjectFile } 40 41 TProjectFile = class(TProjectNode) 45 FileName: string; 42 46 Source: TStringList; 47 Parent: TProject; 43 48 constructor Create; 44 49 destructor Destroy; override; 45 procedure SaveToXMLNode(Node: TDOMNode); override; 46 procedure LoadFromXMLNode(Node: TDOMNode); override; 47 procedure Load; override; 48 procedure Save; override; 49 end; 50 51 { TProjectGroup } 52 53 TProjectGroup = class(TProjectNode) 54 Items: TListProjectNode; 50 procedure SaveToXMLNode(Node: TDOMNode); 51 procedure LoadFromXMLNode(Node: TDOMNode); 52 procedure Load; 53 procedure Save; 54 property Modified: Boolean read FModified write SetModified; 55 end; 56 57 { TProjectFileList } 58 59 TProjectFileList = class(TListObject) 60 Parent: TProject; 55 61 procedure DumpFileList(Files: TListString); 62 procedure Load; 63 procedure Save; 64 procedure SaveToXMLNode(Node: TDOMNode); 65 procedure LoadFromXMLNode(Node: TDOMNode); 66 function SearchFile(FileName: string): TProjectFile; 67 procedure AddFile(FileName: string); 68 end; 69 70 TProject = class 71 private 72 FActive: Boolean; 73 FModified: Boolean; 74 function GetActive: Boolean; 75 procedure SetActive(AValue: Boolean); 76 procedure SetModified(AValue: Boolean); 77 public 78 FileName: string; 79 Files: TProjectFileList; 80 Packages: TProjectPackageList; 81 BuildConfigs: TProjectBuildConfigList; 82 procedure LoadFromFile(FileName: string); 83 procedure SaveToFile(FileName: string); 84 procedure Load; 85 procedure Save; 86 procedure Clear; 56 87 constructor Create; 57 88 destructor Destroy; override; 58 procedure Load; override;59 procedure Save; override;60 procedure SaveToXMLNode(Node: TDOMNode); override;61 procedure LoadFromXMLNode(Node: TDOMNode); override;62 function SearchFile(FileName: string): TProjectFile;63 end;64 65 TProject = class(TProjectGroup)66 private67 FActive: Boolean;68 function GetActive: Boolean;69 function GetFileName: string;70 procedure SetActive(AValue: Boolean);71 public72 RootDir: string;73 procedure LoadFromFile(FileName: string);74 procedure SaveToFile(FileName: string);75 function GetDir(IncludeRoot: Boolean = False): string; override;76 procedure Load; override;77 procedure Save; override;78 procedure SaveToXMLNode(Node: TDOMNode); override;79 procedure LoadFromXMLNode(Node: TDOMNode); override;80 procedure Clear;81 89 property Active: Boolean read GetActive write SetActive; 82 property FileName: string read GetFileName;90 property Modified: Boolean read FModified write SetModified; 83 91 end; 84 92 85 93 implementation 86 94 95 { TProjectPackageList } 96 97 procedure TProjectPackageList.Load; 98 begin 99 100 end; 101 102 procedure TProjectPackageList.Save; 103 begin 104 105 end; 106 107 procedure TProjectPackageList.SaveToXMLNode(Node: TDOMNode); 108 begin 109 110 end; 111 112 procedure TProjectPackageList.LoadFromXMLNode(Node: TDOMNode); 113 begin 114 115 end; 116 87 117 88 118 89 119 { TProjectGroup } 90 120 91 procedure TProjectGroup.DumpFileList(Files: TListString); 92 var 93 I: Integer; 94 begin 95 for I := 0 to Items.Count - 1 do 96 if TProjectNode(Items[I]) is TProjectGroup then 97 TProjectGroup(Items[I]).DumpFileList(Files) 98 else Files.Add(GetDir(True) + TProjectFile(Items[I]).Name); 99 end; 100 101 constructor TProjectGroup.Create; 102 begin 103 inherited; 104 Items := TListProjectNode.Create; 105 end; 106 107 destructor TProjectGroup.Destroy; 108 begin 109 Items.Free; 110 inherited Destroy; 111 end; 112 113 procedure TProjectGroup.Load; 114 var 115 I: Integer; 116 begin 117 inherited Load; 118 for I := 0 to Items.Count - 1 do 119 TProjectNode(Items[I]).Load; 120 end; 121 122 procedure TProjectGroup.Save; 123 var 124 I: Integer; 125 begin 126 for I := 0 to Items.Count - 1 do 127 TProjectNode(Items[I]).Save; 128 end; 129 130 procedure TProjectGroup.SaveToXMLNode(Node: TDOMNode); 131 var 132 I: Integer; 133 NewNode: TDOMNode; 134 begin 135 TDOMElement(Node).SetAttribute('Name', UTF8Decode(Name)); 136 inherited SaveToXMLNode(Node); 137 with Node do begin 138 NewNode := OwnerDocument.CreateElement('Folder'); 139 TDOMElement(NewNode).SetAttribute('Name', UTF8Decode(Name)); 121 procedure TProjectFileList.DumpFileList(Files: TListString); 122 var 123 I: Integer; 124 begin 125 Files.Clear; 126 for I := 0 to Count - 1 do 127 Files.Add(TProjectFile(Items[I]).FileName); 128 end; 129 130 procedure TProjectFileList.Load; 131 var 132 I: Integer; 133 begin 134 for I := 0 to Count - 1 do 135 TProjectFile(Items[I]).Load; 136 end; 137 138 procedure TProjectFileList.Save; 139 var 140 I: Integer; 141 begin 142 for I := 0 to Count - 1 do 143 TProjectFile(Items[I]).Save; 144 end; 145 146 procedure TProjectFileList.SaveToXMLNode(Node: TDOMNode); 147 var 148 I: Integer; 149 NewNode: TDOMNode; 150 begin 151 with Node do 152 for I := 0 to Count - 1 do begin 153 NewNode := OwnerDocument.CreateElement('File'); 154 TProjectFile(Items[I]).SaveToXMLNode(NewNode); 140 155 AppendChild(NewNode); 141 end;142 for I := 0 to Items.Count - 1 do begin143 TProjectNode(Items[I]).SaveToXMLNode(NewNode);144 156 end 145 157 end; 146 158 147 function TProjectGroup.SearchFile(FileName: string): TProjectFile; 148 var 149 NamePart: string; 150 I: Integer; 151 begin 152 if Pos('/', FileName) > 0 then 153 NamePart := Copy(FileName, 1, Pos('/', FileName)) 154 else NamePart := FileName; 159 procedure TProjectFileList.LoadFromXMLNode(Node: TDOMNode); 160 var 161 NewNode: TDomNode; 162 NewFile: TProjectFile; 163 begin 164 NewNode := Node.FirstChild; 165 while Assigned(NewNode) do begin 166 if NewNode.NodeName = 'File' then begin 167 NewFile := TProjectFile.Create; 168 NewFile.Parent := Parent; 169 NewFile.LoadFromXMLNode(NewNode); 170 Add(NewFile); 171 end; 172 NewNode := NewNode.NextSibling; 173 end; 174 end; 175 176 function TProjectFileList.SearchFile(FileName: string): TProjectFile; 177 var 178 I: Integer; 179 begin 155 180 I := 0; 156 while (I < Items.Count) and (ExtractFileNameOnly(TProjectNode(Items[I]).Name) <> NamePart) do Inc(I); 157 if I < Items.Count then begin 158 if TProjectNode(Items[I]) is TProjectFile then 159 Result := TProjectFile(Items[I]) 160 else begin 161 Delete(FileName, 1, Length(FileName) + 1); 162 TProjectGroup(Items[I]).SearchFile(FileName); 163 end; 164 end else Result := nil; 181 while (I < Count) and (TProjectFile(Items[I]).FileName <> FileName) do Inc(I); 182 if I < Count then Result := TProjectFile(Items[I]) 183 else Result := nil; 184 end; 185 186 procedure TProjectFileList.AddFile(FileName: string); 187 var 188 NewFile: TProjectFile; 189 begin 190 NewFile := TProjectFile(AddNew(TProjectFile.Create)); 191 NewFile.Parent := Parent; 192 NewFile.FileName := FileName; 165 193 end; 166 194 167 195 { TProjectFile } 196 197 procedure TProjectFile.SetModified(const AValue: Boolean); 198 begin 199 if FModified = AValue then Exit; 200 FModified := True; 201 if AValue then Parent.Modified := True; 202 end; 168 203 169 204 constructor TProjectFile.Create; … … 182 217 NewNode: TDOMNode; 183 218 begin 184 inherited SaveToXMLNode(Node);185 219 with Node do begin 186 NewNode := OwnerDocument.CreateElement('File ');187 TDOMElement(NewNode).SetAttribute('Name', UTF8Decode(Name));220 NewNode := OwnerDocument.CreateElement('FileName'); 221 NewNode.TextContent := UTF8Decode(FileName); 188 222 AppendChild(NewNode); 189 223 end; … … 192 226 193 227 procedure TProjectFile.LoadFromXMLNode(Node: TDOMNode); 194 begin 195 inherited LoadFromXMLNode(Node); 196 Load; 228 var 229 NewNode: TDOMNode; 230 begin 231 with Node do begin 232 NewNode := FindNode('FileName'); 233 if Assigned(NewNode) then 234 FileName := UTF8Encode(NewNode.TextContent); 235 end; 236 if FileExistsUTF8(FileName) then Load; 197 237 end; 198 238 199 239 procedure TProjectFile.Load; 200 240 begin 201 inherited Load; 202 Source.LoadFromFile(Parent.GetDir(True) + Name); 241 Source.LoadFromFile(ExtractFileDir(Parent.FileName) + DirectorySeparator + FileName); 203 242 end; 204 243 … … 206 245 begin 207 246 if Modified then 208 Source.SaveToFile(Parent.GetDir(True) + Name); 209 inherited Save; 210 end; 211 212 { TProjectNode } 213 214 procedure TProjectNode.SetModified(const AValue: Boolean); 215 begin 216 if FModified=AValue then exit; 217 FModified:=AValue; 218 if Assigned(Parent) then Parent.Modified := AValue; 219 end; 220 221 procedure TProjectNode.SaveToXMLNode(Node: TDOMNode); 222 begin 223 224 end; 225 226 procedure TProjectNode.LoadFromXMLNode(Node: TDOMNode); 227 begin 228 Name := UTF8Encode(string(TDOMElement(Node).GetAttribute('Name'))); 229 end; 230 231 procedure TProjectNode.Load; 232 begin 233 234 end; 235 236 procedure TProjectNode.Save; 237 begin 238 Modified := False; 239 end; 240 241 function TProjectNode.GetDir(IncludeRoot: Boolean = False): string; 242 begin 243 if Assigned(Parent) then Result := Parent.GetDir(IncludeRoot) + Name + DirectorySeparator 244 else Result := Name + DirectorySeparator; 247 Source.SaveToFile(FileName); 245 248 end; 246 249 … … 250 253 begin 251 254 Result := FActive; 252 end;253 254 function TProject.GetFileName: string;255 begin256 Result := GetDir(True) + Name + ProjectExt;257 255 end; 258 256 … … 264 262 end; 265 263 264 procedure TProject.SetModified(AValue: Boolean); 265 begin 266 if FModified = AValue then Exit; 267 FModified := AValue; 268 end; 269 266 270 procedure TProject.LoadFromFile(FileName: string); 267 271 var … … 274 278 try 275 279 Clear; 276 RootDir := ExtractFileDir(FileName) + '/'; 277 //NewNode := Doc.DocumentElement.FindNode('Files'); 278 Name := ExtractFileName(FileName); 279 Name := Copy(Name, 1, Length(Name) - Length(ExtractFileExt(FileName))); 280 280 Self.FileName := FileName; 281 281 ReadXMLFile(Doc, UTF8Decode(FileName)); 282 282 283 NewNode := Doc.DocumentElement.FindNode('F older');283 NewNode := Doc.DocumentElement.FindNode('Files'); 284 284 if Assigned(NewNode) then 285 LoadFromXMLNode(NewNode); 285 Files.LoadFromXMLNode(NewNode); 286 NewNode := Doc.DocumentElement.FindNode('Packages'); 287 if Assigned(NewNode) then 288 Packages.LoadFromXMLNode(NewNode); 286 289 finally 287 290 Doc.Free; 288 291 end; 289 292 FModified := False; 290 end;291 292 procedure TProjectGroup.LoadFromXMLNode(Node: TDOMNode);293 var294 Child: TDOMNode;295 ProjectNode: TProjectNode;296 NodeType: string;297 begin298 Name := UTF8Encode(TDOMElement(Node).GetAttribute('Name'));299 Child := Node.FirstChild;300 while Assigned(Child) do begin301 if Child.NodeName = 'Folder' then302 ProjectNode := TProjectGroup.Create303 else if Child.NodeName = 'File' then304 ProjectNode := TProjectFile.Create305 else ProjectNode := nil;306 if Assigned(ProjectNode) then begin307 ProjectNode.Parent := Self;308 ProjectNode.LoadFromXMLNode(Child);309 Items.Add(ProjectNode);310 end;311 312 Child := Child.NextSibling;313 end;314 293 end; 315 294 … … 328 307 AppendChild(RootNode); 329 308 with RootNode do begin 309 NewNode := CreateElement('Files'); 310 Files.SaveToXMLNode(NewNode); 311 AppendChild(NewNode); 312 313 NewNode := CreateElement('Packages'); 314 Packages.SaveToXMLNode(NewNode); 315 AppendChild(NewNode); 330 316 end; 331 SaveToXMLNode(RootNode);332 317 WriteXMLFile(Doc, UTF8Decode(FileName)); 333 318 finally … … 335 320 end; 336 321 FModified := False; 337 inherited Save;338 end;339 340 function TProject.GetDir(IncludeRoot: Boolean): string;341 begin342 if IncludeRoot then Result := RootDir else Result := '';343 322 end; 344 323 345 324 procedure TProject.Load; 346 325 begin 347 inherited Load; 326 Files.Load; 327 Packages.Load; 348 328 end; 349 329 350 330 procedure TProject.Save; 351 331 begin 352 inherited Save; 353 end; 354 355 procedure TProject.SaveToXMLNode(Node: TDOMNode); 356 begin 357 inherited SaveToXMLNode(Node); 358 end; 359 360 procedure TProject.LoadFromXMLNode(Node: TDOMNode); 361 begin 362 inherited LoadFromXMLNode(Node); 332 Files.Save; 333 Packages.Save; 363 334 end; 364 335 365 336 procedure TProject.Clear; 366 337 begin 367 Items.Clear; 338 Files.Clear; 339 Packages.Clear; 340 end; 341 342 constructor TProject.Create; 343 begin 344 Files := TProjectFileList.Create; 345 Files.Parent := Self; 346 Packages := TProjectPackageList.Create; 347 Packages.Parent := Self; 348 end; 349 350 destructor TProject.Destroy; 351 begin 352 Files.Free; 353 Packages.Free; 354 BuildConfigs.Free; 355 inherited Destroy; 368 356 end; 369 357
Note:
See TracChangeset
for help on using the changeset viewer.