Ignore:
Timestamp:
Aug 10, 2010, 1:48:38 PM (14 years ago)
Author:
george
Message:

Fix: View proper source file after click to error message.
Made partial changes to support unit interface and implementation sections.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DelphiToC/UProject.pas

    r54 r55  
    66
    77uses
    8   Classes, SysUtils, Contnrs;
     8  Classes, SysUtils, Contnrs, Dialogs;
    99
    1010type
     
    1313
    1414  TProjectNode = class
     15    Parent: TProjectNode;
    1516    Name: string;
    1617    procedure Load; virtual;
    1718    procedure Save; virtual;
     19    function GetDir(IncludeRoot: Boolean = False): string; virtual;
     20  end;
     21
     22  { TProjectFile }
     23
     24  TProjectFile = class(TProjectNode)
     25    Source: TStringList;
     26    ProducedCode: TStringList;
     27    constructor Create;
     28    destructor Destroy; override;
     29    procedure Load; override;
     30    procedure Save; override;
    1831  end;
    1932
     
    2639    procedure Load; override;
    2740    procedure Save; override;
    28   end;
    29 
    30   { TProjectFile }
    31 
    32   TProjectFile = class(TProjectNode)
    33     Source: TStringList;
    34     ProducedCode: TStringList;
    35     FileName: string;
    36     constructor Create;
    37     destructor Destroy; override;
    38     procedure Load; override;
    39     procedure Save; override;
     41    function SearchFile(FileName: string): TProjectFile;
    4042  end;
    4143
    4244  TProject = class(TProjectGroup)
     45    RootDir: string;
     46    function GetDir(IncludeRoot: Boolean = False): string; override;
    4347  end;
    4448
     
    7680end;
    7781
     82function TProjectGroup.SearchFile(FileName: string): TProjectFile;
     83var
     84  NamePart: string;
     85  I: Integer;
     86begin
     87  if Pos('/', FileName) > 0 then
     88    NamePart := Copy(FileName, 1, Pos('/', FileName))
     89    else NamePart := FileName;
     90  I := 0;
     91  while (I < Items.Count) and (TProjectNode(Items[I]).Name <> NamePart) do Inc(I);
     92  if I < Items.Count then begin
     93    if TProjectNode(Items[I]) is TProjectFile then Result := TProjectFile(Items[I])
     94    else begin
     95      Delete(FileName, 1, Length(FileName) + 1);
     96      TProjectGroup(Items[I]).SearchFile(FileName);
     97    end;
     98  end else Result := nil;
     99end;
     100
    78101{ TProjectFile }
    79102
     
    94117begin
    95118  inherited Load;
    96   Source.LoadFromFile(FileName);
     119  Source.LoadFromFile(Parent.GetDir(True) + Name);
    97120end;
    98121
     
    100123begin
    101124  inherited Save;
    102   Source.SaveToFile(FileName);
     125  Source.SaveToFile(Parent.GetDir(True) + Name);
    103126end;
    104127
     
    115138end;
    116139
     140function TProjectNode.GetDir(IncludeRoot: Boolean = False): string;
     141begin
     142  if Assigned(Parent) then Result := Parent.GetDir(IncludeRoot) + Name + '/'
     143  else Result := Name + '/';
     144end;
     145
     146{ TProject }
     147
     148function TProject.GetDir(IncludeRoot: Boolean): string;
     149begin
     150  if IncludeRoot then Result := RootDir else Result := '';
     151end;
     152
    117153end.
    118154
Note: See TracChangeset for help on using the changeset viewer.