Skip to content

Commit 0465187

Browse files
authored
Fix: Improve re-select if filter for application or settingsview is applied or removed (#2325)
* Fix: Improve re-select if filter for application or settingsview is applied / removed * Docs: #2325
1 parent 42d9b85 commit 0465187

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ public ApplicationInfo SelectedApplication
175175
}
176176
}
177177

178-
private ApplicationName _filterLastViewName;
179-
private int? _filterLastCount;
178+
private ApplicationName _searchLastSelectedApplicationName;
180179

181180
private string _search = string.Empty;
182181
public string Search
@@ -189,25 +188,19 @@ public string Search
189188

190189
_search = value;
191190

191+
// Store the current selected application name
192192
if (SelectedApplication != null)
193-
_filterLastViewName = SelectedApplication.Name;
193+
_searchLastSelectedApplicationName = SelectedApplication.Name;
194194

195+
// Refresh (apply filter)
195196
Applications.Refresh();
196197

197-
var sourceCollection = Applications.SourceCollection.Cast<ApplicationInfo>();
198-
var filteredCollection = Applications.Cast<ApplicationInfo>();
198+
// Try to select the last selected application
199+
if (!Applications.IsEmpty && SelectedApplication == null)
200+
SelectedApplication = Applications.Cast<ApplicationInfo>().FirstOrDefault(x => x.Name == _searchLastSelectedApplicationName) ?? Applications.Cast<ApplicationInfo>().FirstOrDefault();
199201

200-
var sourceInfos = sourceCollection as ApplicationInfo[] ?? sourceCollection.ToArray();
201-
var filteredInfos = filteredCollection as ApplicationInfo[] ?? filteredCollection.ToArray();
202-
203-
_filterLastCount ??= sourceInfos.Length;
204-
205-
SelectedApplication = _filterLastCount > filteredInfos.Length ? filteredInfos.FirstOrDefault() : sourceInfos.FirstOrDefault(x => x.Name == _filterLastViewName);
206-
207-
_filterLastCount = filteredInfos.Length;
208-
209-
// Show note when there was nothing found
210-
SearchNothingFound = filteredInfos.Length == 0;
202+
// Show note if nothing was found
203+
SearchNothingFound = Applications.IsEmpty;
211204

212205
OnPropertyChanged();
213206
}
@@ -577,8 +570,8 @@ private void LoadApplicationList()
577570

578571
_isApplicationListLoading = false;
579572

580-
// Select the application
581-
SelectedApplication = Applications.SourceCollection.Cast<ApplicationInfo>().FirstOrDefault(x => x.Name == (CommandLineManager.Current.Application != ApplicationName.None ? CommandLineManager.Current.Application : SettingsManager.Current.General_DefaultApplicationViewName));
573+
// Select the application
574+
SelectedApplication = Applications.Cast<ApplicationInfo>().FirstOrDefault(x => x.Name == (CommandLineManager.Current.Application != ApplicationName.None ? CommandLineManager.Current.Application : SettingsManager.Current.General_DefaultApplicationViewName));
582575

583576
// Scroll into view
584577
if (SelectedApplication != null)

Source/NETworkManager/ViewModels/SettingsViewModel.cs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public int SelectedTabIndex
3434

3535
public ICollectionView SettingsViews { get; private set; }
3636

