Add project files.

This commit is contained in:
Ankitkumar Satapara
2026-04-17 22:31:58 +05:30
commit 21aaef6776
473 changed files with 50152 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
using Nodify.UndoRedo;
using System.Collections.Generic;
using System.Windows;
namespace Nodify.Shapes.Canvas.UndoRedo
{
public class MoveShapesAction : IAction
{
private readonly IReadOnlyCollection<ShapeViewModel> _shapes;
private readonly Vector _offset;
public string? Label => "Move shapes";
public MoveShapesAction(IReadOnlyCollection<ShapeViewModel> shapes, Vector offset)
{
_shapes = shapes;
_offset = offset;
}
public void Execute()
=> ApplyOffset(_offset);
public void Undo()
=> ApplyOffset(-_offset);
private void ApplyOffset(Vector offset)
{
foreach (var shape in _shapes)
{
shape.Location += offset;
}
}
}
}

View File

@@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Nodify.UndoRedo;
namespace Nodify.Shapes.Canvas.UndoRedo
{
public class ResizeShapesAction : IAction
{
private readonly IReadOnlyCollection<ShapeViewModel> _resizedShapes;
private readonly Dictionary<ShapeViewModel, Size> _initialSizes;
private Dictionary<ShapeViewModel, Size>? _finalSizes;
private readonly Dictionary<ShapeViewModel, Point> _initialLocations;
private Dictionary<ShapeViewModel, Point>? _finalLocations;
public ResizeShapesAction(CanvasViewModel canvas)
{
_resizedShapes = canvas.SelectedShapes;
_initialSizes = _resizedShapes.ToDictionary(x => x, x => new Size(x.Width, x.Height));
_initialLocations = _resizedShapes.ToDictionary(x => x, x => x.Location);
}
public string? Label => "Resize shapes";
public void Execute()
{
_finalLocations?.ForEach(x => x.Key.Location = x.Value);
_finalSizes?.ForEach(x =>
{
x.Key.Width = x.Value.Width;
x.Key.Height = x.Value.Height;
});
}
public void Undo()
{
_initialSizes.ForEach(x =>
{
x.Key.Width = x.Value.Width;
x.Key.Height = x.Value.Height;
});
_initialLocations.ForEach(x => x.Key.Location = x.Value);
}
public void SaveSizes()
{
_finalLocations = _resizedShapes.ToDictionary(x => x, x => x.Location);
_finalSizes = _resizedShapes.ToDictionary(x => x, x => new Size(x.Width, x.Height));
}
}
}

View File

@@ -0,0 +1,59 @@
using Nodify.UndoRedo;
using System.Collections.Generic;
namespace Nodify.Shapes.Canvas.UndoRedo
{
public class SelectShapesAction : IAction
{
public string? Label => "Select shapes";
private readonly IReadOnlyCollection<ShapeViewModel> _nodes;
private readonly CanvasViewModel _canvas;
public SelectShapesAction(IReadOnlyCollection<ShapeViewModel> nodes, CanvasViewModel canvas)
{
_nodes = nodes;
_canvas = canvas;
}
public void Execute()
{
_canvas.SelectedShapes.AddRange(_nodes);
}
public void Undo()
{
_canvas.SelectedShapes.RemoveRange(_nodes);
}
public override string? ToString()
=> Label;
}
public class DeselectShapesAction : IAction
{
public string? Label => "Deselect shapes";
private readonly IReadOnlyCollection<ShapeViewModel> _nodes;
private readonly CanvasViewModel _canvas;
public DeselectShapesAction(IReadOnlyCollection<ShapeViewModel> nodes, CanvasViewModel canvas)
{
_nodes = nodes;
_canvas = canvas;
}
public void Execute()
{
_canvas.SelectedShapes.RemoveRange(_nodes);
}
public void Undo()
{
_canvas.SelectedShapes.AddRange(_nodes);
}
public override string? ToString()
=> Label;
}
}