Skip to content

Commit 85cb4d7

Browse files
authored
Feature: #3109 - Add F2/Delete hotkeys in HostsFileEditor & Refactor (#3113)
* Feature: Improve command exec & use hotkeys * Feature: Use dialog for admin error message
1 parent 029b3e8 commit 85cb4d7

22 files changed

+112
-31
lines changed

Source/NETworkManager/ViewModels/HostsFileEditorViewModel.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,21 @@ private async Task RestartAsAdminAction()
473473
}
474474
catch (Exception ex)
475475
{
476-
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error, ex.Message,
477-
MessageDialogStyle.Affirmative, AppearanceManager.MetroDialog);
476+
var childWindow = new OKMessageChildWindow();
477+
478+
var childWindowViewModel = new OKMessageViewModel(_ =>
479+
{
480+
childWindow.IsOpen = false;
481+
ConfigurationManager.Current.IsChildWindowOpen = false;
482+
}, ex.Message, Strings.OK, ChildWindowIcon.Error);
483+
484+
childWindow.Title = Strings.Error;
485+
486+
childWindow.DataContext = childWindowViewModel;
487+
488+
ConfigurationManager.Current.IsChildWindowOpen = true;
489+
490+
await (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow);
478491
}
479492
}
480493

Source/NETworkManager/Views/AWSSessionManagerSettingsView.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)
4141

4242
private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
4343
{
44-
_viewModel.EditAWSProfile().ConfigureAwait(false);
44+
if (_viewModel.EditAWSProfileCommand.CanExecute(null))
45+
_viewModel.EditAWSProfileCommand.Execute(null);
4546
}
4647
}

Source/NETworkManager/Views/CredentialsPasswordProfileFileChildWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public CredentialsPasswordProfileFileChildWindow()
1313

1414
private void ChildWindow_OnLoaded(object sender, RoutedEventArgs e)
1515
{
16-
// Focus the PasswordBox when the child window is loaded
1716
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
1817
{
1918
PasswordBoxPassword.Focus();

Source/NETworkManager/Views/DNSLookupSettingsView.xaml.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System.Windows;
1+
using MahApps.Metro.Controls.Dialogs;
2+
using NETworkManager.ViewModels;
3+
using System.Windows;
24
using System.Windows.Controls;
35
using System.Windows.Input;
4-
using MahApps.Metro.Controls.Dialogs;
5-
using NETworkManager.ViewModels;
66

77
namespace NETworkManager.Views;
88

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

2525
private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
2626
{
27-
_viewModel.EditDNSServer().ConfigureAwait(false);
27+
if (_viewModel.EditDNSServerCommand.CanExecute(null))
28+
_viewModel.EditDNSServerCommand.Execute(null);
2829
}
2930
}

Source/NETworkManager/Views/GroupChildWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public GroupChildWindow(Window parentWindow)
2727

2828
private void ChildWindow_OnLoaded(object sender, RoutedEventArgs e)
2929
{
30-
// Focus the PasswordBox when the child window is loaded
3130
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
3231
{
3332
TextBoxName.Focus();

Source/NETworkManager/Views/HostsFileEditorEntryChildWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public HostsFileEditorEntryChildWindow()
1313

1414
private void ChildWindow_OnLoaded(object sender, RoutedEventArgs e)
1515
{
16-
// Focus the PasswordBox when the child window is loaded
1716
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
1817
{
1918
TextBoxIPAddress.Focus();

Source/NETworkManager/Views/HostsFileEditorView.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
</controls:MultiSelectDataGrid.Resources>
170170
<controls:MultiSelectDataGrid.RowStyle>
171171
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource MahApps.Styles.DataGridRow}">
172+
<EventSetter Event="MouseDoubleClick" Handler="DataGridRow_MouseDoubleClick" />
172173
<Setter Property="ContextMenu" Value="{StaticResource MultiRowContextMenu}" />
173174
<Style.Triggers>
174175
<DataTrigger
@@ -197,6 +198,10 @@
197198
SortMemberPath="Hostname"
198199
MinWidth="200" />
199200
</controls:MultiSelectDataGrid.Columns>
201+
<controls:MultiSelectDataGrid.InputBindings>
202+
<KeyBinding Command="{Binding EditEntryCommand}" Key="F2" />
203+
<KeyBinding Command="{Binding DeleteEntryCommand}" Key="Delete" />
204+
</controls:MultiSelectDataGrid.InputBindings>
200205
</controls:MultiSelectDataGrid>
201206
<Grid Grid.Column="0" Grid.Row="4">
202207
<Grid.ColumnDefinitions>

Source/NETworkManager/Views/HostsFileEditorView.xaml.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Windows;
2-
using System.Windows.Controls;
3-
using MahApps.Metro.Controls.Dialogs;
1+
using MahApps.Metro.Controls.Dialogs;
42
using NETworkManager.ViewModels;
3+
using System.Windows;
4+
using System.Windows.Controls;
55

66
namespace NETworkManager.Views;
77

@@ -30,4 +30,10 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)
3030
if (sender is ContextMenu menu)
3131
menu.DataContext = _viewModel;
3232
}
33+
34+
private void DataGridRow_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
35+
{
36+
if (_viewModel.EditEntryCommand.CanExecute(null))
37+
_viewModel.EditEntryCommand.Execute(null);
38+
}
3339
}

Source/NETworkManager/Views/OKCancelInfoMessageChildWindow.xaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
AllowMove="True"
1818
TitleForeground="{DynamicResource MahApps.Brushes.Gray3}"
1919
CloseByEscape="False"
20-
OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray.SemiTransparent}"
20+
OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray.SemiTransparent}"
21+
Loaded="ChildWindow_Loaded"
2122
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:OKCancelInfoMessageViewModel}">
2223
<Grid Margin="10">
2324
<Grid.RowDefinitions>
@@ -40,13 +41,15 @@
4041
<TextBlock Grid.Column="2" Grid.Row="0"
4142
VerticalAlignment="Center"
4243
Text="{Binding Message}"
43-
Style="{StaticResource ResourceKey=WrapTextBlock}"/>
44+
Style="{StaticResource ResourceKey=WrapTextBlock}"/>
4445
</Grid>
4546
</ScrollViewer>
4647
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
47-
<Button Content="{Binding OKButtonText}" Command="{Binding Path=OKCommand}" IsDefault="True"
48+
<Button x:Name="ButtonOK"
49+
Content="{Binding OKButtonText}" Command="{Binding Path=OKCommand}" IsDefault="True"
4850
Style="{StaticResource ResourceKey=HighlightedButton}" Margin="0,0,10,0" />
49-
<Button Content="{Binding CancelButtonText}" Command="{Binding Path=CancelCommand}" IsCancel="True"
51+
<Button x:Name="ButtonCancel"
52+
Content="{Binding CancelButtonText}" Command="{Binding Path=CancelCommand}" IsCancel="True"
5053
Style="{StaticResource ResourceKey=DefaultButton}" />
5154
</StackPanel>
5255
</Grid>
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
namespace NETworkManager.Views;
1+
using System;
2+
using System.Windows.Threading;
3+
4+
namespace NETworkManager.Views;
25

36
public partial class OKCancelInfoMessageChildWindow
47
{
58
public OKCancelInfoMessageChildWindow()
69
{
710
InitializeComponent();
811
}
12+
13+
private void ChildWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
14+
{
15+
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
16+
{
17+
ButtonOK.Focus();
18+
}));
19+
}
920
}

0 commit comments

Comments
 (0)