Skip to content

Commit

Permalink
Don't force focus change after rename if renamed node was not selected (
Browse files Browse the repository at this point in the history
dnSpy#1595)

* Remove unneeded SelectItems calls

* Don't force focus change after rename if renamed node was not selected
  • Loading branch information
holly-hacker authored Nov 8, 2020
1 parent 559a7d9 commit db2e8c0
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 18 deletions.
1 change: 0 additions & 1 deletion Extensions/dnSpy.AsmEditor/Assembly/AssemblyCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ public void Execute() {
info.AssemblyRef.PublicKeyOrToken = newOptions.PublicKey;
}
}
asmNode.TreeNode.TreeView.SelectItems(new[] { asmNode });
asmNode.TreeNode.RefreshUI();
}

Expand Down
8 changes: 6 additions & 2 deletions Extensions/dnSpy.AsmEditor/Event/EventDefCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,15 @@ public void Execute() {
Debug.Assert(b);
if (!b)
throw new InvalidOperationException();

var isNodeSelected = eventNode.TreeNode.TreeView.SelectedItem == eventNode;

origParentNode.TreeNode.Children.RemoveAt(origParentChildIndex);
newOptions.CopyTo(eventNode.EventDef);

origParentNode.TreeNode.AddChild(eventNode.TreeNode);
origParentNode.TreeNode.TreeView.SelectItems(new[] { eventNode });

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { eventNode });
}
else
newOptions.CopyTo(eventNode.EventDef);
Expand Down
8 changes: 6 additions & 2 deletions Extensions/dnSpy.AsmEditor/Field/FieldDefCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,15 @@ public void Execute() {
Debug.Assert(b);
if (!b)
throw new InvalidOperationException();

var isNodeSelected = fieldNode.TreeNode.TreeView.SelectedItem == fieldNode;

origParentNode.TreeNode.Children.RemoveAt(origParentChildIndex);
newOptions.CopyTo(fieldNode.FieldDef);

origParentNode.TreeNode.AddChild(fieldNode.TreeNode);
origParentNode.TreeNode.TreeView.SelectItems(new[] { fieldNode });

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { fieldNode });
}
else
newOptions.CopyTo(fieldNode.FieldDef);
Expand Down
8 changes: 6 additions & 2 deletions Extensions/dnSpy.AsmEditor/Method/MethodDefCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,15 @@ public void Execute() {
Debug.Assert(b);
if (!b)
throw new InvalidOperationException();

var isNodeSelected = methodNode.TreeNode.TreeView.SelectedItem == methodNode;

origParentNode.TreeNode.Children.RemoveAt(origParentChildIndex);
newOptions.CopyTo(methodNode.MethodDef);

origParentNode.TreeNode.AddChild(methodNode.TreeNode);
origParentNode.TreeNode.TreeView.SelectItems(new[] { methodNode });

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { methodNode });
}
else
newOptions.CopyTo(methodNode.MethodDef);
Expand Down
1 change: 0 additions & 1 deletion Extensions/dnSpy.AsmEditor/Module/ModuleCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ static void Execute(Lazy<IUndoCommandService> undoCommandService, IAppService ap

void WriteModuleOptions(ModuleOptions theOptions) {
theOptions.CopyTo(modNode.Document.ModuleDef!);
modNode.TreeNode.TreeView.SelectItems(new[] { modNode });
modNode.TreeNode.RefreshUI();
}

Expand Down
15 changes: 13 additions & 2 deletions Extensions/dnSpy.AsmEditor/Namespace/NamespaceCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,20 @@ public void Execute() {
Debug.Assert(b);
if (!b)
throw new InvalidOperationException();

var isNodeSelected = nsNode.TreeNode.TreeView.SelectedItem == nsNode;

origParentNode.TreeNode.Children.RemoveAt(origParentChildIndex);
nsNode.Name = newName;

foreach (var typeNode in origChildren)
typeNode.TypeDef.Namespace = newNamespace;

origParentNode.TreeNode.AddChild(nsNode.TreeNode);
origParentNode.TreeNode.TreeView.SelectItems(new[] { nsNode });

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { nsNode });

nsNode.TreeNode.RefreshUI();
}

Expand All @@ -481,6 +487,8 @@ public void Undo() {
}
}
else {
var isNodeSelected = nsNode.TreeNode.TreeView.SelectedItem == nsNode;

bool b = origParentNode.TreeNode.Children.Remove(nsNode.TreeNode);
Debug.Assert(b);
if (!b)
Expand All @@ -491,7 +499,10 @@ public void Undo() {

nsNode.Name = origName;
origParentNode.TreeNode.Children.Insert(origParentChildIndex, nsNode.TreeNode);
origParentNode.TreeNode.TreeView.SelectItems(new[] { nsNode });

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { nsNode });

nsNode.TreeNode.RefreshUI();
}

