private void RegisterInputActions()
        {
            MateriaInputManager.Add(InputManagerCommand.Clear, (e) =>
            {
                UINodePoint.SelectOrigin = null;
                popupShelf?.Close();
                popupShelf = null;
            });
            MateriaInputManager.Add(InputManagerCommand.Copy, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument) && !(Keyboard.FocusedElement is LayerItem) &&
                    !(Keyboard.FocusedElement is UILayers))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];
                    g.TryAndCopy();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Paste, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument) && !(Keyboard.FocusedElement is LayerItem) &&
                    !(Keyboard.FocusedElement is UILayers))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];
                    g.TryAndPaste();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Save, (e) =>
            {
                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g   = graphs[GraphDocuments.SelectedContentIndex];
                    var doc = documents[GraphDocuments.SelectedContentIndex];
                    HandleSave(g, doc);
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Delete, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument) && !(Keyboard.FocusedElement is LayerItem) &&
                    !(Keyboard.FocusedElement is UILayers))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];
                    g.TryAndDelete();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Undo, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument) && !(Keyboard.FocusedElement is LayerItem) &&
                    !(Keyboard.FocusedElement is UILayers))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];

                    Point m2 = Mouse.GetPosition(g.ViewPort);

                    if (m2.X < 0 || m2.Y < 0 || m2.X > g.ViewPort.ActualWidth || m2.Y > g.ViewPort.ActualHeight)
                    {
                        return;
                    }

                    g.TryAndUndo();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Redo, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument) && !(Keyboard.FocusedElement is LayerItem) &&
                    !(Keyboard.FocusedElement is UILayers))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];

                    Point m2 = Mouse.GetPosition(g.ViewPort);

                    if (m2.X < 0 || m2.Y < 0 || m2.X > g.ViewPort.ActualWidth || m2.Y > g.ViewPort.ActualHeight)
                    {
                        return;
                    }

                    g.TryAndRedo();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.PopupShelf, (e) =>
            {
                if (popupShelf != null && popupShelf.IsActive)
                {
                    return;
                }

                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument) && !(Keyboard.FocusedElement is LayerItem) &&
                    !(Keyboard.FocusedElement is UILayers))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g    = graphs[GraphDocuments.SelectedContentIndex];
                    Point m  = Mouse.GetPosition(this);
                    Point m2 = Mouse.GetPosition(g.ViewPort);

                    if (m2.X < 0 || m2.Y < 0 || m2.X > g.ViewPort.ActualWidth || m2.Y > g.ViewPort.ActualHeight)
                    {
                        return;
                    }
                    g.PrepareInsert();
                    popupShelf?.Close();
                    popupShelf         = new UIPopupShelf();
                    popupShelf.Closed += PopupShelf_Closed;
                    popupShelf.Hide();
                    popupShelf.Graph = g;
                    popupShelf.Open(m.X, m.Y);
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Comment, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument) && !(Keyboard.FocusedElement is LayerItem) &&
                    !(Keyboard.FocusedElement is UILayers))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];

                    Point m2 = Mouse.GetPosition(g.ViewPort);

                    if (m2.X < 0 || m2.Y < 0 || m2.X > g.ViewPort.ActualWidth || m2.Y > g.ViewPort.ActualHeight)
                    {
                        return;
                    }

                    g.TryAndComment();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Pin, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument) && !(Keyboard.FocusedElement is LayerItem) &&
                    !(Keyboard.FocusedElement is UILayers))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];

                    Point m2 = Mouse.GetPosition(g.ViewPort);

                    if (m2.X < 0 || m2.Y < 0 || m2.X > g.ViewPort.ActualWidth || m2.Y > g.ViewPort.ActualHeight)
                    {
                        return;
                    }

                    g.TryAndPin();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.NextPin, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument) && !(Keyboard.FocusedElement is LayerItem) &&
                    !(Keyboard.FocusedElement is UILayers))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g     = graphs[GraphDocuments.SelectedContentIndex];
                    e.Handled = true;
                    g.NextPin();
                }
            });
        }
        private void RegisterInputActions()
        {
            MateriaInputManager.Add(InputManagerCommand.Clear, (e) =>
            {
                UINodePoint.SelectOrigin = null;
                if (popupShelf != null)
                {
                    popupShelf.Hide();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Copy, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];
                    g.TryAndCopy();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Paste, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];
                    g.TryAndPaste();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Save, (e) =>
            {
                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g   = graphs[GraphDocuments.SelectedContentIndex];
                    var doc = documents[GraphDocuments.SelectedContentIndex];
                    HandleSave(g, doc);
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Delete, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];
                    g.TryAndDelete();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Undo, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];

                    Point m2 = Mouse.GetPosition(g.ViewPort);

                    if (m2.X < 0 || m2.Y < 0 || m2.X > g.ViewPort.ActualWidth || m2.Y > g.ViewPort.ActualHeight)
                    {
                        return;
                    }

                    g.TryAndUndo();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Redo, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];

                    Point m2 = Mouse.GetPosition(g.ViewPort);

                    if (m2.X < 0 || m2.Y < 0 || m2.X > g.ViewPort.ActualWidth || m2.Y > g.ViewPort.ActualHeight)
                    {
                        return;
                    }

                    g.TryAndRedo();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.PopupShelf, (e) =>
            {
                if (popupShelf == null || popupShelf.Visibility == Visibility.Visible)
                {
                    return;
                }

                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];
                    g.PrepareInsert();
                    var pop   = popupShelf;
                    pop.Graph = g;
                    Point m   = Mouse.GetPosition(this);
                    Point m2  = Mouse.GetPosition(g.ViewPort);

                    if (m2.X < 0 || m2.Y < 0 || m2.X > g.ViewPort.ActualWidth || m2.Y > g.ViewPort.ActualHeight)
                    {
                        return;
                    }

                    pop.Left = m.X;
                    pop.Top  = m.Y;
                    pop.Show();
                    pop.Focus();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Comment, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];

                    Point m2 = Mouse.GetPosition(g.ViewPort);

                    if (m2.X < 0 || m2.Y < 0 || m2.X > g.ViewPort.ActualWidth || m2.Y > g.ViewPort.ActualHeight)
                    {
                        return;
                    }

                    g.TryAndComment();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.Pin, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g = graphs[GraphDocuments.SelectedContentIndex];

                    Point m2 = Mouse.GetPosition(g.ViewPort);

                    if (m2.X < 0 || m2.Y < 0 || m2.X > g.ViewPort.ActualWidth || m2.Y > g.ViewPort.ActualHeight)
                    {
                        return;
                    }

                    g.TryAndPin();
                }
            });
            MateriaInputManager.Add(InputManagerCommand.NextPin, (e) =>
            {
                if (!(Keyboard.FocusedElement is IUIGraphNode) && !(Keyboard.FocusedElement is UIGraph) &&
                    Keyboard.FocusedElement != this && !(Keyboard.FocusedElement is LayoutDocument))
                {
                    return;
                }

                if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count)
                {
                    var g     = graphs[GraphDocuments.SelectedContentIndex];
                    e.Handled = true;
                    g.NextPin();
                }
            });
        }