控件树下方显示当前选中控件的 Path
- 控件树标签页底部新增 Path 横条:显示选中节点的 XPath,右侧「复制」按钮 - 选中节点、300ms 实时刷新换快照、清空/切换窗口时都会同步更新 - 布局自检加入该区域,避免像以前那样「加了控件但界面上看不到」 - 实测(进程内宿主 + 合成树):选中 Button 显示 /Window[1]/Button[@AutomationId='okButton'],选中其子 Text 显示 .../Text[1],清空后回到提示文本,横条在屏幕工作区内 - 回归测试 23/23 通过 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -162,6 +162,11 @@ namespace pacs_win_uia
|
|||||||
private readonly Label _monitorCaption;
|
private readonly Label _monitorCaption;
|
||||||
// 中栏:控件树搜索面板(搜索条件、仅显示匹配、匹配导航)。
|
// 中栏:控件树搜索面板(搜索条件、仅显示匹配、匹配导航)。
|
||||||
private readonly ControlTreeSearchPanel _treeSearchPanel;
|
private readonly ControlTreeSearchPanel _treeSearchPanel;
|
||||||
|
|
||||||
|
// 控件树下方的"当前选中控件 Path"横条:只显示 + 可复制,不参与定位。
|
||||||
|
private readonly Panel _selectedPathPanel;
|
||||||
|
private readonly TextBox _selectedPathBox;
|
||||||
|
private readonly Button _copySelectedPathButton;
|
||||||
// 中栏:列表结果页顶部的说明标签。
|
// 中栏:列表结果页顶部的说明标签。
|
||||||
private readonly Label _listResultHint;
|
private readonly Label _listResultHint;
|
||||||
// 工具栏:「设置」按钮。
|
// 工具栏:「设置」按钮。
|
||||||
@@ -482,8 +487,34 @@ namespace pacs_win_uia
|
|||||||
_listResultTab.Controls.Add(_listResultGrid);
|
_listResultTab.Controls.Add(_listResultGrid);
|
||||||
_listResultTab.Controls.Add(_listResultHint);
|
_listResultTab.Controls.Add(_listResultHint);
|
||||||
_treeSearchPanel = new ControlTreeSearchPanel { Dock = DockStyle.Top };
|
_treeSearchPanel = new ControlTreeSearchPanel { Dock = DockStyle.Top };
|
||||||
|
// 控件树下方的选中 Path 横条(Dock 顺序:先加 Fill,后加 Top/Right,避免盖住树)。
|
||||||
|
_selectedPathPanel = new Panel { Dock = DockStyle.Bottom, Height = 52, Padding = new Padding(4) };
|
||||||
|
_selectedPathBox = new TextBox
|
||||||
|
{
|
||||||
|
Dock = DockStyle.Fill,
|
||||||
|
ReadOnly = true,
|
||||||
|
Multiline = true,
|
||||||
|
WordWrap = false,
|
||||||
|
ScrollBars = ScrollBars.Vertical,
|
||||||
|
BackColor = Color.White,
|
||||||
|
Text = "(在控件树里选中一个节点,这里显示它的 XPath)"
|
||||||
|
};
|
||||||
|
_copySelectedPathButton = new Button { Dock = DockStyle.Right, Width = 56, Text = "复制" };
|
||||||
|
_copySelectedPathButton.Click += delegate { CopySelectedPath(); };
|
||||||
|
var selectedPathCaption = new Label
|
||||||
|
{
|
||||||
|
Dock = DockStyle.Top,
|
||||||
|
Height = 18,
|
||||||
|
Text = "选中控件 Path(XPath,可直接复制到「按 path 定位」或监控列表):",
|
||||||
|
ForeColor = Color.DarkSlateGray,
|
||||||
|
AutoEllipsis = true
|
||||||
|
};
|
||||||
|
_selectedPathPanel.Controls.Add(_selectedPathBox);
|
||||||
|
_selectedPathPanel.Controls.Add(_copySelectedPathButton);
|
||||||
|
_selectedPathPanel.Controls.Add(selectedPathCaption);
|
||||||
_controlTreeTab = new TabPage("控件树");
|
_controlTreeTab = new TabPage("控件树");
|
||||||
_controlTreeTab.Controls.Add(_controlTree);
|
_controlTreeTab.Controls.Add(_controlTree);
|
||||||
|
_controlTreeTab.Controls.Add(_selectedPathPanel);
|
||||||
_controlTreeTab.Controls.Add(_treeSearchPanel);
|
_controlTreeTab.Controls.Add(_treeSearchPanel);
|
||||||
_resultTabs.TabPages.Add(_controlTreeTab);
|
_resultTabs.TabPages.Add(_controlTreeTab);
|
||||||
_resultTabs.TabPages.Add(_listResultTab);
|
_resultTabs.TabPages.Add(_listResultTab);
|
||||||
@@ -887,6 +918,7 @@ namespace pacs_win_uia
|
|||||||
new LayoutRegion("窗口搜索框", _windowSearchBox, 120, 20),
|
new LayoutRegion("窗口搜索框", _windowSearchBox, 120, 20),
|
||||||
new LayoutRegion("结果标签页(控件树/列表结果)", _resultTabs, 200, 200),
|
new LayoutRegion("结果标签页(控件树/列表结果)", _resultTabs, 200, 200),
|
||||||
new LayoutRegion("控件树", _controlTree, 200, 200),
|
new LayoutRegion("控件树", _controlTree, 200, 200),
|
||||||
|
new LayoutRegion("选中控件Path", _selectedPathPanel, 200, 30),
|
||||||
new LayoutRegion("列表结果表格", _listResultGrid, 60, 60),
|
new LayoutRegion("列表结果表格", _listResultGrid, 60, 60),
|
||||||
new LayoutRegion("属性网格", _propertyGrid, 200, 120),
|
new LayoutRegion("属性网格", _propertyGrid, 200, 120),
|
||||||
new LayoutRegion("控件监控列表", _monitorEditor, 200, 150),
|
new LayoutRegion("控件监控列表", _monitorEditor, 200, 150),
|
||||||
@@ -1438,6 +1470,8 @@ namespace pacs_win_uia
|
|||||||
_treeRootHandle = IntPtr.Zero;
|
_treeRootHandle = IntPtr.Zero;
|
||||||
_treeUiaRoot = null;
|
_treeUiaRoot = null;
|
||||||
_monitorEditor.SetTreeRoot(null);
|
_monitorEditor.SetTreeRoot(null);
|
||||||
|
_monitorEditor.SetCurrentNode(null, null);
|
||||||
|
UpdateSelectedPathText(null);
|
||||||
_currentElement = null;
|
_currentElement = null;
|
||||||
_inspectedWindow = null;
|
_inspectedWindow = null;
|
||||||
_lastListResult = null;
|
_lastListResult = null;
|
||||||
@@ -2414,6 +2448,50 @@ namespace pacs_win_uia
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 控件树下方横条:刷新"当前选中控件 Path"。传 null 表示没有选中。
|
||||||
|
// 只用内存里的树计算(无跨进程调用),所以 300ms 刷新时调用它不会拖慢界面。
|
||||||
|
private void UpdateSelectedPathText(ControlTreeNode node)
|
||||||
|
{
|
||||||
|
if (_selectedPathBox == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node == null)
|
||||||
|
{
|
||||||
|
_selectedPathBox.Text = "(在控件树里选中一个节点,这里显示它的 XPath)";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string path = node.CanonicalPath ?? DescribeNodePath(node);
|
||||||
|
_selectedPathBox.Text = string.IsNullOrEmpty(path) ? "(该节点没有可用的 Path)" : path;
|
||||||
|
// 让长路径从头显示,而不是停在中间。
|
||||||
|
_selectedPathBox.SelectionStart = 0;
|
||||||
|
_selectedPathBox.SelectionLength = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 复制横条里的 Path,方便粘到监控列表或「按 path 定位」。
|
||||||
|
private void CopySelectedPath()
|
||||||
|
{
|
||||||
|
string path = _selectedPathBox == null ? null : _selectedPathBox.Text;
|
||||||
|
if (string.IsNullOrEmpty(path) || path.StartsWith("(", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
SetStatus("当前没有选中的控件 Path 可复制。", null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Clipboard.SetText(path);
|
||||||
|
SetStatus("已复制选中控件 Path:" + path, null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
AppLog.Warn("复制选中控件 Path 失败。", ex);
|
||||||
|
SetStatus("复制失败:" + ex.Message, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The path text of a node, in the same format the resolver reads. Built from the tree already in
|
/// The path text of a node, in the same format the resolver reads. Built from the tree already in
|
||||||
/// memory (no cross-process calls), so it can be shown in the property grid and copied into
|
/// memory (no cross-process calls), so it can be shown in the property grid and copied into
|
||||||
@@ -2625,6 +2703,8 @@ namespace pacs_win_uia
|
|||||||
_currentNode = selected;
|
_currentNode = selected;
|
||||||
_currentElement = selected == null ? null : selected.Uia;
|
_currentElement = selected == null ? null : selected.Uia;
|
||||||
_monitorEditor.SetCurrentNode(selected, _inspectedWindow);
|
_monitorEditor.SetCurrentNode(selected, _inspectedWindow);
|
||||||
|
// 实时刷新(300ms)会换掉节点快照,Path 文本必须跟着更新。
|
||||||
|
UpdateSelectedPathText(selected);
|
||||||
_readListItem.Enabled = _currentElement != null && _currentElement.IsAvailable &&
|
_readListItem.Enabled = _currentElement != null && _currentElement.IsAvailable &&
|
||||||
_currentElement.Element != null && !_picker.IsPicking;
|
_currentElement.Element != null && !_picker.IsPicking;
|
||||||
_screenshotItem.Enabled = _ocrItem.Enabled = _copyFeaturesItem.Enabled = selected != null;
|
_screenshotItem.Enabled = _ocrItem.Enabled = _copyFeaturesItem.Enabled = selected != null;
|
||||||
@@ -2729,6 +2809,7 @@ namespace pacs_win_uia
|
|||||||
_propertyGrid.SelectedObject = SelectedObjectFor(node);
|
_propertyGrid.SelectedObject = SelectedObjectFor(node);
|
||||||
_monitorEditor.SetCurrentNode(node, _inspectedWindow);
|
_monitorEditor.SetCurrentNode(node, _inspectedWindow);
|
||||||
ShowNodeProperties(node);
|
ShowNodeProperties(node);
|
||||||
|
UpdateSelectedPathText(node);
|
||||||
|
|
||||||
if (_currentElement != null && _currentElement.IsAvailable && _currentElement.Element != null)
|
if (_currentElement != null && _currentElement.IsAvailable && _currentElement.Element != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user