37+
private SettingsViewName _searchLastSelectedSettingsViewName;
38+
3739
private string _search;
3840
public string Search
3941
{
@@ -45,10 +47,19 @@ public string Search
4547

4648
_search = value;
4749

50+
// Store the current selected settings view name
51+
if (SelectedSettingsView != null)
52+
_searchLastSelectedSettingsViewName = SelectedSettingsView.Name;
53+
54+
// Refresh (apply filter)
4855
SettingsViews.Refresh();
4956

50-
// Show note when there was nothing found
51-
SearchNothingFound = !SettingsViews.Cast<SettingsViewInfo>().Any();
57+
// Try to select the last selected application
58+
if (!SettingsViews.IsEmpty && SelectedSettingsView == null)
59+
SelectedSettingsView = SettingsViews.Cast<SettingsViewInfo>().FirstOrDefault(x => x.Name == _searchLastSelectedSettingsViewName) ?? SettingsViews.Cast<SettingsViewInfo>().FirstOrDefault();
60+
61+
// Show note if nothing was found
62+
SearchNothingFound = SettingsViews.IsEmpty;
5263

5364
OnPropertyChanged();
5465
}
@@ -110,7 +121,7 @@ public SettingsViewInfo SelectedSettingsView
110121
private SettingsUpdateView _settingsUpdateView;
111122
private SettingsSettingsView _settingsSettingsView;
112123
private SettingsProfilesView _settingsProfilesView;
113-
private DashboardSettingsView _dashboardSettingsView;
124+
private DashboardSettingsView _dashboardSettingsView;
114125
private IPScannerSettingsView _ipScannerSettingsView;
115126
private PortScannerSettingsView _portScannerSettingsView;
116127
private PingMonitorSettingsView _pingMonitorSettingsView;
@@ -124,7 +135,7 @@ public SettingsViewInfo SelectedSettingsView
124135
private WebConsoleSettingsView _webConsoleSettingsView;
125136
private SNMPSettingsView _snmpSettingsView;
126137
private SNTPLookupSettingsView _sntpLookupSettingsView;
127-
private WakeOnLANSettingsView _wakeOnLANSettingsView;
138+
private WakeOnLANSettingsView _wakeOnLANSettingsView;
128139
private BitCalculatorSettingsView _bitCalculatorSettingsView;
129140
#endregion
130141

@@ -169,14 +180,18 @@ private void ClearSearchAction()
169180
#region Methods
170181
public void ChangeSettingsView(ApplicationName applicationName)
171182
{
172-
// Don't change the view, if the user has filtered the settings...
173-
if (!string.IsNullOrEmpty(Search))
183+
if (SettingsViews.IsEmpty)
174184
return;
175185

176-
if (Enum.GetNames(typeof(SettingsViewName)).Contains(applicationName.ToString()) && ApplicationName.None.ToString() != applicationName.ToString())
177-
SelectedSettingsView = SettingsViews.SourceCollection.Cast<SettingsViewInfo>().FirstOrDefault(x => x.Name.ToString() == applicationName.ToString());
178-
else
179-
SelectedSettingsView = SettingsViews.SourceCollection.Cast<SettingsViewInfo>().FirstOrDefault(x => x.Name == SettingsViewName.General);
186+
// Try to find application in (filtered) settings views
187+
var selectedApplicationSettingsView = SettingsViews.Cast<SettingsViewInfo>().FirstOrDefault(x => x.Name.ToString() == applicationName.ToString());
188+
189+
// Update selected settings view if application is found in (filtered) settings views
190+
if (selectedApplicationSettingsView != null)
191+
SelectedSettingsView = selectedApplicationSettingsView;
192+
193+
// Set default settings view
194+
SelectedSettingsView ??= SettingsViews.Cast<SettingsViewInfo>().FirstOrDefault();
180195
}
181196

182197
private void ChangeSettingsContent(SettingsViewInfo settingsViewInfo)
@@ -222,7 +237,7 @@ private void ChangeSettingsContent(SettingsViewInfo settingsViewInfo)
222237
_settingsAutostartView ??= new SettingsAutostartView();
223238

224239
SettingsContent = _settingsAutostartView;
225-
break;
240+
break;
226241
case SettingsViewName.Update:
227242
_settingsUpdateView ??= new SettingsUpdateView();
228243

@@ -295,7 +310,7 @@ private void ChangeSettingsContent(SettingsViewInfo settingsViewInfo)
295310
break;
296311
case SettingsViewName.WebConsole:
297312
_webConsoleSettingsView ??= new WebConsoleSettingsView();
298-
313+
299314
SettingsContent = _webConsoleSettingsView;
300315
break;
301316
case SettingsViewName.SNMP:
@@ -312,7 +327,7 @@ private void ChangeSettingsContent(SettingsViewInfo settingsViewInfo)
312327
_wakeOnLANSettingsView ??= new WakeOnLANSettingsView();
313328

314329
SettingsContent = _wakeOnLANSettingsView;
315-
break;
330+
break;
316331
case SettingsViewName.BitCalculator:
317332
_bitCalculatorSettingsView ??= new BitCalculatorSettingsView();
318333

