diff --git a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs
index 63043aa91..ca0aaee77 100644
--- a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs
+++ b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs
@@ -9,6 +9,8 @@ using FlaxEditor.GUI.Drag;
using FlaxEditor.GUI.Tree;
using FlaxEditor.Scripting;
using FlaxEditor.Utilities;
+using FlaxEditor.Windows;
+using FlaxEditor.Windows.Assets;
using FlaxEngine;
using FlaxEngine.GUI;
using Object = FlaxEngine.Object;
@@ -265,7 +267,7 @@ namespace FlaxEditor.SceneGraph.GUI
///
/// Starts the actor renaming action.
///
- public void StartRenaming()
+ public void StartRenaming(EditorWindow window)
{
// Block renaming during scripts reload
if (Editor.Instance.ProgressReporting.CompileScripts.IsActive)
@@ -273,16 +275,22 @@ namespace FlaxEditor.SceneGraph.GUI
Select();
- // Disable scrolling of scene view
- Editor.Instance.Windows.SceneWin.ScrollingOnSceneTreeView(false);
+ // Disable scrolling of view
+ if (window is SceneTreeWindow)
+ (window as SceneTreeWindow).ScrollingOnSceneTreeView(false);
+ else if (window is PrefabWindow)
+ (window as PrefabWindow).ScrollingOnTreeView(false);
// Start renaming the actor
var dialog = RenamePopup.Show(this, HeaderRect, _actorNode.Name, false);
dialog.Renamed += OnRenamed;
dialog.Closed += popup =>
{
- // Enable scrolling of scene view
- Editor.Instance.Windows.SceneWin.ScrollingOnSceneTreeView(true);
+ // Enable scrolling of view
+ if (window is SceneTreeWindow)
+ (window as SceneTreeWindow).ScrollingOnSceneTreeView(true);
+ else if (window is PrefabWindow)
+ (window as PrefabWindow).ScrollingOnTreeView(true);
};
}
@@ -290,9 +298,6 @@ namespace FlaxEditor.SceneGraph.GUI
{
using (new UndoBlock(ActorNode.Root.Undo, Actor, "Rename"))
Actor.Name = renamePopup.Text;
-
- // Enable scrolling of scene view
- Editor.Instance.Windows.SceneWin.ScrollingOnSceneTreeView(true);
}
///
diff --git a/Source/Editor/Windows/Assets/PrefabWindow.Actions.cs b/Source/Editor/Windows/Assets/PrefabWindow.Actions.cs
index d16bc13f6..fc7a9123d 100644
--- a/Source/Editor/Windows/Assets/PrefabWindow.Actions.cs
+++ b/Source/Editor/Windows/Assets/PrefabWindow.Actions.cs
@@ -153,6 +153,9 @@ namespace FlaxEditor.Windows.Assets
{
OnPasteAction(pasteAction);
}
+
+ // Scroll to new selected node
+ ScrollToSelectedNode();
}
///
@@ -180,6 +183,9 @@ namespace FlaxEditor.Windows.Assets
{
OnPasteAction(pasteAction);
}
+
+ // Scroll to new selected node
+ ScrollToSelectedNode();
}
private void OnPasteAction(PasteActorsAction pasteAction)
@@ -328,6 +334,9 @@ namespace FlaxEditor.Windows.Assets
}, action2.ActionString);
action.Do();
Undo.AddAction(action);
+
+ _treePanel.PerformLayout();
+ _treePanel.PerformLayout();
}
}
}
diff --git a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs
index ea93e11d9..8d3e3a8ec 100644
--- a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs
+++ b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs
@@ -67,7 +67,7 @@ namespace FlaxEditor.Windows.Assets
private DragHandlers _dragHandlers;
public SceneTreePanel(PrefabWindow window)
- : base(ScrollBars.Vertical)
+ : base(ScrollBars.None)
{
_window = window;
Offsets = Margin.Zero;
@@ -310,7 +310,7 @@ namespace FlaxEditor.Windows.Assets
{
if (selection.Count != 0)
Select(actor);
- actor.TreeNode.StartRenaming();
+ actor.TreeNode.StartRenaming(this);
}
}
diff --git a/Source/Editor/Windows/Assets/PrefabWindow.cs b/Source/Editor/Windows/Assets/PrefabWindow.cs
index 3a4e544c1..03e706c45 100644
--- a/Source/Editor/Windows/Assets/PrefabWindow.cs
+++ b/Source/Editor/Windows/Assets/PrefabWindow.cs
@@ -23,6 +23,7 @@ namespace FlaxEditor.Windows.Assets
private readonly SplitPanel _split1;
private readonly SplitPanel _split2;
private readonly TextBox _searchBox;
+ private readonly Panel _treePanel;
private readonly PrefabTree _tree;
private readonly PrefabWindowViewport _viewport;
private readonly CustomEditorPresenter _propertiesEditor;
@@ -132,17 +133,26 @@ namespace FlaxEditor.Windows.Assets
};
_searchBox.TextChanged += OnSearchBoxTextChanged;
+ _treePanel = new Panel()
+ {
+ AnchorPreset = AnchorPresets.StretchAll,
+ Offsets = new Margin(0.0f, 0.0f, headerPanel.Bottom, 0.0f),
+ ScrollBars = ScrollBars.Both,
+ IsScrollable = true,
+ Parent = sceneTreePanel,
+ };
+
// Prefab structure tree
Graph = new LocalSceneGraph(new CustomRootNode(this));
_tree = new PrefabTree
{
- Y = headerPanel.Bottom,
Margin = new Margin(0.0f, 0.0f, -16.0f, 0.0f), // Hide root node
+ IsScrollable = true,
};
_tree.AddChild(Graph.Root.TreeNode);
_tree.SelectedChanged += OnTreeSelectedChanged;
_tree.RightClick += OnTreeRightClick;
- _tree.Parent = sceneTreePanel;
+ _tree.Parent = _treePanel;
headerPanel.Parent = sceneTreePanel;
// Prefab viewport
@@ -192,6 +202,32 @@ namespace FlaxEditor.Windows.Assets
InputActions.Add(options => options.Rename, Rename);
InputActions.Add(options => options.FocusSelection, _viewport.FocusSelection);
}
+
+ ///
+ /// Enables or disables vertical and horizontal scrolling on the tree panel.
+ ///
+ /// The state to set scrolling to
+ public void ScrollingOnTreeView(bool enabled)
+ {
+ if (_treePanel.VScrollBar != null)
+ _treePanel.VScrollBar.ThumbEnabled = enabled;
+ if (_treePanel.HScrollBar != null)
+ _treePanel.HScrollBar.ThumbEnabled = enabled;
+ }
+
+ ///
+ /// Scrolls to the selected node in the tree.
+ ///
+ public void ScrollToSelectedNode()
+ {
+ // Scroll to node
+ var nodeSelection = _tree.Selection;
+ if (nodeSelection.Count != 0)
+ {
+ var scrollControl = nodeSelection[nodeSelection.Count - 1];
+ _treePanel.ScrollViewTo(scrollControl);
+ }
+ }
private void OnSearchBoxTextChanged()
{
@@ -211,6 +247,22 @@ namespace FlaxEditor.Windows.Assets
PerformLayout();
}
+ ///
+ public override bool OnMouseUp(Float2 location, MouseButton button)
+ {
+ if (base.OnMouseUp(location, button))
+ return true;
+
+ if (button == MouseButton.Right && _treePanel.ContainsPoint(ref location))
+ {
+ _tree.Deselect();
+ var locationCM = location + _searchBox.BottomLeft;
+ ShowContextMenu(Parent, ref locationCM);
+ return true;
+ }
+ return false;
+ }
+
private void OnScriptsReloadBegin()
{
_isScriptsReloading = true;
diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs
index 396bd3747..8542cd693 100644
--- a/Source/Editor/Windows/SceneTreeWindow.cs
+++ b/Source/Editor/Windows/SceneTreeWindow.cs
@@ -249,7 +249,7 @@ namespace FlaxEditor.Windows
{
if (selection.Count != 0)
Editor.SceneEditing.Select(actor);
- actor.TreeNode.StartRenaming();
+ actor.TreeNode.StartRenaming(this);
}
}