Browse Source

Fix #2019: Add MMB shortcut to "Open in new tab" for tree view and links

pull/2030/head
Siegfried Pammer 5 years ago
parent
commit
27744e6006
  1. 2
      ILSpy/Commands/DecompileInNewViewCommand.cs
  2. 16
      ILSpy/MainWindow.xaml.cs
  3. 8
      ILSpy/TextView/DecompilerTextView.cs
  4. 9
      ILSpy/TreeNodes/ILSpyTreeNode.cs
  5. 8
      SharpTreeView/SharpTreeNode.cs
  6. 9
      SharpTreeView/SharpTreeViewItem.cs

2
ILSpy/Commands/DecompileInNewViewCommand.cs

@ -28,7 +28,7 @@ using ICSharpCode.ILSpy.TreeNodes;
namespace ICSharpCode.ILSpy.Commands namespace ICSharpCode.ILSpy.Commands
{ {
[ExportContextMenuEntry(Header = nameof(Resources.DecompileToNewPanel), Icon = "images/Search", Category = nameof(Resources.Analyze), Order = 90)] [ExportContextMenuEntry(Header = nameof(Resources.DecompileToNewPanel), InputGestureText = "MMB", Icon = "images/Search", Category = nameof(Resources.Analyze), Order = 90)]
internal sealed class DecompileInNewViewCommand : IContextMenuEntry internal sealed class DecompileInNewViewCommand : IContextMenuEntry
{ {
public bool IsVisible(TextViewContext context) public bool IsVisible(TextViewContext context)

16
ILSpy/MainWindow.xaml.cs

@ -875,7 +875,12 @@ namespace ICSharpCode.ILSpy
public void JumpToReference(object reference) public void JumpToReference(object reference)
{ {
JumpToReferenceAsync(reference).HandleExceptions(); JumpToReference(reference, inNewTabPage: false);
}
public void JumpToReference(object reference, bool inNewTabPage)
{
JumpToReferenceAsync(reference, inNewTabPage).HandleExceptions();
} }
/// <summary> /// <summary>
@ -886,6 +891,11 @@ namespace ICSharpCode.ILSpy
/// The task will be marked as canceled if the decompilation is canceled. /// The task will be marked as canceled if the decompilation is canceled.
/// </returns> /// </returns>
public Task JumpToReferenceAsync(object reference) public Task JumpToReferenceAsync(object reference)
{
return JumpToReferenceAsync(reference, inNewTabPage: false);
}
public Task JumpToReferenceAsync(object reference, bool inNewTabPage)
{ {
decompilationTask = TaskHelper.CompletedTask; decompilationTask = TaskHelper.CompletedTask;
switch (reference) { switch (reference) {
@ -900,7 +910,7 @@ namespace ICSharpCode.ILSpy
foreach (var handler in protocolHandlers) { foreach (var handler in protocolHandlers) {
var node = handler.Value.Resolve(protocol, file, unresolvedEntity.Handle, out bool newTabPage); var node = handler.Value.Resolve(protocol, file, unresolvedEntity.Handle, out bool newTabPage);
if (node != null) { if (node != null) {
SelectNode(node, newTabPage); SelectNode(node, newTabPage || inNewTabPage);
return decompilationTask; return decompilationTask;
} }
} }
@ -915,7 +925,7 @@ namespace ICSharpCode.ILSpy
default: default:
ILSpyTreeNode treeNode = FindTreeNode(reference); ILSpyTreeNode treeNode = FindTreeNode(reference);
if (treeNode != null) if (treeNode != null)
SelectNode(treeNode); SelectNode(treeNode, inNewTabPage);
break; break;
} }
return decompilationTask; return decompilationTask;

8
ILSpy/TextView/DecompilerTextView.cs

@ -820,7 +820,7 @@ namespace ICSharpCode.ILSpy.TextView
/// <summary> /// <summary>
/// Jumps to the definition referred to by the <see cref="ReferenceSegment"/>. /// Jumps to the definition referred to by the <see cref="ReferenceSegment"/>.
/// </summary> /// </summary>
internal void JumpToReference(ReferenceSegment referenceSegment) internal void JumpToReference(ReferenceSegment referenceSegment, bool openInNewTab)
{ {
object reference = referenceSegment.Reference; object reference = referenceSegment.Reference;
if (referenceSegment.IsLocal) { if (referenceSegment.IsLocal) {
@ -849,7 +849,7 @@ namespace ICSharpCode.ILSpy.TextView
return; return;
} }
} }
MainWindow.Instance.JumpToReference(reference); MainWindow.Instance.JumpToReference(reference, openInNewTab);
} }
Point? mouseDownPos; Point? mouseDownPos;
@ -866,7 +866,7 @@ namespace ICSharpCode.ILSpy.TextView
Vector dragDistance = e.GetPosition(this) - mouseDownPos.Value; Vector dragDistance = e.GetPosition(this) - mouseDownPos.Value;
if (Math.Abs(dragDistance.X) < SystemParameters.MinimumHorizontalDragDistance if (Math.Abs(dragDistance.X) < SystemParameters.MinimumHorizontalDragDistance
&& Math.Abs(dragDistance.Y) < SystemParameters.MinimumVerticalDragDistance && Math.Abs(dragDistance.Y) < SystemParameters.MinimumVerticalDragDistance
&& e.ChangedButton == MouseButton.Left) && (e.ChangedButton == MouseButton.Left || e.ChangedButton == MouseButton.Middle))
{ {
// click without moving mouse // click without moving mouse
var referenceSegment = GetReferenceSegmentAtMousePosition(); var referenceSegment = GetReferenceSegmentAtMousePosition();
@ -878,7 +878,7 @@ namespace ICSharpCode.ILSpy.TextView
// cursor position and the mouse position. // cursor position and the mouse position.
textEditor.TextArea.MouseSelectionMode = MouseSelectionMode.None; textEditor.TextArea.MouseSelectionMode = MouseSelectionMode.None;
JumpToReference(referenceSegment); JumpToReference(referenceSegment, e.ChangedButton == MouseButton.Middle || Keyboard.Modifiers.HasFlag(ModifierKeys.Shift));
} }
} }
} }

