h2pas gui: implemented projects and configs

git-svn-id: trunk@9637 -
This commit is contained in:
mattias 2006-07-19 22:46:57 +00:00
parent 5ba422890c
commit 4e7d43b405
13 changed files with 2297 additions and 59 deletions

2
.gitattributes vendored
View File

@ -151,6 +151,8 @@ components/fpcunit/ide/testcaseopts.lrs svneol=native#text/pascal
components/fpcunit/ide/testcaseopts.pas svneol=native#text/pascal
components/fpcunit/lib/README.txt svneol=native#text/plain
components/fpcunit/xmlreporter.pas svneol=native#text/plain
components/h2pas/h2pasconfig.pas svneol=native#text/plain
components/h2pas/h2pasconvert.pas svneol=native#text/plain
components/h2pas/h2pasdlg.lfm svneol=native#text/plain
components/h2pas/h2pasdlg.lrs svneol=native#text/plain
components/h2pas/h2pasdlg.pas svneol=native#text/plain

View File

@ -0,0 +1,84 @@
{ Copyright (C) 2006 Mattias Gaertner
This source is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This code is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
A copy of the GNU General Public License is available on the World Wide Web
at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
Abstract: Options
}
unit H2PasConfig;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LazConfigStorage;
type
TH2PasProject = class;
TH2PasFile = class(TPersistent)
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Assign(Source: TPersistent); override;
procedure Load(Config: TConfigStorage);
procedure Save(Config: TConfigStorage);
public
property Project: TH2PasProject;
property Filename: string;
property Enabled: boolean read FEnabled write FEnabled;
property Modified: boolean;
end;
TH2PasProject = class(TPersistent)
private
FCHeaderFiles: TFPList;// list of TH2PasFile
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Assign(Source: TPersistent); override;
procedure Load(Config: TConfigStorage);
procedure Save(Config: TConfigStorage);
public
property CHeaderFileCount: integer read GetCHeaderFileCount;
property CHeaderFiles[Index: integer]: TH2PasFile read GetCHeaderFiles;
property Modified: boolean;
end;
TH2PasOptions = class(TPersistent)
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Assign(Source: TPersistent); override;
procedure Load(Config: TConfigStorage);
procedure Save(Config: TConfigStorage);
public
property ProjectHistory: TStrings;
property CurrentProjectFilename: string read FCurrentProjectFilename
write FCurrentProjectFilename;
property WindowSize: TPoint;
property AutoOpenLastProject: boolean read FAutoOpenLastProject
write FAutoOpenLastProject;
property Modified: boolean read FModified write FModified;
end;
implementation
end.

View File

