From dcb8bd49fb43bef26b95075d24c347c9067671d6 Mon Sep 17 00:00:00 2001 From: juha Date: Thu, 3 Oct 2019 22:58:20 +0000 Subject: [PATCH] Designer: Support Undo for properties of subcomponents like 'LabeledEdit1.SubLabel'. Issue #36071. git-svn-id: trunk@61974 - --- designer/designer.pp | 14 ++++++++++---- lcl/controls.pp | 1 + lcl/include/control.inc | 23 +++++++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/designer/designer.pp b/designer/designer.pp index 6062381fda..fc272c93d9 100644 --- a/designer/designer.pp +++ b/designer/designer.pp @@ -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; diff --git a/lcl/controls.pp b/lcl/controls.pp index d0ae64a219..ba69ca67d4 100644 --- a/lcl/controls.pp +++ b/lcl/controls.pp @@ -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 diff --git a/lcl/include/control.inc b/lcl/include/control.inc index 80186f2b50..3646b1cf25 100644 --- a/lcl/include/control.inc +++ b/lcl/include/control.inc @@ -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