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 ...';
dlgCCOTestCompilerDate = 'Test: Checking compiler date ...';
lisCCOErrorCaption = 'Error';
lisErrorLoadingFile2 = 'Error loading file "%s":%s%s';
lisNoneClickToChooseOne = 'none, click to choose one';
lisTreeNeedsRefresh = 'Tree needs refresh';
lisEMDEmtpyMethods = 'Emtpy Methods';
lisEMDSearchInTheseClassSections = 'Search in these class sections:';

View File

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

View File

@ -38,9 +38,9 @@ unit AddToPackageDlg;
interface
uses
Math, Classes, SysUtils, LCLType, Forms, Controls, Buttons,
Math, Classes, SysUtils, LCLType, Forms, Controls, Buttons, ExtDlgs,
StdCtrls, ExtCtrls, Dialogs, FileUtil, ComCtrls, AVL_Tree, LCLProc,
NewItemIntf, ProjectIntf, PackageIntf,
NewItemIntf, ProjectIntf, PackageIntf, FormEditingIntf,
LazarusIDEStrConsts, IDEWindowIntf, InputHistory, CodeToolManager, IDEDefs,
IDEProcs, EnvironmentOpts, PackageSystem, PackageDefs, ComponentReg,
AddDirToPkgDlg;
@ -57,6 +57,7 @@ type
);
TAddToPkgResult = class
public
Pkg: TLazPackage;
AddType: TAddToPkgType;
Dependency: TPkgDependency;
@ -68,6 +69,7 @@ type
FileType: TPkgFileType;
PkgFileFlags: TPkgFileFlags;
UsedUnitname: string;
IconFile: string;
AutoAddLFMFile: boolean;
AutoAddLRSFile: boolean;
NewItem: TNewIDEItemTemplate;
@ -84,6 +86,8 @@ type
TAddToPackageDlg = class(TForm)
CancelDependButton: TBitBtn;
CancelNewComponentButton: TBitBtn;
ComponentIconLabel: TLabel;
ComponentIconSpeedButton: TSpeedButton;
NewCompBtnPanel: TPanel;
NewComponentButton: TBitBtn;
NewDepBtnPanel: TPanel;
@ -141,6 +145,7 @@ type
procedure CancelAddUnitButtonClick(Sender: TObject);
procedure CancelNewComponentButtonClick(Sender: TObject);
procedure ClassNameEditChange(Sender: TObject);
procedure ComponentIconSpeedButtonClick(Sender: TObject);
procedure ComponentUnitFileBrowseButtonClick(Sender: TObject);
procedure ComponentUnitFileShortenButtonClick(Sender: TObject);
procedure FilesAddButtonClick(Sender: TObject);
@ -166,6 +171,7 @@ type
FOnGetUnitRegisterInfo: TOnGetUnitRegisterInfo;
fPkgComponents: TAVLTree;// tree of TPkgComponent
fPackages: TAVLTree;// tree of TLazPackage or TPackageLink
FComponentIconFilename: string;
procedure SetLazPackage(const AValue: TLazPackage);
procedure SetupComponents;
procedure SetupNewFilePage;
@ -179,6 +185,7 @@ type
function SwitchRelativeAbsoluteFilename(const Filename: string): string;
procedure FillNewFileTreeView;
function FindFileInFilesList(AFilename: string): Integer;
procedure LoadComponentIcon(AFilename: string);
public
Params: TAddToPkgResult;
procedure UpdateAvailableAncestorTypes;
@ -457,6 +464,29 @@ begin
AutoCompleteNewComponentUnitName;
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);
var
SaveDialog: TSaveDialog;
@ -724,6 +754,7 @@ begin
Params.Unit_Name:=ComponentUnitNameEdit.Text;
Params.UnitFilename:=ComponentUnitFileEdit.Text;
Params.UsedUnitname:='';
Params.IconFile:=FComponentIconFilename;
// check Ancestor Type
if not IsValidIdent(Params.AncestorType) then begin
@ -835,6 +866,7 @@ begin
x:=Max(x,PalettePageLabel.Left+PalettePageLabel.Width);
x:=Max(x,ComponentUnitFileLabel.Left+ComponentUnitFileLabel.Width);
x:=Max(x,ComponentUnitNameLabel.Left+ComponentUnitNameLabel.Width);
x:=Max(x,ComponentIconLabel.Left+ComponentIconLabel.Width);
AncestorComboBox.Left:=x+6;
end;
@ -1038,6 +1070,10 @@ begin
Text:='';
end;
ComponentIconLabel.Caption:='Icon (maximum 24x24)';
ComponentIconSpeedButton.Width:=ComponentPaletteBtnWidth;
ComponentIconSpeedButton.Height:=ComponentPaletteBtnHeight;
with NewComponentButton do begin
Caption:=lisLazBuildOk;
end;
@ -1240,6 +1276,37 @@ begin
Result:=-1;
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;
var
ANode: TAVLTreeNode;

View File

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

View File

@ -45,7 +45,7 @@ uses
{$ENDIF}
// FCL, LCL
TypInfo, Classes, SysUtils, LCLProc, Forms, Controls, Dialogs, Menus,
StringHashList, Translations,
StringHashList, Translations, LResources,
// codetools
CodeToolsConfig, CodeToolManager, CodeCache, NonPascalCodeTools,
BasicCodeTools, DefineTemplates, FileProcs, AVL_Tree, Laz_XMLCfg,
@ -784,8 +784,59 @@ var
UsesLine: String;
NewSource: String;
UnitDirectives: String;
IconLRSFilename: String;
BinFileStream: TFileStream;
BinMemStream: TMemoryStream;
BinExt: String;
ResourceType: String;
ResourceName: String;
ResMemStream: TMemoryStream;
CodeBuf: TCodeBuffer;
begin
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
LE:=LineEnding;
UsesLine:='Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs';
@ -824,7 +875,11 @@ begin
+'implementation'+LE
+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
+'end;'+LE
+LE