@ -0,0 +1,876 @@
{ Copyright (C) 2006 Mattias Gaertner
This source is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This code is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
A copy of the GNU General Public License is available on the World Wide Web
at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
}
unit H2PasConvert;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LCLProc, LazConfigStorage, XMLPropStorage, FileUtil;
type
TH2PasProject = class;
{ TH2PasFile }
TH2PasFile = class(TPersistent)
private
FEnabled: boolean;
FFilename: string;
FModified: boolean;
FProject: TH2PasProject;
procedure SetEnabled(const AValue: boolean);
procedure SetFilename(const AValue: string);
procedure SetModified(const AValue: boolean);
procedure SetProject(const AValue: TH2PasProject);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Assign(Source: TPersistent); override;
function IsEqual(AFile: TH2PasFile): boolean;
procedure Load(Config: TConfigStorage);
procedure Save(Config: TConfigStorage);
public
property Project: TH2PasProject read FProject write SetProject;
property Filename: string read FFilename write SetFilename;
property Enabled: boolean read FEnabled write SetEnabled;
property Modified: boolean read FModified write SetModified;
end;
{ TH2PasProject }
TH2PasProject = class(TPersistent)
private
FBaseDir: string;
FCHeaderFiles: TFPList;// list of TH2PasFile
FConstantsInsteadOfEnums: boolean;
FCreateIncludeFile: boolean;
FFilename: string;
FIsVirtual: boolean;
FLibname: string;
FModified: boolean;
FOutputDirectory: string;
FOutputExt: string;
FPalmOSSYSTrap: boolean;
FPforPointers: boolean;
FStripComments: boolean;
FTforTypedefs: boolean;
FUseExternal: boolean;
FUseExternalLibname: boolean;
FVarParams: boolean;
FWin32Header: boolean;
function GetCHeaderFileCount: integer;
function GetCHeaderFiles(Index: integer): TH2PasFile;
procedure InternalAddCHeaderFile(AFile: TH2PasFile);
procedure InternalRemoveCHeaderFile(AFile: TH2PasFile);
procedure SetConstantsInsteadOfEnums(const AValue: boolean);
procedure SetCreateIncludeFile(const AValue: boolean);
procedure SetFilename(const AValue: string);
procedure SetLibname(const AValue: string);
procedure SetModified(const AValue: boolean);
procedure FilenameChanged;
procedure SetOutputDirectory(const AValue: string);
procedure SetOutputExt(const AValue: string);
procedure SetPalmOSSYSTrap(const AValue: boolean);
procedure SetPforPointers(const AValue: boolean);
procedure SetStripComments(const AValue: boolean);
procedure SetTforTypedefs(const AValue: boolean);
procedure SetUseExternal(const AValue: boolean);
procedure SetUseExternalLibname(const AValue: boolean);
procedure SetVarParams(const AValue: boolean);
procedure SetWin32Header(const AValue: boolean);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Assign(Source: TPersistent); override;
function IsEqual(AProject: TH2PasProject): boolean;
procedure Load(Config: TConfigStorage);
procedure Save(Config: TConfigStorage);
procedure LoadFromFile(const AFilename: string);
procedure SaveToFile(const AFilename: string);
procedure AddFiles(List: TStrings);
procedure DeleteFiles(List: TStrings);
function CHeaderFileWithFilename(const AFilename: string): TH2PasFile;
function CHeaderFileIndexWithFilename(const AFilename: string): integer;
function ShortenFilename(const AFilename: string): string;
function LongenFilename(const AFilename: string): string;
function NormalizeFilename(const AFilename: string): string;
public
property CHeaderFileCount: integer read GetCHeaderFileCount;
property CHeaderFiles[Index: integer]: TH2PasFile read GetCHeaderFiles;
property Modified: boolean read FModified write SetModified;
property Filename: string read FFilename write SetFilename;
property BaseDir: string read FBaseDir;
property IsVirtual: boolean read FIsVirtual;
// h2pas options
property ConstantsInsteadOfEnums: boolean read FConstantsInsteadOfEnums write SetConstantsInsteadOfEnums;
property CreateIncludeFile: boolean read FCreateIncludeFile write SetCreateIncludeFile;
property Libname: string read FLibname write SetLibname;
property OutputExt: string read FOutputExt write SetOutputExt;
property PalmOSSYSTrap: boolean read FPalmOSSYSTrap write SetPalmOSSYSTrap;
property PforPointers: boolean read FPforPointers write SetPforPointers;
property StripComments: boolean read FStripComments write SetStripComments;
property TforTypedefs: boolean read FTforTypedefs write SetTforTypedefs;
property UseExternal: boolean read FUseExternal write SetUseExternal;
property UseExternalLibname: boolean read FUseExternalLibname write SetUseExternalLibname;
property VarParams: boolean read FVarParams write SetVarParams;
property Win32Header: boolean read FWin32Header write SetWin32Header;
property OutputDirectory: string read FOutputDirectory write SetOutputDirectory;
end;
{ TH2PasConverter }
TH2PasConverter = class(TPersistent)
private
FAutoOpenLastProject: boolean;
Fh2pasFilename: string;
FModified: boolean;
FProject: TH2PasProject;
FProjectHistory: TStrings;
FWindowSize: TPoint;
function GetCurrentProjectFilename: string;
procedure SetAutoOpenLastProject(const AValue: boolean);
procedure SetCurrentProjectFilename(const AValue: string);
procedure SetProject(const AValue: TH2PasProject);
procedure SetProjectHistory(const AValue: TStrings);
procedure SetWindowSize(const AValue: TPoint);
procedure Seth2pasFilename(const AValue: string);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Assign(Source: TPersistent); override;
function IsEqual(AConverter: TH2PasConverter): boolean;
procedure Load(Config: TConfigStorage);
procedure Save(Config: TConfigStorage);
procedure LoadFromFile(const AFilename: string);
procedure SaveToFile(const AFilename: string);
procedure LoadProject(const Filename: string);
procedure SaveProject(const Filename: string);
public
property Project: TH2PasProject read FProject write SetProject;
property ProjectHistory: TStrings read FProjectHistory write SetProjectHistory;
property CurrentProjectFilename: string read GetCurrentProjectFilename
write SetCurrentProjectFilename;
property WindowSize: TPoint read FWindowSize write SetWindowSize;
property AutoOpenLastProject: boolean read FAutoOpenLastProject
write SetAutoOpenLastProject;
property h2pasFilename: string read Fh2pasFilename write Seth2pasFilename;
property Modified: boolean read FModified write FModified;
end;
implementation
{ TH2PasFile }
procedure TH2PasFile.SetFilename(const AValue: string);
var
NewValue: String;
begin
NewValue:=TrimFilename(AValue);
if FFilename=NewValue then exit;
FFilename:=NewValue;
Modified:=true;
end;
procedure TH2PasFile.SetEnabled(const AValue: boolean);
begin
if FEnabled=AValue then exit;
FEnabled:=AValue;
Modified:=true;
end;
procedure TH2PasFile.SetModified(const AValue: boolean);
begin
if FModified=AValue then exit;
FModified:=AValue;
if FModified and (Project<>nil) then
Project.Modified:=true;
end;
procedure TH2PasFile.SetProject(const AValue: TH2PasProject);
begin
if FProject=AValue then exit;
if FProject<>nil then begin
FProject.InternalRemoveCHeaderFile(Self);
end;
FProject:=AValue;
if FProject<>nil then begin
FProject.InternalAddCHeaderFile(Self);
end;
Modified:=true;
end;
constructor TH2PasFile.Create;
begin
Clear;
end;
destructor TH2PasFile.Destroy;
begin
if FProject<>nil then begin
Project:=nil;
end;
Clear;
inherited Destroy;
end;
procedure TH2PasFile.Clear;
begin
FEnabled:=true;
FFilename:='';
FModified:=false;
end;
procedure TH2PasFile.Assign(Source: TPersistent);
var
Src: TH2PasFile;
begin
if Source is TH2PasFile then begin
Src:=TH2PasFile(Source);
if not IsEqual(Src) then begin
FEnabled:=Src.FEnabled;
FFilename:=Src.FFilename;
Modified:=true;
end;
end else begin
inherited Assign(Source);
end;
end;
function TH2PasFile.IsEqual(AFile: TH2PasFile): boolean;
begin
Result:=(CompareFilenames(Filename,AFile.Filename)=0)
and (Enabled=AFile.Enabled);
end;
procedure TH2PasFile.Load(Config: TConfigStorage);
begin
FEnabled:=Config.GetValue('Enabled/Value',true);
FFilename:=Config.GetValue('Filename/Value','');
if Project<>nil then
FFilename:=Project.NormalizeFilename(FFilename);
FModified:=false;
end;
procedure TH2PasFile.Save(Config: TConfigStorage);
var
AFilename: String;
begin
Config.SetDeleteValue('Enabled/Value',Enabled,true);
AFilename:=FFilename;
if Project<>nil then
AFilename:=Project.ShortenFilename(AFilename);
Config.SetDeleteValue('Filename/Value',AFilename,'');
FModified:=false;
end;
{ TH2PasProject }
function TH2PasProject.GetCHeaderFileCount: integer;
begin
Result:=FCHeaderFiles.Count;
end;
function TH2PasProject.GetCHeaderFiles(Index: integer): TH2PasFile;
begin
Result:=TH2PasFile(FCHeaderFiles[Index]);
end;
procedure TH2PasProject.InternalAddCHeaderFile(AFile: TH2PasFile);
begin
FCHeaderFiles.Add(AFile);
end;
procedure TH2PasProject.InternalRemoveCHeaderFile(AFile: TH2PasFile);
begin
FCHeaderFiles.Remove(AFile);
end;
procedure TH2PasProject.SetConstantsInsteadOfEnums(const AValue: boolean);
begin
if FConstantsInsteadOfEnums=AValue then exit;
FConstantsInsteadOfEnums:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetCreateIncludeFile(const AValue: boolean);
begin
if FCreateIncludeFile=AValue then exit;
FCreateIncludeFile:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetFilename(const AValue: string);
var
NewValue: String;
begin
NewValue:=TrimFilename(AValue);
if FFilename=NewValue then exit;
FFilename:=NewValue;
FilenameChanged;
Modified:=true;
end;
procedure TH2PasProject.SetLibname(const AValue: string);
begin
if FLibname=AValue then exit;
FLibname:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetModified(const AValue: boolean);
begin
if FModified=AValue then exit;
FModified:=AValue;
end;
procedure TH2PasProject.FilenameChanged;
begin
FIsVirtual:=(FFilename='') or (not FilenameIsAbsolute(FFilename));
FBaseDir:=ExtractFilePath(FFilename);
end;
procedure TH2PasProject.SetOutputDirectory(const AValue: string);
begin
if FOutputDirectory=AValue then exit;
FOutputDirectory:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetOutputExt(const AValue: string);
begin
if FOutputExt=AValue then exit;
FOutputExt:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetPalmOSSYSTrap(const AValue: boolean);
begin
if FPalmOSSYSTrap=AValue then exit;
FPalmOSSYSTrap:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetPforPointers(const AValue: boolean);
begin
if FPforPointers=AValue then exit;
FPforPointers:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetStripComments(const AValue: boolean);
begin
if FStripComments=AValue then exit;
FStripComments:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetTforTypedefs(const AValue: boolean);
begin
if FTforTypedefs=AValue then exit;
FTforTypedefs:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetUseExternal(const AValue: boolean);
begin
if FUseExternal=AValue then exit;
FUseExternal:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetUseExternalLibname(const AValue: boolean);
begin
if FUseExternalLibname=AValue then exit;
FUseExternalLibname:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetVarParams(const AValue: boolean);
begin
if FVarParams=AValue then exit;
FVarParams:=AValue;
Modified:=true;
end;
procedure TH2PasProject.SetWin32Header(const AValue: boolean);
begin
if FWin32Header=AValue then exit;
FWin32Header:=AValue;
Modified:=true;
end;
constructor TH2PasProject.Create;
begin
FCHeaderFiles:=TFPList.Create;
Clear;
end;
destructor TH2PasProject.Destroy;
begin
Clear;
FreeAndNil(FCHeaderFiles);
inherited Destroy;
end;
procedure TH2PasProject.Clear;
begin
// FFilename is kept
FConstantsInsteadOfEnums:=true;
FCreateIncludeFile:=true;
FLibname:='';
FOutputExt:='.inc';
FPalmOSSYSTrap:=false;
FPforPointers:=true;
FStripComments:=false;
FTforTypedefs:=false;
FUseExternal:=false;
FUseExternalLibname:=true;
FVarParams:=false;
FWin32Header:=false;
FOutputDirectory:='';
while CHeaderFileCount>0 do
CHeaderFiles[CHeaderFileCount-1].Free;
FModified:=false;
end;
procedure TH2PasProject.Assign(Source: TPersistent);
var
Src: TH2PasProject;
i: Integer;
NewCHeaderFile: TH2PasFile;
begin
if Source is TH2PasProject then begin
Src:=TH2PasProject(Source);
if not IsEqual(Src) then begin
// FFilename is kept
FConstantsInsteadOfEnums:=Src.FConstantsInsteadOfEnums;
FCreateIncludeFile:=Src.FCreateIncludeFile;
FLibname:=Src.FLibname;
FOutputExt:=Src.FOutputExt;
FPalmOSSYSTrap:=Src.FPalmOSSYSTrap;
FPforPointers:=Src.FPforPointers;
FStripComments:=Src.FStripComments;
FTforTypedefs:=Src.FTforTypedefs;
FUseExternal:=Src.FUseExternal;
FUseExternalLibname:=Src.FUseExternalLibname;
FVarParams:=Src.FVarParams;
FWin32Header:=Src.FWin32Header;
FOutputDirectory:=Src.FOutputDirectory;
Clear;
for i:=0 to Src.CHeaderFileCount-1 do begin
NewCHeaderFile:=TH2PasFile.Create;
NewCHeaderFile.Project:=Self;
NewCHeaderFile.Assign(Src.CHeaderFiles[i]);
end;
Modified:=true;
end;
end else begin
inherited Assign(Source);
end;
end;
function TH2PasProject.IsEqual(AProject: TH2PasProject): boolean;
var
i: Integer;
begin
Result:=(AProject.CHeaderFileCount=CHeaderFileCount)
and (FConstantsInsteadOfEnums=AProject.FConstantsInsteadOfEnums)
and (FCreateIncludeFile=AProject.FCreateIncludeFile)
and (FLibname=AProject.FLibname)
and (FOutputExt=AProject.FOutputExt)
and (FPalmOSSYSTrap=AProject.FPalmOSSYSTrap)
and (FPforPointers=AProject.FPforPointers)
and (FStripComments=AProject.FStripComments)
and (FTforTypedefs=AProject.FTforTypedefs)
and (FUseExternal=AProject.FUseExternal)
and (FUseExternalLibname=AProject.FUseExternalLibname)
and (FVarParams=AProject.FVarParams)
and (FWin32Header=AProject.FWin32Header)
and (FOutputDirectory=AProject.FOutputDirectory);
if not Result then exit;
for i:=0 to CHeaderFileCount-1 do
if not CHeaderFiles[i].IsEqual(AProject.CHeaderFiles[i]) then exit(false);
end;
procedure TH2PasProject.Load(Config: TConfigStorage);
var
NewCHeaderFileCount: LongInt;
NewCHeaderFile: TH2PasFile;
i: Integer;
begin
// FFilename is not saved
FConstantsInsteadOfEnums:=Config.GetValue('ConstantsInsteadOfEnums/Value',true);
FCreateIncludeFile:=Config.GetValue('CreateIncludeFile/Value',true);
FLibname:=Config.GetValue('Libname/Value','');
FOutputExt:=Config.GetValue('OutputExt/Value','.inc');
FPalmOSSYSTrap:=Config.GetValue('PalmOSSYSTrap/Value',false);
FPforPointers:=Config.GetValue('PforPointers/Value',true);
FStripComments:=Config.GetValue('StripComments/Value',false);
FTforTypedefs:=Config.GetValue('TforTypedefs/Value',false);
FUseExternal:=Config.GetValue('UseExternal/Value',false);
FUseExternalLibname:=Config.GetValue('UseExternalLibname/Value',true);
FVarParams:=Config.GetValue('VarParams/Value',false);
FWin32Header:=Config.GetValue('Win32Header/Value',false);
FOutputDirectory:=NormalizeFilename(Config.GetValue('OutputDirectory/Value',''));
// load CHeaderFiles
Config.AppendBasePath('CHeaderFiles');
try
NewCHeaderFileCount:=Config.GetValue('Count',0);
for i:=0 to NewCHeaderFileCount-1 do begin
Config.AppendBasePath('File'+IntToStr(i+1));
try
NewCHeaderFile:=TH2PasFile.Create;
NewCHeaderFile.Project:=Self;
NewCHeaderFile.Load(Config);
finally
Config.UndoAppendBasePath;
end;
end;
finally
Config.UndoAppendBasePath;
end;
FModified:=false;
end;
procedure TH2PasProject.Save(Config: TConfigStorage);
var
i: Integer;
begin
// FFilename is kept
Config.SetDeleteValue('ConstantsInsteadOfEnums/Value',FConstantsInsteadOfEnums,true);
Config.SetDeleteValue('CreateIncludeFile/Value',FCreateIncludeFile,true);
Config.SetDeleteValue('Libname/Value',FLibname,'');
Config.SetDeleteValue('OutputExt/Value',FOutputExt,'.inc');
Config.SetDeleteValue('PalmOSSYSTrap/Value',FPalmOSSYSTrap,false);
Config.SetDeleteValue('PforPointers/Value',FPforPointers,true);
Config.SetDeleteValue('StripComments/Value',FStripComments,false);
Config.SetDeleteValue('TforTypedefs/Value',FTforTypedefs,false);
Config.SetDeleteValue('UseExternal/Value',FUseExternal,false);
Config.SetDeleteValue('UseExternalLibname/Value',FUseExternalLibname,true);
Config.SetDeleteValue('VarParams/Value',FVarParams,false);
Config.SetDeleteValue('Win32Header/Value',FWin32Header,false);
Config.SetDeleteValue('OutputDirectory/Value',ShortenFilename(FOutputDirectory),'');
// save CHeaderFiles
Config.AppendBasePath('CHeaderFiles');
try
Config.SetDeleteValue('Count',CHeaderFileCount,0);
for i:=0 to CHeaderFileCount-1 do begin
Config.AppendBasePath('File'+IntToStr(i+1));
try
CHeaderFiles[i].Save(Config);
finally
Config.UndoAppendBasePath;
end;
end;
finally
Config.UndoAppendBasePath;
end;
FModified:=false;
end;
procedure TH2PasProject.LoadFromFile(const AFilename: string);
var
Config: TXMLConfigStorage;
begin
Config:=TXMLConfigStorage.Create(AFilename,true);
try
Load(Config);
finally
Config.Free;
end;
end;
procedure TH2PasProject.SaveToFile(const AFilename: string);
var
Config: TXMLConfigStorage;
begin
Config:=TXMLConfigStorage.Create(AFilename,false);
try
Save(Config);
DebugLn(['TH2PasProject.SaveToFile ',AFilename]);
Config.WriteToDisk;
finally
Config.Free;
end;
end;
procedure TH2PasProject.AddFiles(List: TStrings);
var
i: Integer;
NewFilename: string;
NewFile: TH2PasFile;
begin
if List=nil then exit;
for i:=0 to List.Count-1 do begin
NewFilename:=CleanAndExpandFilename(List[i]);
if (NewFilename='') or (not FileExists(NewFilename)) then exit;
if CHeaderFileWithFilename(NewFilename)<>nil then exit;
NewFile:=TH2PasFile.Create;
NewFile.Project:=Self;
NewFile.Filename:=NewFilename;
end;
end;
procedure TH2PasProject.DeleteFiles(List: TStrings);
var
i: Integer;
NewFilename: String;
CurFile: TH2PasFile;
begin
if List=nil then exit;
for i:=0 to List.Count-1 do begin
NewFilename:=CleanAndExpandFilename(List[i]);
if (NewFilename='') then exit;
CurFile:=CHeaderFileWithFilename(NewFilename);
if CurFile<>nil then begin
CurFile.Free;
end;
end;
end;
function TH2PasProject.CHeaderFileWithFilename(const AFilename: string
): TH2PasFile;
var
i: LongInt;
begin
i:=CHeaderFileIndexWithFilename(AFilename);
if i>=0 then
Result:=CHeaderFiles[i]
else
Result:=nil;
end;
function TH2PasProject.CHeaderFileIndexWithFilename(const AFilename: string
): integer;
begin
Result:=CHeaderFileCount-1;
while (Result>=0)
and (CompareFilenames(AFilename,CHeaderFiles[Result].Filename)<>0) do
dec(Result);
end;
function TH2PasProject.ShortenFilename(const AFilename: string): string;
begin
if IsVirtual then
Result:=AFilename
else
Result:=CreateRelativePath(AFilename,fBaseDir);
end;
function TH2PasProject.LongenFilename(const AFilename: string): string;
begin
if IsVirtual then
Result:=AFilename
else if not FilenameIsAbsolute(AFilename) then
Result:=TrimFilename(BaseDir+AFilename);
end;
function TH2PasProject.NormalizeFilename(const AFilename: string): string;
begin
Result:=LongenFilename(SetDirSeparators(AFilename));
end;
{ TH2PasConverter }
function TH2PasConverter.GetCurrentProjectFilename: string;
begin
if FProjectHistory.Count>0 then
Result:=FProjectHistory[FProjectHistory.Count-1]
else
Result:='';
end;
procedure TH2PasConverter.SetAutoOpenLastProject(const AValue: boolean);
begin
if FAutoOpenLastProject=AValue then exit;
FAutoOpenLastProject:=AValue;
Modified:=true;
end;
procedure TH2PasConverter.SetCurrentProjectFilename(const AValue: string);
const
ProjectHistoryMax=30;
var
NewValue: String;
begin
NewValue:=TrimFilename(AValue);
if NewValue='' then exit;
if CompareFilenames(GetCurrentProjectFilename,NewValue)=0 then exit;
FProjectHistory.Add(NewValue);
while FProjectHistory.Count>ProjectHistoryMax do
FProjectHistory.Delete(0);
Modified:=true;
end;
procedure TH2PasConverter.SetProject(const AValue: TH2PasProject);
begin
if FProject=AValue then exit;
FProject:=AValue;
if FProject<>nil then begin
if FProject.Filename<>'' then
CurrentProjectFilename:=FProject.Filename;
end;
end;
procedure TH2PasConverter.SetProjectHistory(const AValue: TStrings);
begin
if FProjectHistory=AValue then exit;
FProjectHistory.Assign(AValue);
end;
procedure TH2PasConverter.SetWindowSize(const AValue: TPoint);
begin
if ComparePoints(FWindowSize,AValue)=0 then exit;
FWindowSize:=AValue;
Modified:=true;
end;
procedure TH2PasConverter.Seth2pasFilename(const AValue: string);
begin
if Fh2pasFilename=AValue then exit;
Fh2pasFilename:=AValue;
Modified:=true;
end;
constructor TH2PasConverter.Create;
begin
FProjectHistory:=TStringList.Create;
Clear;
end;
destructor TH2PasConverter.Destroy;
begin
FreeAndNil(FProject);
Clear;
inherited Destroy;
end;
procedure TH2PasConverter.Clear;
begin
FAutoOpenLastProject:=true;
if FProject<>nil then FreeAndNil(FProject);
FProjectHistory.Clear;
FWindowSize:=Point(0,0);
Fh2pasFilename:='h2pas';
FModified:=false;
end;
procedure TH2PasConverter.Assign(Source: TPersistent);
var
Src: TH2PasConverter;
begin
if Source is TH2PasConverter then begin
Src:=TH2PasConverter(Source);
if not IsEqual(Src) then begin
Clear;
// Note: project is kept unchanged
FProjectHistory.Assign(Src.FProjectHistory);
FWindowSize:=Src.FWindowSize;
Fh2pasFilename:=Src.Fh2pasFilename;
Modified:=true;
end;
end else begin
inherited Assign(Source);
end;
end;
function TH2PasConverter.IsEqual(AConverter: TH2PasConverter): boolean;
begin
if (FAutoOpenLastProject<>AConverter.FAutoOpenLastProject)
or (ComparePoints(FWindowSize,AConverter.FWindowSize)<>0)
or (Fh2pasFilename<>AConverter.h2pasFilename)
or (not FProjectHistory.Equals(AConverter.FProjectHistory))
then
exit(false);
Result:=true;
end;
procedure TH2PasConverter.Load(Config: TConfigStorage);
begin
FAutoOpenLastProject:=Config.GetValue('AutoOpenLastProject/Value',true);
Fh2pasFilename:=Config.GetValue('h2pas/Filename','h2pas');
Config.GetValue('WindowSize/',FWindowSize,Point(0,0));
Config.GetValue('ProjectHistory/',FProjectHistory);
// Note: project is saved in its own file
end;
procedure TH2PasConverter.Save(Config: TConfigStorage);
begin
Config.SetDeleteValue('AutoOpenLastProject/Value',FAutoOpenLastProject,true);
Config.SetDeleteValue('h2pas/Filename',Fh2pasFilename,'h2pas');
Config.SetDeleteValue('WindowSize/',FWindowSize,Point(0,0));
Config.SetValue('ProjectHistory/',FProjectHistory);
end;
procedure TH2PasConverter.LoadFromFile(const AFilename: string);
var
Config: TXMLConfigStorage;
begin
Config:=TXMLConfigStorage.Create(AFilename,true);
try
Load(Config);
finally
Config.Free;
end;
end;
procedure TH2PasConverter.SaveToFile(const AFilename: string);
var
Config: TXMLConfigStorage;
begin
Config:=TXMLConfigStorage.Create(AFilename,false);
try
Save(Config);
Config.WriteToDisk;
finally
Config.Free;
end;
end;
procedure TH2PasConverter.LoadProject(const Filename: string);
begin
DebugLn(['TH2PasConverter.LoadProject ',Filename]);
if FProject=nil then
FProject:=TH2PasProject.Create;
FProject.Filename:=Filename;
FProject.LoadFromFile(Filename);
CurrentProjectFilename:=Filename;
end;
procedure TH2PasConverter.SaveProject(const Filename: string);
begin
DebugLn(['TH2PasConverter.SaveProject ',Filename]);
FProject.Filename:=Filename;
FProject.SaveToFile(Filename);
CurrentProjectFilename:=Filename;
end;
end.

