mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 18:22:54 +02:00
ide: add resources with relative paths, process relative paths and macroses during resource processing
git-svn-id: trunk@43281 -
This commit is contained in:
parent
8bf097e799
commit
7aae9b8287
@ -25,7 +25,7 @@ object ResourcesOptionsFrame: TResourcesOptionsFrame
|
|||||||
Columns = <
|
Columns = <
|
||||||
item
|
item
|
||||||
Caption = 'FileName'
|
Caption = 'FileName'
|
||||||
Width = 300
|
Width = 200
|
||||||
end
|
end
|
||||||
item
|
item
|
||||||
Caption = 'Type'
|
Caption = 'Type'
|
||||||
@ -33,7 +33,7 @@ object ResourcesOptionsFrame: TResourcesOptionsFrame
|
|||||||
end
|
end
|
||||||
item
|
item
|
||||||
Caption = 'Resource'
|
Caption = 'Resource'
|
||||||
Width = 376
|
Width = 326
|
||||||
end>
|
end>
|
||||||
RowSelect = True
|
RowSelect = True
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
@ -132,6 +132,7 @@ object ResourcesOptionsFrame: TResourcesOptionsFrame
|
|||||||
TabOrder = 3
|
TabOrder = 3
|
||||||
end
|
end
|
||||||
object dlgOpen: TOpenDialog
|
object dlgOpen: TOpenDialog
|
||||||
|
Options = [ofAllowMultiSelect, ofEnableSizing, ofViewDetail]
|
||||||
left = 146
|
left = 146
|
||||||
top = 93
|
top = 93
|
||||||
end
|
end
|
||||||
|
@ -36,6 +36,7 @@ type
|
|||||||
procedure lbResourcesSelectItem(Sender: TObject; Item: TListItem;
|
procedure lbResourcesSelectItem(Sender: TObject; Item: TListItem;
|
||||||
Selected: Boolean);
|
Selected: Boolean);
|
||||||
private
|
private
|
||||||
|
FProject: TProject;
|
||||||
procedure AddResource(AFileName: String);
|
procedure AddResource(AFileName: String);
|
||||||
procedure AddResourceItem(ResFile: String; ResType: TUserResourceType; ResName: String);
|
procedure AddResourceItem(ResFile: String; ResType: TUserResourceType; ResName: String);
|
||||||
public
|
public
|
||||||
@ -53,9 +54,18 @@ implementation
|
|||||||
{ TResourcesOptionsFrame }
|
{ TResourcesOptionsFrame }
|
||||||
|
|
||||||
procedure TResourcesOptionsFrame.btnAddClick(Sender: TObject);
|
procedure TResourcesOptionsFrame.btnAddClick(Sender: TObject);
|
||||||
|
var
|
||||||
|
FileName: String;
|
||||||
begin
|
begin
|
||||||
if dlgOpen.Execute then
|
if dlgOpen.Execute then
|
||||||
AddResource(dlgOpen.FileName);
|
begin
|
||||||
|
for FileName in dlgOpen.Files do
|
||||||
|
begin
|
||||||
|
if not FProject.IsVirtual then
|
||||||
|
FileName := CreateRelativePath(FileName, FProject.ProjectDirectory);
|
||||||
|
AddResource(FileName);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TResourcesOptionsFrame.btnClearClick(Sender: TObject);
|
procedure TResourcesOptionsFrame.btnClearClick(Sender: TObject);
|
||||||
@ -175,6 +185,7 @@ var
|
|||||||
List: TResourceList;
|
List: TResourceList;
|
||||||
I: Integer;
|
I: Integer;
|
||||||
begin
|
begin
|
||||||
|
FProject := Project;
|
||||||
lbResources.Items.Clear;
|
lbResources.Items.Clear;
|
||||||
List := Project.ProjResources.UserResources.List;
|
List := Project.ProjResources.UserResources.List;
|
||||||
lbResources.Items.BeginUpdate;
|
lbResources.Items.BeginUpdate;
|
||||||
|
@ -37,7 +37,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, Laz2_XMLCfg, lazutf8classes, Process, LCLProc,
|
Classes, SysUtils, FileUtil, Laz2_XMLCfg, lazutf8classes, Process, LCLProc,
|
||||||
Controls, Graphics, Forms, CodeToolManager, FileProcs, LazConf, LResources,
|
Controls, Graphics, Forms, CodeToolManager, FileProcs, LazConf, LResources,
|
||||||
ProjectIntf, ProjectResourcesIntf, IDEMsgIntf, IDEExternToolIntf, LazarusIDEStrConsts,
|
ProjectIntf, ProjectResourcesIntf, IDEMsgIntf, IDEExternToolIntf, MacroIntf, LazarusIDEStrConsts,
|
||||||
resource, bitmapresource, groupresource, groupiconresource, groupcursorresource;
|
resource, bitmapresource, groupresource, groupiconresource, groupcursorresource;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -59,7 +59,8 @@ type
|
|||||||
ResName: String;
|
ResName: String;
|
||||||
procedure ReadFromProjectFile(AConfig: TXMLConfig; Path: String);
|
procedure ReadFromProjectFile(AConfig: TXMLConfig; Path: String);
|
||||||
procedure WriteToProjectFile(AConfig: TXMLConfig; Path: String);
|
procedure WriteToProjectFile(AConfig: TXMLConfig; Path: String);
|
||||||
function CreateResource: TAbstractResource;
|
function CreateResource(ProjectDirectory: String): TAbstractResource;
|
||||||
|
function GetRealFileName(ProjectDirectory: String): String;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TResourceList }
|
{ TResourceList }
|
||||||
@ -132,15 +133,19 @@ begin
|
|||||||
AConfig.SetValue(Path + 'ResourceName', ResName);
|
AConfig.SetValue(Path + 'ResourceName', ResName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TResourceItem.CreateResource: TAbstractResource;
|
function TResourceItem.CreateResource(ProjectDirectory: String): TAbstractResource;
|
||||||
var
|
var
|
||||||
Stream: TFileStream;
|
Stream: TFileStream;
|
||||||
TypeDesc, NameDesc: TResourceDesc;
|
TypeDesc, NameDesc: TResourceDesc;
|
||||||
|
RealFileName: String;
|
||||||
begin
|
begin
|
||||||
Result := nil;
|
Result := nil;
|
||||||
if FileExistsUTF8(FileName) then
|
|
||||||
|
RealFileName := GetRealFileName(ProjectDirectory);
|
||||||
|
|
||||||
|
if FileExistsUTF8(RealFileName) then
|
||||||
begin
|
begin
|
||||||
Stream := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite);
|
Stream := TFileStream.Create(UTF8ToSys(RealFileName), fmOpenRead or fmShareDenyWrite);
|
||||||
try
|
try
|
||||||
NameDesc := TResourceDesc.Create(ResName);
|
NameDesc := TResourceDesc.Create(ResName);
|
||||||
case ResType of
|
case ResType of
|
||||||
@ -187,6 +192,16 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResourceItem.GetRealFileName(ProjectDirectory: String): String;
|
||||||
|
begin
|
||||||
|
Result := FileName;
|
||||||
|
if not IDEMacros.SubstituteMacros(Result) then
|
||||||
|
debugln(['TResourceItem.GetRealFileName failed FileName="', FileName, '"']);
|
||||||
|
Result := TrimFilename(Result);
|
||||||
|
if not FilenameIsAbsolute(Result) then
|
||||||
|
Result := TrimFilename(AppendPathDelim(ProjectDirectory) + Result);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResourceList }
|
{ TResourceList }
|
||||||
|
|
||||||
function TResourceList.GetItem(AIndex: Integer): PResourceItem;
|
function TResourceList.GetItem(AIndex: Integer): PResourceItem;
|
||||||
@ -223,11 +238,13 @@ function TProjectUserResources.UpdateResources(AResources: TAbstractProjectResou
|
|||||||
var
|
var
|
||||||
I: Integer;
|
I: Integer;
|
||||||
ARes: TAbstractResource;
|
ARes: TAbstractResource;
|
||||||
|
ProjectDirectory: String;
|
||||||
begin
|
begin
|
||||||
Result := True;
|
Result := True;
|
||||||
|
ProjectDirectory := ExtractFilePath(MainFileName);
|
||||||
for I := 0 to List.Count - 1 do
|
for I := 0 to List.Count - 1 do
|
||||||
begin
|
begin
|
||||||
ARes := List[I]^.CreateResource;
|
ARes := List[I]^.CreateResource(ProjectDirectory);
|
||||||
if Assigned(ARes) then
|
if Assigned(ARes) then
|
||||||
AResources.AddSystemResource(ARes);
|
AResources.AddSystemResource(ARes);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user