|
@@ -4,6 +4,8 @@ using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Input;
|
|
|
+using PixiEditor.Helpers;
|
|
|
+using PixiEditor.Helpers.Extensions;
|
|
|
using PixiEditor.Models.Controllers;
|
|
|
using PixiEditor.Models.DataHolders;
|
|
|
using PixiEditor.Models.Enums;
|
|
@@ -17,7 +19,9 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
{
|
|
|
public class SelectTool : ReadonlyTool
|
|
|
{
|
|
|
- private Selection oldSelection;
|
|
|
+ private IEnumerable<Coordinates> oldSelectedPoints;
|
|
|
+
|
|
|
+ private static Selection ActiveSelection { get => ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection; }
|
|
|
|
|
|
public SelectTool()
|
|
|
{
|
|
@@ -30,32 +34,20 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
|
|
|
public override void OnRecordingLeftMouseDown(MouseEventArgs e)
|
|
|
{
|
|
|
- Enum.TryParse((Toolbar.GetSetting<DropdownSetting>("SelectMode")?.Value as ComboBoxItem)?.Content as string, out SelectionType selectionType);
|
|
|
- SelectionType = selectionType;
|
|
|
+ SelectionType = Toolbar.GetEnumSetting<SelectionType>("SelectMode").Value;
|
|
|
|
|
|
- oldSelection = null;
|
|
|
- Selection selection = ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection;
|
|
|
- if (selection != null && selection.SelectedPoints != null)
|
|
|
- {
|
|
|
- oldSelection = selection;
|
|
|
- }
|
|
|
+ oldSelectedPoints = new ReadOnlyCollection<Coordinates>(ActiveSelection.SelectedPoints);
|
|
|
}
|
|
|
|
|
|
public override void OnStoppedRecordingMouseUp(MouseEventArgs e)
|
|
|
{
|
|
|
- if (ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection.SelectedPoints.Count() <= 1)
|
|
|
+ if (ActiveSelection.SelectedPoints.Count <= 1)
|
|
|
{
|
|
|
// If we have not selected multiple points, clear the selection
|
|
|
- ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection.Clear();
|
|
|
+ ActiveSelection.Clear();
|
|
|
}
|
|
|
|
|
|
- ViewModelMain.Current.BitmapManager.ActiveDocument.UndoManager.AddUndoChange(
|
|
|
- new Change(
|
|
|
- "SelectedPoints",
|
|
|
- oldSelection.SelectedPoints,
|
|
|
- new ObservableCollection<Coordinates>(ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection.SelectedPoints),
|
|
|
- "Select pixels",
|
|
|
- ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection));
|
|
|
+ SelectionHelpers.AddSelectionUndoStep(ViewModelMain.Current.BitmapManager.ActiveDocument, oldSelectedPoints, SelectionType);
|
|
|
}
|
|
|
|
|
|
public override void Use(Coordinates[] pixels)
|