View File

@ -1,43 +1,49 @@
object H2PasDialog: TH2PasDialog
Caption = 'H2PasDialog'
ClientHeight = 534
ClientHeight = 501
ClientWidth = 785
KeyPreview = True
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnDestroy = FormDestroy
OnKeyDown = FormKeyDown
PixelsPerInch = 112
HorzScrollBar.Page = 784
VertScrollBar.Page = 533
VertScrollBar.Page = 500
Left = 326
Height = 534
Height = 501
Top = 178
Width = 785
object MainPageControl: TPageControl
ActivePage = FilesTabSheet
Align = alClient
TabIndex = 0
ActivePage = h2pasOptionsTabSheet
Align = alTop
Anchors = [akTop, akLeft, akRight, akBottom]
TabIndex = 1
TabOrder = 0
Height = 534
AnchorSideBottom.Control = OpenSettingsButton
Height = 465
Width = 785
object FilesTabSheet: TTabSheet
Caption = 'FilesTabSheet'
ClientHeight = 504
ClientHeight = 435
ClientWidth = 781
Left = 2
Height = 504
Height = 435
Top = 28
Width = 781
object CHeaderFilesCheckListBox: TCheckListBox
Align = alLeft
OnItemClick = CHeaderFilesCheckListBoxItemClick
TabOrder = 0
TopIndex = -1
Height = 504
Height = 435
Width = 255
end
object AddCHeaderFilesButton: TButton
BorderSpacing.Left = 6
BorderSpacing.InnerBorder = 4
Caption = 'AddCHeaderFilesButton'
OnClick = AddCHeaderFilesButtonClick
TabOrder = 1
AnchorSideLeft.Control = CHeaderFilesSplitter1
AnchorSideLeft.Side = asrBottom
@ -50,6 +56,7 @@ object H2PasDialog: TH2PasDialog
BorderSpacing.Left = 6
BorderSpacing.InnerBorder = 4
Caption = 'DeleteCHeaderFilesButton'
OnClick = DeleteCHeaderFilesButtonClick
TabOrder = 2
AnchorSideLeft.Control = CHeaderFilesSplitter1
AnchorSideLeft.Side = asrBottom
@ -62,6 +69,7 @@ object H2PasDialog: TH2PasDialog
BorderSpacing.Left = 6
BorderSpacing.InnerBorder = 4
Caption = 'SelectAllCHeaderFilesButton'
OnClick = SelectAllCHeaderFilesButtonClick
TabOrder = 3
AnchorSideLeft.Control = CHeaderFilesSplitter1
AnchorSideLeft.Side = asrBottom
@ -74,6 +82,7 @@ object H2PasDialog: TH2PasDialog
BorderSpacing.Left = 6
BorderSpacing.InnerBorder = 4
Caption = 'UnselectAllCHeaderFilesButton'
OnClick = UnselectAllCHeaderFilesButtonClick
TabOrder = 4
AnchorSideLeft.Control = CHeaderFilesSplitter1
AnchorSideLeft.Side = asrBottom
@ -83,13 +92,353 @@ object H2PasDialog: TH2PasDialog
Width = 185
end
object CHeaderFilesSplitter1: TSplitter
Height = 504
Height = 435
Width = 5
Cursor = crHSplit
Left = 255
Height = 504
Height = 435
Width = 5
end
end
object h2pasOptionsTabSheet: TTabSheet
Caption = 'h2pasOptionsTabSheet'
ClientHeight = 435
ClientWidth = 781
Left = 2
Height = 435
Top = 28
Width = 781
object LibNameLabel: TLabel
BorderSpacing.Top = 10
Caption = 'LibNameLabel'
Color = clNone
ParentColor = False
AnchorSideTop.Control = LibnameEdit
AnchorSideTop.Side = asrCenter
Left = 6
Height = 13
Top = 116
Width = 81
end
object OutputExtLabel: TLabel
Caption = 'OutputExtLabel'
Color = clNone
ParentColor = False
AnchorSideTop.Control = OutputExtEdit
AnchorSideTop.Side = asrCenter
Left = 6
Height = 13
Top = 301
Width = 86
end
object OutputDirLabel: TLabel
Caption = 'OutputDirLabel'
Color = clNone
ParentColor = False
AnchorSideTop.Control = OutputDirEdit
AnchorSideTop.Side = asrCenter
Left = 6
Height = 13
Top = 330
Width = 85
end
object UseExternalCheckBox: TCheckBox
Caption = 'UseExternalCheckBox'
OnChange = UseExternalCheckBoxChange
TabOrder = 0
Left = 6
Height = 20
Top = 7
Width = 150
end
object UseExternalLibnameCheckBox: TCheckBox
BorderSpacing.Top = 6
Caption = 'UseExternalLibnameCheckBox'
OnChange = UseExternalLibnameCheckBoxChange
TabOrder = 1
AnchorSideTop.Control = UseExternalCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 20
Top = 33
Width = 197
end
object ConstantsInsteadOfEnumsCheckBox: TCheckBox
BorderSpacing.Top = 6
Caption = 'ConstantsInsteadOfEnumsCheckBox'
OnChange = ConstantsInsteadOfEnumsCheckBoxChange
TabOrder = 2
AnchorSideTop.Control = UseExternalLibnameCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 20
Top = 59
Width = 229
end
object IncludeFileCheckBox: TCheckBox
BorderSpacing.Top = 6
Caption = 'IncludeFileCheckBox'
OnChange = IncludeFileCheckBoxChange
TabOrder = 3
AnchorSideTop.Control = ConstantsInsteadOfEnumsCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 20
Top = 85
Width = 146
end
object LibnameEdit: TEdit
BorderSpacing.Left = 6
BorderSpacing.Top = 6
OnEditingDone = LibnameEditEditingDone
TabOrder = 4
Text = 'LibnameEdit'
AnchorSideLeft.Control = LibNameLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = IncludeFileCheckBox
AnchorSideTop.Side = asrBottom
Left = 93
Height = 23
Top = 111
Width = 113
end
object PforPointersCheckBox: TCheckBox
BorderSpacing.Top = 6
Caption = 'PforPointersCheckBox'
OnChange = PforPointersCheckBoxChange
TabOrder = 5
AnchorSideTop.Control = LibnameEdit
AnchorSideTop.Side = asrBottom
Left = 6
Height = 20
Top = 140
Width = 151
end
object StripCommentsCheckBox: TCheckBox
BorderSpacing.Top = 6
Caption = 'StripCommentsCheckBox'
OnChange = StripCommentsCheckBoxChange
TabOrder = 6
AnchorSideTop.Control = PforPointersCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 20
Top = 166
Width = 166
end
object TforTypedefsCheckBox: TCheckBox
BorderSpacing.Top = 6
Caption = 'TforTypedefsCheckBox'
OnChange = TforTypedefsCheckBoxChange
TabOrder = 7
AnchorSideTop.Control = StripCommentsCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 20
Top = 192
Width = 156
end
object VarParamsCheckBox: TCheckBox
BorderSpacing.Top = 6
Caption = 'VarParamsCheckBox'
OnChange = VarParamsCheckBoxChange
TabOrder = 8
AnchorSideTop.Control = TforTypedefsCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 20
Top = 218
Width = 145
end
object Win32HeaderCheckBox: TCheckBox
BorderSpacing.Top = 6
Caption = 'Win32HeaderCheckBox'
OnChange = Win32HeaderCheckBoxChange
TabOrder = 9
AnchorSideTop.Control = VarParamsCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 20
Top = 244
Width = 160
end
object PalmOSSYSTrapCheckBox: TCheckBox
BorderSpacing.Top = 6
Caption = 'PalmOSSYSTrapCheckBox'
OnChange = PalmOSSYSTrapCheckBoxChange
TabOrder = 10
AnchorSideTop.Control = Win32HeaderCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 20
Top = 270
Width = 179
end
object OutputExtEdit: TEdit
BorderSpacing.Left = 6
BorderSpacing.Top = 6
OnEditingDone = OutputExtEditEditingDone
TabOrder = 11
Text = 'OutputExtEdit'
AnchorSideLeft.Control = OutputExtLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = PalmOSSYSTrapCheckBox
AnchorSideTop.Side = asrBottom
Left = 98
Height = 23
Top = 296
Width = 80
end
object OutputDirEdit: TEdit
BorderSpacing.Left = 6
BorderSpacing.Top = 6
OnEditingDone = OutputDirEditEditingDone
TabOrder = 12
Text = 'OutputDirEdit'
AnchorSideLeft.Control = OutputDirLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = OutputExtEdit
AnchorSideTop.Side = asrBottom
Left = 97
Height = 23
Top = 325
Width = 397
end
object OutputDirBrowseButton: TButton
Anchors = [akTop, akLeft, akBottom]
BorderSpacing.InnerBorder = 4
Caption = '...'
OnClick = OutputDirBrowseButtonClick
TabOrder = 13
AnchorSideLeft.Control = OutputDirEdit
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = OutputDirEdit
AnchorSideBottom.Control = OutputDirEdit
AnchorSideBottom.Side = asrBottom
Left = 494
Height = 23
Top = 325
Width = 32
end
end
object SettingsTabSheet: TTabSheet
Caption = 'SettingsTabSheet'
ClientHeight = 435
ClientWidth = 781
Left = 2
Height = 435
Top = 28
Width = 781
object H2PasFilenameLabel: TLabel
Caption = 'H2PasFilenameLabel'
Color = clNone
ParentColor = False
AnchorSideTop.Control = H2PasFilenameEdit
AnchorSideTop.Side = asrCenter
Left = 6
Height = 13
Top = 9
Width = 120
end
object OpenLastProjectOnStartCheckBox: TCheckBox
Caption = 'OpenLastProjectOnStartCheckBox'
OnChange = OpenLastProjectOnStartCheckBoxChange
TabOrder = 0
Left = 6
Height = 20
Top = 42
Width = 219
end
object SaveSettingsAsButton: TButton
AutoSize = True
BorderSpacing.InnerBorder = 4
Caption = 'SaveSettingsAsButton'
OnClick = SaveSettingsAsButtonClick
TabOrder = 1
Left = 6
Height = 26
Top = 82
Width = 137
end
object H2PasFilenameEdit: TEdit
BorderSpacing.Left = 6
BorderSpacing.Top = 6
OnEditingDone = H2PasFilenameEditEditingDone
TabOrder = 2
Text = 'H2PasFilenameEdit'
AnchorSideLeft.Control = H2PasFilenameLabel
AnchorSideLeft.Side = asrBottom
Left = 132
Height = 23
Top = 4
Width = 352
end
object h2pasFilenameBrowseButton: TButton
Anchors = [akTop, akLeft, akBottom]
BorderSpacing.InnerBorder = 4
Caption = '...'
OnClick = h2pasFilenameBrowseButtonClick
TabOrder = 3
AnchorSideLeft.Control = H2PasFilenameEdit
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = H2PasFilenameEdit
AnchorSideBottom.Control = H2PasFilenameEdit
AnchorSideBottom.Side = asrBottom
Left = 484
Height = 23
Top = 4
Width = 35
end
end
end
object OpenSettingsButton: TButton
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Around = 5
BorderSpacing.InnerBorder = 4
Caption = 'OpenSettingsButton'
OnClick = OpenSettingsButtonClick
TabOrder = 1
AnchorSideLeft.Control = Owner
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 5
Height = 26
Top = 470
Width = 124
end
object SaveSettingsButton: TButton
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Around = 5
BorderSpacing.InnerBorder = 4
Caption = 'SaveSettingsButton'
OnClick = SaveSettingsButtonClick
TabOrder = 2
AnchorSideLeft.Control = OpenSettingsButton
AnchorSideLeft.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 134
Height = 26
Top = 470
Width = 122
end
object CloseButton: TButton
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Around = 5
BorderSpacing.InnerBorder = 4
Caption = 'CloseButton'
OnClick = CloseButtonClick
TabOrder = 3
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 699
Height = 26
Top = 470
Width = 81
end
end

