IDE: package editor: new component: icon button

git-svn-id: trunk@26165 -
This commit is contained in:
mattias 2010-06-18 05:59:02 +00:00
parent c5c3f76ed1
commit fcd2b67e12
5 changed files with 222 additions and 72 deletions

View File

@ -1880,6 +1880,8 @@ resourcestring
dlgCCOTestMissingPPU = 'Test: Checking missing fpc ppu ...'; dlgCCOTestMissingPPU = 'Test: Checking missing fpc ppu ...';
dlgCCOTestCompilerDate = 'Test: Checking compiler date ...'; dlgCCOTestCompilerDate = 'Test: Checking compiler date ...';
lisCCOErrorCaption = 'Error'; lisCCOErrorCaption = 'Error';
lisErrorLoadingFile2 = 'Error loading file "%s":%s%s';
lisNoneClickToChooseOne = 'none, click to choose one';
lisTreeNeedsRefresh = 'Tree needs refresh'; lisTreeNeedsRefresh = 'Tree needs refresh';
lisEMDEmtpyMethods = 'Emtpy Methods'; lisEMDEmtpyMethods = 'Emtpy Methods';
lisEMDSearchInTheseClassSections = 'Search in these class sections:'; lisEMDSearchInTheseClassSections = 'Search in these class sections:';

View File

