Changeset 47 for trunk/IDE


Ignore:
Timestamp:
Mar 4, 2012, 3:38:44 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Project now hold file list as linear list each include relative path to source instead of tree structure. This allow link to files outside of project folder.
Location:
trunk/IDE
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/IDE/Forms/UFormMain.pas

    r46 r47  
    232232      else Compiler.Analyzer.OnDebugLog := nil;
    233233
    234     if Project.Items.Count > 0 then
    235     with TProjectFile(Project.Items[0]) do begin
     234    if Project.Files.Count > 0 then
     235    with TProjectFile(Project.Files[0]) do begin
    236236      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);
    239239      Compiler.Compile;
    240240    end;
    241     FormProject.TreeViewProjectChange(Self, FormProject.TreeViewProject.Selected);
     241    //FormProject.TreeViewProjectChange(Self, FormProject.TreeViewProject.Selected);
    242242    FormMessages.Reload;
    243243end;
     
    283283  F: TFileStream;
    284284begin
    285   FileName := Project.GetDir(True) + Name + '.pas';
     285  FileName := ExtractFileDir(Project.FileName) + Name + '.pas';
    286286  if FileExists(FileName) then
    287287  try
     
    302302begin
    303303  Title := ApplicationInfo.Name;
    304   if Project.Name <> '' then Title := Project.Name + ' - ' + Title;
     304  if Project.FileName <> '' then Title := Project.FileName + ' - ' + Title;
    305305  if Project.Modified then Title := Title + ' *';
    306306  Caption := Title;
     
    557557
    558558procedure TFormMain.AProjectNewExecute(Sender: TObject);
     559var
     560  NewFile: TProjectFile;
    559561begin
    560562  AProjectClose.Execute;
    561563  Project.Active := True;
    562   Project.Name := SNewProject;
     564  Project.FileName := SNewProject;
     565  Project.Files.AddFile('Unit1.pas');
    563566  UpdateInterface;
    564567end;
  • trunk/IDE/Forms/UFormMessages.pas

    r46 r47  
    7070  if Assigned(ListView1.Selected) then
    7171  with TErrorMessage(ListView1.Selected.Data) do begin
    72     ProjectFile := Project.SearchFile(FileName);
     72    ProjectFile := Project.Files.SearchFile(FileName);
    7373    if Assigned(ProjectFile) then
    7474      SynEditSource.Lines.Assign(ProjectFile.Source);
  • trunk/IDE/Forms/UFormProject.pas

    r45 r47  
    1515    procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode);
    1616  private
    17     procedure UpdateProjectGroup(Node: TTreeNode; Group: TProjectGroup);
     17    procedure UpdateProjectFiles(Node: TTreeNode; Files: TProjectFileList);
    1818  public
    1919    procedure UpdateProjectTree;
     
    3838  with FormMain, FormSourceCode do
    3939  if Assigned(Node) then begin
    40     if TProjectNode(Node.Data) is TProjectFile then begin
     40    if TProjectFile(Node.Data) is TProjectFile then begin
    4141      ProjectFile := TProjectFile(Node.Data);
    4242      SynEditSource.Lines.Assign(TProjectFile(Node.Data).Source);
     
    7575    Clear;
    7676    if Project.Active then begin
    77       NewNode := AddChild(nil, Project.Name);
    78       UpdateProjectGroup(NewNode, Project);
     77      NewNode := AddChild(nil, ExtractFileNameOnly(Project.FileName));
     78      UpdateProjectFiles(NewNode, Project.Files);
    7979      NewNode.Expand(True);
    8080    end;
     
    9292end;
    9393
    94 procedure TFormProject.UpdateProjectGroup(Node: TTreeNode; Group: TProjectGroup);
     94procedure TFormProject.UpdateProjectFiles(Node: TTreeNode; Files: TProjectFileList);
    9595var
    9696  I: Integer;
    9797  NewNode: TTreeNode;
     98  FileName: string;
     99  NamePart: string;
     100  SelNode: TTreeNode;
     101  SubNode: TTreeNode;
    98102begin
    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]);
    106117  end;
    107118end;
    108119
    109 
    110 
    111120end.
    112121
  • trunk/IDE/UProject.pas

    r39 r47  
    11unit UProject;
    22
    3 {$mode objfpc}{$H+}
    4 {$MACRO ON}
     3{$mode Delphi}{$H+}
    54
    65interface
     
    1413
    1514type
    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
    2041  private
    2142    FModified: Boolean;
    2243    procedure SetModified(const AValue: Boolean);
    2344  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;
    4246    Source: TStringList;
     47    Parent: TProject;
    4348    constructor Create;
    4449    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;
    5561    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;
    5687    constructor Create;
    5788    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   private
    67     FActive: Boolean;
    68     function GetActive: Boolean;
    69     function GetFileName: string;
    70     procedure SetActive(AValue: Boolean);
    71   public
    72     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;
    8189    property Active: Boolean read GetActive write SetActive;
    82     property FileName: string read GetFileName;
     90    property Modified: Boolean read FModified write SetModified;
    8391  end;
    8492
    8593implementation
    8694
     95{ TProjectPackageList }
     96
     97procedure TProjectPackageList.Load;
     98begin
     99
     100end;
     101
     102procedure TProjectPackageList.Save;
     103begin
     104
     105end;
     106
     107procedure TProjectPackageList.SaveToXMLNode(Node: TDOMNode);
     108begin
     109
     110end;
     111
     112procedure TProjectPackageList.LoadFromXMLNode(Node: TDOMNode);
     113begin
     114
     115end;
     116
    87117
    88118
    89119{ TProjectGroup }
    90120
    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));
     121procedure TProjectFileList.DumpFileList(Files: TListString);
     122var
     123  I: Integer;
     124begin
     125  Files.Clear;
     126  for I := 0 to Count - 1 do
     127    Files.Add(TProjectFile(Items[I]).FileName);
     128end;
     129
     130procedure TProjectFileList.Load;
     131var
     132  I: Integer;
     133begin
     134  for I := 0 to Count - 1 do
     135    TProjectFile(Items[I]).Load;
     136end;
     137
     138procedure TProjectFileList.Save;
     139var
     140  I: Integer;
     141begin
     142  for I := 0 to Count - 1 do
     143    TProjectFile(Items[I]).Save;
     144end;
     145
     146procedure TProjectFileList.SaveToXMLNode(Node: TDOMNode);
     147var
     148  I: Integer;
     149  NewNode: TDOMNode;
     150begin
     151  with Node do
     152  for I := 0 to Count - 1 do begin
     153    NewNode := OwnerDocument.CreateElement('File');
     154    TProjectFile(Items[I]).SaveToXMLNode(NewNode);
    140155    AppendChild(NewNode);
    141   end;
    142   for I := 0 to Items.Count - 1 do begin
    143     TProjectNode(Items[I]).SaveToXMLNode(NewNode);
    144156  end
    145157end;
    146158
    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;
     159procedure TProjectFileList.LoadFromXMLNode(Node: TDOMNode);
     160var
     161  NewNode: TDomNode;
     162  NewFile: TProjectFile;
     163begin
     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;
     174end;
     175
     176function TProjectFileList.SearchFile(FileName: string): TProjectFile;
     177var
     178  I: Integer;
     179begin
    155180  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;
     184end;
     185
     186procedure TProjectFileList.AddFile(FileName: string);
     187var
     188  NewFile: TProjectFile;
     189begin
     190  NewFile := TProjectFile(AddNew(TProjectFile.Create));
     191  NewFile.Parent := Parent;
     192  NewFile.FileName := FileName;
    165193end;
    166194
    167195{ TProjectFile }
     196
     197procedure TProjectFile.SetModified(const AValue: Boolean);
     198begin
     199  if FModified = AValue then Exit;
     200  FModified := True;
     201  if AValue then Parent.Modified := True;
     202end;
    168203
    169204constructor TProjectFile.Create;
     
    182217  NewNode: TDOMNode;
    183218begin
    184   inherited SaveToXMLNode(Node);
    185219  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);
    188222    AppendChild(NewNode);
    189223  end;
     
    192226
    193227procedure TProjectFile.LoadFromXMLNode(Node: TDOMNode);
    194 begin
    195   inherited LoadFromXMLNode(Node);
    196   Load;
     228var
     229  NewNode: TDOMNode;
     230begin
     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;
    197237end;
    198238
    199239procedure TProjectFile.Load;
    200240begin
    201   inherited Load;
    202   Source.LoadFromFile(Parent.GetDir(True) + Name);
     241  Source.LoadFromFile(ExtractFileDir(Parent.FileName) + DirectorySeparator + FileName);
    203242end;
    204243
     
    206245begin
    207246  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);
    245248end;
    246249
     
    250253begin
    251254  Result := FActive;
    252 end;
    253 
    254 function TProject.GetFileName: string;
    255 begin
    256   Result := GetDir(True) + Name + ProjectExt;
    257255end;
    258256
     
    264262end;
    265263
     264procedure TProject.SetModified(AValue: Boolean);
     265begin
     266  if FModified = AValue then Exit;
     267  FModified := AValue;
     268end;
     269
    266270procedure TProject.LoadFromFile(FileName: string);
    267271var
     
    274278  try
    275279    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;
    281281    ReadXMLFile(Doc, UTF8Decode(FileName));
    282282
    283     NewNode := Doc.DocumentElement.FindNode('Folder');
     283    NewNode := Doc.DocumentElement.FindNode('Files');
    284284    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);
    286289  finally
    287290    Doc.Free;
    288291  end;
    289292  FModified := False;
    290 end;
    291 
    292 procedure TProjectGroup.LoadFromXMLNode(Node: TDOMNode);
    293 var
    294   Child: TDOMNode;
    295   ProjectNode: TProjectNode;
    296   NodeType: string;
    297 begin
    298   Name := UTF8Encode(TDOMElement(Node).GetAttribute('Name'));
    299   Child := Node.FirstChild;
    300   while Assigned(Child) do begin
    301     if Child.NodeName = 'Folder' then
    302       ProjectNode := TProjectGroup.Create
    303     else if Child.NodeName = 'File' then
    304       ProjectNode := TProjectFile.Create
    305     else ProjectNode := nil;
    306     if Assigned(ProjectNode) then begin
    307       ProjectNode.Parent := Self;
    308       ProjectNode.LoadFromXMLNode(Child);
    309       Items.Add(ProjectNode);
    310     end;
    311 
    312     Child := Child.NextSibling;
    313   end;
    314293end;
    315294
     
    328307    AppendChild(RootNode);
    329308    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);
    330316    end;
    331     SaveToXMLNode(RootNode);
    332317    WriteXMLFile(Doc, UTF8Decode(FileName));
    333318  finally
     
    335320  end;
    336321  FModified := False;
    337   inherited Save;
    338 end;
    339 
    340 function TProject.GetDir(IncludeRoot: Boolean): string;
    341 begin
    342   if IncludeRoot then Result := RootDir else Result := '';
    343322end;
    344323
    345324procedure TProject.Load;
    346325begin
    347   inherited Load;
     326  Files.Load;
     327  Packages.Load;
    348328end;
    349329
    350330procedure TProject.Save;
    351331begin
    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;
    363334end;
    364335
    365336procedure TProject.Clear;
    366337begin
    367   Items.Clear;
     338  Files.Clear;
     339  Packages.Clear;
     340end;
     341
     342constructor TProject.Create;
     343begin
     344  Files := TProjectFileList.Create;
     345  Files.Parent := Self;
     346  Packages := TProjectPackageList.Create;
     347  Packages.Parent := Self;
     348end;
     349
     350destructor TProject.Destroy;
     351begin
     352  Files.Free;
     353  Packages.Free;
     354  BuildConfigs.Free;
     355  inherited Destroy;
    368356end;
    369357
Note: See TracChangeset for help on using the changeset viewer.