View File

@ -2,33 +2,155 @@
LazarusResources.Add('TH2PasDialog','FORMDATA',[
'TPF0'#12'TH2PasDialog'#11'H2PasDialog'#7'Caption'#6#11'H2PasDialog'#12'Clien'
+'tHeight'#3#22#2#11'ClientWidth'#3#17#3#10'KeyPreview'#9#8'OnCreate'#7#10'Fo'
+'rmCreate'#9'OnKeyDown'#7#11'FormKeyDown'#13'PixelsPerInch'#2'p'#18'HorzScro'
+'llBar.Page'#3#16#3#18'VertScrollBar.Page'#3#21#2#4'Left'#3'F'#1#6'Height'#3
+#22#2#3'Top'#3#178#0#5'Width'#3#17#3#0#12'TPageControl'#15'MainPageControl'
+#10'ActivePage'#7#13'FilesTabSheet'#5'Align'#7#8'alClient'#8'TabIndex'#2#0#8
+'TabOrder'#2#0#6'Height'#3#22#2#5'Width'#3#17#3#0#9'TTabSheet'#13'FilesTabSh'
+'eet'#7'Caption'#6#13'FilesTabSheet'#12'ClientHeight'#3#248#1#11'ClientWidth'
+#3#13#3#4'Left'#2#2#6'Height'#3#248#1#3'Top'#2#28#5'Width'#3#13#3#0#13'TChec'
+'kListBox'#24'CHeaderFilesCheckListBox'#5'Align'#7#6'alLeft'#8'TabOrder'#2#0
+#8'TopIndex'#2#255#6'Height'#3#248#1#5'Width'#3#255#0#0#0#7'TButton'#21'AddC'
+'HeaderFilesButton'#18'BorderSpacing.Left'#2#6#25'BorderSpacing.InnerBorder'
+#2#4#7'Caption'#6#21'AddCHeaderFilesButton'#8'TabOrder'#2#1#22'AnchorSideLef'
+'t.Control'#7#21'CHeaderFilesSplitter1'#19'AnchorSideLeft.Side'#7#9'asrBotto'
+'m'#4'Left'#3#10#1#6'Height'#2#25#3'Top'#2#12#5'Width'#3#185#0#0#0#7'TButton'
+#24'DeleteCHeaderFilesButton'#18'BorderSpacing.Left'#2#6#25'BorderSpacing.In'
+'nerBorder'#2#4#7'Caption'#6#24'DeleteCHeaderFilesButton'#8'TabOrder'#2#2#22
+'AnchorSideLeft.Control'#7#21'CHeaderFilesSplitter1'#19'AnchorSideLeft.Side'
+#7#9'asrBottom'#4'Left'#3#10#1#6'Height'#2#25#3'Top'#2'3'#5'Width'#3#185#0#0
+#0#7'TButton'#27'SelectAllCHeaderFilesButton'#18'BorderSpacing.Left'#2#6#25
+'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#27'SelectAllCHeaderFilesButton'
+'tHeight'#3#245#1#11'ClientWidth'#3#17#3#10'KeyPreview'#9#12'OnCloseQuery'#7
+#14'FormCloseQuery'#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestr'
+'oy'#9'OnKeyDown'#7#11'FormKeyDown'#13'PixelsPerInch'#2'p'#18'HorzScrollBar.'
+'Page'#3#16#3#18'VertScrollBar.Page'#3#244#1#4'Left'#3'F'#1#6'Height'#3#245#1
+#3'Top'#3#178#0#5'Width'#3#17#3#0#12'TPageControl'#15'MainPageControl'#10'Ac'
+'tivePage'#7#20'h2pasOptionsTabSheet'#5'Align'#7#5'alTop'#7'Anchors'#11#5'ak'
+'Top'#6'akLeft'#7'akRight'#8'akBottom'#0#8'TabIndex'#2#1#8'TabOrder'#2#0#24
+'AnchorSideBottom.Control'#7#18'OpenSettingsButton'#6'Height'#3#209#1#5'Widt'
+'h'#3#17#3#0#9'TTabSheet'#13'FilesTabSheet'#7'Caption'#6#13'FilesTabSheet'#12
+'ClientHeight'#3#179#1#11'ClientWidth'#3#13#3#4'Left'#2#2#6'Height'#3#179#1#3
+'Top'#2#28#5'Width'#3#13#3#0#13'TCheckListBox'#24'CHeaderFilesCheckListBox'#5
+'Align'#7#6'alLeft'#11'OnItemClick'#7'!CHeaderFilesCheckListBoxItemClick'#8
+'TabOrder'#2#0#8'TopIndex'#2#255#6'Height'#3#179#1#5'Width'#3#255#0#0#0#7'TB'
+'utton'#21'AddCHeaderFilesButton'#18'BorderSpacing.Left'#2#6#25'BorderSpacin'
+'g.InnerBorder'#2#4#7'Caption'#6#21'AddCHeaderFilesButton'#7'OnClick'#7#26'A'
+'ddCHeaderFilesButtonClick'#8'TabOrder'#2#1#22'AnchorSideLeft.Control'#7#21
+'CHeaderFilesSplitter1'#19'AnchorSideLeft.Side'#7#9'asrBottom'#4'Left'#3#10#1
+#6'Height'#2#25#3'Top'#2#12#5'Width'#3#185#0#0#0#7'TButton'#24'DeleteCHeader'
+'FilesButton'#18'BorderSpacing.Left'#2#6#25'BorderSpacing.InnerBorder'#2#4#7
+'Caption'#6#24'DeleteCHeaderFilesButton'#7'OnClick'#7#29'DeleteCHeaderFilesB'
+'uttonClick'#8'TabOrder'#2#2#22'AnchorSideLeft.Control'#7#21'CHeaderFilesSpl'
+'itter1'#19'AnchorSideLeft.Side'#7#9'asrBottom'#4'Left'#3#10#1#6'Height'#2#25
+#3'Top'#2'3'#5'Width'#3#185#0#0#0#7'TButton'#27'SelectAllCHeaderFilesButton'
+#18'BorderSpacing.Left'#2#6#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#27
+'SelectAllCHeaderFilesButton'#7'OnClick'#7' SelectAllCHeaderFilesButtonClick'
+#8'TabOrder'#2#3#22'AnchorSideLeft.Control'#7#21'CHeaderFilesSplitter1'#19'A'
+'nchorSideLeft.Side'#7#9'asrBottom'#4'Left'#3#10#1#6'Height'#2#25#3'Top'#2'a'
+#5'Width'#3#185#0#0#0#7'TButton'#29'UnselectAllCHeaderFilesButton'#18'Border'
+'Spacing.Left'#2#6#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#29'Unselec'
+'tAllCHeaderFilesButton'#8'TabOrder'#2#4#22'AnchorSideLeft.Control'#7#21'CHe'
+'aderFilesSplitter1'#19'AnchorSideLeft.Side'#7#9'asrBottom'#4'Left'#3#10#1#6
+'Height'#2#25#3'Top'#3#137#0#5'Width'#3#185#0#0#0#9'TSplitter'#21'CHeaderFil'
+'esSplitter1'#6'Height'#3#248#1#5'Width'#2#5#6'Cursor'#7#8'crHSplit'#4'Left'
+#3#255#0#6'Height'#3#248#1#5'Width'#2#5#0#0#0#0#0
+'tAllCHeaderFilesButton'#7'OnClick'#7'"UnselectAllCHeaderFilesButtonClick'#8
+'TabOrder'#2#4#22'AnchorSideLeft.Control'#7#21'CHeaderFilesSplitter1'#19'Anc'
+'horSideLeft.Side'#7#9'asrBottom'#4'Left'#3#10#1#6'Height'#2#25#3'Top'#3#137
+#0#5'Width'#3#185#0#0#0#9'TSplitter'#21'CHeaderFilesSplitter1'#6'Height'#3
+#179#1#5'Width'#2#5#6'Cursor'#7#8'crHSplit'#4'Left'#3#255#0#6'Height'#3#179#1
+#5'Width'#2#5#0#0#0#9'TTabSheet'#20'h2pasOptionsTabSheet'#7'Caption'#6#20'h2'
+'pasOptionsTabSheet'#12'ClientHeight'#3#179#1#11'ClientWidth'#3#13#3#4'Left'
+#2#2#6'Height'#3#179#1#3'Top'#2#28#5'Width'#3#13#3#0#6'TLabel'#12'LibNameLab'
+'el'#17'BorderSpacing.Top'#2#10#7'Caption'#6#12'LibNameLabel'#5'Color'#7#6'c'
+'lNone'#11'ParentColor'#8#21'AnchorSideTop.Control'#7#11'LibnameEdit'#18'Anc'
+'horSideTop.Side'#7#9'asrCenter'#4'Left'#2#6#6'Height'#2#13#3'Top'#2't'#5'Wi'
+'dth'#2'Q'#0#0#6'TLabel'#14'OutputExtLabel'#7'Caption'#6#14'OutputExtLabel'#5
+'Color'#7#6'clNone'#11'ParentColor'#8#21'AnchorSideTop.Control'#7#13'OutputE'
+'xtEdit'#18'AnchorSideTop.Side'#7#9'asrCenter'#4'Left'#2#6#6'Height'#2#13#3
+'Top'#3'-'#1#5'Width'#2'V'#0#0#6'TLabel'#14'OutputDirLabel'#7'Caption'#6#14
+'OutputDirLabel'#5'Color'#7#6'clNone'#11'ParentColor'#8#21'AnchorSideTop.Con'
+'trol'#7#13'OutputDirEdit'#18'AnchorSideTop.Side'#7#9'asrCenter'#4'Left'#2#6
+#6'Height'#2#13#3'Top'#3'J'#1#5'Width'#2'U'#0#0#9'TCheckBox'#19'UseExternalC'
+'heckBox'#7'Caption'#6#19'UseExternalCheckBox'#8'OnChange'#7#25'UseExternalC'
+'heckBoxChange'#8'TabOrder'#2#0#4'Left'#2#6#6'Height'#2#20#3'Top'#2#7#5'Widt'
+'h'#3#150#0#0#0#9'TCheckBox'#26'UseExternalLibnameCheckBox'#17'BorderSpacing'
+'.Top'#2#6#7'Caption'#6#26'UseExternalLibnameCheckBox'#8'OnChange'#7' UseExt'
+'ernalLibnameCheckBoxChange'#8'TabOrder'#2#1#21'AnchorSideTop.Control'#7#19
+'UseExternalCheckBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2#6#6'He'
+'ight'#2#20#3'Top'#2'!'#5'Width'#3#197#0#0#0#9'TCheckBox'#31'ConstantsInstea'
+'dOfEnumsCheckBox'#17'BorderSpacing.Top'#2#6#7'Caption'#6#31'ConstantsInstea'
+'dOfEnumsCheckBox'#8'OnChange'#7'%ConstantsInsteadOfEnumsCheckBoxChange'#8'T'
+'abOrder'#2#2#21'AnchorSideTop.Control'#7#26'UseExternalLibnameCheckBox'#18
+'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2#20#3'Top'#2';'#5
+'Width'#3#229#0#0#0#9'TCheckBox'#19'IncludeFileCheckBox'#17'BorderSpacing.To'
+'p'#2#6#7'Caption'#6#19'IncludeFileCheckBox'#8'OnChange'#7#25'IncludeFileChe'
+'ckBoxChange'#8'TabOrder'#2#3#21'AnchorSideTop.Control'#7#31'ConstantsInstea'
+'dOfEnumsCheckBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2#6#6'Heigh'
+'t'#2#20#3'Top'#2'U'#5'Width'#3#146#0#0#0#5'TEdit'#11'LibnameEdit'#18'Border'
,'Spacing.Left'#2#6#17'BorderSpacing.Top'#2#6#13'OnEditingDone'#7#22'LibnameE'
+'ditEditingDone'#8'TabOrder'#2#4#4'Text'#6#11'LibnameEdit'#22'AnchorSideLeft'
+'.Control'#7#12'LibNameLabel'#19'AnchorSideLeft.Side'#7#9'asrBottom'#21'Anch'
+'orSideTop.Control'#7#19'IncludeFileCheckBox'#18'AnchorSideTop.Side'#7#9'asr'
+'Bottom'#4'Left'#2']'#6'Height'#2#23#3'Top'#2'o'#5'Width'#2'q'#0#0#9'TCheckB'
+'ox'#20'PforPointersCheckBox'#17'BorderSpacing.Top'#2#6#7'Caption'#6#20'Pfor'
+'PointersCheckBox'#8'OnChange'#7#26'PforPointersCheckBoxChange'#8'TabOrder'#2
+#5#21'AnchorSideTop.Control'#7#11'LibnameEdit'#18'AnchorSideTop.Side'#7#9'as'
+'rBottom'#4'Left'#2#6#6'Height'#2#20#3'Top'#3#140#0#5'Width'#3#151#0#0#0#9'T'
+'CheckBox'#21'StripCommentsCheckBox'#17'BorderSpacing.Top'#2#6#7'Caption'#6
+#21'StripCommentsCheckBox'#8'OnChange'#7#27'StripCommentsCheckBoxChange'#8'T'
+'abOrder'#2#6#21'AnchorSideTop.Control'#7#20'PforPointersCheckBox'#18'Anchor'
+'SideTop.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2#20#3'Top'#3#166#0#5'Wi'
+'dth'#3#166#0#0#0#9'TCheckBox'#20'TforTypedefsCheckBox'#17'BorderSpacing.Top'
+#2#6#7'Caption'#6#20'TforTypedefsCheckBox'#8'OnChange'#7#26'TforTypedefsChec'
+'kBoxChange'#8'TabOrder'#2#7#21'AnchorSideTop.Control'#7#21'StripCommentsChe'
+'ckBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2#20#3'T'
+'op'#3#192#0#5'Width'#3#156#0#0#0#9'TCheckBox'#17'VarParamsCheckBox'#17'Bord'
+'erSpacing.Top'#2#6#7'Caption'#6#17'VarParamsCheckBox'#8'OnChange'#7#23'VarP'
+'aramsCheckBoxChange'#8'TabOrder'#2#8#21'AnchorSideTop.Control'#7#20'TforTyp'
+'edefsCheckBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2
+#20#3'Top'#3#218#0#5'Width'#3#145#0#0#0#9'TCheckBox'#19'Win32HeaderCheckBox'
+#17'BorderSpacing.Top'#2#6#7'Caption'#6#19'Win32HeaderCheckBox'#8'OnChange'#7
+#25'Win32HeaderCheckBoxChange'#8'TabOrder'#2#9#21'AnchorSideTop.Control'#7#17
+'VarParamsCheckBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2#6#6'Heig'
+'ht'#2#20#3'Top'#3#244#0#5'Width'#3#160#0#0#0#9'TCheckBox'#21'PalmOSSYSTrapC'
+'heckBox'#17'BorderSpacing.Top'#2#6#7'Caption'#6#21'PalmOSSYSTrapCheckBox'#8
+'OnChange'#7#27'PalmOSSYSTrapCheckBoxChange'#8'TabOrder'#2#10#21'AnchorSideT'
+'op.Control'#7#19'Win32HeaderCheckBox'#18'AnchorSideTop.Side'#7#9'asrBottom'
+#4'Left'#2#6#6'Height'#2#20#3'Top'#3#14#1#5'Width'#3#179#0#0#0#5'TEdit'#13'O'
+'utputExtEdit'#18'BorderSpacing.Left'#2#6#17'BorderSpacing.Top'#2#6#13'OnEdi'
+'tingDone'#7#24'OutputExtEditEditingDone'#8'TabOrder'#2#11#4'Text'#6#13'Outp'
+'utExtEdit'#22'AnchorSideLeft.Control'#7#14'OutputExtLabel'#19'AnchorSideLef'
+'t.Side'#7#9'asrBottom'#21'AnchorSideTop.Control'#7#21'PalmOSSYSTrapCheckBox'
+#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2'b'#6'Height'#2#23#3'Top'#3
+'('#1#5'Width'#2'P'#0#0#5'TEdit'#13'OutputDirEdit'#18'BorderSpacing.Left'#2#6
+#17'BorderSpacing.Top'#2#6#13'OnEditingDone'#7#24'OutputDirEditEditingDone'#8
+'TabOrder'#2#12#4'Text'#6#13'OutputDirEdit'#22'AnchorSideLeft.Control'#7#14
+'OutputDirLabel'#19'AnchorSideLeft.Side'#7#9'asrBottom'#21'AnchorSideTop.Con'
+'trol'#7#13'OutputExtEdit'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2'a'
+#6'Height'#2#23#3'Top'#3'E'#1#5'Width'#3#141#1#0#0#7'TButton'#21'OutputDirBr'
+'owseButton'#7'Anchors'#11#5'akTop'#6'akLeft'#8'akBottom'#0#25'BorderSpacing'
+'.InnerBorder'#2#4#7'Caption'#6#3'...'#7'OnClick'#7#26'OutputDirBrowseButton'
+'Click'#8'TabOrder'#2#13#22'AnchorSideLeft.Control'#7#13'OutputDirEdit'#19'A'
+'nchorSideLeft.Side'#7#9'asrBottom'#21'AnchorSideTop.Control'#7#13'OutputDir'
+'Edit'#24'AnchorSideBottom.Control'#7#13'OutputDirEdit'#21'AnchorSideBottom.'
+'Side'#7#9'asrBottom'#4'Left'#3#238#1#6'Height'#2#23#3'Top'#3'E'#1#5'Width'#2
+' '#0#0#0#9'TTabSheet'#16'SettingsTabSheet'#7'Caption'#6#16'SettingsTabSheet'
+#12'ClientHeight'#3#179#1#11'ClientWidth'#3#13#3#4'Left'#2#2#6'Height'#3#179
+#1#3'Top'#2#28#5'Width'#3#13#3#0#6'TLabel'#18'H2PasFilenameLabel'#7'Caption'
+#6#18'H2PasFilenameLabel'#5'Color'#7#6'clNone'#11'ParentColor'#8#21'AnchorSi'
+'deTop.Control'#7#17'H2PasFilenameEdit'#18'AnchorSideTop.Side'#7#9'asrCenter'
+#4'Left'#2#6#6'Height'#2#13#3'Top'#2#9#5'Width'#2'x'#0#0#9'TCheckBox'#30'Ope'
+'nLastProjectOnStartCheckBox'#7'Caption'#6#30'OpenLastProjectOnStartCheckBox'
+#8'OnChange'#7'$OpenLastProjectOnStartCheckBoxChange'#8'TabOrder'#2#0#4'Left'
+#2#6#6'Height'#2#20#3'Top'#2'*'#5'Width'#3#219#0#0#0#7'TButton'#20'SaveSetti'
+'ngsAsButton'#8'AutoSize'#9#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#20
+'SaveSettingsAsButton'#7'OnClick'#7#25'SaveSettingsAsButtonClick'#8'TabOrder'
+#2#1#4'Left'#2#6#6'Height'#2#26#3'Top'#2'R'#5'Width'#3#137#0#0#0#5'TEdit'#17
+'H2PasFilenameEdit'#18'BorderSpacing.Left'#2#6#17'BorderSpacing.Top'#2#6#13
+'OnEditingDone'#7#28'H2PasFilenameEditEditingDone'#8'TabOrder'#2#2#4'Text'#6
+#17'H2PasFilenameEdit'#22'AnchorSideLeft.Control'#7#18'H2PasFilenameLabel'#19
+'AnchorSideLeft.Side'#7#9'asrBottom'#4'Left'#3#132#0#6'Height'#2#23#3'Top'#2
+#4#5'Width'#3'`'#1#0#0#7'TButton'#25'h2pasFilenameBrowseButton'#7'Anchors'#11
,#5'akTop'#6'akLeft'#8'akBottom'#0#25'BorderSpacing.InnerBorder'#2#4#7'Captio'
+'n'#6#3'...'#7'OnClick'#7#30'h2pasFilenameBrowseButtonClick'#8'TabOrder'#2#3
+#22'AnchorSideLeft.Control'#7#17'H2PasFilenameEdit'#19'AnchorSideLeft.Side'#7
+#9'asrBottom'#21'AnchorSideTop.Control'#7#17'H2PasFilenameEdit'#24'AnchorSid'
+'eBottom.Control'#7#17'H2PasFilenameEdit'#21'AnchorSideBottom.Side'#7#9'asrB'
+'ottom'#4'Left'#3#228#1#6'Height'#2#23#3'Top'#2#4#5'Width'#2'#'#0#0#0#0#7'TB'
+'utton'#18'OpenSettingsButton'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#8'AutoS'
+'ize'#9#20'BorderSpacing.Around'#2#5#25'BorderSpacing.InnerBorder'#2#4#7'Cap'
+'tion'#6#18'OpenSettingsButton'#7'OnClick'#7#23'OpenSettingsButtonClick'#8'T'
+'abOrder'#2#1#22'AnchorSideLeft.Control'#7#5'Owner'#24'AnchorSideBottom.Cont'
+'rol'#7#5'Owner'#21'AnchorSideBottom.Side'#7#9'asrBottom'#4'Left'#2#5#6'Heig'
+'ht'#2#26#3'Top'#3#214#1#5'Width'#2'|'#0#0#7'TButton'#18'SaveSettingsButton'
+#7'Anchors'#11#6'akLeft'#8'akBottom'#0#8'AutoSize'#9#20'BorderSpacing.Around'
+#2#5#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#18'SaveSettingsButton'#7
+'OnClick'#7#23'SaveSettingsButtonClick'#8'TabOrder'#2#2#22'AnchorSideLeft.Co'
+'ntrol'#7#18'OpenSettingsButton'#19'AnchorSideLeft.Side'#7#9'asrBottom'#24'A'
+'nchorSideBottom.Control'#7#5'Owner'#21'AnchorSideBottom.Side'#7#9'asrBottom'
+#4'Left'#3#134#0#6'Height'#2#26#3'Top'#3#214#1#5'Width'#2'z'#0#0#7'TButton'
+#11'CloseButton'#7'Anchors'#11#7'akRight'#8'akBottom'#0#8'AutoSize'#9#20'Bor'
+'derSpacing.Around'#2#5#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#11'Cl'
+'oseButton'#7'OnClick'#7#16'CloseButtonClick'#8'TabOrder'#2#3#23'AnchorSideR'
+'ight.Control'#7#5'Owner'#20'AnchorSideRight.Side'#7#9'asrBottom'#24'AnchorS'
+'ideBottom.Control'#7#5'Owner'#21'AnchorSideBottom.Side'#7#9'asrBottom'#4'Le'
+'ft'#3#187#2#6'Height'#2#26#3'Top'#3#214#1#5'Width'#2'Q'#0#0#0
]);

