mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 06:39:39 +02:00
Merged revision(s) 61973-61974 #c32570a990-#c32570a990 from trunk:
Designer: Explode a big WITH block in TDesigner.ExecuteUndoItem. Use another temp variable. ........ Designer: Support Undo for properties of subcomponents like 'LabeledEdit1.SubLabel'. Issue #36071. ........ git-svn-id: branches/fixes_2_0@61993 -
This commit is contained in:
parent
0bfecba09a
commit
6706333a0b
@ -1421,81 +1421,82 @@ procedure TDesigner.ExecuteUndoItem(IsActUndo: boolean);
|
|||||||
|
|
||||||
procedure SetPropVal(AVal: variant);
|
procedure SetPropVal(AVal: variant);
|
||||||
var
|
var
|
||||||
tmpStr, str: string;
|
tmpStr, tmpFieldN, str: string;
|
||||||
tmpCompName: TComponentName;
|
tmpCompN: TComponentName;
|
||||||
tmpObj: TObject;
|
tmpObj: TObject;
|
||||||
tmpInt: integer;
|
tmpInt: integer;
|
||||||
aPropType: PTypeInfo;
|
aPropType: PTypeInfo;
|
||||||
begin
|
begin
|
||||||
tmpCompName := FUndoList[FUndoCurr].compName;
|
tmpCompN := FUndoList[FUndoCurr].compName;
|
||||||
if FUndoList[FUndoCurr].fieldName = 'Name' then
|
tmpFieldN := FUndoList[FUndoCurr].fieldName;
|
||||||
|
if tmpFieldN = 'Name' then
|
||||||
begin
|
begin
|
||||||
if IsActUndo then
|
if IsActUndo then
|
||||||
tmpCompName := FUndoList[FUndoCurr].newVal
|
tmpCompN := FUndoList[FUndoCurr].newVal
|
||||||
else
|
else
|
||||||
tmpCompName := FUndoList[FUndoCurr].oldVal;
|
tmpCompN := FUndoList[FUndoCurr].oldVal;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if FForm.Name <> tmpCompName then
|
if FForm.Name <> tmpCompN then
|
||||||
tmpObj := TObject(FForm.FindComponent(tmpCompName))
|
tmpObj := TObject(FForm.FindSubComponent(tmpCompN))
|
||||||
else
|
else
|
||||||
tmpObj := TObject(FForm);
|
tmpObj := TObject(FForm);
|
||||||
|
|
||||||
if VarIsError(AVal) or VarIsEmpty(AVal) or VarIsNull(AVal) then
|
if VarIsError(AVal) or VarIsEmpty(AVal) or VarIsNull(AVal) then
|
||||||
ShowMessage('error: invalid var type');
|
ShowMessage('error: invalid var type');
|
||||||
tmpStr := VarToStr(AVal);
|
tmpStr := VarToStr(AVal);
|
||||||
|
//DebugLn(['TDesigner.ExecuteUndoItem: FForm=', FForm.Name, ', CompName=', tmpCompN,
|
||||||
|
// ', FieldName=', tmpFieldN, ', tmpObj=', tmpObj, ', tmpStr=', tmpStr, ', IsActUndo=', IsActUndo]);
|
||||||
|
|
||||||
with FUndoList[FUndoCurr] do begin
|
if FUndoList[FUndoCurr].propInfo<>nil then
|
||||||
if propInfo<>nil then
|
begin
|
||||||
begin
|
aPropType:=FUndoList[FUndoCurr].propInfo^.propType;
|
||||||
aPropType:=propInfo^.propType;
|
case aPropType^.Kind of
|
||||||
case aPropType^.Kind of
|
tkInteger, tkInt64:
|
||||||
tkInteger, tkInt64:
|
|
||||||
begin
|
|
||||||
if (aPropType^.Name = 'TColor') or
|
|
||||||
(aPropType^.Name = 'TGraphicsColor') then
|
|
||||||
SetOrdProp(tmpObj, fieldName, StringToColor(tmpStr))
|
|
||||||
else if aPropType^.Name = 'TCursor' then
|
|
||||||
SetOrdProp(tmpObj, fieldName, StringToCursor(tmpStr))
|
|
||||||
else
|
|
||||||
SetOrdProp(tmpObj, fieldName, StrToInt(tmpStr));
|
|
||||||
end;
|
|
||||||
tkChar, tkWChar, tkUChar:
|
|
||||||
begin
|
|
||||||
if Length(tmpStr) = 1 then
|
|
||||||
SetOrdProp(tmpObj, FUndoList[FUndoCurr].fieldName, Ord(tmpStr[1]))
|
|
||||||
else if (tmpStr[1] = '#') then
|
|
||||||
begin
|
|
||||||
str := Copy(tmpStr, 2, Length(tmpStr) - 1);
|
|
||||||
if TryStrToInt(str, tmpInt) and (tmpInt >= 0) and (tmpInt <= High(Byte)) then
|
|
||||||
SetOrdProp(tmpObj, FUndoList[FUndoCurr].fieldName, tmpInt);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
tkEnumeration:
|
|
||||||
SetEnumProp(tmpObj, FUndoList[FUndoCurr].fieldName, tmpStr);
|
|
||||||
tkFloat:
|
|
||||||
SetFloatProp(tmpObj, fieldName, StrToFloat(tmpStr));
|
|
||||||
tkBool:
|
|
||||||
SetOrdProp(tmpObj, FUndoList[FUndoCurr].fieldName, Integer(StrToBoolOI(tmpStr)));
|
|
||||||
tkString, tkLString, tkAString, tkUString, tkWString:
|
|
||||||
SetStrProp(tmpObj, fieldName, tmpStr);
|
|
||||||
tkSet:
|
|
||||||
SetSetProp(tmpObj, FUndoList[FUndoCurr].fieldName, tmpStr);
|
|
||||||
tkVariant:
|
|
||||||
SetVariantProp(tmpObj, fieldName, AVal);
|
|
||||||
else
|
|
||||||
ShowMessage(Format('error: unknown TTypeKind(%d)', [Integer(aPropType^.Kind)]));
|
|
||||||
end;
|
|
||||||
end else begin
|
|
||||||
// field is not published
|
|
||||||
if tmpObj is TComponent then
|
|
||||||
begin
|
begin
|
||||||
// special case: TComponent.Left,Top
|
if (aPropType^.Name = 'TColor') or
|
||||||
if CompareText(fieldName,'Left')=0 then
|
(aPropType^.Name = 'TGraphicsColor') then
|
||||||
SetDesignInfoLeft(TComponent(tmpObj),StrToInt(tmpStr))
|
SetOrdProp(tmpObj, tmpFieldN, StringToColor(tmpStr))
|
||||||
else if CompareText(fieldName,'Top')=0 then
|
else if aPropType^.Name = 'TCursor' then
|
||||||
SetDesignInfoTop(TComponent(tmpObj),StrToInt(tmpStr));
|
SetOrdProp(tmpObj, tmpFieldN, StringToCursor(tmpStr))
|
||||||
|
else
|
||||||
|
SetOrdProp(tmpObj, tmpFieldN, StrToInt(tmpStr));
|
||||||
end;
|
end;
|
||||||
|
tkChar, tkWChar, tkUChar:
|
||||||
|
begin
|
||||||
|
if Length(tmpStr) = 1 then
|
||||||
|
SetOrdProp(tmpObj, tmpFieldN, Ord(tmpStr[1]))
|
||||||
|
else if (tmpStr[1] = '#') then
|
||||||
|
begin
|
||||||
|
str := Copy(tmpStr, 2, Length(tmpStr) - 1);
|
||||||
|
if TryStrToInt(str, tmpInt) and (tmpInt >= 0) and (tmpInt <= High(Byte)) then
|
||||||
|
SetOrdProp(tmpObj, tmpFieldN, tmpInt);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
tkEnumeration:
|
||||||
|
SetEnumProp(tmpObj, tmpFieldN, tmpStr);
|
||||||
|
tkFloat:
|
||||||
|
SetFloatProp(tmpObj, tmpFieldN, StrToFloat(tmpStr));
|
||||||
|
tkBool:
|
||||||
|
SetOrdProp(tmpObj, tmpFieldN, Integer(StrToBoolOI(tmpStr)));
|
||||||
|
tkString, tkLString, tkAString, tkUString, tkWString:
|
||||||
|
SetStrProp(tmpObj, tmpFieldN, tmpStr);
|
||||||
|
tkSet:
|
||||||
|
SetSetProp(tmpObj, tmpFieldN, tmpStr);
|
||||||
|
tkVariant:
|
||||||
|
SetVariantProp(tmpObj, tmpFieldN, AVal);
|
||||||
|
else
|
||||||
|
ShowMessage(Format('error: unknown TTypeKind(%d)', [Integer(aPropType^.Kind)]));
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
// field is not published
|
||||||
|
if tmpObj is TComponent then
|
||||||
|
begin
|
||||||
|
// special case: TComponent.Left,Top
|
||||||
|
if CompareText(tmpFieldN,'Left')=0 then
|
||||||
|
SetDesignInfoLeft(TComponent(tmpObj),StrToInt(tmpStr))
|
||||||
|
else if CompareText(tmpFieldN,'Top')=0 then
|
||||||
|
SetDesignInfoTop(TComponent(tmpObj),StrToInt(tmpStr));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
PropertyEditorHook.Modified(tmpObj);
|
PropertyEditorHook.Modified(tmpObj);
|
||||||
@ -1802,6 +1803,7 @@ var
|
|||||||
SaveControlSelection: TControlSelection;
|
SaveControlSelection: TControlSelection;
|
||||||
AStream: TStringStream;
|
AStream: TStringStream;
|
||||||
APropInfo: PPropInfo;
|
APropInfo: PPropInfo;
|
||||||
|
Comp: TComponent;
|
||||||
begin
|
begin
|
||||||
Result := (FUndoLock = 0);
|
Result := (FUndoLock = 0);
|
||||||
if not Result then Exit;
|
if not Result then Exit;
|
||||||
@ -1857,9 +1859,12 @@ begin
|
|||||||
compName := '';
|
compName := '';
|
||||||
parentName := '';
|
parentName := '';
|
||||||
if aPersistent is TComponent then begin
|
if aPersistent is TComponent then begin
|
||||||
compName := TComponent(aPersistent).Name;
|
Comp := TComponent(aPersistent);
|
||||||
if TComponent(aPersistent).HasParent then
|
compName := Comp.Name;
|
||||||
parentName := TComponent(aPersistent).GetParentComponent.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;
|
end;
|
||||||
opType := aOpType;
|
opType := aOpType;
|
||||||
isValid := true;
|
isValid := true;
|
||||||
|
@ -1616,6 +1616,7 @@ type
|
|||||||
function GetParentComponent: TComponent; override;
|
function GetParentComponent: TComponent; override;
|
||||||
function IsParentOf(AControl: TControl): boolean; virtual;
|
function IsParentOf(AControl: TControl): boolean; virtual;
|
||||||
function GetTopParent: TControl;
|
function GetTopParent: TControl;
|
||||||
|
function FindSubComponent(AName: string): TComponent;
|
||||||
function IsVisible: Boolean; virtual;// checks parents too
|
function IsVisible: Boolean; virtual;// checks parents too
|
||||||
function IsControlVisible: Boolean; virtual;// does not check parents
|
function IsControlVisible: Boolean; virtual;// does not check parents
|
||||||
function IsEnabled: Boolean; // checks parent too
|
function IsEnabled: Boolean; // checks parent too
|
||||||
|
@ -5244,10 +5244,6 @@ begin
|
|||||||
Result := Parent;
|
Result := Parent;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
|
||||||
function TControl.IsParentOf(AControl: TControl): boolean;
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------}
|
|
||||||
function TControl.IsParentOf(AControl: TControl): boolean;
|
function TControl.IsParentOf(AControl: TControl): boolean;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
@ -5266,6 +5262,25 @@ begin
|
|||||||
Result := Result.Parent;
|
Result := Result.Parent;
|
||||||
end;
|
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
|
Method: TControl.SendToBack
|
||||||
Params: None
|
Params: None
|
||||||
|
Loading…
Reference in New Issue
Block a user