Skip to content

Commit

Permalink
Merge pull request #181 from miroiu/feature/lock-selection
Browse files Browse the repository at this point in the history
Add LockSelection and UnlockSelection to NodifyEditor
  • Loading branch information
miroiu authored Dec 18, 2024
2 parents d87a048 + e98bc99 commit a8e3fee
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 52 additions & 3 deletions Examples/Nodify.Shared/Themes/Icons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,60 @@
</Rectangle.Fill>
</Rectangle>

<Rectangle x:Key="LockIcon"
x:Shared="False"
Width="16"
Height="16">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#00FFFFFF"
Geometry="M16,16H0V0H16Z" />
<GeometryDrawing Brush="#0A212121"
Geometry="M2.5,14.5h10v-8H2.5Z" />
<GeometryDrawing Brush="#FF212121"
Geometry="M8,12H7V9H8Z" />
<GeometryDrawing Brush="#FF212121"
Geometry="M12.5,6H11V4.536a3.5,3.5,0,0,0-7,0V6H2.5L2,6.5v8l.5.5h10l.5-.5v-8ZM5,4.536a2.5,2.5,0,0,1,5,0V6H5ZM12,14H3V7h9Z" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>

<Rectangle x:Key="UnlockIcon"
x:Shared="False"
Width="16"
Height="16">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#00FFFFFF"
Geometry="M16,16H0V0H16Z" />
<GeometryDrawing Brush="#0A212121"
Geometry="M1.5,14.5h10v-8H1.5Z" />
<GeometryDrawing Brush="#FF212121"
Geometry="M7,12H6V9H7Z" />
<GeometryDrawing Brush="#FF212121"
Geometry="M12.5,1.036A3.5,3.5,0,0,0,9,4.536V6H1.5L1,6.5v8l.5.5h10l.5-.5v-8L11.5,6H10V4.536a2.5,2.5,0,0,1,5,0V5h1V4.536A3.5,3.5,0,0,0,12.5,1.036ZM11,7v7H2V7Z" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>

<PathGeometry x:Key="CloseGeometry"
x:Shared="False"
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="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" />

<PathGeometry x:Key="AddGeometry"
x:Shared="False"
Figures="M15 5L15 15L5 15L5 17L15 17L15 27L17 27L17 17L27 17L27 15L17 15L17 5Z"/>
Figures="M15 5L15 15L5 15L5 17L15 17L15 27L17 27L17 17L27 17L27 15L17 15L17 5Z" />

</ResourceDictionary>
6 changes: 6 additions & 0 deletions Examples/Nodify.StateMachine/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@
<MenuItem Header="_Rename"
Icon="{StaticResource RenameIcon}"
Command="{Binding RenameStateCommand}" />
<MenuItem Header="_Lock"
Icon="{StaticResource LockIcon}"
Command="{x:Static nodify:EditorCommands.LockSelection}" />
<MenuItem Header="_Unlock"
Icon="{StaticResource UnlockIcon}"
Command="{x:Static nodify:EditorCommands.UnlockSelection}" />
<MenuItem Header="_Alignment"
Icon="{StaticResource AlignTopIcon}">
<MenuItem Header="_Top"
Expand Down
48 changes: 48 additions & 0 deletions Nodify/Editor/EditorCommands.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using Nodify.Interactivity;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;

namespace Nodify
{
/// <summary>
/// Provides common commands for the <see cref="NodifyEditor"/>.
/// </summary>
public static class EditorCommands
{
/// <summary>
Expand Down Expand Up @@ -51,6 +55,16 @@ public static class EditorCommands
/// </summary>
public static RoutedUICommand Align { get; } = new RoutedUICommand("Align", nameof(Align), typeof(EditorCommands));

/// <summary>
/// Locks the position of the <see cref="NodifyEditor.SelectedContainers"/>.
/// </summary>
public static RoutedUICommand LockSelection { get; } = new RoutedUICommand("Lock selection", nameof(LockSelection), typeof(EditorCommands));

/// <summary>
/// Unlocks the position of the <see cref="NodifyEditor.SelectedContainers"/>.
/// </summary>
public static RoutedUICommand UnlockSelection { get; } = new RoutedUICommand("Unlock selection", nameof(UnlockSelection), typeof(EditorCommands));

internal static void RegisterCommandBindings<T>()
{
CommandManager.RegisterClassCommandBinding(typeof(T), new CommandBinding(ZoomIn, OnZoomIn, OnQueryStatusZoomIn));
Expand All @@ -59,6 +73,40 @@ internal static void RegisterCommandBindings<T>()
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)
Expand Down
22 changes: 22 additions & 0 deletions Nodify/Editor/NodifyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,28 @@ public void AlignContainers(IEnumerable<ItemContainer> containers, Alignment ali
IsDragging = false;
}

/// <summary>
/// Locks the position of the <see cref="SelectedContainers"/>.
/// </summary>
public void LockSelection()
{
foreach (var container in SelectedContainers)
{
container.IsDraggable = false;
}
}

/// <summary>
/// Unlocks the position of the <see cref="SelectedContainers"/>.
/// </summary>
public void UnlockSelection()
{
foreach (var container in SelectedContainers)
{
container.IsDraggable = true;
}
}

#endregion

#region Connector handling
Expand Down

0 comments on commit a8e3fee

Please sign in to comment.