View File

@ -23,28 +23,110 @@ interface
uses
Classes, SysUtils, LCLProc, LCLType, LResources, Forms, Controls, Graphics,
Dialogs, ComCtrls, Buttons, H2PasStrConsts,
TextTools, MenuIntf, IDECommands, StdCtrls, ExtCtrls, CheckLst, SynEdit;
Dialogs, ComCtrls, Buttons, StdCtrls, ExtCtrls, CheckLst, SynEdit,
LazConfigStorage, FileUtil,
MenuIntf, IDECommands, BaseIDEIntf, LazIDEIntf,
H2PasStrConsts, H2PasConvert;
type
{ TH2PasDialog }
TH2PasDialog = class(TForm)
AddCHeaderFilesButton: TButton;
h2pasFilenameBrowseButton: TButton;
H2PasFilenameEdit: TEdit;
H2PasFilenameLabel: TLabel;
OutputDirBrowseButton: TButton;
MainPageControl: TPageControl;
// c header files
FilesTabSheet: TTabSheet;
CHeaderFilesSplitter1: TSplitter;
AddCHeaderFilesButton: TButton;
UnselectAllCHeaderFilesButton: TButton;
SelectAllCHeaderFilesButton: TButton;
DeleteCHeaderFilesButton: TButton;
CHeaderFilesCheckListBox: TCheckListBox;
MainPageControl: TPageControl;
FilesTabSheet: TTabSheet;
// h2pas
h2pasOptionsTabSheet: TTabSheet;
ConstantsInsteadOfEnumsCheckBox: TCheckBox;
IncludeFileCheckBox: TCheckBox;
LibnameEdit: TEdit;
LibNameLabel: TLabel;
OutputExtEdit: TEdit;
OutputExtLabel: TLabel;
PalmOSSYSTrapCheckBox: TCheckBox;
PforPointersCheckBox: TCheckBox;
StripCommentsCheckBox: TCheckBox;
TforTypedefsCheckBox: TCheckBox;
UseExternalCheckBox: TCheckBox;
UseExternalLibnameCheckBox: TCheckBox;
VarParamsCheckBox: TCheckBox;
Win32HeaderCheckBox: TCheckBox;
OutputDirEdit: TEdit;
OutputDirLabel: TLabel;
// settings
SettingsTabSheet: TTabSheet;
SaveSettingsAsButton: TButton;
OpenLastProjectOnStartCheckBox: TCheckBox;
// buttons at bottom
OpenSettingsButton: TButton;
SaveSettingsButton: TButton;
CloseButton: TButton;
procedure AddCHeaderFilesButtonClick(Sender: TObject);
procedure CHeaderFilesCheckListBoxItemClick(Sender: TObject; Index: LongInt
);
procedure CloseButtonClick(Sender: TObject);
procedure ConstantsInsteadOfEnumsCheckBoxChange(Sender: TObject);
procedure DeleteCHeaderFilesButtonClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure H2PasFilenameEditEditingDone(Sender: TObject);
procedure IncludeFileCheckBoxChange(Sender: TObject);
procedure LibnameEditEditingDone(Sender: TObject);
procedure OpenLastProjectOnStartCheckBoxChange(Sender: TObject);
procedure OpenSettingsButtonClick(Sender: TObject);
procedure OutputDirBrowseButtonClick(Sender: TObject);
procedure OutputDirEditEditingDone(Sender: TObject);
procedure OutputExtEditEditingDone(Sender: TObject);
procedure PalmOSSYSTrapCheckBoxChange(Sender: TObject);
procedure PforPointersCheckBoxChange(Sender: TObject);
procedure SaveSettingsAsButtonClick(Sender: TObject);
procedure SaveSettingsButtonClick(Sender: TObject);
procedure SelectAllCHeaderFilesButtonClick(Sender: TObject);
procedure StripCommentsCheckBoxChange(Sender: TObject);
procedure TforTypedefsCheckBoxChange(Sender: TObject);
procedure UnselectAllCHeaderFilesButtonClick(Sender: TObject);
procedure UseExternalCheckBoxChange(Sender: TObject);
procedure UseExternalLibnameCheckBoxChange(Sender: TObject);
procedure VarParamsCheckBoxChange(Sender: TObject);
procedure Win32HeaderCheckBoxChange(Sender: TObject);
procedure h2pasFilenameBrowseButtonClick(Sender: TObject);
private
{ private declarations }
FConverter: TH2PasConverter;
function GetProject: TH2PasProject;
procedure UpdateCaption;
procedure UpdateFilesPage;
procedure UpdateH2PasPage;
procedure UpdateSettingsPage;
function ShowSelectDirDialog(const Title: string;
var ADirectory: string): boolean;
function ShowOpenFileDialog(const Title: string;
var AFilename: string): boolean;
public
{ public declarations }
function SaveSettings: TModalResult;
function SaveGlobalSettings: TModalResult;
function LoadGlobalSettings: TModalResult;
function SaveProject(const Filename: string; Flags: TSaveFlags): TModalResult;
function OpenProject(const Filename: string; Flags: TOpenFlags): TModalResult;
property Converter: TH2PasConverter read FConverter;
property Project: TH2PasProject read GetProject;
end;
var
@ -52,7 +134,8 @@ var
CmdH2PasTool: TIDECommand = nil;
procedure ExecuteH2PasTool(Sender: TObject);
procedure Register;
implementation
@ -88,12 +171,574 @@ procedure TH2PasDialog.FormCreate(Sender: TObject);
begin
Caption:=h2pCHeaderFileConverter;
FilesTabSheet.Caption:='C header files';
AddCHeaderFilesButton.Caption:='Add .h files ...';
DeleteCHeaderFilesButton.Caption:='Delete selected .h files';
SelectAllCHeaderFilesButton.Caption:='Enable all .h files';
UnselectAllCHeaderFilesButton.Caption:='Disable all .h files';
h2pasOptionsTabSheet.Caption:='h2pas';
ConstantsInsteadOfEnumsCheckBox.Caption:='-e Emit a series of constants instead of an enumeration type for the C enum construct';
IncludeFileCheckBox.Caption:='-i Create an include file instead of a unit';
LibNameLabel.Caption:='-l Library name';
OutputExtLabel.Caption:='Output extension of new file';
PalmOSSYSTrapCheckBox.Caption:='-x Handle SYS_TRAP of the PalmOS header files';
PforPointersCheckBox.Caption:='-p Use the letter P in front of pointer type parameters instead of "^"';
StripCommentsCheckBox.Caption:='-s Strip comments';
TforTypedefsCheckBox.Caption:='-t Prepend typedef type names with the letter T';
UseExternalCheckBox.Caption:='-d Use external; for all procedures';
UseExternalLibnameCheckBox.Caption:='-D Use external libname name "func_name" for function and procedure';
VarParamsCheckBox.Caption:='-v Replace pointer parameters by call by reference parameters';
Win32HeaderCheckBox.Caption:='-w Handle special win32 macros';
OutputDirLabel.Caption:='Output directory';
SettingsTabSheet.Caption:='Settings';
H2PasFilenameLabel.Caption:='h2pas program path';
OpenLastProjectOnStartCheckBox.Caption:='Open last settings on start';
SaveSettingsAsButton.Caption:='Save settings as ...';
OpenSettingsButton.Caption:='&Open Settings';
SaveSettingsButton.Caption:='&Save Settings';
CloseButton.Caption:='&Close';
// create converter
FConverter:=TH2PasConverter.Create;
LoadGlobalSettings;
// create project
if Converter.AutoOpenLastProject
and FileExists(Converter.CurrentProjectFilename) then
OpenProject(Converter.CurrentProjectFilename,[]);
if Project=nil then begin
Converter.Project:=TH2PasProject.Create;
UpdateH2PasPage;
end;
UpdateCaption;
end;
procedure TH2PasDialog.FormCloseQuery(Sender: TObject; var CanClose: boolean);
var
DlgResult: TModalResult;
begin
//DebugLn(['TH2PasDialog.FormCloseQuery Converter.Modified=',Converter.Modified,' Project.Modified=',Project.Modified]);
if Converter.Modified
or ((Project<>nil) and (Project.Modified)) then begin
DlgResult:=QuestionDlg('Save changes?',
'Save settings?',mtConfirmation,
[mrYes,'Save and exit',mrNo,'Discard changes and exit',
mrCancel,'Do not exit'],0);
case DlgResult of
mrYes: CanClose:=SaveSettings=mrOk;
mrNo: ;
else CanClose:=false;
end;
end;
end;
procedure TH2PasDialog.CloseButtonClick(Sender: TObject);
begin
Close;
end;
procedure TH2PasDialog.ConstantsInsteadOfEnumsCheckBoxChange(Sender: TObject);
begin
Project.ConstantsInsteadOfEnums:=ConstantsInsteadOfEnumsCheckBox.Checked;
end;
procedure TH2PasDialog.DeleteCHeaderFilesButtonClick(Sender: TObject);
var
DeleteFiles: TStringList;
Target: TStrings;
i: Integer;
begin
DeleteFiles:=TStringList.Create;
Target:=CHeaderFilesCheckListBox.Items;
for i:=0 to Target.Count-1 do begin
if CHeaderFilesCheckListBox.Selected[i] then
DeleteFiles.Add(Project.LongenFilename(Target[i]));
end;
if DeleteFiles.Count>0 then begin
if QuestionDlg('Confirm removal',
'Delete these .h files from list?'#13
+#13
+DeleteFiles.Text,
mtConfirmation,[mrYes,'Remove all files',mrCancel],0)=mrYes
then begin
Project.DeleteFiles(DeleteFiles);
end;
UpdateFilesPage;
end;
DeleteFiles.Free;
end;
procedure TH2PasDialog.AddCHeaderFilesButtonClick(Sender: TObject);
var
OpenDialog: TOpenDialog;
begin
OpenDialog:=TOpenDialog.Create(nil);
try
InitIDEFileDialog(OpenDialog);
OpenDialog.Title:='Add .h files ...';
OpenDialog.Options:=OpenDialog.Options+[ofAllowMultiSelect,ofFileMustExist];
if OpenDialog.Execute then begin
Project.AddFiles(OpenDialog.Files);
UpdateFilesPage;
end;
finally
StoreIDEFileDialog(OpenDialog);
OpenDialog.Free;
end;
end;
procedure TH2PasDialog.CHeaderFilesCheckListBoxItemClick(Sender: TObject;
Index: LongInt);
var
AFilename: string;
AFile: TH2PasFile;
begin
if (Index<0) then exit;
AFilename:=Project.LongenFilename(CHeaderFilesCheckListBox.Items[Index]);
AFile:=Project.CHeaderFileWithFilename(AFilename);
if AFile<>nil then
AFile.Enabled:=CHeaderFilesCheckListBox.Checked[Index];
end;
procedure TH2PasDialog.FormDestroy(Sender: TObject);
begin
FreeAndNil(FConverter);
end;
procedure TH2PasDialog.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key=VK_ESCAPE) and (Shift=[]) then ModalResult:=mrCancel;
if (Key=VK_ESCAPE) and (Shift=[]) then begin
ModalResult:=mrCancel;
Key:=VK_UNKNOWN;
end;
if (Key=VK_S) and (Shift=[ssCtrl]) then begin
SaveSettings;
Key:=VK_UNKNOWN;
end;
end;
procedure TH2PasDialog.H2PasFilenameEditEditingDone(Sender: TObject);
begin
Converter.h2pasFilename:=H2PasFilenameEdit.Text;
end;
procedure TH2PasDialog.IncludeFileCheckBoxChange(Sender: TObject);
begin
Project.CreateIncludeFile:=IncludeFileCheckBox.Checked;
end;
procedure TH2PasDialog.LibnameEditEditingDone(Sender: TObject);
begin
Project.Libname:=LibnameEdit.Text;
end;
procedure TH2PasDialog.OpenLastProjectOnStartCheckBoxChange(Sender: TObject);
begin
Converter.AutoOpenLastProject:=OpenLastProjectOnStartCheckBox.Checked;
end;
procedure TH2PasDialog.OpenSettingsButtonClick(Sender: TObject);
var
OpenDialog: TOpenDialog;
begin
OpenDialog:=TOpenDialog.Create(nil);
try
InitIDEFileDialog(OpenDialog);
OpenDialog.Title:='Open project ...';
OpenDialog.Options:=OpenDialog.Options+[ofFileMustExist];
if OpenDialog.Execute then begin
OpenProject(OpenDialog.FileName,[]);
end;
finally
StoreIDEFileDialog(OpenDialog);
OpenDialog.Free;
end;
end;
procedure TH2PasDialog.OutputDirBrowseButtonClick(Sender: TObject);
var
ADirectory: String;
begin
ADirectory:=OutputDirEdit.Text;
if not ShowSelectDirDialog('Output directory',ADirectory) then exit;
Project.OutputDirectory:=Project.ShortenFilename(ADirectory);
OutputDirEdit.Text:=Project.OutputDirectory;
end;
procedure TH2PasDialog.OutputDirEditEditingDone(Sender: TObject);
begin
Project.OutputDirectory:=OutputDirEdit.Text;
end;
procedure TH2PasDialog.OutputExtEditEditingDone(Sender: TObject);
begin
Project.OutputExt:=OutputExtEdit.Text;
end;
procedure TH2PasDialog.PalmOSSYSTrapCheckBoxChange(Sender: TObject);
begin
Project.PalmOSSYSTrap:=PalmOSSYSTrapCheckBox.Checked;
end;
procedure TH2PasDialog.PforPointersCheckBoxChange(Sender: TObject);
begin
Project.PforPointers:=PforPointersCheckBox.Checked;
end;
procedure TH2PasDialog.SaveSettingsAsButtonClick(Sender: TObject);
begin
SaveProject('',[sfSaveAs]);
end;
procedure TH2PasDialog.SaveSettingsButtonClick(Sender: TObject);
begin
SaveProject('',[]);
end;
procedure TH2PasDialog.SelectAllCHeaderFilesButtonClick(Sender: TObject);
var
i: Integer;
begin
for i:=0 to CHeaderFilesCheckListBox.Items.Count-1 do
CHeaderFilesCheckListBox.Selected[i]:=true;
end;
procedure TH2PasDialog.StripCommentsCheckBoxChange(Sender: TObject);
begin
Project.StripComments:=StripCommentsCheckBox.Checked;
end;
procedure TH2PasDialog.TforTypedefsCheckBoxChange(Sender: TObject);
begin
Project.TforTypedefs:=TforTypedefsCheckBox.Checked;
end;
procedure TH2PasDialog.UnselectAllCHeaderFilesButtonClick(Sender: TObject);
var
i: Integer;
begin
for i:=0 to CHeaderFilesCheckListBox.Items.Count-1 do
CHeaderFilesCheckListBox.Selected[i]:=false;
end;
procedure TH2PasDialog.UseExternalCheckBoxChange(Sender: TObject);
begin
Project.UseExternal:=UseExternalCheckBox.Checked;
end;
procedure TH2PasDialog.UseExternalLibnameCheckBoxChange(Sender: TObject);
begin
Project.UseExternalLibname:=UseExternalLibnameCheckBox.Checked;
end;
procedure TH2PasDialog.VarParamsCheckBoxChange(Sender: TObject);
begin
Project.VarParams:=VarParamsCheckBox.Checked;
end;
procedure TH2PasDialog.Win32HeaderCheckBoxChange(Sender: TObject);
begin
Project.Win32Header:=Win32HeaderCheckBox.Checked;
end;
procedure TH2PasDialog.h2pasFilenameBrowseButtonClick(Sender: TObject);
var
AFilename: String;
begin
AFilename:=H2PasFilenameEdit.Text;
if not ShowOpenFileDialog('Filename of h2pas program',AFilename) then exit;
Converter.h2pasFilename:=AFilename;
H2PasFilenameEdit.Text:=Converter.h2pasFilename;
end;
function TH2PasDialog.GetProject: TH2PasProject;
begin
Result:=Converter.Project;
end;
procedure TH2PasDialog.UpdateCaption;
var
s: String;
begin
s:=h2pCHeaderFileConverter;
if Project<>nil then
s:=s+' - '+ExtractFileNameOnly(Project.Filename);
Caption:=s;
end;
procedure TH2PasDialog.UpdateFilesPage;
var
i: Integer;
Target: TStrings;
CurFile: TH2PasFile;
OldSelected: TStringList;
s: String;
begin
Target:=CHeaderFilesCheckListBox.Items;
Target.BeginUpdate;
// remember old selection
OldSelected:=TStringList.Create;
for i:=0 to Target.Count-1 do begin
if CHeaderFilesCheckListBox.Selected[i] then
OldSelected.Add(Target[i]);
end;
// replace items in CHeaderFilesCheckListBox and restore selection
for i:=0 to Project.CHeaderFileCount-1 do begin
CurFile:=Project.CHeaderFiles[i];
s:=Project.ShortenFilename(CurFile.Filename);
if Target.Count>i then
Target[i]:=s
else
Target.Add(s);
CHeaderFilesCheckListBox.Checked[i]:=CurFile.Enabled;
CHeaderFilesCheckListBox.Selected[i]:=
OldSelected.IndexOf(CurFile.Filename)>=0;
end;
// remove unneeded item
while Target.Count>Project.CHeaderFileCount do
Target.Delete(Target.Count-1);
Target.EndUpdate;
OldSelected.Free;
end;
procedure TH2PasDialog.UpdateH2PasPage;
begin
ConstantsInsteadOfEnumsCheckBox.Checked:=Project.ConstantsInsteadOfEnums;
IncludeFileCheckBox.Checked:=Project.CreateIncludeFile;
LibnameEdit.Text:=Project.Libname;
OutputExtEdit.Text:=Project.OutputExt;
PalmOSSYSTrapCheckBox.Checked:=Project.PalmOSSYSTrap;
PforPointersCheckBox.Checked:=Project.PforPointers;
StripCommentsCheckBox.Checked:=Project.StripComments;
TforTypedefsCheckBox.Checked:=Project.TforTypedefs;
UseExternalCheckBox.Checked:=Project.UseExternal;
UseExternalLibnameCheckBox.Checked:=Project.UseExternalLibname;
VarParamsCheckBox.Checked:=Project.VarParams;
Win32HeaderCheckBox.Checked:=Project.Win32Header;
OutputDirEdit.Text:=Project.ShortenFilename(Project.OutputDirectory);
end;
procedure TH2PasDialog.UpdateSettingsPage;
begin
H2PasFilenameEdit.Text:=Converter.h2pasFilename;
OpenLastProjectOnStartCheckBox.Checked:=Converter.AutoOpenLastProject;
end;
function TH2PasDialog.ShowSelectDirDialog(const Title: string;
var ADirectory: string): boolean;
var
SelectDirDialog: TSelectDirectoryDialog;
begin
Result:=false;
SelectDirDialog:=TSelectDirectoryDialog.Create(nil);
try
InitIDEFileDialog(SelectDirDialog);
SelectDirDialog.Title:=Title;
if (ADirectory<>'')
and (FilenameIsAbsolute(ADirectory)) then
SelectDirDialog.InitialDir:=ADirectory;
if SelectDirDialog.Execute then begin
ADirectory:=SelectDirDialog.FileName;
Result:=true;
end;
finally
StoreIDEFileDialog(SelectDirDialog);
SelectDirDialog.Free;
end;
end;
function TH2PasDialog.ShowOpenFileDialog(const Title: string;
var AFilename: string): boolean;
var
OpenDialog: TOpenDialog;
begin
Result:=false;
OpenDialog:=TOpenDialog.Create(nil);
try
InitIDEFileDialog(OpenDialog);
OpenDialog.Title:=Title;
if (AFilename<>'')
and (FilenameIsAbsolute(AFilename)) then
OpenDialog.InitialDir:=ExtractFilePath(AFilename);
if AFilename<>'' then
OpenDialog.Filename:=ExtractFileName(AFilename);
if OpenDialog.Execute then begin
AFilename:=OpenDialog.FileName;
Result:=true;
end;
finally
StoreIDEFileDialog(OpenDialog);
OpenDialog.Free;
end;
end;
function TH2PasDialog.SaveSettings: TModalResult;
begin
Result:=SaveGlobalSettings;
if Result<>mrOk then exit;
if (Project<>nil) and Project.Modified then
Result:=SaveProject('',[]);
end;
function TH2PasDialog.SaveGlobalSettings: TModalResult;
var
Config: TConfigStorage;
begin
Result:=mrCancel;
try
Config:=GetIDEConfigStorage('h2pastool.xml',false);
try
Converter.WindowSize:=Point(Width,Height);
Converter.Save(Config);
Config.WriteToDisk;
finally
Config.Free;
end;
Result:=mrOk;
except
on E: Exception do begin
MessageDlg('Write error',
'Error writing global config:'#13
+E.Message,mtError,[mbCancel],0);
end;
end;
end;
function TH2PasDialog.LoadGlobalSettings: TModalResult;
var
Config: TConfigStorage;
begin
Result:=mrCancel;
try
Config:=GetIDEConfigStorage('h2pastool.xml',true);
try
Converter.Load(Config);
if (Converter.WindowSize.X>50)
and (Converter.WindowSize.X<Screen.Width)
and (Converter.WindowSize.Y>50)
and (Converter.WindowSize.Y<Screen.Height)
then
SetBounds(Left,Top,Converter.WindowSize.X,Converter.WindowSize.Y);
UpdateSettingsPage;
finally
Config.Free;
end;
Result:=mrOk;
except
on E: Exception do begin
MessageDlg('Read error',
'Error reading global config:'#13
+E.Message,mtError,[mbCancel],0);
end;
end;
end;
function TH2PasDialog.SaveProject(const Filename: string; Flags: TSaveFlags
): TModalResult;
var
NewFilename: String;
SaveDialog: TSaveDialog;
NewPath: String;
begin
Result:=mrCancel;
if Project=nil then exit(mrOk);
NewFilename:=Filename;
if NewFilename='' then
NewFilename:=Project.Filename;
// choose a filename
if (not FilenameIsAbsolute(NewFilename))
or (sfSaveAs in Flags) then begin
SaveDialog:=TSaveDialog.Create(nil);
try
InitIDEFileDialog(SaveDialog);
SaveDialog.Title:='Save project as ...';
//choose a nice default name
if NewFilename='' then
NewFilename:='project1.h2p';
SaveDialog.FileName:=NewFilename;
NewPath:=ExtractFilePath(NewFilename);
if NewPath<>'' then
SaveDialog.InitialDir:=NewPath;
if (not SaveDialog.Execute) then exit;
NewFilename:=SaveDialog.FileName;
if NewFilename='' then exit;
// append default file extension
if ExtractFileExt(NewFilename)='' then
NewFilename:=NewFilename+'.h2p';
// warn if overwriting
if FileExists(NewFilename) then begin
if QuestionDlg('Replace file?',
'The file "'+NewFilename+'"'#13
+'already exists.',
mtConfirmation,[mrOk,'Overwrite',mrCancel,'Cancel'],0)<>mrOk
then exit;
end;
finally
StoreIDEFileDialog(SaveDialog);
SaveDialog.Free;
end;
end;
// save
try
Converter.SaveProject(NewFilename);
Result:=mrOk;
except
on E: Exception do begin
MessageDlg('Write error',
'Error writing global config:'#13
+E.Message,mtError,[mbCancel],0);
end;
end;
UpdateCaption;
end;
function TH2PasDialog.OpenProject(const Filename: string; Flags: TOpenFlags
): TModalResult;
var
NewFilename: String;
begin
Result:=mrCancel;
NewFilename:=ExpandFileName(TrimFilename(Filename));
if not FileExists(NewFilename) then begin
if ofOnlyIfExists in Flags then begin
MessageDlg('File not found',
'File not found: "'+NewFilename+'"',mtError,[mbCancel],0);
exit;
end;
end;
// create new project
if Project=nil then
Converter.Project:=TH2PasProject.Create;
if FileExists(NewFilename) then begin
// load
try
Converter.LoadProject(NewFilename);
Result:=mrOk;
except
on E: Exception do begin
MessageDlg('Read error',
'Error reading project from file'#13
+NewFilename+#13
+#13
+E.Message,mtError,[mbCancel],0);
end;
end;
end else begin
// new project
Project.Clear;
Converter.CurrentProjectFilename:=NewFilename;
Project.Filename:=NewFilename;
end;
UpdateCaption;
UpdateFilesPage;
UpdateH2PasPage;
end;
initialization

