Skip to content

Feature: #3109 - Add F2/Delete hotkeys in HostsFileEditor & Refactor #3113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Source/NETworkManager/ViewModels/HostsFileEditorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,21 @@ private async Task RestartAsAdminAction()
}
catch (Exception ex)
{
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error, ex.Message,
MessageDialogStyle.Affirmative, AppearanceManager.MetroDialog);
var childWindow = new OKMessageChildWindow();

var childWindowViewModel = new OKMessageViewModel(_ =>
{
childWindow.IsOpen = false;
ConfigurationManager.Current.IsChildWindowOpen = false;
}, ex.Message, Strings.OK, ChildWindowIcon.Error);

childWindow.Title = Strings.Error;

childWindow.DataContext = childWindowViewModel;

ConfigurationManager.Current.IsChildWindowOpen = true;

await (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)

private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
_viewModel.EditAWSProfile().ConfigureAwait(false);
if (_viewModel.EditAWSProfileCommand.CanExecute(null))
_viewModel.EditAWSProfileCommand.Execute(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public CredentialsPasswordProfileFileChildWindow()

private void ChildWindow_OnLoaded(object sender, RoutedEventArgs e)
{
// Focus the PasswordBox when the child window is loaded
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
{
PasswordBoxPassword.Focus();
Expand Down
9 changes: 5 additions & 4 deletions Source/NETworkManager/Views/DNSLookupSettingsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Windows;
using MahApps.Metro.Controls.Dialogs;
using NETworkManager.ViewModels;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using MahApps.Metro.Controls.Dialogs;
using NETworkManager.ViewModels;

namespace NETworkManager.Views;

Expand All @@ -24,6 +24,7 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)

private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
_viewModel.EditDNSServer().ConfigureAwait(false);
if (_viewModel.EditDNSServerCommand.CanExecute(null))
_viewModel.EditDNSServerCommand.Execute(null);
}
}
1 change: 0 additions & 1 deletion Source/NETworkManager/Views/GroupChildWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public GroupChildWindow(Window parentWindow)

private void ChildWindow_OnLoaded(object sender, RoutedEventArgs e)
{
// Focus the PasswordBox when the child window is loaded
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
{
TextBoxName.Focus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public HostsFileEditorEntryChildWindow()

private void ChildWindow_OnLoaded(object sender, RoutedEventArgs e)
{
// Focus the PasswordBox when the child window is loaded
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
{
TextBoxIPAddress.Focus();
Expand Down
5 changes: 5 additions & 0 deletions Source/NETworkManager/Views/HostsFileEditorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
</controls:MultiSelectDataGrid.Resources>
<controls:MultiSelectDataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource MahApps.Styles.DataGridRow}">
<EventSetter Event="MouseDoubleClick" Handler="DataGridRow_MouseDoubleClick" />
<Setter Property="ContextMenu" Value="{StaticResource MultiRowContextMenu}" />
<Style.Triggers>
<DataTrigger
Expand Down Expand Up @@ -197,6 +198,10 @@
SortMemberPath="Hostname"
MinWidth="200" />
</controls:MultiSelectDataGrid.Columns>
<controls:MultiSelectDataGrid.InputBindings>
<KeyBinding Command="{Binding EditEntryCommand}" Key="F2" />
<KeyBinding Command="{Binding DeleteEntryCommand}" Key="Delete" />
</controls:MultiSelectDataGrid.InputBindings>
</controls:MultiSelectDataGrid>
<Grid Grid.Column="0" Grid.Row="4">
<Grid.ColumnDefinitions>
Expand Down
12 changes: 9 additions & 3 deletions Source/NETworkManager/Views/HostsFileEditorView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using MahApps.Metro.Controls.Dialogs;
using MahApps.Metro.Controls.Dialogs;
using NETworkManager.ViewModels;
using System.Windows;
using System.Windows.Controls;

namespace NETworkManager.Views;

Expand Down Expand Up @@ -30,4 +30,10 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)
if (sender is ContextMenu menu)
menu.DataContext = _viewModel;
}

private void DataGridRow_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (_viewModel.EditEntryCommand.CanExecute(null))
_viewModel.EditEntryCommand.Execute(null);
}
}
11 changes: 7 additions & 4 deletions Source/NETworkManager/Views/OKCancelInfoMessageChildWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
AllowMove="True"
TitleForeground="{DynamicResource MahApps.Brushes.Gray3}"
CloseByEscape="False"
OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray.SemiTransparent}"
OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray.SemiTransparent}"
Loaded="ChildWindow_Loaded"
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:OKCancelInfoMessageViewModel}">
<Grid Margin="10">
<Grid.RowDefinitions>
Expand All @@ -40,13 +41,15 @@
<TextBlock Grid.Column="2" Grid.Row="0"
VerticalAlignment="Center"
Text="{Binding Message}"
Style="{StaticResource ResourceKey=WrapTextBlock}"/>
Style="{StaticResource ResourceKey=WrapTextBlock}"/>
</Grid>
</ScrollViewer>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="{Binding OKButtonText}" Command="{Binding Path=OKCommand}" IsDefault="True"
<Button x:Name="ButtonOK"
Content="{Binding OKButtonText}" Command="{Binding Path=OKCommand}" IsDefault="True"
Style="{StaticResource ResourceKey=HighlightedButton}" Margin="0,0,10,0" />
<Button Content="{Binding CancelButtonText}" Command="{Binding Path=CancelCommand}" IsCancel="True"
<Button x:Name="ButtonCancel"
Content="{Binding CancelButtonText}" Command="{Binding Path=CancelCommand}" IsCancel="True"
Style="{StaticResource ResourceKey=DefaultButton}" />
</StackPanel>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
namespace NETworkManager.Views;
using System;
using System.Windows.Threading;

