mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 13:09:35 +02:00
IDE: Rename control in designer by pressing F2. Issue #23497
git-svn-id: trunk@39660 -
This commit is contained in:
parent
074f42f249
commit
6bad0c04f9
@ -53,15 +53,13 @@ type
|
||||
property NewComponent: TComponent read FNewComponent write SetNewComponent;
|
||||
end;
|
||||
|
||||
function ShowComponentNameDialog(LookupRoot: TComponent; NewComponent: TComponent;
|
||||
var NewName: string): TModalResult;
|
||||
function ShowComponentNameDialog(LookupRoot: TComponent; NewComponent: TComponent): string;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
function ShowComponentNameDialog(LookupRoot: TComponent; NewComponent: TComponent;
|
||||
var NewName: string): TModalResult;
|
||||
function ShowComponentNameDialog(LookupRoot: TComponent; NewComponent: TComponent): string;
|
||||
var
|
||||
AskCompNameDialog: TAskCompNameDialog;
|
||||
begin
|
||||
@ -69,10 +67,10 @@ begin
|
||||
try
|
||||
AskCompNameDialog.LookupRoot:=LookupRoot;
|
||||
AskCompNameDialog.NewComponent:=NewComponent;
|
||||
AskCompNameDialog.NewName:=NewName;
|
||||
Result:=AskCompNameDialog.ShowModal;
|
||||
if Result=mrOk then
|
||||
NewName:=AskCompNameDialog.NewName;
|
||||
AskCompNameDialog.NewName:=NewComponent.Name;
|
||||
Result:=NewComponent.Name; // Default name is the component's current name.
|
||||
if AskCompNameDialog.ShowModal=mrOk then
|
||||
Result:=AskCompNameDialog.NewName;
|
||||
finally
|
||||
AskCompNameDialog.Free;
|
||||
end;
|
||||
|
@ -1850,7 +1850,6 @@ var
|
||||
NewParentControl: TWinControl;
|
||||
NewComponent: TComponent;
|
||||
NewComponentClass: TComponentClass;
|
||||
NewName: String;
|
||||
DisableAutoSize: Boolean;
|
||||
NewControl: TControl;
|
||||
begin
|
||||
@ -1961,12 +1960,9 @@ var
|
||||
if Assigned(FOnSetDesigning) then
|
||||
FOnSetDesigning(Self,NewComponent,True);
|
||||
|
||||
if EnvironmentOptions.CreateComponentFocusNameProperty then begin
|
||||
if EnvironmentOptions.CreateComponentFocusNameProperty then
|
||||
// ask user for name
|
||||
NewName:=NewComponent.Name;
|
||||
ShowComponentNameDialog(LookupRoot,NewComponent,NewName);
|
||||
NewComponent.Name:=NewName;
|
||||
end;
|
||||
NewComponent.Name:=ShowComponentNameDialog(LookupRoot,NewComponent);
|
||||
|
||||
// tell IDE about the new component (e.g. add it to the source)
|
||||
NotifyPersistentAdded(NewComponent);
|
||||
@ -2317,7 +2313,9 @@ var
|
||||
Shift: TShiftState;
|
||||
Command: word;
|
||||
Handled: boolean;
|
||||
|
||||
Current: TComponent;
|
||||
NewName: String;
|
||||
|
||||
procedure Nudge(x, y: integer);
|
||||
begin
|
||||
if (ssCtrl in Shift) then
|
||||
@ -2341,16 +2339,12 @@ begin
|
||||
{$IFDEF VerboseDesigner}
|
||||
DebugLn(['TDesigner.KEYDOWN ',TheMessage.CharCode,' ',TheMessage.KeyData]);
|
||||
{$ENDIF}
|
||||
|
||||
Shift := KeyDataToShiftState(TheMessage.KeyData);
|
||||
|
||||
Handled := False;
|
||||
|
||||
if Mediator<>nil then
|
||||
Mediator.KeyDown(Sender,TheMessage.CharCode,Shift);
|
||||
|
||||
Command := FTheFormEditor.TranslateKeyToDesignerCommand(
|
||||
TheMessage.CharCode, Shift);
|
||||
Command := FTheFormEditor.TranslateKeyToDesignerCommand(TheMessage.CharCode, Shift);
|
||||
//DebugLn(['TDesigner.KEYDOWN Command=',dbgs(Command),' ',TheMessage.CharCode,' ',dbgs(Shift)]);
|
||||
DoProcessCommand(Self, Command, Handled);
|
||||
//DebugLn(['TDesigner.KeyDown Command=',Command,' Handled=',Handled,' TheMessage.CharCode=',TheMessage.CharCode]);
|
||||
@ -2395,6 +2389,17 @@ begin
|
||||
DoSelectAll
|
||||
else
|
||||
Handled := False;
|
||||
|
||||
VK_F2:
|
||||
if (ControlSelection.Count=1) and ControlSelection[0].IsTComponent then begin
|
||||
Current := TComponent(ControlSelection[0].Persistent);
|
||||
NewName := ShowComponentNameDialog(LookupRoot, Current);
|
||||
if NewName <> Current.Name then begin
|
||||
Current.Name:=NewName;
|
||||
GlobalDesignHook.ComponentRenamed(Current);
|
||||
end;
|
||||
end
|
||||
|
||||
else
|
||||
Handled := False;
|
||||
end;
|
||||
|
@ -13276,6 +13276,10 @@ end;
|
||||
procedure TMainIDE.OnPropHookComponentRenamed(AComponent: TComponent);
|
||||
begin
|
||||
FormEditor1.UpdateComponentName(AComponent);
|
||||
// Component can be renamed in designer and OI must be updated
|
||||
if ObjectInspector1<>nil then
|
||||
// This does not update the Name property on Windows. ToDo: find out how to update it.
|
||||
ObjectInspector1.Update;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.OnPropHookModified(Sender: TObject);
|
||||
|
Loading…
Reference in New Issue
Block a user