From 500608b383dc14310994b60abd035a7d180054c7 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Tue, 2 Apr 2019 15:21:45 -0500 Subject: [PATCH] fixed a few more bugs in the config window --- .../ConfigWindowTests/ConfigWindowGeneralTests.cs | 13 +++++++++++++ .../ConnectionInfoPropertyGrid.cs | 10 ++++++---- .../FilteredPropertyGrid/FilteredPropertyGrid.cs | 4 ++-- mRemoteV1/UI/Window/ConfigWindow.cs | 11 +++++++---- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowGeneralTests.cs b/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowGeneralTests.cs index 33e66559..1656b469 100644 --- a/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowGeneralTests.cs +++ b/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowGeneralTests.cs @@ -126,6 +126,19 @@ namespace mRemoteNGTests.UI.Window.ConfigWindowTests Assert.That(_configWindow.CanShowProperties, Is.EqualTo(selectedObjectNotNull)); } + [TestCaseSource(nameof(EveryNodeType))] + public void InheritancePropertiesAreVisibleInCertainCases(ConnectionInfo selectedObject) + { + _configWindow.SelectedTreeNode = selectedObject; + + var shouldBeAvailable = selectedObject != null && + !(selectedObject is RootNodeInfo) && + !(selectedObject is PuttySessionInfo) && + !(selectedObject.Parent is RootNodeInfo); + + Assert.That(_configWindow.CanShowInheritance, Is.EqualTo(shouldBeAvailable)); + } + private static IEnumerable ConnectionInfoGeneralTestCases() { var protocolTypes = typeof(ProtocolType).GetEnumValues().OfType(); diff --git a/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/ConnectionInfoPropertyGrid.cs b/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/ConnectionInfoPropertyGrid.cs index dab41fb8..edc135c8 100644 --- a/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/ConnectionInfoPropertyGrid.cs +++ b/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/ConnectionInfoPropertyGrid.cs @@ -33,8 +33,6 @@ namespace mRemoteNG.UI.Controls.ConnectionInfoPropertyGrid get => _selectedConnectionInfo; set { - if (value == null) - return; if (_selectedConnectionInfo == value) return; @@ -97,7 +95,7 @@ namespace mRemoteNG.UI.Controls.ConnectionInfoPropertyGrid SelectedObject = SelectedConnectionInfo; break; case PropertyMode.Inheritance: - SelectedObject = SelectedConnectionInfo.Inheritance; + SelectedObject = SelectedConnectionInfo?.Inheritance; break; case PropertyMode.DefaultConnection: SelectedObject = DefaultConnectionInfo.Instance; @@ -107,13 +105,17 @@ namespace mRemoteNG.UI.Controls.ConnectionInfoPropertyGrid break; } - ShowHideGridItems(); + if (SelectedObject != null) + ShowHideGridItems(); } private void ShowHideGridItems() { try { + if (SelectedConnectionInfo == null) + return; + if (RootNodeSelected && PropertyMode == PropertyMode.Connection) { if (SelectedConnectionInfo is RootPuttySessionsNodeInfo) diff --git a/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs b/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs index c0f6589f..80e3ae41 100644 --- a/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs +++ b/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs @@ -125,8 +125,8 @@ namespace mRemoteNG.UI.Controls.FilteredPropertyGrid } else if (_mWrapper.SelectedObject != value) { - var needrefresh = value.GetType() != _mWrapper.SelectedObject.GetType(); - _mWrapper.SelectedObject = value; + var needrefresh = value?.GetType() != _mWrapper.SelectedObject?.GetType(); + _mWrapper.SelectedObject = value ?? new object(); if (needrefresh) RefreshProperties(); } diff --git a/mRemoteV1/UI/Window/ConfigWindow.cs b/mRemoteV1/UI/Window/ConfigWindow.cs index 6367a262..44a6e35f 100644 --- a/mRemoteV1/UI/Window/ConfigWindow.cs +++ b/mRemoteV1/UI/Window/ConfigWindow.cs @@ -208,7 +208,8 @@ namespace mRemoteNG.UI.Window public bool InheritanceVisible => _btnShowInheritance.Checked; public bool CanShowInheritance => !_pGrid.RootNodeSelected && - _pGrid.SelectedConnectionInfo.Parent != null && + SelectedTreeNode != null && + _pGrid.SelectedConnectionInfo?.Parent != null && !(_pGrid.SelectedConnectionInfo.Parent is RootNodeInfo); public bool DefaultPropertiesVisible => _btnShowDefaultProperties.Checked; @@ -389,12 +390,14 @@ namespace mRemoteNG.UI.Window private void UpdateIconButton() { - _btnIcon.Enabled = !_pGrid.IsShowingDefaultProperties && - !_pGrid.RootNodeSelected; + _btnIcon.Enabled = + _pGrid.SelectedConnectionInfo != null && + !_pGrid.IsShowingDefaultProperties && + !_pGrid.RootNodeSelected; _btnIcon.Image = _btnIcon.Enabled ? ConnectionIcon - .FromString(_pGrid.SelectedConnectionInfo.Icon) + .FromString(_pGrid.SelectedConnectionInfo?.Icon)? .ToBitmap() : null; }