namespace NETworkManager.Views;

public partial class OKCancelInfoMessageChildWindow
{
public OKCancelInfoMessageChildWindow()
{
InitializeComponent();
}

private void ChildWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
{
ButtonOK.Focus();
}));
}
}
6 changes: 4 additions & 2 deletions Source/NETworkManager/Views/OKMessageChildWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
AllowMove="True"
TitleForeground="{DynamicResource MahApps.Brushes.Gray3}"
CloseByEscape="False"
OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray.SemiTransparent}"
OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray.SemiTransparent}"
Loaded="ChildWindow_Loaded"
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:OKMessageViewModel}">
<simpleChildWindow:ChildWindow.Resources>
<converters:ChildWindowIconToRectangleStyleConverter x:Key="ChildWindowIconToRectangleStyleConverter" />
Expand Down Expand Up @@ -47,7 +48,8 @@
</Grid>
</ScrollViewer>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="{Binding OKButtonText}" Command="{Binding Path=OKCommand}" IsDefault="True"
<Button x:Name="ButtonOK"
Content="{Binding OKButtonText}" Command="{Binding Path=OKCommand}" IsDefault="True"
Style="{StaticResource ResourceKey=HighlightedButton}" />
</StackPanel>
</Grid>
Expand Down
13 changes: 12 additions & 1 deletion Source/NETworkManager/Views/OKMessageChildWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
namespace NETworkManager.Views;
using System;
using System.Windows.Threading;

namespace NETworkManager.Views;

public partial class OKMessageChildWindow
{
public OKMessageChildWindow()
{
InitializeComponent();
}

private void ChildWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
{
ButtonOK.Focus();
}));
}
}
3 changes: 2 additions & 1 deletion Source/NETworkManager/Views/PortScannerSettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private void RowContextMenu_OnOpened(object sender, RoutedEventArgs e)

private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
_viewModel.EditPortProfile().ConfigureAwait(false);
if (_viewModel.EditPortProfileCommand.CanExecute(null))
_viewModel.EditPortProfileCommand.Execute(null);
}
}
1 change: 0 additions & 1 deletion Source/NETworkManager/Views/ProfileChildWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public ProfileChildWindow(Window parentWindow)