@@ -331,4 +346,4 @@ public DocumentationIdentifier GetDocumentationIdentifier()
331346
};
332347
}
333348
#endregion
334-
}
349+
}

docs/Changelog/next-release.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Breaking changes
6262
- Fix default value for Remote Desktop sreen size [#2293](https://github.com/BornToBeRoot/NETworkManager/pull/2293){:target="\_blank"}
6363
- Enable Remote Desktop `Use gateway credentials` only if logon method is set to `Userpass` [#2316](https://github.com/BornToBeRoot/NETworkManager/pull/2316){:target="\_blank"}
6464
- Fix validation rule for TigerVNC port [#2309](https://github.com/BornToBeRoot/NETworkManager/pull/2309){:target="\_blank"}
65+
- Settings
66+
- Settings view is now re-selected if the filter (search) is removed [#2325](https://github.com/BornToBeRoot/NETworkManager/pull/2325){:target="\_blank"}
67+
- If settings are opened again, the last selected settings view is now selected (except an application was selected that has a settings view, then the settings view of the application is selected) [#2325](https://github.com/BornToBeRoot/NETworkManager/pull/2325){:target="\_blank"}
6568

6669
## Deprecated
6770

@@ -73,7 +76,7 @@ Deprecated
7376

7477
## Other
7578

76-
- Code cleanup [#2100](https://github.com/BornToBeRoot/NETworkManager/pull/2100){:target="\_blank"} [#2172](https://github.com/BornToBeRoot/NETworkManager/pull/2172){:target="\_blank"} [#2254](https://github.com/BornToBeRoot/NETworkManager/pull/2254){:target="\_blank"}
79+
- Code cleanup [#2100](https://github.com/BornToBeRoot/NETworkManager/pull/2100){:target="\_blank"} [#2172](https://github.com/BornToBeRoot/NETworkManager/pull/2172){:target="\_blank"} [#2254](https://github.com/BornToBeRoot/NETworkManager/pull/2254){:target="\_blank"} [#2325](https://github.com/BornToBeRoot/NETworkManager/pull/2325){:target="\_blank"}
7780
- Language files updated [#transifex](https://github.com/BornToBeRoot/NETworkManager/pulls?q=author%3Aapp%2Ftransifex-integration){:target="\_blank"}
7881
- Dependencies updated [#dependencies](https://github.com/BornToBeRoot/NETworkManager/pulls?q=author%3Aapp%2Fdependabot){:target="\_blank"}
7982
- Add documentation for:
@@ -83,7 +86,7 @@ Deprecated
8386
- Application > DNS Lookup [#2273](https://github.com/BornToBeRoot/NETworkManager/pull/2273){:target="\_blank"}
8487
- Application > Remote Desktop [#2293](https://github.com/BornToBeRoot/NETworkManager/pull/2293){:target="\_blank"} [#2324](https://github.com/BornToBeRoot/NETworkManager/pull/2324){:target="\_blank"}
8588
- Application > PowerShell [#2249](https://github.com/BornToBeRoot/NETworkManager/pull/2249){:target="\_blank"} [#2324](https://github.com/BornToBeRoot/NETworkManager/pull/2324){:target="\_blank"}
86-
- Application > PuTTY [#2324](https://github.com/BornToBeRoot/NETworkManager/pull/2324){:target="\_blank"}
89+
- Application > PuTTY [#2324](https://github.com/BornToBeRoot/NETworkManager/pull/2324){:target="\_blank"}
8790
- Application > TigerVNC [#2248](https://github.com/BornToBeRoot/NETworkManager/pull/2248){:target="\_blank"} [#2324](https://github.com/BornToBeRoot/NETworkManager/pull/2324){:target="\_blank"}
8891
- Application > Web Console [#2244](https://github.com/BornToBeRoot/NETworkManager/pull/2244){:target="\_blank"} [#2324](https://github.com/BornToBeRoot/NETworkManager/pull/2324){:target="\_blank"}
8992
- Application > SNMP [#2289](https://github.com/BornToBeRoot/NETworkManager/pull/2289){:target="\_blank"} [#2293](https://github.com/BornToBeRoot/NETworkManager/pull/2293){:target="\_blank"}

0 commit comments

Comments
 (0)