Initial import

This commit is contained in:
mlemanczyk committed 2012-09-24 20:55:07 +02:00
1 parent ea3f8549e4
commit fa6feafba7
133 files changed
+17503 -4

No files matched your search

@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Operations.Uses;
namespace DelphiProjectHandler.Operations.Projects
{
public abstract class AbstractDelphiProjectOperation : IDelphiFileOperation
{
private IUsesListOperation fOperation;
private IProjectOperationSettings fSettings;
private IProjectOperationState fState;
protected IUsesListOperation Operation
{
get { return fOperation; }
set { fOperation = value; }
}
protected IProjectOperationSettings Settings
{
get { return fSettings; }
set { fSettings = value; }
}
protected IProjectOperationState State
{
get { return fState; }
set { fState = value; }
}
protected virtual string ReplaceContent(string iContent, string iOldValue, string iNewValue)
{
return iContent.Replace(iOldValue, iNewValue);
}
protected IProjectOperationSettings CreateProjectSettings(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths)
{
IProjectOperationSettings vSettings = new ProjectOperationSettings();
vSettings.RequiredUnits = aRequiredUnits;
vSettings.UnitsToManipulate = aUnitsToManipulate;
vSettings.UsePaths = aUsePaths;
return vSettings;
}
protected IUnitItemBuilder CreateUnitItemBuilder(string aFileName, bool aUsePaths)
{
return new ProjectUnitItemBuilder(aFileName, aUsePaths);
}
protected abstract IUsesListOperation CreateUsesOperation(string aFileName, IProjectOperationSettings aSettings, IUnitItemBuilder aBuilder);
public AbstractDelphiProjectOperation(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths)
{
fState = new ProjectOperationState();
fSettings = CreateProjectSettings(aRequiredUnits, aUnitsToManipulate, aUsePaths);
}
public virtual void Initialize(string aFileName, string aFileContent)
{
State.FileContent = aFileContent;
State.OriginalUsesClause = UsesClauseReader.ExtractUses(aFileContent);
State.Units = UsesClauseReader.GetUnits(State.FileContent);
IUnitItemBuilder vBuilder = CreateUnitItemBuilder(aFileName, Settings.UsePaths);
fOperation = CreateUsesOperation(aFileName, Settings, vBuilder);
Operation.Initialize(State.Units);
}
public bool CanProcess()
{
return Operation.CanProcess();
}
public string Execute()
{
if (!Operation.Execute())
return State.FileContent;
return ReplaceContent(State.FileContent, State.OriginalUsesClause, State.Units.ToString());
}
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using DelphiProjectHandler.Operations.Uses;
namespace DelphiProjectHandler.Operations.Projects
{
public class DelphiProjectAddUnitOperation: AbstractDelphiProjectOperation
{
protected override IUsesListOperation CreateUsesOperation(string aFileName, IProjectOperationSettings aSettings, IUnitItemBuilder aBuilder)
{
IUsesListOperationSettings vUsesSettings = new UsesListOperationSettings();
vUsesSettings.RequiredUnits = aSettings.RequiredUnits;
vUsesSettings.UnitItemBuilder = aBuilder;
vUsesSettings.UnitsToManipulate = aSettings.UnitsToManipulate;
return new UsesListAddOperation(vUsesSettings);
}
public DelphiProjectAddUnitOperation(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths)
: base(aRequiredUnits, aUnitsToManipulate, aUsePaths)
{
}
}
}
@@ -0,0 +1,23 @@
using System;
using DelphiProjectHandler.Operations.Uses;
using System.Collections.Generic;
namespace DelphiProjectHandler.Operations.Projects
{
public class DelphiProjectFixFormsOperation: AbstractDelphiProjectOperation
{
protected override IUsesListOperation CreateUsesOperation(string aFileName, IProjectOperationSettings aSettings, IUnitItemBuilder aBuilder)
{
IUsesListOperationSettings vUsesSettings = new UsesListOperationSettings();
vUsesSettings.RequiredUnits = aSettings.RequiredUnits;
vUsesSettings.UnitItemBuilder = aBuilder;
vUsesSettings.UnitsToManipulate = aSettings.UnitsToManipulate;
return new UsesListFixFormOperation(vUsesSettings);
}
public DelphiProjectFixFormsOperation(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths): base(aRequiredUnits, aUnitsToManipulate, aUsePaths)
{
}
}
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
using DelphiProjectHandler.Operations.Uses;
namespace DelphiProjectHandler.Operations.Projects
{
public class DelphiProjectFixPathsOperation: AbstractDelphiProjectOperation
{
protected override IUsesListOperation CreateUsesOperation(string aFileName, IProjectOperationSettings aSettings, IUnitItemBuilder aBuilder)
{
IUsesListOperationSettings vUsesSettings = new UsesListOperationSettings();
vUsesSettings.RequiredUnits = aSettings.RequiredUnits;
vUsesSettings.UnitItemBuilder = aBuilder;
vUsesSettings.UnitsToManipulate = aSettings.UnitsToManipulate;
return new UsesListFixPathOperation(vUsesSettings);
}
public DelphiProjectFixPathsOperation(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths): base(aRequiredUnits, aUnitsToManipulate, aUsePaths)
{
}
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using DelphiProjectHandler.Operations.Uses;
namespace DelphiProjectHandler.Operations.Projects
{
public class DelphiProjectRemoveUnitOperation: AbstractDelphiProjectOperation
{
public DelphiProjectRemoveUnitOperation(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths)
: base(aRequiredUnits, aUnitsToManipulate, aUsePaths)
{
}
protected override IUsesListOperation CreateUsesOperation(string aFileName, IProjectOperationSettings aSettings, IUnitItemBuilder aBuilder)
{
IUsesListOperationSettings vUsesSettings = new UsesListOperationSettings();
vUsesSettings.RequiredUnits = aSettings.RequiredUnits;
vUsesSettings.UnitItemBuilder = aBuilder;
vUsesSettings.UnitsToManipulate = aSettings.UnitsToManipulate;
return new UsesListDeleteOperation(vUsesSettings);
}
}
}
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Projects
{
public interface IProjectOperationSettings
{
ICollection<string> RequiredUnits { get; set; }
ICollection<string> UnitsToManipulate { get; set; }
bool UsePaths { get; set; }
}
}
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Projects
{
public interface IProjectOperationState : IOperationState
{
string FileContent { get; set; }
string OriginalUsesClause { get; set; }
UnitList Units { get; set; }
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Projects
{
public class ProjectOperationSettings: IProjectOperationSettings
{
private ICollection<string> fRequiredUnits;
public ICollection<string> RequiredUnits
{
get { return fRequiredUnits; }
set { fRequiredUnits = value; }
}
private ICollection<string> fUnitsToManipulate;
public ICollection<string> UnitsToManipulate
{
get { return fUnitsToManipulate; }
set { fUnitsToManipulate = value; }
}
private bool fUsePaths;
public bool UsePaths
{
get { return fUsePaths; }
set { fUsePaths = value; }
}
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Projects
{
public class ProjectOperationState : IProjectOperationState
{
private string fFileContent;
public string FileContent
{
get { return fFileContent; }
set { fFileContent = value; }
}
private string fOriginalUsesState;
public string OriginalUsesClause
{
get { return fOriginalUsesState; }
set { fOriginalUsesState = value; }
}
private UnitList fUnits;
public UnitList Units
{
get { return fUnits; }
set { fUnits = value; }
}
}
}
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using DelphiProjectHandler.Dialogs;
namespace DelphiProjectHandler.Operations.Projects
{
/// <summary>
/// UnitItem builder for creating complete project file unit item. New UnitItem will have all properties set that are normally used in a project Delphi file. It will also
/// search for corresponding dfm file.
/// </summary>
class ProjectUnitItemBuilder: IUnitItemBuilder
{
/// <summary>
/// Complete fileName or path of the project file. It is used to calculate new unit item path relative to project file location.
/// </summary>
public string BasePath
{
get { return fBasePath; }
}
private string fBasePath;
/// <summary>
/// Indicates, if unit paths should be added in a project file style, when converting the unit list to uses clause.
/// </summary>
public bool UsePaths
{
get { return fUsePaths; }
}
private bool fUsePaths;
/// <summary>
/// Creates new instance of the ProjectItemBuilder.
/// </summary>
/// <param name="aBasePath">Complete fileName or path of the project file. It is used to calculate new unit item path relative to project file location.</param>
public ProjectUnitItemBuilder(string aBasePath, bool aUsePaths)
{
fBasePath = aBasePath;
fUsePaths = aUsePaths;
}
/// <summary>
/// Creates new UnitItem object and fills it will all required information that can be used in a project file. Requires valid RelativePath builder and UnitFormFinder.
/// It finds corresponding form for the unit automatically. Path is always set relatively to the BasePath.
/// </summary>
/// <param name="aUnitFileName"></param>
/// <returns></returns>
public UnitItem Create(string aUnitFileName)
{
UnitItem vResult = new UnitItem();
vResult.Name = Path.GetFileNameWithoutExtension(aUnitFileName);
vResult.UsePath = UsePaths;
if (!aUnitFileName.Equals(""))
vResult.Path = Path.GetDirectoryName(aUnitFileName);
vResult.Path = RelativePath.GetRelativeFileName(BasePath, vResult.Path);
vResult.Form = UnitFormReader.GetUnitForm(aUnitFileName);
return vResult;
}
}
}