Designer, OI: Synchronize z-order changes. Issue #20450, patch from Mike Thompson.

git-svn-id: trunk@47039 -
This commit is contained in:
juha 2014-11-30 13:13:08 +00:00
parent 9996c5feef
commit c589873743
2 changed files with 46 additions and 49 deletions

View File

@ -5320,6 +5320,7 @@ end;
procedure TObjectInspectorDlg.DoZOrderItemClick(Sender: TObject); procedure TObjectInspectorDlg.DoZOrderItemClick(Sender: TObject);
var var
Control: TControl; Control: TControl;
NewSelection: TPersistentSelectionList;
begin begin
if not (Sender is TMenuItem) then Exit; if not (Sender is TMenuItem) then Exit;
if (Selection.Count <> 1) or if (Selection.Count <> 1) or
@ -5333,6 +5334,25 @@ begin
2: Control.Parent.SetControlIndex(Control, Control.Parent.GetControlIndex(Control) + 1); 2: Control.Parent.SetControlIndex(Control, Control.Parent.GetControlIndex(Control) + 1);
3: Control.Parent.SetControlIndex(Control, Control.Parent.GetControlIndex(Control) - 1); 3: Control.Parent.SetControlIndex(Control, Control.Parent.GetControlIndex(Control) - 1);
end; end;
// Ensure controls that belong to a container are rearranged if required.
Control.Parent.ReAlign;
// Ensure the order of controls in the OI now reflects the new ZOrder
NewSelection := TPersistentSelectionList.Create;
try
NewSelection.ForceUpdate:=True;
NewSelection.Add(Control.Parent);
SetSelection(NewSelection);
NewSelection.Clear;
NewSelection.ForceUpdate:=True;
NewSelection.Add(Control);
SetSelection(NewSelection);
finally
NewSelection.Free;
end;
DoModified(Self); DoModified(Self);
end; end;

View File

@ -217,10 +217,7 @@ type
procedure DoShowTabOrderEditor; procedure DoShowTabOrderEditor;
procedure DoShowChangeClassDialog; procedure DoShowChangeClassDialog;
procedure DoShowObjectInspector; procedure DoShowObjectInspector;
procedure DoOrderMoveSelectionToFront; procedure DoChangeZOrder(TheAction: Integer);
procedure DoOrderMoveSelectionToBack;
procedure DoOrderForwardSelectionOne;
procedure DoOrderBackSelectionOne;
procedure GiveComponentsNames; procedure GiveComponentsNames;
procedure NotifyPersistentAdded(APersistent: TPersistent); procedure NotifyPersistentAdded(APersistent: TPersistent);
@ -1421,25 +1418,7 @@ begin
OnShowObjectInspector(Self); OnShowObjectInspector(Self);
end; end;
procedure TDesigner.DoOrderMoveSelectionToFront; procedure TDesigner.DoChangeZOrder(TheAction: Integer);
begin
if ControlSelection.Count <> 1 then Exit;
if not ControlSelection[0].IsTControl then Exit;
TControl(ControlSelection[0].Persistent).BringToFront;
Modified;
end;
procedure TDesigner.DoOrderMoveSelectionToBack;
begin
if ControlSelection.Count <> 1 then Exit;
if not ControlSelection[0].IsTControl then Exit;
TControl(ControlSelection[0].Persistent).SendToBack;
Modified;
end;
procedure TDesigner.DoOrderForwardSelectionOne;
var var
Control: TControl; Control: TControl;
Parent: TWinControl; Parent: TWinControl;
@ -1449,26 +1428,24 @@ begin
Control := TControl(ControlSelection[0].Persistent); Control := TControl(ControlSelection[0].Persistent);
Parent := Control.Parent; Parent := Control.Parent;
if Parent = nil then Exit; if (Parent = nil) and (TheAction in [2, 3]) then Exit;
Parent.SetControlIndex(Control, Parent.GetControlIndex(Control) + 1); case TheAction of
0: Control.BringToFront;
1: Control.SendToBack;
2: Parent.SetControlIndex(Control, Parent.GetControlIndex(Control) + 1);
3: Parent.SetControlIndex(Control, Parent.GetControlIndex(Control) - 1);
end;
Modified; // Ensure the order of controls in the OI now reflects the new ZOrder
end; // Unfortunately, if there is no parent, this code doesn't achieve a refresh
// of ComponentTree in the OI
procedure TDesigner.DoOrderBackSelectionOne; if assigned(Parent) then
var begin
Control: TControl; Parent.ReAlign;
Parent: TWinControl; SelectOnlyThisComponent(Parent);
begin end;
if ControlSelection.Count <> 1 then Exit; SelectOnlyThisComponent(Control);
if not ControlSelection[0].IsTControl then Exit;
Control := TControl(ControlSelection[0].Persistent);
Parent := Control.Parent;
if Parent = nil then Exit;
Parent.SetControlIndex(Control, Parent.GetControlIndex(Control) - 1);
Modified; Modified;
end; end;
@ -1590,10 +1567,10 @@ begin
ecDesignerCopy : CopySelection; ecDesignerCopy : CopySelection;
ecDesignerCut : CutSelection; ecDesignerCut : CutSelection;
ecDesignerPaste : PasteSelection([cpsfFindUniquePositions]); ecDesignerPaste : PasteSelection([cpsfFindUniquePositions]);
ecDesignerMoveToFront : DoOrderMoveSelectionToFront; ecDesignerMoveToFront : DoChangeZOrder(0);
ecDesignerMoveToBack : DoOrderMoveSelectionToBack; ecDesignerMoveToBack : DoChangeZOrder(1);
ecDesignerForwardOne : DoOrderForwardSelectionOne; ecDesignerForwardOne : DoChangeZOrder(2);
ecDesignerBackOne : DoOrderBackSelectionOne; ecDesignerBackOne : DoChangeZOrder(3);
else else
Exit; Exit;
end; end;
@ -4122,22 +4099,22 @@ end;
procedure TDesigner.OnOrderMoveToFrontMenuClick(Sender: TObject); procedure TDesigner.OnOrderMoveToFrontMenuClick(Sender: TObject);
begin begin
DoOrderMoveSelectionToFront; DoChangeZOrder(0);
end; end;
procedure TDesigner.OnOrderMoveToBackMenuClick(Sender: TObject); procedure TDesigner.OnOrderMoveToBackMenuClick(Sender: TObject);
begin begin
DoOrderMoveSelectionToBack; DoChangeZOrder(1);
end; end;
procedure TDesigner.OnOrderForwardOneMenuClick(Sender: TObject); procedure TDesigner.OnOrderForwardOneMenuClick(Sender: TObject);
begin begin
DoOrderForwardSelectionOne; DoChangeZOrder(2);
end; end;
procedure TDesigner.OnOrderBackOneMenuClick(Sender: TObject); procedure TDesigner.OnOrderBackOneMenuClick(Sender: TObject);
begin begin
DoOrderBackSelectionOne; DoChangeZOrder(3);
end; end;
procedure TDesigner.HintTimer(Sender: TObject); procedure TDesigner.HintTimer(Sender: TObject);