private void ChildWindow_OnLoaded(object sender, RoutedEventArgs e)
{
// Focus the PasswordBox when the child window is loaded
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
{
TextBoxName.Focus();
Expand Down
3 changes: 2 additions & 1 deletion Source/NETworkManager/Views/SNMPSettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private void RowContextMenu_OnOpened(object sender, RoutedEventArgs e)

private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
_viewModel.EditOIDProfile().ConfigureAwait(false);
if(_viewModel.EditOIDProfileCommand.CanExecute(null))
_viewModel.EditOIDProfileCommand.Execute(null);
}
}
3 changes: 2 additions & 1 deletion Source/NETworkManager/Views/SNTPLookupSettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)

private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
_viewModel.EditServer().ConfigureAwait(false);
if(_viewModel.EditServerCommand.CanExecute(null))
_viewModel.EditServerCommand.Execute(null);
}
}
3 changes: 2 additions & 1 deletion Source/NETworkManager/Views/SettingsProfilesView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)

private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
_viewModel.EditProfileFileCommand.Execute(null);
if (_viewModel.EditProfileFileCommand.CanExecute(null))
_viewModel.EditProfileFileCommand.Execute(null);
}
}
4 changes: 3 additions & 1 deletion Source/NETworkManager/Views/UpgradeChildWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CloseByEscape="False"
Padding="20"
OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray8}"
Loaded="ChildWindow_Loaded"
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:UpgradeViewModel}">
<Grid Margin="10">
<Grid.RowDefinitions>
Expand Down Expand Up @@ -76,7 +77,8 @@
</Button>
</StackPanel>
</ScrollViewer>
<Button Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" Content="{x:Static Member=localization:Strings.Continue}"
<Button x:Name="ButtonContinue"
Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" Content="{x:Static Member=localization:Strings.Continue}"
Command="{Binding Path=ContinueCommand}" IsDefault="True"
Style="{StaticResource ResourceKey=HighlightedButton}" />
</Grid>
Expand Down
13 changes: 12 additions & 1 deletion Source/NETworkManager/Views/UpgradeChildWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
namespace NETworkManager.Views;
using System;
using System.Windows.Threading;

namespace NETworkManager.Views;

public partial class UpgradeChildWindow
{
public UpgradeChildWindow()
{
InitializeComponent();
}

private void ChildWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
{
ButtonContinue.Focus();
}));
}
}
4 changes: 3 additions & 1 deletion Source/NETworkManager/Views/WelcomeChildWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CloseByEscape="False"
Padding="20"
OverlayBrush="{DynamicResource MahApps.Brushes.Gray8}"
Loaded="ChildWindow_Loaded"
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:WelcomeViewModel}">
<Grid Margin="10">
<Grid.RowDefinitions>
Expand Down Expand Up @@ -125,7 +126,8 @@
</StackPanel>
</StackPanel>
</ScrollViewer>
<Button Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" Content="{x:Static Member=localization:Strings.Continue}"
<Button x:Name="ButtonContinue"
Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" Content="{x:Static Member=localization:Strings.Continue}"
Command="{Binding ContinueCommand}" IsDefault="True"
Style="{StaticResource ResourceKey=HighlightedButton}" />
</Grid>
Expand Down
13 changes: 12 additions & 1 deletion Source/NETworkManager/Views/WelcomeChildWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
namespace NETworkManager.Views;
using System;
using System.Windows.Threading;

namespace NETworkManager.Views;

public partial class WelcomeChildWindow
{
public WelcomeChildWindow()
{
InitializeComponent();
}

private void ChildWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
{
ButtonContinue.Focus();
}));
}
}
4 changes: 3 additions & 1 deletion Website/docs/application/hosts-file-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ In addition, further actions can be performed using the buttons below:

With `F5` you can refresh the hosts file.

Right-click on the result to enable, disable, edit or delete an entry, or to copy or export the information.
Right-click on the result to `enable`, `disable`, `edit` or `delete` an entry, or to `copy` or `export` the information.

You can also use the Hotkeys `F2` (`edit`) or `Del` (`delete`) on a selected entry.

:::