-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selecting the closest layer when deleting #613
Changes from 2 commits
dbf28cb
405752a
4a4cc73
ebdd64c
389cd5a
373677f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System.Collections.Immutable; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
|
@@ -15,6 +16,7 @@ | |
using PixiEditor.Models.IO; | ||
using PixiEditor.Models.Localization; | ||
using PixiEditor.ViewModels.SubViewModels.Document; | ||
using PixiEditor.Views.UserControls.Layers; | ||
|
||
namespace PixiEditor.ViewModels.SubViewModels.Main; | ||
#nullable enable | ||
|
@@ -48,10 +50,44 @@ public bool CanDeleteSelected() | |
[Command.Basic("PixiEditor.Layer.DeleteSelected", "LAYER_DELETE_SELECTED", "LAYER_DELETE_SELECTED_DESCRIPTIVE", CanExecute = "PixiEditor.Layer.CanDeleteSelected", IconPath = "Trash.png")] | ||
public void DeleteSelected() | ||
{ | ||
var member = Owner.DocumentManagerSubViewModel.ActiveDocument?.SelectedStructureMember; | ||
var doc = Owner.DocumentManagerSubViewModel?.ActiveDocument; | ||
|
||
var member = doc.SelectedStructureMember; | ||
if (member is null) | ||
return; | ||
|
||
member.Document.Operations.DeleteStructureMember(member.GuidValue); | ||
|
||
if (doc.StructureHelper.GetAllLayers().Count > 1) | ||
{ | ||
//Declare the layer that will be selected | ||
var baseLayer = doc.StructureHelper.GetAllLayers()[doc.StructureHelper.GetAllLayers().ToArray().Length - 1]; | ||
|
||
for (int i = 0; i < doc.StructureHelper.GetAllLayers().Count; i++) | ||
{ | ||
//Checking that the selected layer and the deleted layer are not the same | ||
if (doc.StructureHelper.GetAllLayers()[i] == member) | ||
{ | ||
//Selecting the new layer | ||
if (i > 0) | ||
{ | ||
baseLayer = doc.StructureHelper.GetAllLayers()[i-1]; | ||
} | ||
else if (i == doc.StructureHelper.GetAllLayers().Count - 1) | ||
{ | ||
baseLayer = doc.StructureHelper.GetAllLayers()[i]; | ||
} | ||
else if (i == 0) | ||
{ | ||
baseLayer = doc.StructureHelper.GetAllLayers().ToArray()[i+1]; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
doc.Operations.AddSoftSelectedMember(baseLayer.GuidValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Soft" selection is used in the case where you have multiple layers selected. To handle drawing in that case, we need to choose a single layer to draw on. Because of that there are two types of selection, "Hard" selection (only one layer can be hard-selected) and "Soft" selection (any selected layers that aren't the main one will be "soft" selected). It looks like you are trying to hard-select |
||
doc.InternalSetSelectedMember(baseLayer); | ||
} | ||
} | ||
|
||
[Evaluator.CanExecute("PixiEditor.Layer.HasSelectedMembers")] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are calling
GetAllLayers()
8 times, which is very inefficient, call it once and cast to array once.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this?