Ignore:
Timestamp:
Oct 18, 2010, 10:00:00 AM (14 years ago)
Author:
george
Message:
  • Added: Storing application setting in system registry.
  • Added: Loading project files.
  • Added: Remembering last opened files.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Transpascal/UProject.pas

    r60 r66  
    66
    77uses
    8   Classes, SysUtils, Contnrs, Dialogs;
     8  Classes, SysUtils, Contnrs, Dialogs, DOM, XMLWrite, XMLRead;
    99
    1010type
     
    1515    Parent: TProjectNode;
    1616    Name: string;
     17    procedure SaveToXMLNode(Node: TDOMNode); virtual;
     18    procedure LoadFromXMLNode(Node: TDOMNode); virtual;
    1719    procedure Load; virtual;
    1820    procedure Save; virtual;
     
    2628    constructor Create;
    2729    destructor Destroy; override;
     30    procedure SaveToXMLNode(Node: TDOMNode); override;
     31    procedure LoadFromXMLNode(Node: TDOMNode); override;
    2832    procedure Load; override;
    2933    procedure Save; override;
     
    3842    procedure Load; override;
    3943    procedure Save; override;
     44    procedure SaveToXMLNode(Node: TDOMNode); override;
     45    procedure LoadFromXMLNode(Node: TDOMNode); override;
    4046    function SearchFile(FileName: string): TProjectFile;
    4147  end;
     
    4349  TProject = class(TProjectGroup)
    4450    RootDir: string;
     51    procedure LoadFromFile(FileName: string);
     52    procedure SaveToFile(FileName: string);
    4553    function GetDir(IncludeRoot: Boolean = False): string; override;
     54    procedure Load; override;
     55    procedure Save; override;
     56    procedure SaveToXMLNode(Node: TDOMNode); override;
     57    procedure LoadFromXMLNode(Node: TDOMNode); override;
     58    procedure Clear;
    4659  end;
    4760
     
    7790  for I := 0 to Items.Count - 1 do
    7891    TProjectNode(Items[I]).Save;
     92end;
     93
     94procedure TProjectGroup.SaveToXMLNode(Node: TDOMNode);
     95begin
     96  inherited SaveToXMLNode(Node);
    7997end;
    8098
     
    111129end;
    112130
     131procedure TProjectFile.SaveToXMLNode(Node: TDOMNode);
     132begin
     133  inherited SaveToXMLNode(Node);
     134end;
     135
     136procedure TProjectFile.LoadFromXMLNode(Node: TDOMNode);
     137begin
     138  inherited LoadFromXMLNode(Node);
     139  Load;
     140end;
     141
    113142procedure TProjectFile.Load;
    114143begin
     
    125154{ TProjectNode }
    126155
     156procedure TProjectNode.SaveToXMLNode(Node: TDOMNode);
     157begin
     158
     159end;
     160
     161procedure TProjectNode.LoadFromXMLNode(Node: TDOMNode);
     162begin
     163  Name := UTF8Encode(string(TDOMElement(Node).GetAttribute('Name')));
     164end;
     165
    127166procedure TProjectNode.Load;
    128167begin
     
    143182{ TProject }
    144183
     184procedure TProject.LoadFromFile(FileName: string);
     185var
     186  Doc: TXMLDocument;
     187  NewNode: TDOMNode;
     188  NewSubNode: TDOMNode;
     189  I: Integer;
     190  Text: string;
     191begin
     192  try
     193    Clear;
     194    RootDir := ExtractFileDir(FileName) + '/';
     195    Name := ExtractFileName(FileName);
     196    Name := Copy(Name, 1, Length(Name) - Length(ExtractFileExt(FileName)));
     197
     198    ReadXMLFile(Doc, UTF8Decode(FileName));
     199
     200    NewNode := Doc.DocumentElement.FindNode('Files');
     201    if Assigned(NewNode) then
     202      LoadFromXMLNode(NewNode);
     203  finally
     204    Doc.Free;
     205  end;
     206end;
     207
     208procedure TProjectGroup.LoadFromXMLNode(Node: TDOMNode);
     209var
     210  Child: TDOMNode;
     211  ProjectNode: TProjectNode;
     212  NodeType: string;
     213begin
     214  Name := UTF8Encode(TDOMElement(Node).GetAttribute('Name'));
     215  Child := Node.FirstChild;
     216  while Assigned(Child) do begin
     217    NodeType := TDOMElement(Child).GetAttribute('Type');
     218    if NodeType = 'Folder' then
     219      ProjectNode := TProjectGroup.Create
     220    else if NodeType = 'File' then
     221      ProjectNode := TProjectFile.Create
     222    else ProjectNode := nil;
     223    if Assigned(ProjectNode) then begin
     224      ProjectNode.Parent := Self;
     225      ProjectNode.LoadFromXMLNode(Child);
     226      Items.Add(ProjectNode);
     227    end;
     228
     229    Child := Child.NextSibling;
     230  end;
     231end;
     232
     233procedure TProject.SaveToFile(FileName: string);
     234begin
     235
     236end;
     237
    145238function TProject.GetDir(IncludeRoot: Boolean): string;
    146239begin
     
    148241end;
    149242
     243procedure TProject.Load;
     244begin
     245  inherited Load;
     246end;
     247
     248procedure TProject.Save;
     249begin
     250  inherited Save;
     251end;
     252
     253procedure TProject.SaveToXMLNode(Node: TDOMNode);
     254begin
     255  inherited SaveToXMLNode(Node);
     256end;
     257
     258procedure TProject.LoadFromXMLNode(Node: TDOMNode);
     259begin
     260  inherited LoadFromXMLNode(Node);
     261end;
     262
     263procedure TProject.Clear;
     264begin
     265  Items.Clear;
     266end;
     267
    150268end.
    151269
Note: See TracChangeset for help on using the changeset viewer.