From 9dcf71dc31a4e59d13c6e509e960adab7bbde8d7 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Wed, 25 Jul 2018 08:05:48 -0500 Subject: [PATCH] new connection tree nodes will survive filtering until they exit edit mode resolves #1038 --- .../Controls/ConnectionTree/ConnectionTree.cs | 37 ++++++++++++++++--- .../ConnectionTreeSearchTextFilter.cs | 13 ++++++- mRemoteV1/UI/Window/ConnectionTreeWindow.cs | 9 +---- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs index c15f45b53..e73294e2f 100644 --- a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs +++ b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs @@ -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() + /// + /// Filters tree items based on the given + /// + /// The text to filter by + public void ApplyFilter(string filterText) { - base.UpdateFiltering(); - AutoResizeColumn(Columns[0]); + UseFiltering = true; + _connectionTreeSearchTextFilter.FilterText = filterText; + ModelFilter = _connectionTreeSearchTextFilter; + } + + /// + /// Removes all item filtering from the connection tree + /// + 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) diff --git a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTreeSearchTextFilter.cs b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTreeSearchTextFilter.cs index e31c0a5aa..82e388584 100644 --- a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTreeSearchTextFilter.cs +++ b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTreeSearchTextFilter.cs @@ -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; } = ""; + /// + /// A list of objects that should + /// always be included in the output, regardless of matching + /// the desired . + /// + public List SpecialInclusionList { get; } = new List(); + 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) || diff --git a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs index 99f0c520e..da8cec915 100644 --- a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs +++ b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs @@ -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 {