|
|
|
@ -2,6 +2,8 @@ |
|
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
|
|
|
|
using System.Reactive.Linq; |
|
|
|
using Perspex.Controls; |
|
|
|
using Perspex.VisualTree; |
|
|
|
using ReactiveUI; |
|
|
|
|
|
|
|
namespace Perspex.Diagnostics.ViewModels |
|
|
|
@ -29,5 +31,72 @@ namespace Perspex.Diagnostics.ViewModels |
|
|
|
} |
|
|
|
|
|
|
|
public ControlDetailsViewModel Details => _details.Value; |
|
|
|
|
|
|
|
public TreeNode FindNode(IControl control) |
|
|
|
{ |
|
|
|
foreach (var node in Nodes) |
|
|
|
{ |
|
|
|
var result = FindNode(node, control); |
|
|
|
|
|
|
|
if (result != null) |
|
|
|
{ |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public void SelectControl(IControl control) |
|
|
|
{ |
|
|
|
var node = default(TreeNode); |
|
|
|
|
|
|
|
while (node == null && control != null) |
|
|
|
{ |
|
|
|
node = FindNode(control); |
|
|
|
|
|
|
|
if (node == null) |
|
|
|
{ |
|
|
|
control = control.GetVisualParent<IControl>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (node != null) |
|
|
|
{ |
|
|
|
SelectedNode = node; |
|
|
|
ExpandNode(node.Parent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void ExpandNode(TreeNode node) |
|
|
|
{ |
|
|
|
if (node != null) |
|
|
|
{ |
|
|
|
node.IsExpanded = true; |
|
|
|
ExpandNode(node.Parent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private TreeNode FindNode(TreeNode node, IControl control) |
|
|
|
{ |
|
|
|
if (node.Control == control) |
|
|
|
{ |
|
|
|
return node; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
foreach (var child in node.Children) |
|
|
|
{ |
|
|
|
var result = FindNode(child, control); |
|
|
|
|
|
|
|
if (result != null) |
|
|
|
{ |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|