@ -20,7 +20,7 @@ object AddToPackageDlg: TAddToPackageDlg
Top = 0 Top = 0
Width = 658 Width = 658
Align = alClient Align = alClient
PageIndex = 3 PageIndex = 1
TabOrder = 0 TabOrder = 0
object NewFilePage: TPage object NewFilePage: TPage
Caption = 'New File' Caption = 'New File'
@ -54,8 +54,8 @@ object AddToPackageDlg: TAddToPackageDlg
Align = alClient Align = alClient
BorderSpacing.Bottom = 5 BorderSpacing.Bottom = 5
Caption = 'NewFileDescriptionGroupBox' Caption = 'NewFileDescriptionGroupBox'
ClientHeight = 245 ClientHeight = 249
ClientWidth = 403 ClientWidth = 407
TabOrder = 1 TabOrder = 1
object NewFileHelpLabel: TLabel object NewFileHelpLabel: TLabel
Left = 0 Left = 0
@ -186,16 +186,16 @@ object AddToPackageDlg: TAddToPackageDlg
end end
object NewComponentPage: TPage object NewComponentPage: TPage
Caption = 'New Component' Caption = 'New Component'
ClientWidth = 656 ClientWidth = 654
ClientHeight = 295 ClientHeight = 289
OnResize = NewComponentPageResize OnResize = NewComponentPageResize
object AncestorTypeLabel: TLabel object AncestorTypeLabel: TLabel
AnchorSideTop.Control = AncestorComboBox AnchorSideTop.Control = AncestorComboBox
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 18 Height = 18
Top = 11 Top = 10
Width = 120 Width = 123
Caption = 'AncestorTypeLabel' Caption = 'AncestorTypeLabel'
ParentColor = False ParentColor = False
end end
@ -204,8 +204,8 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 18 Height = 18
Top = 45 Top = 43
Width = 108 Width = 110
Caption = 'ClassNameLabel' Caption = 'ClassNameLabel'
ParentColor = False ParentColor = False
end end
@ -214,8 +214,8 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 18 Height = 18
Top = 79 Top = 76
Width = 110 Width = 112
Caption = 'PalettePageLabel' Caption = 'PalettePageLabel'
ParentColor = False ParentColor = False
end end
@ -224,8 +224,8 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 18 Height = 18
Top = 113 Top = 109
Width = 156 Width = 161
Caption = 'ComponentUnitFileLabel' Caption = 'ComponentUnitFileLabel'
ParentColor = False ParentColor = False
end end
@ -234,8 +234,8 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 18 Height = 18
Top = 146 Top = 142
Width = 175 Width = 177
Caption = 'ComponentUnitNameLabel' Caption = 'ComponentUnitNameLabel'
ParentColor = False ParentColor = False
end end
@ -243,7 +243,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = NewComponentPage AnchorSideTop.Control = NewComponentPage
Left = 184 Left = 184
Height = 29 Height = 27
Top = 6 Top = 6
Width = 200 Width = 200
BorderSpacing.Top = 6 BorderSpacing.Top = 6
@ -259,8 +259,8 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 384 Left = 384
Height = 22 Height = 22
Top = 9 Top = 8
Width = 193 Width = 202
Caption = 'AncestorShowAllCheckBox' Caption = 'AncestorShowAllCheckBox'
Checked = True Checked = True
OnClick = AncestorShowAllCheckBoxClick OnClick = AncestorShowAllCheckBoxClick
@ -275,7 +275,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 184 Left = 184
Height = 27 Height = 27
Top = 41 Top = 39
Width = 200 Width = 200
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6 BorderSpacing.Top = 6
@ -290,8 +290,8 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideRight.Control = AncestorComboBox AnchorSideRight.Control = AncestorComboBox
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 184 Left = 184
Height = 29 Height = 27
Top = 74 Top = 72
Width = 200 Width = 200
BorderSpacing.Top = 6 BorderSpacing.Top = 6
ItemHeight = 0 ItemHeight = 0
@ -305,8 +305,8 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideRight.Control = ComponentUnitFileBrowseButton AnchorSideRight.Control = ComponentUnitFileBrowseButton
Left = 184 Left = 184
Height = 27 Height = 27
Top = 109 Top = 105
Width = 414 Width = 300
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6 BorderSpacing.Top = 6
TabOrder = 4 TabOrder = 4
@ -317,11 +317,11 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Control = ComponentUnitFileEdit AnchorSideTop.Control = ComponentUnitFileEdit
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ComponentUnitFileShortenButton AnchorSideRight.Control = ComponentUnitFileShortenButton
Left = 598 Left = 484
Height = 29 Height = 27
Hint = 'Save file dialog' Hint = 'Save file dialog'
Top = 108 Top = 105
Width = 24 Width = 85
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
Caption = '...' Caption = '...'
@ -336,11 +336,11 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = NewComponentPage AnchorSideRight.Control = NewComponentPage
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 622 Left = 569
Height = 29 Height = 27
Hint = 'Shorten or expand filename' Hint = 'Shorten or expand filename'
Top = 108 Top = 105
Width = 34 Width = 85
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
Caption = '<>' Caption = '<>'
@ -357,7 +357,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 184 Left = 184
Height = 27 Height = 27
Top = 142 Top = 138
Width = 200 Width = 200
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6 BorderSpacing.Top = 6
@ -366,21 +366,21 @@ object AddToPackageDlg: TAddToPackageDlg
end end
object NewCompBtnPanel: TPanel object NewCompBtnPanel: TPanel
Left = 0 Left = 0
Height = 41 Height = 39
Top = 254 Top = 250
Width = 656 Width = 654
Align = alBottom Align = alBottom
AutoSize = True AutoSize = True
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 41 ClientHeight = 39
ClientWidth = 656 ClientWidth = 654
TabOrder = 8 TabOrder = 8
object NewComponentButton: TBitBtn object NewComponentButton: TBitBtn
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 249 Left = 228
Height = 29 Height = 27
Top = 6 Top = 6
Width = 176 Width = 185
Align = alRight Align = alRight
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -428,10 +428,10 @@ object AddToPackageDlg: TAddToPackageDlg
end end
object CancelNewComponentButton: TBitBtn object CancelNewComponentButton: TBitBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
Left = 431 Left = 419
Height = 29 Height = 27
Top = 6 Top = 6
Width = 219 Width = 229
Align = alRight Align = alRight
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -478,6 +478,32 @@ object AddToPackageDlg: TAddToPackageDlg
TabOrder = 1 TabOrder = 1
end end
end end
object ComponentIconLabel: TLabel
AnchorSideLeft.Control = ComponentUnitNameLabel
AnchorSideTop.Control = ComponentIconSpeedButton
AnchorSideTop.Side = asrCenter
Left = 5
Height = 18
Top = 175
Width = 138
Caption = 'ComponentIconLabel'
ParentColor = False
end
object ComponentIconSpeedButton: TSpeedButton
AnchorSideLeft.Control = ComponentUnitNameEdit
AnchorSideTop.Control = ComponentUnitNameEdit
AnchorSideTop.Side = asrBottom
Left = 184
Height = 26
Top = 171
Width = 28
BorderSpacing.Top = 6
Color = clBtnFace
NumGlyphs = 0
OnClick = ComponentIconSpeedButtonClick
ShowHint = True
ParentShowHint = False
end
end end
object NewRequirementPage: TPage object NewRequirementPage: TPage
Caption = 'New Requirement' Caption = 'New Requirement'
@ -679,14 +705,14 @@ object AddToPackageDlg: TAddToPackageDlg
end end
object AddFilesPage: TPage object AddFilesPage: TPage
Caption = 'Add Files' Caption = 'Add Files'
ClientWidth = 656 ClientWidth = 654
ClientHeight = 295 ClientHeight = 289
object FilesListView: TListView object FilesListView: TListView
AnchorSideBottom.Control = FilesBrowseButton AnchorSideBottom.Control = FilesBrowseButton
Left = 0 Left = 0
Height = 249 Height = 245
Top = 0 Top = 0
Width = 656 Width = 654
Align = alClient Align = alClient
BorderSpacing.Bottom = 5 BorderSpacing.Bottom = 5
Columns = < Columns = <
@ -705,21 +731,21 @@ object AddToPackageDlg: TAddToPackageDlg
end end
object AddFilesBtnPanel: TPanel object AddFilesBtnPanel: TPanel
Left = 0 Left = 0
Height = 41 Height = 39
Top = 254 Top = 250
Width = 656 Width = 654
Align = alBottom Align = alBottom
AutoSize = True AutoSize = True
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 41 ClientHeight = 39
ClientWidth = 656 ClientWidth = 654
TabOrder = 1 TabOrder = 1
object FilesBrowseButton: TButton object FilesBrowseButton: TButton
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 28 Left = -16
Height = 29 Height = 27
Top = 6 Top = 6
Width = 128 Width = 139
Align = alRight Align = alRight
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -729,10 +755,10 @@ object AddToPackageDlg: TAddToPackageDlg
end end
object FilesAddButton: TButton object FilesAddButton: TButton
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
Left = 543 Left = 532
Height = 29 Height = 27
Top = 6 Top = 6
Width = 107 Width = 116
Align = alRight Align = alRight
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -742,10 +768,10 @@ object AddToPackageDlg: TAddToPackageDlg
end end
object FilesShortenButton: TBitBtn object FilesShortenButton: TBitBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
Left = 268 Left = 245
Height = 29 Height = 27
Top = 6 Top = 6
Width = 136 Width = 141
Align = alRight Align = alRight
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -755,10 +781,10 @@ object AddToPackageDlg: TAddToPackageDlg
end end
object FilesDeleteButton: TBitBtn object FilesDeleteButton: TBitBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
Left = 410 Left = 392
Height = 29 Height = 27
Top = 6 Top = 6
Width = 127 Width = 134
Align = alRight Align = alRight
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -767,10 +793,10 @@ object AddToPackageDlg: TAddToPackageDlg
TabOrder = 3 TabOrder = 3
end end
object FilesDirButton: TButton object FilesDirButton: TButton
Left = 162 Left = 129
Height = 29 Height = 27
Top = 6 Top = 6
Width = 100 Width = 110
Align = alRight Align = alRight
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6

