Designer: Support Undo for properties of subcomponents like 'LabeledEdit1.SubLabel'. Issue #36071.

git-svn-id: trunk@61974 -
This commit is contained in:
juha 2019-10-03 22:58:20 +00:00
parent c32570a990
commit dcb8bd49fb
3 changed files with 30 additions and 8 deletions

View File

@ -1438,13 +1438,15 @@ procedure TDesigner.ExecuteUndoItem(IsActUndo: boolean);
end;
if FForm.Name <> tmpCompN then
tmpObj := TObject(FForm.FindComponent(tmpCompN))
tmpObj := TObject(FForm.FindSubComponent(tmpCompN))
else
tmpObj := TObject(FForm);
if VarIsError(AVal) or VarIsEmpty(AVal) or VarIsNull(AVal) then
ShowMessage('error: invalid var type');
tmpStr := VarToStr(AVal);
//DebugLn(['TDesigner.ExecuteUndoItem: FForm=', FForm.Name, ', CompName=', tmpCompN,
// ', FieldName=', tmpFieldN, ', tmpObj=', tmpObj, ', tmpStr=', tmpStr, ', IsActUndo=', IsActUndo]);
if FUndoList[FUndoCurr].propInfo<>nil then
begin
@ -1801,6 +1803,7 @@ var
SaveControlSelection: TControlSelection;
AStream: TStringStream;
APropInfo: PPropInfo;
Comp: TComponent;
begin
Result := (FUndoLock = 0);
if not Result then Exit;
@ -1856,9 +1859,12 @@ begin
compName := '';
parentName := '';
if aPersistent is TComponent then begin
compName := TComponent(aPersistent).Name;
if TComponent(aPersistent).HasParent then
parentName := TComponent(aPersistent).GetParentComponent.Name;
Comp := TComponent(aPersistent);
compName := Comp.Name;
if Comp.Owner <> LookupRoot then // This is a subcomponent.
compName := Comp.Owner.Name + '.' + compName; // Add owner to the name.
if Comp.HasParent then
parentName := Comp.GetParentComponent.Name;
end;
opType := aOpType;
isValid := true;

View File

@ -1629,6 +1629,7 @@ type
function GetParentComponent: TComponent; override;
function IsParentOf(AControl: TControl): boolean; virtual;
function GetTopParent: TControl;
function FindSubComponent(AName: string): TComponent;
function IsVisible: Boolean; virtual;// checks parents too
function IsControlVisible: Boolean; virtual;// does not check parents
function IsEnabled: Boolean; // checks parent too

View File

@ -5244,10 +5244,6 @@ begin
Result := Parent;
end;
{------------------------------------------------------------------------------
function TControl.IsParentOf(AControl: TControl): boolean;
------------------------------------------------------------------------------}
function TControl.IsParentOf(AControl: TControl): boolean;
begin
Result := False;
@ -5266,6 +5262,25 @@ begin
Result := Result.Parent;
end;
function TControl.FindSubComponent(AName: string): TComponent;
// Like TComponent.FindComponent but finds also a subcomponent which name is
// separated by a dot. For example 'LabeledEdit1.SubLabel'.
var
i: Integer;
SubName: String;
begin
i := Pos('.', AName);
if i > 0 then begin
SubName := Copy(AName, i+1, Length(AName));
Delete(AName, i, Length(AName));
end
else
SubName := '';
Result := FindComponent(AName);
if Assigned(Result) and (SubName<>'') then
Result := Result.FindComponent(SubName);
end;
{------------------------------------------------------------------------------
Method: TControl.SendToBack
Params: None