summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@gmail.com>2014-08-09 17:18:31 +0100
committerGraeme Geldenhuys <graemeg@gmail.com>2014-08-09 18:06:24 +0100
commit664266e7d0b78bccc0b6ccd4467c9325e7533962 (patch)
tree7a38e2d4654a1165750f3a82952bee15de4309f1
parent14f124ca73c3df78f317b513897482df112a594b (diff)
downloadfpGUI-664266e7d0b78bccc0b6ccd4467c9325e7533962.tar.xz
maximus: refactored some code, moving from main form to various classes
Moved some functionality from the main form unit, into the unitlist.pas unit.
-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;