Expand Down
14 changes: 11 additions & 3 deletions Extensions/dnSpy.AsmEditor/Property/PropertyDefCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,15 @@ public void Execute() {
Debug.Assert(b);
if (!b)
throw new InvalidOperationException();

var isNodeSelected = propNode.TreeNode.TreeView.SelectedItem == propNode;

origParentNode.TreeNode.Children.RemoveAt(origParentChildIndex);
newOptions.CopyTo(propNode.PropertyDef);

origParentNode.TreeNode.AddChild(propNode.TreeNode);
origParentNode.TreeNode.TreeView.SelectItems(new[] { propNode });

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { propNode });
}
else
newOptions.CopyTo(propNode.PropertyDef);
Expand All @@ -424,14 +428,18 @@ public void Execute() {

public void Undo() {
if (nameChanged) {
var isNodeSelected = propNode.TreeNode.TreeView.SelectedItem == propNode;

bool b = origParentNode.TreeNode.Children.Remove(propNode.TreeNode);
Debug.Assert(b);
if (!b)
throw new InvalidOperationException();

origOptions.CopyTo(propNode.PropertyDef);
origParentNode.TreeNode.Children.Insert(origParentChildIndex, propNode.TreeNode);
origParentNode.TreeNode.TreeView.SelectItems(new[] { propNode });

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { propNode });
}
else
origOptions.CopyTo(propNode.PropertyDef);
Expand Down
14 changes: 11 additions & 3 deletions Extensions/dnSpy.AsmEditor/Resources/ResourceCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,11 +1075,15 @@ public void Execute() {
Debug.Assert(b);
if (!b)
throw new InvalidOperationException();

var isNodeSelected = rsrcNode.Node.TreeNode.TreeView.SelectedItem == rsrcNode.Node;

origParentNode.TreeNode.Children.RemoveAt(origParentChildIndex);
newOptions.CopyTo(rsrcNode.Resource);

origParentNode.TreeNode.AddChild(rsrcNode.Node.TreeNode);
origParentNode.TreeNode.TreeView.SelectItems(new[] { rsrcNode.Node });

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { rsrcNode.Node });
}
else
newOptions.CopyTo(rsrcNode.Resource);
Expand All @@ -1088,14 +1092,18 @@ public void Execute() {

public void Undo() {
if (nameChanged) {
var isNodeSelected = rsrcNode.Node.TreeNode.TreeView.SelectedItem == rsrcNode.Node;

bool b = origParentNode.TreeNode.Children.Remove(rsrcNode.Node.TreeNode);
Debug.Assert(b);
if (!b)
throw new InvalidOperationException();

origOptions.CopyTo(rsrcNode.Resource);
origParentNode.TreeNode.Children.Insert(origParentChildIndex, rsrcNode.Node.TreeNode);
origParentNode.TreeNode.TreeView.SelectItems(new[] { rsrcNode.Node });

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { rsrcNode.Node });
}
else
origOptions.CopyTo(rsrcNode.Resource);
Expand Down
14 changes: 12 additions & 2 deletions Extensions/dnSpy.AsmEditor/Types/TypeDefCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,22 +530,32 @@ public void Execute() {
Debug.Assert(b);
if (!b)
throw new InvalidOperationException();

var isNodeSelected = typeNode.TreeNode.TreeView.SelectedItem == typeNode;

origParentNode.TreeNode.Children.RemoveAt(origParentChildIndex);
newOptions.CopyTo(typeNode.TypeDef, module);

nsNodeCreator.Add();
nsNodeCreator.NamespaceNode.TreeNode.AddChild(typeNode.TreeNode);

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { typeNode });
}
else if (nameChanged) {
bool b = origParentChildIndex < origParentNode.TreeNode.Children.Count && origParentNode.TreeNode.Children[origParentChildIndex] == typeNode.TreeNode;
Debug.Assert(b);
if (!b)
throw new InvalidOperationException();

var isNodeSelected = typeNode.TreeNode.TreeView.SelectedItem == typeNode;

origParentNode.TreeNode.Children.RemoveAt(origParentChildIndex);
newOptions.CopyTo(typeNode.TypeDef, module);

origParentNode.TreeNode.AddChild(typeNode.TreeNode);
origParentNode.TreeNode.TreeView.SelectItems(new[] { typeNode });

if (isNodeSelected)
origParentNode.TreeNode.TreeView.SelectItems(new[] { typeNode });
}
else
newOptions.CopyTo(typeNode.TypeDef, module);
Expand Down

0 comments on commit db2e8c0

Please sign in to comment.