View File

@ -38,9 +38,9 @@ unit AddToPackageDlg;
interface interface
uses uses
Math, Classes, SysUtils, LCLType, Forms, Controls, Buttons, Math, Classes, SysUtils, LCLType, Forms, Controls, Buttons, ExtDlgs,
StdCtrls, ExtCtrls, Dialogs, FileUtil, ComCtrls, AVL_Tree, LCLProc, StdCtrls, ExtCtrls, Dialogs, FileUtil, ComCtrls, AVL_Tree, LCLProc,
NewItemIntf, ProjectIntf, PackageIntf, NewItemIntf, ProjectIntf, PackageIntf, FormEditingIntf,
LazarusIDEStrConsts, IDEWindowIntf, InputHistory, CodeToolManager, IDEDefs, LazarusIDEStrConsts, IDEWindowIntf, InputHistory, CodeToolManager, IDEDefs,
IDEProcs, EnvironmentOpts, PackageSystem, PackageDefs, ComponentReg, IDEProcs, EnvironmentOpts, PackageSystem, PackageDefs, ComponentReg,
AddDirToPkgDlg; AddDirToPkgDlg;
@ -57,6 +57,7 @@ type
); );
TAddToPkgResult = class TAddToPkgResult = class
public
Pkg: TLazPackage; Pkg: TLazPackage;
AddType: TAddToPkgType; AddType: TAddToPkgType;
Dependency: TPkgDependency; Dependency: TPkgDependency;
@ -68,6 +69,7 @@ type
FileType: TPkgFileType; FileType: TPkgFileType;
PkgFileFlags: TPkgFileFlags; PkgFileFlags: TPkgFileFlags;
UsedUnitname: string; UsedUnitname: string;
IconFile: string;
AutoAddLFMFile: boolean; AutoAddLFMFile: boolean;
AutoAddLRSFile: boolean; AutoAddLRSFile: boolean;
NewItem: TNewIDEItemTemplate; NewItem: TNewIDEItemTemplate;
@ -84,6 +86,8 @@ type
TAddToPackageDlg = class(TForm) TAddToPackageDlg = class(TForm)
CancelDependButton: TBitBtn; CancelDependButton: TBitBtn;
CancelNewComponentButton: TBitBtn; CancelNewComponentButton: TBitBtn;
ComponentIconLabel: TLabel;
ComponentIconSpeedButton: TSpeedButton;
NewCompBtnPanel: TPanel; NewCompBtnPanel: TPanel;
NewComponentButton: TBitBtn; NewComponentButton: TBitBtn;
NewDepBtnPanel: TPanel; NewDepBtnPanel: TPanel;
@ -141,6 +145,7 @@ type
procedure CancelAddUnitButtonClick(Sender: TObject); procedure CancelAddUnitButtonClick(Sender: TObject);
procedure CancelNewComponentButtonClick(Sender: TObject); procedure CancelNewComponentButtonClick(Sender: TObject);
procedure ClassNameEditChange(Sender: TObject); procedure ClassNameEditChange(Sender: TObject);
procedure ComponentIconSpeedButtonClick(Sender: TObject);
procedure ComponentUnitFileBrowseButtonClick(Sender: TObject); procedure ComponentUnitFileBrowseButtonClick(Sender: TObject);
procedure ComponentUnitFileShortenButtonClick(Sender: TObject); procedure ComponentUnitFileShortenButtonClick(Sender: TObject);
procedure FilesAddButtonClick(Sender: TObject); procedure FilesAddButtonClick(Sender: TObject);
@ -166,6 +171,7 @@ type
FOnGetUnitRegisterInfo: TOnGetUnitRegisterInfo; FOnGetUnitRegisterInfo: TOnGetUnitRegisterInfo;
fPkgComponents: TAVLTree;// tree of TPkgComponent fPkgComponents: TAVLTree;// tree of TPkgComponent
fPackages: TAVLTree;// tree of TLazPackage or TPackageLink fPackages: TAVLTree;// tree of TLazPackage or TPackageLink
FComponentIconFilename: string;
procedure SetLazPackage(const AValue: TLazPackage); procedure SetLazPackage(const AValue: TLazPackage);
procedure SetupComponents; procedure SetupComponents;
procedure SetupNewFilePage; procedure SetupNewFilePage;
@ -179,6 +185,7 @@ type
function SwitchRelativeAbsoluteFilename(const Filename: string): string; function SwitchRelativeAbsoluteFilename(const Filename: string): string;
procedure FillNewFileTreeView; procedure FillNewFileTreeView;
function FindFileInFilesList(AFilename: string): Integer; function FindFileInFilesList(AFilename: string): Integer;
procedure LoadComponentIcon(AFilename: string);
public public
Params: TAddToPkgResult; Params: TAddToPkgResult;
procedure UpdateAvailableAncestorTypes; procedure UpdateAvailableAncestorTypes;
@ -457,6 +464,29 @@ begin
AutoCompleteNewComponentUnitName; AutoCompleteNewComponentUnitName;
end; end;
procedure TAddToPackageDlg.ComponentIconSpeedButtonClick(Sender: TObject);
var
Dlg: TOpenPictureDialog;
begin
Dlg:=TOpenPictureDialog.Create(nil);
try
InputHistories.ApplyFileDialogSettings(Dlg);
Dlg.InitialDir:=LazPackage.GetFileDialogInitialDir(ExtractFilePath(ComponentUnitFileEdit.Text));
Dlg.Title := 'Choose a component icon 24x24';
Dlg.Options := Dlg.Options+[ofPathMustExist];
Dlg.Filter:='PNG|*.png'
+'|Bitmap, bmp|*.bmp'
+'|Pixmap, xpm|*.xpm'
+'|'+lisAllFiles+'|'+GetAllFilesMask;
if Dlg.Execute then begin
LoadComponentIcon(Dlg.FileName);
end;
InputHistories.StoreFileDialogSettings(Dlg);
finally
Dlg.Free;
end;
end;
procedure TAddToPackageDlg.ComponentUnitFileBrowseButtonClick(Sender: TObject); procedure TAddToPackageDlg.ComponentUnitFileBrowseButtonClick(Sender: TObject);
var var
SaveDialog: TSaveDialog; SaveDialog: TSaveDialog;
@ -724,6 +754,7 @@ begin
Params.Unit_Name:=ComponentUnitNameEdit.Text; Params.Unit_Name:=ComponentUnitNameEdit.Text;
Params.UnitFilename:=ComponentUnitFileEdit.Text; Params.UnitFilename:=ComponentUnitFileEdit.Text;
Params.UsedUnitname:=''; Params.UsedUnitname:='';
Params.IconFile:=FComponentIconFilename;
// check Ancestor Type // check Ancestor Type
if not IsValidIdent(Params.AncestorType) then begin if not IsValidIdent(Params.AncestorType) then begin
@ -835,6 +866,7 @@ begin
x:=Max(x,PalettePageLabel.Left+PalettePageLabel.Width); x:=Max(x,PalettePageLabel.Left+PalettePageLabel.Width);
x:=Max(x,ComponentUnitFileLabel.Left+ComponentUnitFileLabel.Width); x:=Max(x,ComponentUnitFileLabel.Left+ComponentUnitFileLabel.Width);
x:=Max(x,ComponentUnitNameLabel.Left+ComponentUnitNameLabel.Width); x:=Max(x,ComponentUnitNameLabel.Left+ComponentUnitNameLabel.Width);
x:=Max(x,ComponentIconLabel.Left+ComponentIconLabel.Width);
AncestorComboBox.Left:=x+6; AncestorComboBox.Left:=x+6;
end; end;
@ -1038,6 +1070,10 @@ begin
Text:=''; Text:='';
end; end;
ComponentIconLabel.Caption:='Icon (maximum 24x24)';
ComponentIconSpeedButton.Width:=ComponentPaletteBtnWidth;
ComponentIconSpeedButton.Height:=ComponentPaletteBtnHeight;
with NewComponentButton do begin with NewComponentButton do begin
Caption:=lisLazBuildOk; Caption:=lisLazBuildOk;
end; end;
@ -1240,6 +1276,37 @@ begin
Result:=-1; Result:=-1;
end; end;
procedure TAddToPackageDlg.LoadComponentIcon(AFilename: string);
var
ShortFilename: String;
Image: TImage;
begin
try
Image:=TImage.Create(nil);
try
Image.Picture.LoadFromFile(AFilename);
ComponentIconSpeedButton.Glyph.Assign(Image.Picture.Graphic);
ShortFilename:=AFilename;
LazPackage.ShortenFilename(ShortFilename,true);
ComponentIconSpeedButton.Hint:=
ShortFilename+' ('+IntToStr(ComponentIconSpeedButton.Glyph.Width)
+'x'+IntToStr(ComponentIconSpeedButton.Glyph.Height)+')';
FComponentIconFilename:=AFilename;
finally
Image.Free;
end;
except
on E: Exception do begin
MessageDlg(lisCCOErrorCaption,
Format(lisErrorLoadingFile2, [AFilename, #13, E.Message]), mtError, [
mbCancel], 0);
ComponentIconSpeedButton.Glyph.Clear;
FComponentIconFilename:='';
ComponentIconSpeedButton.Hint:=lisNoneClickToChooseOne;
end;
end;
end;
procedure TAddToPackageDlg.UpdateAvailableAncestorTypes; procedure TAddToPackageDlg.UpdateAvailableAncestorTypes;
var var
ANode: TAVLTreeNode; ANode: TAVLTreeNode;

View File

@ -1112,7 +1112,7 @@ procedure TPackageEditorForm.AddBitBtnClick(Sender: TObject);
// add file // add file
with AddParams do with AddParams do
FNextSelectedPart := LazPackage.AddFile(UnitFilename,Unit_Name,FileType, FNextSelectedPart := LazPackage.AddFile(UnitFilename,Unit_Name,FileType,
PkgFileFlags,cpNormal); PkgFileFlags,cpNormal);
// add dependency // add dependency
if AddParams.Dependency<>nil then begin if AddParams.Dependency<>nil then begin
PackageGraph.AddDependencyToPackage(LazPackage,AddParams.Dependency); PackageGraph.AddDependencyToPackage(LazPackage,AddParams.Dependency);

View File

@ -45,7 +45,7 @@ uses
{$ENDIF} {$ENDIF}
// FCL, LCL // FCL, LCL
TypInfo, Classes, SysUtils, LCLProc, Forms, Controls, Dialogs, Menus, TypInfo, Classes, SysUtils, LCLProc, Forms, Controls, Dialogs, Menus,
StringHashList, Translations, StringHashList, Translations, LResources,
// codetools // codetools
CodeToolsConfig, CodeToolManager, CodeCache, NonPascalCodeTools, CodeToolsConfig, CodeToolManager, CodeCache, NonPascalCodeTools,
BasicCodeTools, DefineTemplates, FileProcs, AVL_Tree, Laz_XMLCfg, BasicCodeTools, DefineTemplates, FileProcs, AVL_Tree, Laz_XMLCfg,
@ -784,8 +784,59 @@ var
UsesLine: String; UsesLine: String;
NewSource: String; NewSource: String;
UnitDirectives: String; UnitDirectives: String;
IconLRSFilename: String;
BinFileStream: TFileStream;
BinMemStream: TMemoryStream;
BinExt: String;
ResourceType: String;
ResourceName: String;
ResMemStream: TMemoryStream;
CodeBuf: TCodeBuffer;
begin begin
Result:=mrCancel; Result:=mrCancel;
// create icon resource
IconLRSFilename:='';
if Params.IconFile<>'' then begin
IconLRSFilename:=ChangeFileExt(Params.UnitFilename,'')+'_icon.lrs';
CodeBuf:=CodeToolBoss.CreateFile(IconLRSFilename);
if CodeBuf=nil then begin
debugln(['TPkgManager.OnPackageEditorCreateFile file create failed: ',IconLRSFilename]);
exit;
end;
try
BinFileStream:=TFileStream.Create(UTF8ToSys(Params.IconFile),fmOpenRead);
try
BinMemStream:=TMemoryStream.Create;
ResMemStream:=TMemoryStream.Create;
try
BinMemStream.CopyFrom(BinFileStream,BinFileStream.Size);
BinMemStream.Position:=0;
BinExt:=uppercase(ExtractFileExt(Params.IconFile));
ResourceType:=copy(BinExt,2,length(BinExt)-1);
ResourceName:=ExtractFileNameOnly(Params.IconFile);
BinaryToLazarusResourceCode(BinMemStream,ResMemStream
,ResourceName,ResourceType);
ResMemStream.Position:=0;
CodeBuf.LoadFromStream(ResMemStream);
Result:=SaveCodeBuffer(CodeBuf);
if Result<>mrOk then exit;
finally
BinMemStream.Free;
ResMemStream.Free;
end;
finally
BinFileStream.Free;
end;
except
on E: Exception do begin
MessageDlg(lisCCOErrorCaption,
Format(lisErrorLoadingFile2, [Params.IconFile, #13, E.Message]), mtError, [
mbCancel], 0);
end;
end;
end;
// create sourcecode // create sourcecode
LE:=LineEnding; LE:=LineEnding;
UsesLine:='Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs'; UsesLine:='Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs';
@ -824,7 +875,11 @@ begin
+'implementation'+LE +'implementation'+LE
+LE +LE
+'procedure Register;'+LE +'procedure Register;'+LE
+'begin'+LE +'begin'+LE;
if IconLRSFilename<>'' then
NewSource:=NewSource
+' {$I '+ExtractFileName(IconLRSFilename)+'}'+LE;
NewSource:=NewSource
+' RegisterComponents('''+Params.PageName+''',['+Params.NewClassName+']);'+LE +' RegisterComponents('''+Params.PageName+''',['+Params.NewClassName+']);'+LE
+'end;'+LE +'end;'+LE
+LE +LE