new connection tree nodes will survive filtering until they exit edit mode

resolves #1038
This commit is contained in:
David Sparer
2018-07-25 08:05:48 -05:00
parent 8bf9af0ed8
commit 9dcf71dc31
3 changed files with 45 additions and 14 deletions

View File

@@ -20,7 +20,8 @@ namespace mRemoteNG.UI.Controls
private readonly ConnectionTreeDragAndDropHandler _dragAndDropHandler = new ConnectionTreeDragAndDropHandler();
private readonly PuttySessionsManager _puttySessionsManager = PuttySessionsManager.Instance;
private readonly StatusImageList _statusImageList = new StatusImageList();
private bool _nodeInEditMode;
private readonly ConnectionTreeSearchTextFilter _connectionTreeSearchTextFilter = new ConnectionTreeSearchTextFilter();
private bool _nodeInEditMode;
private bool _allowEdit;
private ConnectionContextMenu _contextMenu;
private ConnectionTreeModel _connectionTreeModel;
@@ -54,8 +55,6 @@ namespace mRemoteNG.UI.Controls
UseOverlays = false;
}
protected override void Dispose(bool disposing)
{
if (disposing)
@@ -265,6 +264,9 @@ namespace mRemoteNG.UI.Controls
if (SelectedNode?.GetTreeNodeType() == TreeNodeType.PuttyRoot || SelectedNode?.GetTreeNodeType() == TreeNodeType.PuttySession)
return;
// the new node will survive filtering if filtering is active
_connectionTreeSearchTextFilter.SpecialInclusionList.Add(newNode);
// use root node if no node is selected
ConnectionInfo parentNode = SelectedNode ?? GetRootConnectionNode();
DefaultConnectionInfo.Instance.SaveTo(newNode);
@@ -332,10 +334,24 @@ namespace mRemoteNG.UI.Controls
AutoResizeColumn(Columns[0]);
}
protected override void UpdateFiltering()
/// <summary>
/// Filters tree items based on the given <see cref="filterText"/>
/// </summary>
/// <param name="filterText">The text to filter by</param>
public void ApplyFilter(string filterText)
{
base.UpdateFiltering();
AutoResizeColumn(Columns[0]);
UseFiltering = true;
_connectionTreeSearchTextFilter.FilterText = filterText;
ModelFilter = _connectionTreeSearchTextFilter;
}
/// <summary>
/// Removes all item filtering from the connection tree
/// </summary>
public void RemoveFilter()
{
UseFiltering = false;
ResetColumnFiltering();
}
private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
@@ -360,6 +376,12 @@ namespace mRemoteNG.UI.Controls
}
}
protected override void UpdateFiltering()
{
base.UpdateFiltering();
AutoResizeColumn(Columns[0]);
}
private void tvConnections_AfterSelect(object sender, EventArgs e)
{
try
@@ -431,6 +453,9 @@ namespace mRemoteNG.UI.Controls
ConnectionTreeModel.RenameNode(SelectedNode, e.Label);
_nodeInEditMode = false;
_allowEdit = false;
// ensures that if we are filtering and a new item is added that doesn't match the filter, it will be filtered out
_connectionTreeSearchTextFilter.SpecialInclusionList.Clear();
UpdateFiltering();
Windows.ConfigForm.SelectedTreeNode = SelectedNode;
}
catch (Exception ex)

View File

@@ -1,4 +1,5 @@
using BrightIdeasSoftware;
using System.Collections.Generic;
using BrightIdeasSoftware;
using mRemoteNG.Connection;
namespace mRemoteNG.UI.Controls
@@ -7,12 +8,22 @@ namespace mRemoteNG.UI.Controls
{
public string FilterText { get; set; } = "";
/// <summary>
/// A list of <see cref="ConnectionInfo"/> objects that should
/// always be included in the output, regardless of matching
/// the desired <see cref="FilterText"/>.
/// </summary>
public List<ConnectionInfo> SpecialInclusionList { get; } = new List<ConnectionInfo>();
public bool Filter(object modelObject)
{
var objectAsConnectionInfo = modelObject as ConnectionInfo;
if (objectAsConnectionInfo == null)
return false;
if (SpecialInclusionList.Contains(objectAsConnectionInfo))
return true;
var filterTextLower = FilterText.ToLowerInvariant();
if (objectAsConnectionInfo.Name.ToLowerInvariant().Contains(filterTextLower) ||

View File

@@ -19,7 +19,6 @@ namespace mRemoteNG.UI.Window
private readonly ConnectionContextMenu _contextMenu;
private readonly IConnectionInitiator _connectionInitiator = new ConnectionInitiator();
private ThemeManager _themeManager;
private readonly ConnectionTreeSearchTextFilter _connectionTreeSearchTextFilter = new ConnectionTreeSearchTextFilter();
public ConnectionInfo SelectedNode => olvConnections.SelectedNode;
@@ -43,7 +42,6 @@ namespace mRemoteNG.UI.Window
SetMenuEventHandlers();
SetConnectionTreeEventHandlers();
Settings.Default.PropertyChanged += OnAppSettingsChanged;
olvConnections.ModelFilter = _connectionTreeSearchTextFilter;
}
private void OnAppSettingsChanged(object o, PropertyChangedEventArgs propertyChangedEventArgs)
@@ -243,13 +241,10 @@ namespace mRemoteNG.UI.Window
{
if (txtSearch.Text == "" || txtSearch.Text == Language.strSearchPrompt)
{
olvConnections.UseFiltering = false;
olvConnections.ResetColumnFiltering();
olvConnections.RemoveFilter();
return;
}
olvConnections.UseFiltering = true;
_connectionTreeSearchTextFilter.FilterText = txtSearch.Text;
olvConnections.ModelFilter = _connectionTreeSearchTextFilter;
olvConnections.ApplyFilter(txtSearch.Text);
}
else
{