diff --git a/CHANGELOG.md b/CHANGELOG.md index c53bb018..9ba22613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ > - Added Select, BeginSelecting, UpdateSelection, EndSelecting, CancelSelecting and AllowSelectionCancellation to NodifyEditor > - Added IsDragging, BeginDragging, UpdateDragging, EndDragging and CancelDragging to NodifyEditor > - Added AlignSelection and AlignContainers methods to NodifyEditor +> - Added LockSelection and UnlockSelection methods to NodifyEditor and EditorCommands > - Added ItemsMoved routed event to NodifyEditor > - Added HasCustomContextMenu dependency property to NodifyEditor, ItemContainer, Connector and BaseConnection > - Added Select, BeginDragging, UpdateDragging, EndDragging and CancelDragging to ItemContainer diff --git a/Examples/Nodify.Shared/Themes/Icons.xaml b/Examples/Nodify.Shared/Themes/Icons.xaml index a5ecaef5..24e75aee 100644 --- a/Examples/Nodify.Shared/Themes/Icons.xaml +++ b/Examples/Nodify.Shared/Themes/Icons.xaml @@ -714,11 +714,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + Figures="M9.15625 6.3125L6.3125 9.15625L22.15625 25L6.21875 40.96875L9.03125 43.78125L25 27.84375L40.9375 43.78125L43.78125 40.9375L27.84375 25L43.6875 9.15625L40.84375 6.3125L25 22.15625Z" /> + + Figures="M15 5L15 15L5 15L5 17L15 17L15 27L17 27L17 17L27 17L27 15L17 15L17 5Z" /> + \ No newline at end of file diff --git a/Examples/Nodify.StateMachine/MainWindow.xaml b/Examples/Nodify.StateMachine/MainWindow.xaml index e04158b1..c707a3ff 100644 --- a/Examples/Nodify.StateMachine/MainWindow.xaml +++ b/Examples/Nodify.StateMachine/MainWindow.xaml @@ -171,6 +171,12 @@ + + + /// Provides common commands for the . + /// public static class EditorCommands { /// @@ -51,6 +55,16 @@ public static class EditorCommands /// public static RoutedUICommand Align { get; } = new RoutedUICommand("Align", nameof(Align), typeof(EditorCommands)); + /// + /// Locks the position of the . + /// + public static RoutedUICommand LockSelection { get; } = new RoutedUICommand("Lock selection", nameof(LockSelection), typeof(EditorCommands)); + + /// + /// Unlocks the position of the . + /// + public static RoutedUICommand UnlockSelection { get; } = new RoutedUICommand("Unlock selection", nameof(UnlockSelection), typeof(EditorCommands)); + internal static void RegisterCommandBindings() { CommandManager.RegisterClassCommandBinding(typeof(T), new CommandBinding(ZoomIn, OnZoomIn, OnQueryStatusZoomIn)); @@ -59,6 +73,40 @@ internal static void RegisterCommandBindings() CommandManager.RegisterClassCommandBinding(typeof(T), new CommandBinding(BringIntoView, OnBringIntoView, OnQueryBringIntoViewStatus)); CommandManager.RegisterClassCommandBinding(typeof(T), new CommandBinding(FitToScreen, OnFitToScreen, OnQueryFitToScreenStatus)); CommandManager.RegisterClassCommandBinding(typeof(T), new CommandBinding(Align, OnAlign, OnQueryAlignStatus)); + CommandManager.RegisterClassCommandBinding(typeof(T), new CommandBinding(LockSelection, OnLock, OnQueryLockStatus)); + CommandManager.RegisterClassCommandBinding(typeof(T), new CommandBinding(UnlockSelection, OnUnlock, OnQueryUnlockStatus)); + } + + private static void OnQueryLockStatus(object sender, CanExecuteRoutedEventArgs e) + { + if (sender is NodifyEditor editor) + { + e.CanExecute = editor.SelectedContainers.Any(x => x.IsDraggable); + } + } + + private static void OnLock(object sender, ExecutedRoutedEventArgs e) + { + if (sender is NodifyEditor editor) + { + editor.LockSelection(); + } + } + + private static void OnQueryUnlockStatus(object sender, CanExecuteRoutedEventArgs e) + { + if (sender is NodifyEditor editor) + { + e.CanExecute = editor.SelectedContainers.Any(x => !x.IsDraggable); + } + } + + private static void OnUnlock(object sender, ExecutedRoutedEventArgs e) + { + if (sender is NodifyEditor editor) + { + editor.UnlockSelection(); + } } private static void OnQueryAlignStatus(object sender, CanExecuteRoutedEventArgs e) diff --git a/Nodify/Editor/NodifyEditor.cs b/Nodify/Editor/NodifyEditor.cs index 3f68c633..f52188a5 100644 --- a/Nodify/Editor/NodifyEditor.cs +++ b/Nodify/Editor/NodifyEditor.cs @@ -739,6 +739,28 @@ public void AlignContainers(IEnumerable containers, Alignment ali IsDragging = false; } + /// + /// Locks the position of the . + /// + public void LockSelection() + { + foreach (var container in SelectedContainers) + { + container.IsDraggable = false; + } + } + + /// + /// Unlocks the position of the . + /// + public void UnlockSelection() + { + foreach (var container in SelectedContainers) + { + container.IsDraggable = true; + } + } + #endregion #region Connector handling