resolved bug that would sometimes disable connection tree hot keys

bug was introduced in #652. I made sure that the original issue is still resolved
This commit is contained in:
David Sparer
2017-11-04 22:04:08 -05:00
parent 7a002e4b89
commit 88d735ed56
3 changed files with 43 additions and 41 deletions

View File

@@ -20,7 +20,9 @@ namespace mRemoteNG.UI.Controls
private ConnectionTreeModel _connectionTreeModel;
private readonly ConnectionTreeDragAndDropHandler _dragAndDropHandler = new ConnectionTreeDragAndDropHandler();
private readonly PuttySessionsManager _puttySessionsManager = PuttySessionsManager.Instance;
private bool _nodeInEditMode;
private bool _allowEdit;
private ConnectionContextMenu _contextMenu;
public ConnectionInfo SelectedNode => (ConnectionInfo) SelectedObject;
@@ -59,6 +61,8 @@ namespace mRemoteNG.UI.Controls
SmallImageList = imageList.GetImageList();
AddColumns(imageList.ImageGetter);
LinkModelToView();
_contextMenu = new ConnectionContextMenu(this);
ContextMenuStrip = _contextMenu;
SetupDropSink();
SetEventHandlers();
}
@@ -108,7 +112,8 @@ namespace mRemoteNG.UI.Controls
CellToolTipShowing += tvConnections_CellToolTipShowing;
ModelCanDrop += _dragAndDropHandler.HandleEvent_ModelCanDrop;
ModelDropped += _dragAndDropHandler.HandleEvent_ModelDropped;
BeforeLabelEdit += HandleCheckForValidEdit;
BeforeLabelEdit += OnBeforeLabelEdit;
AfterLabelEdit += OnAfterLabelEdit;
}
/// <summary>
@@ -263,20 +268,6 @@ namespace mRemoteNG.UI.Controls
{
_allowEdit = true;
SelectedItem.BeginEdit();
Runtime.SaveConnectionsAsync();
}
public void HandleCheckForValidEdit(object sender, LabelEditEventArgs e)
{
if (!(sender is ConnectionTree)) return;
if (_allowEdit)
{
_allowEdit = false;
}
else
{
e.CancelEdit = true;
}
}
public void DeleteSelectedNode()
@@ -337,6 +328,41 @@ namespace mRemoteNG.UI.Controls
Runtime.MessageCollector.AddExceptionStackTrace("tvConnections_MouseMove (UI.Window.ConnectionTreeWindow) failed", ex);
}
}
private void OnBeforeLabelEdit(object sender, LabelEditEventArgs e)
{
if (_nodeInEditMode || !(sender is ConnectionTree))
return;
if (!_allowEdit || SelectedNode is PuttySessionInfo || SelectedNode is RootPuttySessionsNodeInfo)
{
e.CancelEdit = true;
return;
}
_nodeInEditMode = true;
_contextMenu.DisableShortcutKeys();
}
private void OnAfterLabelEdit(object sender, LabelEditEventArgs e)
{
if (!_nodeInEditMode)
return;
try
{
_contextMenu.EnableShortcutKeys();
ConnectionTreeModel.RenameNode(SelectedNode, e.Label);
_nodeInEditMode = false;
_allowEdit = false;
Windows.ConfigForm.SelectedTreeNode = SelectedNode;
Runtime.SaveConnectionsAsync();
}
catch (Exception ex)
{
Runtime.MessageCollector.AddExceptionStackTrace("tvConnections_AfterLabelEdit (UI.Window.ConnectionTreeWindow) failed", ex);
}
}
#endregion
}
}

View File

@@ -12,6 +12,7 @@ namespace mRemoteNG.UI.Controls
FillsFreeSpace = false;
AspectGetter = item => ((ConnectionInfo) item).Name;
ImageGetter = imageGetterDelegate;
AutoCompleteEditor = false;
}
}
}

View File

@@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using mRemoteNG.Tree.Root;
using mRemoteNG.UI.Controls;
using WeifenLuo.WinFormsUI.Docking;
@@ -15,10 +16,8 @@ namespace mRemoteNG.UI.Window
{
public partial class ConnectionTreeWindow
{
private readonly ConnectionContextMenu _contextMenu;
private readonly IConnectionInitiator _connectionInitiator = new ConnectionInitiator();
public ConnectionInfo SelectedNode => olvConnections.SelectedNode;
public ConnectionTree ConnectionTree
@@ -32,8 +31,6 @@ namespace mRemoteNG.UI.Window
WindowType = WindowType.Tree;
DockPnl = panel;
InitializeComponent();
_contextMenu = new ConnectionContextMenu(olvConnections);
olvConnections.ContextMenuStrip = _contextMenu;
SetMenuEventHandlers();
SetConnectionTreeEventHandlers();
Settings.Default.PropertyChanged += (sender, args) => SetConnectionTreeEventHandlers();
@@ -84,8 +81,6 @@ namespace mRemoteNG.UI.Window
private void SetConnectionTreeEventHandlers()
{
olvConnections.NodeDeletionConfirmer = new SelectedConnectionDeletionConfirmer(olvConnections, MessageBox.Show);
olvConnections.BeforeLabelEdit += tvConnections_BeforeLabelEdit;
olvConnections.AfterLabelEdit += tvConnections_AfterLabelEdit;
olvConnections.KeyDown += tvConnections_KeyDown;
olvConnections.KeyPress += tvConnections_KeyPress;
SetTreePostSetupActions();
@@ -171,26 +166,6 @@ namespace mRemoteNG.UI.Window
Runtime.SaveConnectionsAsync();
}
private void tvConnections_BeforeLabelEdit(object sender, LabelEditEventArgs e)
{
_contextMenu.DisableShortcutKeys();
}
private void tvConnections_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
try
{
_contextMenu.EnableShortcutKeys();
ConnectionTree.ConnectionTreeModel.RenameNode(SelectedNode, e.Label);
Windows.ConfigForm.SelectedTreeNode = SelectedNode;
Runtime.SaveConnectionsAsync();
}
catch (Exception ex)
{
Runtime.MessageCollector.AddExceptionStackTrace("tvConnections_AfterLabelEdit (UI.Window.ConnectionTreeWindow) failed", ex);
}
}
#endregion
#region Search