using CommunityToolkit.Mvvm.ComponentModel;
using OpenTap.Addin;
using OpenTapEditor.Util;
using SeqEditor.Util;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using UILib;
namespace OpenTapEditor
{
///
/// VariableTree.xaml 的交互逻辑
///
[ObservableObject]
public partial class VariableReadOnlyTree : UserControl
{
[ObservableProperty]
private bool initEdit = false;
public EditBox EditingCell { get; private set; } = null;
public VariableReadOnlyTree()
{
this.Loaded += VariableReadOnlyTree_Loaded;
InitializeComponent();
BindingOperations.SetBinding(fileGlobalView, TreeListView.ItemsSourceProperty,
new Binding(nameof(Datasource))
{
Source = this,
Mode = BindingMode.TwoWay,
});
}
private void VariableReadOnlyTree_Loaded(object sender, RoutedEventArgs e)
{
InitEdit = true;
}
public static DependencyProperty DatasourceProperty = DependencyProperty.Register(
"Datasource",
typeof(ObservableCollection),
typeof(VariableReadOnlyTree),
new PropertyMetadata(null)
);
public event EventHandler ItemDoubleClicked;
public string Prefix { get; set; }
public ObservableCollection Datasource
{
get => (ObservableCollection)GetValue(DatasourceProperty);
set
{
SetValue(DatasourceProperty, value);
}
}
private void OnPreviewMouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
DependencyObject source = e.OriginalSource as DependencyObject;
while (source != null && source.GetType() != typeof(TreeListViewItem))
{
source = System.Windows.Media.VisualTreeHelper.GetParent(source);
}
if (source != null)
{
TreeListViewItem item = source as TreeListViewItem;
item.Focus();
var variable = item.DataContext;
CreateContextMenu(item, variable);
}
else
{
CreateContextMenu(null, null);
}
}
public List