9
ILSpy/TreeNodes/ILSpyTreeNode.cs

@ -16,9 +16,12 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Windows;
using System.Windows.Threading;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using ICSharpCode.TreeView; using ICSharpCode.TreeView;
@ -69,6 +72,12 @@ namespace ICSharpCode.ILSpy.TreeNodes
return false; return false;
} }
public override void ActivateItemSecondary(RoutedEventArgs e)
{
MainWindow.Instance.SelectNode(this, inNewTabPage: true);
MainWindow.Instance.Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)MainWindow.Instance.RefreshDecompiledView);
}
/// <summary> /// <summary>
/// Used to implement special save logic for some items. /// Used to implement special save logic for some items.
/// This method is called on the main thread when only a single item is selected. /// This method is called on the main thread when only a single item is selected.

8
SharpTreeView/SharpTreeNode.cs

@ -24,6 +24,7 @@ using System.Windows;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Input;
namespace ICSharpCode.TreeView namespace ICSharpCode.TreeView
{ {
@ -681,6 +682,13 @@ namespace ICSharpCode.TreeView
{ {
} }
/// <summary>
/// Gets called when the item is clicked with the middle mouse button.
/// </summary>
public virtual void ActivateItemSecondary(RoutedEventArgs e)
{
}
public override string ToString() public override string ToString()
{ {
// used for keyboard navigation // used for keyboard navigation

9
SharpTreeView/SharpTreeViewItem.cs

@ -119,6 +119,15 @@ namespace ICSharpCode.TreeView
} }
} }
protected override void OnMouseUp(MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Middle) {
Node.ActivateItemSecondary(e);
} else {
base.OnMouseUp(e);
}
}
#endregion #endregion
#region Drag and Drop #region Drag and Drop

Loading…
Cancel
Save