mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 02:58:05 +02:00
Designer: AskCompNameDialog redone. Issue #28116, patch from Alexey Torgashin
git-svn-id: trunk@49073 -
This commit is contained in:
parent
579e2fa2e6
commit
929870eadc
@ -1,17 +1,18 @@
|
||||
object AskCompNameDialog: TAskCompNameDialog
|
||||
Left = 299
|
||||
Height = 91
|
||||
Height = 135
|
||||
Top = 177
|
||||
Width = 366
|
||||
BorderIcons = [biSystemMenu]
|
||||
Caption = 'AskCompNameDialog'
|
||||
ClientHeight = 91
|
||||
ClientHeight = 135
|
||||
ClientWidth = 366
|
||||
OnCreate = FormCreate
|
||||
Position = poDesktopCenter
|
||||
LCLVersion = '0.9.29'
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.5'
|
||||
object Label1: TLabel
|
||||
Left = 6
|
||||
Height = 18
|
||||
Height = 15
|
||||
Top = 6
|
||||
Width = 300
|
||||
Align = alTop
|
||||
@ -24,8 +25,8 @@ object AskCompNameDialog: TAskCompNameDialog
|
||||
end
|
||||
object NameEdit: TEdit
|
||||
Left = 6
|
||||
Height = 22
|
||||
Top = 30
|
||||
Height = 23
|
||||
Top = 27
|
||||
Width = 354
|
||||
Align = alTop
|
||||
BorderSpacing.Around = 6
|
||||
@ -35,24 +36,36 @@ object AskCompNameDialog: TAskCompNameDialog
|
||||
TabOrder = 0
|
||||
Text = 'NameEdit'
|
||||
end
|
||||
object OkButton: TButton
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 26
|
||||
Top = 103
|
||||
Width = 354
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
CloseButton.DefaultCaption = True
|
||||
CancelButton.Name = 'CancelButton'
|
||||
CancelButton.DefaultCaption = True
|
||||
TabOrder = 2
|
||||
ShowButtons = [pbOK, pbCancel]
|
||||
ShowBevel = False
|
||||
end
|
||||
object InfoPanel: TPanel
|
||||
AnchorSideLeft.Control = NameEdit
|
||||
AnchorSideTop.Control = NameEdit
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Control = NameEdit
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 276
|
||||
Height = 20
|
||||
Top = 58
|
||||
Width = 84
|
||||
Anchors = [akTop, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'OkButton'
|
||||
Constraints.MinWidth = 75
|
||||
Default = True
|
||||
OnClick = OkButtonClick
|
||||
ParentShowHint = False
|
||||
ShowHint = True
|
||||
Left = 6
|
||||
Height = 38
|
||||
Top = 56
|
||||
Width = 354
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
BevelOuter = bvNone
|
||||
TabOrder = 1
|
||||
end
|
||||
end
|
||||
|
@ -26,53 +26,51 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LCLProc, FileUtil, Forms, Controls, Graphics,
|
||||
Dialogs, StdCtrls, PropEdits, LazarusIDEStrConsts;
|
||||
Dialogs, StdCtrls, ButtonPanel, ExtCtrls, PropEdits, LazarusIDEStrConsts;
|
||||
|
||||
type
|
||||
|
||||
{ TAskCompNameDialog }
|
||||
|
||||
TAskCompNameDialog = class(TForm)
|
||||
OkButton: TButton;
|
||||
ButtonPanel1: TButtonPanel;
|
||||
InfoPanel: TPanel;
|
||||
NameEdit: TEdit;
|
||||
Label1: TLabel;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure NameEditChange(Sender: TObject);
|
||||
procedure OkButtonClick(Sender: TObject);
|
||||
private
|
||||
FLookupRoot: TComponent;
|
||||
FNewComponent: TComponent;
|
||||
function GetNewName: TComponentName;
|
||||
procedure SetLookupRoot(const AValue: TComponent);
|
||||
procedure SetNewComponent(const AValue: TComponent);
|
||||
procedure SetNewName(const AValue: TComponentName);
|
||||
public
|
||||
function IsValidName(AName: TComponentName; out ErrorMsg: string): boolean;
|
||||
property LookupRoot: TComponent read FLookupRoot write SetLookupRoot;
|
||||
property LookupRoot: TComponent read FLookupRoot write FLookupRoot;
|
||||
property NewName: TComponentName read GetNewName write SetNewName;
|
||||
property NewComponent: TComponent read FNewComponent write SetNewComponent;
|
||||
property NewComponent: TComponent read FNewComponent write FNewComponent;
|
||||
end;
|
||||
|
||||
function ShowComponentNameDialog(LookupRoot: TComponent; NewComponent: TComponent): string;
|
||||
function ShowComponentNameDialog(ALookupRoot: TComponent; ANewComponent: TComponent): string;
|
||||
|
||||
implementation
|
||||
|
||||
uses Math;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
function ShowComponentNameDialog(LookupRoot: TComponent; NewComponent: TComponent): string;
|
||||
var
|
||||
AskCompNameDialog: TAskCompNameDialog;
|
||||
function ShowComponentNameDialog(ALookupRoot: TComponent; ANewComponent: TComponent): string;
|
||||
begin
|
||||
AskCompNameDialog:=TAskCompNameDialog.Create(nil);
|
||||
with TAskCompNameDialog.Create(nil) do
|
||||
try
|
||||
AskCompNameDialog.LookupRoot:=LookupRoot;
|
||||
AskCompNameDialog.NewComponent:=NewComponent;
|
||||
AskCompNameDialog.NewName:=NewComponent.Name;
|
||||
Result:=NewComponent.Name; // Default name is the component's current name.
|
||||
if AskCompNameDialog.ShowModal=mrOk then
|
||||
Result:=AskCompNameDialog.NewName;
|
||||
LookupRoot:=ALookupRoot;
|
||||
NewComponent:=ANewComponent;
|
||||
NewName:=NewComponent.Name;
|
||||
Result:=NewComponent.Name; // Default name is the component's current name.
|
||||
if ShowModal=mrOk then
|
||||
Result:=NewName;
|
||||
finally
|
||||
AskCompNameDialog.Free;
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -83,34 +81,18 @@ begin
|
||||
Caption:=lisChooseName;
|
||||
Label1.Caption:=lisChooseANameForTheComponent;
|
||||
NameEdit.Hint:=lisTheComponentNameMustBeUniqueInAllComponentsOnTheFo;
|
||||
OkButton.Caption:=lisMenuOk;
|
||||
OkButton.Enabled:=false;
|
||||
ButtonPanel1.OKButton.Caption:=lisOk;
|
||||
ButtonPanel1.CancelButton.Caption:=lisCancel;
|
||||
ButtonPanel1.OKButton.Enabled:=false;
|
||||
end;
|
||||
|
||||
procedure TAskCompNameDialog.NameEditChange(Sender: TObject);
|
||||
var
|
||||
ErrorMsg: string;
|
||||
begin
|
||||
OkButton.Enabled:=IsValidName(NameEdit.Text,ErrorMsg);
|
||||
OkButton.ShowHint:=ErrorMsg<>'';
|
||||
OkButton.Hint:=ErrorMsg;
|
||||
end;
|
||||
|
||||
procedure TAskCompNameDialog.OkButtonClick(Sender: TObject);
|
||||
begin
|
||||
ModalResult:=mrOk;
|
||||
end;
|
||||
|
||||
procedure TAskCompNameDialog.SetLookupRoot(const AValue: TComponent);
|
||||
begin
|
||||
if FLookupRoot=AValue then exit;
|
||||
FLookupRoot:=AValue;
|
||||
end;
|
||||
|
||||
procedure TAskCompNameDialog.SetNewComponent(const AValue: TComponent);
|
||||
begin
|
||||
if FNewComponent=AValue then exit;
|
||||
FNewComponent:=AValue;
|
||||
ButtonPanel1.OKButton.Enabled:=IsValidName(NameEdit.Text,ErrorMsg);
|
||||
InfoPanel.Caption:=ErrorMsg;
|
||||
InfoPanel.Color:=IfThen(ErrorMsg<>'', clInfoBk, clDefault);
|
||||
end;
|
||||
|
||||
function TAskCompNameDialog.GetNewName: TComponentName;
|
||||
|
Loading…
Reference in New Issue
Block a user