summaryrefslogtreecommitdiff
path: root/examples/apps/ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/apps/ide/src')
-rw-r--r--examples/apps/ide/src/frm_main.pas26
-rw-r--r--examples/apps/ide/src/unitlist.pas26
2 files changed, 37 insertions, 15 deletions
diff --git a/examples/apps/ide/src/frm_main.pas b/examples/apps/ide/src/frm_main.pas
index fe903c31..65985631 100644
--- a/examples/apps/ide/src/frm_main.pas
+++ b/examples/apps/ide/src/frm_main.pas
@@ -1,7 +1,7 @@
{
fpGUI IDE - Maximus
- Copyright (C) 2012 - 2013 Graeme Geldenhuys
+ Copyright (C) 2012 - 2014 Graeme Geldenhuys
See the file COPYING.modifiedLGPL, included in this distribution,
for details about redistributing fpGUI.
@@ -541,18 +541,18 @@ var
r: TfpgTreeNode;
n: TfpgTreeNode;
begin
- u := TUnit.Create;
- u.FileName := AUnitName;
- u.Opened := True;
- GProject.UnitList.Add(u);
- // add reference to tabsheet
- pcEditor.ActivePage.TagPointer := u;
- s := fpgExtractRelativepath(GProject.ProjectDir, u.FileName);
- r := GetUnitsNode;
- n := r.AppendText(s);
- // add reference to treenode
- n.Data := u;
- tvProject.Invalidate;
+ u := GProject.UnitList.AddFilename(AUnitName);
+ if Assigned(n) then
+ begin
+ // add reference to tabsheet
+ pcEditor.ActivePage.TagPointer := u;
+ s := u.GetRelativePath;
+ r := GetUnitsNode;
+ n := r.AppendText(s);
+ // add reference to treenode
+ n.Data := u;
+ tvProject.Invalidate;
+ end;
end;
procedure TMainForm.miProjectAddUnitToProject(Sender: TObject);
diff --git a/examples/apps/ide/src/unitlist.pas b/examples/apps/ide/src/unitlist.pas
index 827326e7..37e9a9cd 100644
--- a/examples/apps/ide/src/unitlist.pas
+++ b/examples/apps/ide/src/unitlist.pas
@@ -1,7 +1,7 @@
{
fpGUI IDE - Maximus
- Copyright (C) 2012 - 2013 Graeme Geldenhuys
+ Copyright (C) 2012 - 2014 Graeme Geldenhuys
See the file COPYING.modifiedLGPL, included in this distribution,
for details about redistributing fpGUI.
@@ -31,6 +31,7 @@ type
function GetUnitName: TfpgString;
public
constructor Create;
+ function GetRelativePath: TfpgString;
property FileName: TfpgString read FFilename write FFilename;
property UnitName: TfpgString read GetUnitName;
property Opened: Boolean read FOpened write FOpened;
@@ -48,6 +49,7 @@ type
function Count: integer;
function FindByName(const AUnitName: TfpgString): TUnit;
function FileExists(const AFilename: TfpgString): Boolean;
+ function AddFileName(const AFilename: TfpgString): TUnit;
procedure Add(NewUnit: TUnit);
procedure Clear;
procedure Delete(AIndex: integer);
@@ -58,7 +60,8 @@ type
implementation
uses
- fpg_utils;
+ fpg_utils,
+ project;
{ TUnitList }
@@ -128,6 +131,20 @@ begin
end;
end;
+function TUnitList.AddFileName(const AFilename: TfpgString): TUnit;
+var
+ u: TUnit;
+begin
+ if not FileExists(AFilename) then
+ begin
+ u := TUnit.Create;
+ u.FileName := AFilename;
+ u.Opened := True;
+ Add(u);
+ Result := u;
+ end;
+end;
+
procedure TUnitList.Add(NewUnit: TUnit);
var
l: Integer;
@@ -176,6 +193,11 @@ begin
Result := fpgExtractFileName(Filename);
end;
+function TUnit.GetRelativePath: TfpgString;
+begin
+ Result := fpgExtractRelativepath(GProject.ProjectDir, FileName);
+end;
+
constructor TUnit.Create;
begin
inherited Create;