View File

@ -5,7 +5,7 @@
<CompilerOptions>
<Version Value="5"/>
<SearchPaths>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)/"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<Generate Value="Faster"/>
@ -14,16 +14,28 @@
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Files Count="2">
<Files Count="5">
<Item1>
<Filename Value="h2pasconvert.pas"/>
<UnitName Value="h2pasconvert"/>
</Item1>
<Item2>
<Filename Value="h2pasdlg.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="H2PasDlg"/>
</Item1>
<Item2>
</Item2>
<Item3>
<Filename Value="h2pasdlg.lfm"/>
<Type Value="LFM"/>
</Item3>
<Item4>
<Filename Value="h2pasdlg.lrs"/>
<Type Value="LRS"/>
</Item4>
<Item5>
<Filename Value="h2passtrconsts.pas"/>
<UnitName Value="H2PasStrConsts"/>
</Item2>
</Item5>
</Files>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="3">

View File

@ -1,5 +1,5 @@
{ This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install the package.
{ Diese Datei wurde automatisch von Lazarus erzeugt. Sie darf nicht bearbeitet werden!
Dieser Quelltext dient nur dem Übersetzen und Installieren des Packages.
}
unit H2PasWizard;
@ -7,7 +7,7 @@ unit H2PasWizard;
interface
uses
H2PasDlg, H2PasStrConsts, LazarusPackageIntf;
H2PasConvert, H2PasDlg, H2PasStrConsts, LazarusPackageIntf;
implementation

View File

@ -71,9 +71,9 @@ uses
// synedit
SynEditKeyCmds,
// IDE interface
AllIDEIntf, ObjectInspector, PropEdits, MacroIntf, IDECommands, SrcEditorIntf,
NewItemIntf, IDEMsgIntf, PackageIntf, ProjectIntf, MenuIntf, LazIDEIntf,
IDEDialogs,
AllIDEIntf, BaseIDEIntf, ObjectInspector, PropEdits, MacroIntf, IDECommands,
SrcEditorIntf, NewItemIntf, IDEMsgIntf, PackageIntf, ProjectIntf, MenuIntf,
LazIDEIntf, IDEDialogs,
// protocol
IDEProtocol,
// compile
@ -304,6 +304,8 @@ type
IDEWindowClass: TCustomFormClass);
function OnExecuteIDECommand(Sender: TObject; Command: word): boolean;
function OnSelectDirectory(const Title, InitialDir: string): string;
procedure OnInitIDEFileDialog(AFileDialog: TFileDialog);
procedure OnStoreIDEFileDialog(AFileDialog: TFileDialog);
// Environment options dialog events
procedure OnLoadEnvironmentSettings(Sender: TObject;
@ -1432,6 +1434,8 @@ end;
procedure TMainIDE.SetupDialogs;
begin
LazIDESelectDirectory:=@OnSelectDirectory;
InitIDEFileDialog:=@OnInitIDEFileDialog;
StoreIDEFileDialog:=@OnStoreIDEFileDialog;
end;
procedure TMainIDE.SetupComponentNoteBook;
@ -2609,6 +2613,16 @@ begin
end;
end;
procedure TMainIDE.OnInitIDEFileDialog(AFileDialog: TFileDialog);
begin
InputHistories.ApplyFileDialogSettings(AFileDialog);
end;
procedure TMainIDE.OnStoreIDEFileDialog(AFileDialog: TFileDialog);
begin
InputHistories.StoreFileDialogSettings(AFileDialog);
end;
procedure TMainIDE.OnExecuteIDEShortCut(Sender: TObject; var Key: word;
Shift: TShiftState;
IDEWindowClass: TCustomFormClass);

View File

@ -22,16 +22,19 @@ unit BaseIDEIntf;
interface
uses
Classes, SysUtils, LazConfigStorage;
Classes, SysUtils, LazConfigStorage, Dialogs;
type
TGetIDEConfigStorage = function(const Filename: string; LoadFromDisk: Boolean
): TConfigStorage;
TInitIDEFileDialog = procedure(AFileDialog: TFileDialog) of object;
TStoreIDEFileDialog = procedure(AFileDialog: TFileDialog) of object;
var
DefaultConfigClass: TConfigStorageClass = nil; // will be set by the IDE
GetIDEConfigStorage: TGetIDEConfigStorage = nil; // will be set by the IDE
InitIDEFileDialog: TInitIDEFileDialog = nil; // will be set by the IDE
StoreIDEFileDialog: TStoreIDEFileDialog = nil ; // will be set by the IDE
implementation

View File

@ -80,6 +80,7 @@ function ChompPathDelim(const Path: string): string;
function TrimFilename(const AFilename: string): string;
function CleanAndExpandFilename(const Filename: string): string;
function CleanAndExpandDirectory(const Filename: string): string;
function CreateRelativePath(const Filename, BaseDirectory: string): string;
function FileIsInPath(const Filename, Path: string): boolean;
function FileIsInDirectory(const Filename, Directory: string): boolean;
function FileInFilenameMasks(const Filename, Masks: string): boolean;

View File

@ -866,6 +866,84 @@ begin
Result:=AppendPathDelim(CleanAndExpandFilename(Filename));
end;
function CreateRelativePath(const Filename, BaseDirectory: string): string;
var
FileNameLength: Integer;
BaseDirLen: Integer;
MinLen: Integer;
SamePos: Integer;
UpDirCount: Integer;
BaseDirPos: Integer;
ResultPos: Integer;
i: Integer;
FileNameRestLen: Integer;
begin
Result:=Filename;
if (BaseDirectory='') or (Filename='') then exit;
// check for different windows file drives
if (CompareText(ExtractFileDrive(Filename),
ExtractFileDrive(BaseDirectory))<>0)
then
exit;
FileNameLength:=length(Filename);
BaseDirLen:=length(BaseDirectory);
// skip matching directories
MinLen:=FileNameLength;
if MinLen>BaseDirLen then MinLen:=BaseDirLen;
SamePos:=1;
while (SamePos<=MinLen) do begin
{$IFDEF CaseInsensitiveFilenames}
if AnsiStrLIComp(@FileName[SamePos],@BaseDirectory[SamePos],1)=0
{$ELSE}
if FileName[SamePos]=BaseDirectory[SamePos]
{$ENDIF}
then
inc(SamePos)
else
break;
end;
if (SamePos>MinLen)
and (((SamePos<=BaseDirLen) and (BaseDirectory[SamePos]=PathDelim))
or ((SamePos<=FileNameLength) and (Filename[SamePos]=PathDelim))
or (BaseDirLen=FileNameLength))
then begin
// Filename lies in BaseDirectory
// or Filename is parent directory of BaseDirectory
// or Filename is BaseDirectory
end else begin
// difference found -> step back to path delimiter
repeat
dec(SamePos);
if (SamePos<1) then exit;
until (FileName[SamePos]=PathDelim);
end;
if (SamePos=1) and (Filename[1]=PathDelim) then exit;
// calculate needed up directories
UpDirCount:=0;
BaseDirPos:=SamePos+1;
while (BaseDirPos<=BaseDirLen) do begin
if BaseDirectory[BaseDirPos]=PathDelim then inc(UpDirCount);
inc(BaseDirPos);
end;
if BaseDirectory[BaseDirLen]<>PathDelim then inc(UpDirCount);
// create relative filename
FileNameRestLen:=FileNameLength-SamePos;
SetLength(Result,3*UpDirCount+FileNameRestLen);
ResultPos:=1;
for i:=1 to UpDirCount do begin
Result[ResultPos]:='.';
Result[ResultPos+1]:='.';
Result[ResultPos+2]:=PathDelim;
inc(ResultPos,3);
end;
if FileNameRestLen>0 then
Move(Filename[SamePos+1],Result[ResultPos],FileNameRestLen);
end;
{------------------------------------------------------------------------------
function FileIsInPath(const Filename, Path: string): boolean;
------------------------------------------------------------------------------}

View File

@ -51,6 +51,9 @@ type
function GetValue(const APath: String; ADefault: Boolean): Boolean;
procedure GetValue(const APath: String; out ARect: TRect;
const ADefault: TRect);
procedure GetValue(const APath: String; out APoint: TPoint;
const ADefault: TPoint);
procedure GetValue(const APath: String; const List: TStrings);
procedure SetValue(const APath, AValue: String);
procedure SetDeleteValue(const APath, AValue, DefValue: String);
procedure SetValue(const APath: String; AValue: Integer);
@ -59,6 +62,9 @@ type
procedure SetDeleteValue(const APath: String; AValue, DefValue: Boolean);
procedure SetValue(const APath: String; const AValue: TRect);
procedure SetDeleteValue(const APath: String; const AValue, DefValue: TRect);
procedure SetValue(const APath: String; const AValue: TPoint);
procedure SetDeleteValue(const APath: String; const AValue, DefValue: TPoint);
procedure SetValue(const APath: String; const AValue: TStrings);
procedure DeletePath(const APath: string);
procedure DeleteValue(const APath: string);
property CurrentBasePath: string read FCurrentBasePath;
@ -113,6 +119,30 @@ begin
ARect.Bottom:=GetValue(APath+'Bottom',ADefault.Bottom);
end;
procedure TConfigStorage.GetValue(const APath: String; out APoint: TPoint;
const ADefault: TPoint);
begin
APoint.X:=GetValue(APath+'X',ADefault.X);
APoint.Y:=GetValue(APath+'Y',ADefault.Y);
end;
procedure TConfigStorage.GetValue(const APath: String; const List: TStrings);
var
NewCount: LongInt;
i: Integer;
NewLine: String;
begin
NewCount:=GetValue(APath+'Count',0);
for i:=0 to NewCount-1 do begin
NewLine:=GetValue(APath+'Item'+IntToStr(i+1),'');
if List.Count>i then
List[i]:=NewLine
else
List.Add(NewLine);
end;
while List.Count>NewCount do List.Delete(List.Count-1);
end;
procedure TConfigStorage.SetValue(const APath, AValue: String);
begin
SetFullPathValue(ExtendPath(APath),AValue);
@ -162,6 +192,28 @@ begin
SetDeleteValue(APath+'Bottom',AValue.Bottom,DefValue.Bottom);
end;
procedure TConfigStorage.SetValue(const APath: String; const AValue: TPoint);
begin
SetValue(APath+'X',AValue.X);
SetValue(APath+'Y',AValue.Y);
end;
procedure TConfigStorage.SetDeleteValue(const APath: String; const AValue,
DefValue: TPoint);
begin
SetDeleteValue(APath+'X',AValue.X,DefValue.X);
SetDeleteValue(APath+'Y',AValue.Y,DefValue.Y);
end;
procedure TConfigStorage.SetValue(const APath: String; const AValue: TStrings);
var
i: Integer;
begin
SetDeleteValue(APath+'Count',AValue.Count,0);
for i:=0 to AValue.Count-1 do
SetDeleteValue(APath+'Item'+IntToStr(i+1),AValue[i],'');
end;
procedure TConfigStorage.DeletePath(const APath: string);
begin
DeleteFullPath(ExtendPath(APath));