|
@@ -133,6 +133,8 @@ namespace InABox.DynamicGrid
|
|
|
}
|
|
|
|
|
|
public delegate void OnSelectItem(DynamicTreeNode node);
|
|
|
+
|
|
|
+ public delegate void OnContextMenuOpening(DynamicTreeNode node, ContextMenu menu);
|
|
|
|
|
|
public abstract class DynamicTreeView<T> : ContentControl where T : BaseObject, new()
|
|
|
{
|
|
@@ -143,17 +145,18 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
protected CoreTable Data { get; private set; }
|
|
|
|
|
|
- private ContextMenu _menu = null;
|
|
|
- private SfTreeGrid _tree = null;
|
|
|
- private DockPanel _dock = null;
|
|
|
- private Grid _grid = null;
|
|
|
- private Button _add = null;
|
|
|
- private Button _edit = null;
|
|
|
- private Button _delete = null;
|
|
|
- private Label _spacer = null;
|
|
|
+ private ContextMenu _menu;
|
|
|
+ private SfTreeGrid _tree;
|
|
|
+ private DockPanel _dock;
|
|
|
+ private Grid _grid;
|
|
|
+ private Button _add;
|
|
|
+ private Button _edit;
|
|
|
+ private Button _delete;
|
|
|
+ private Label _spacer;
|
|
|
|
|
|
public FluentList<DynamicTreeOption> Options { get; private set; }
|
|
|
public event OnSelectItem OnSelectItem;
|
|
|
+ public event OnContextMenuOpening OnContextMenuOpening;
|
|
|
|
|
|
private double minRowHeight = 30D;
|
|
|
private double maxRowHeight = 30D;
|
|
@@ -208,7 +211,8 @@ namespace InABox.DynamicGrid
|
|
|
_tree.HeaderRowHeight = 0D;
|
|
|
_tree.SelectionChanged += (o,e) => OnSelectItem?.Invoke(_tree.SelectedItem as DynamicTreeNode);
|
|
|
_tree.AllowSelectionOnExpanderClick = false;
|
|
|
-
|
|
|
+
|
|
|
+ _tree.ContextMenuOpening += _tree_ContextMenuOpening;
|
|
|
_tree.ContextMenu = _menu;
|
|
|
_tree.Background = new SolidColorBrush(Colors.DimGray);
|
|
|
|
|
@@ -258,6 +262,54 @@ namespace InABox.DynamicGrid
|
|
|
SizeChanged += DynamicTreeView_SizeChanged;
|
|
|
}
|
|
|
|
|
|
+ #region Public Interface
|
|
|
+
|
|
|
+ public void AddItem(DynamicTreeNode? parentNode = null, bool edit = true)
|
|
|
+ {
|
|
|
+ var id = parentNode?.ID ?? Guid.Empty;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ T item = DoCreateItem(id);
|
|
|
+ if (edit)
|
|
|
+ {
|
|
|
+ if (DoEditItem(item))
|
|
|
+ {
|
|
|
+ DoSaveItem(item);
|
|
|
+ Refresh();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DoSaveItem(item);
|
|
|
+ Refresh();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ MessageBox.Show(e.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ private void _tree_ContextMenuOpening(object sender, ContextMenuEventArgs e)
|
|
|
+ {
|
|
|
+ _menu.Items.Clear();
|
|
|
+ if (OnContextMenuOpening is not null)
|
|
|
+ {
|
|
|
+ OnContextMenuOpening.Invoke((_tree.SelectedItem as DynamicTreeNode)!, _menu);
|
|
|
+ if(_menu.Items.Count == 0)
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _menu.AddItem("Add Item", null, (_tree.SelectedItem as DynamicTreeNode)!.ID, AddItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void DynamicTreeView_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
|
{
|
|
|
CalculateRowHeight();
|
|
@@ -324,7 +376,6 @@ namespace InABox.DynamicGrid
|
|
|
protected virtual T DoCreateItem(Guid parent)
|
|
|
{
|
|
|
T result = new T();
|
|
|
- var node = _tree.SelectedItem as DynamicTreeNode;
|
|
|
CoreUtils.SetPropertyValue(result, CoreUtils.GetFullPropertyName(ParentID, "."), parent);
|
|
|
return result;
|
|
|
}
|
|
@@ -356,7 +407,7 @@ namespace InABox.DynamicGrid
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
MessageBox.Show(e.Message);
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void EditItem(Button button)
|