mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-01 01:49:06 +08:00
[Hosts]Add delete entry button and fix focusing issue (#31418)
* [Hosts] Add delete entry button Fix focusing issue when clicking toggle switch or delete button * fix button accessibility * address feedback --------- Co-authored-by: Davide Giacometti <davide.giacometti@outlook.it>
This commit is contained in:
parent
76de196ee6
commit
1e47914ba0
@ -265,6 +265,9 @@
|
|||||||
<!-- Duplicate -->
|
<!-- Duplicate -->
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
<!-- ToggleSwitch -->
|
<!-- ToggleSwitch -->
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<!-- DeleteEntry -->
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
@ -348,9 +351,20 @@
|
|||||||
Width="40"
|
Width="40"
|
||||||
MinWidth="0"
|
MinWidth="0"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
|
GotFocus="Entries_GotFocus"
|
||||||
IsOn="{x:Bind Active, Mode=TwoWay}"
|
IsOn="{x:Bind Active, Mode=TwoWay}"
|
||||||
OffContent=""
|
OffContent=""
|
||||||
OnContent="" />
|
OnContent="" />
|
||||||
|
<Button
|
||||||
|
x:Uid="DeleteEntryBtn"
|
||||||
|
Grid.Column="5"
|
||||||
|
Height="32"
|
||||||
|
Click="Delete_Click"
|
||||||
|
CommandParameter="{x:Bind (models:Entry)}"
|
||||||
|
Content="{ui:FontIcon Glyph=,
|
||||||
|
FontSize=16}"
|
||||||
|
GotFocus="Entries_GotFocus"
|
||||||
|
Style="{StaticResource SubtleButtonStyle}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListView.ItemTemplate>
|
</ListView.ItemTemplate>
|
||||||
|
@ -55,13 +55,14 @@ namespace Hosts.Views
|
|||||||
|
|
||||||
private async void Entries_ItemClick(object sender, ItemClickEventArgs e)
|
private async void Entries_ItemClick(object sender, ItemClickEventArgs e)
|
||||||
{
|
{
|
||||||
await ShowEditDialogAsync(e.ClickedItem as Entry);
|
Entry entry = e.ClickedItem as Entry;
|
||||||
|
ViewModel.Selected = entry;
|
||||||
|
await ShowEditDialogAsync(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ShowEditDialogAsync(Entry entry)
|
public async Task ShowEditDialogAsync(Entry entry)
|
||||||
{
|
{
|
||||||
var resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
var resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
||||||
ViewModel.Selected = entry;
|
|
||||||
EntryDialog.Title = resourceLoader.GetString("UpdateEntry_Title");
|
EntryDialog.Title = resourceLoader.GetString("UpdateEntry_Title");
|
||||||
EntryDialog.PrimaryButtonText = resourceLoader.GetString("UpdateBtn");
|
EntryDialog.PrimaryButtonText = resourceLoader.GetString("UpdateBtn");
|
||||||
EntryDialog.PrimaryButtonCommand = UpdateCommand;
|
EntryDialog.PrimaryButtonCommand = UpdateCommand;
|
||||||
@ -179,10 +180,16 @@ namespace Hosts.Views
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Entries_GotFocus(object sender, RoutedEventArgs e)
|
private void Entries_GotFocus(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var listView = sender as ListView;
|
var element = sender as FrameworkElement;
|
||||||
if (listView.SelectedItem == null && listView.Items.Count > 0)
|
var entry = element.DataContext as Entry;
|
||||||
|
|
||||||
|
if (entry != null)
|
||||||
{
|
{
|
||||||
listView.SelectedIndex = 0;
|
ViewModel.Selected = entry;
|
||||||
|
}
|
||||||
|
else if (Entries.SelectedItem == null && Entries.Items.Count > 0)
|
||||||
|
{
|
||||||
|
Entries.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,6 +193,13 @@
|
|||||||
<data name="DeleteDialogAreYouSure.Text" xml:space="preserve">
|
<data name="DeleteDialogAreYouSure.Text" xml:space="preserve">
|
||||||
<value>Are you sure you want to delete this entry?</value>
|
<value>Are you sure you want to delete this entry?</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="DeleteEntryBtn.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
|
||||||
|
<value>Delete</value>
|
||||||
|
</data>
|
||||||
|
<data name="DeleteEntryBtn.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
|
||||||
|
<value>Delete (Delete)</value>
|
||||||
|
<comment>"Delete" between parentheses refers to the Delete keyboard key</comment>
|
||||||
|
</data>
|
||||||
<data name="Duplicate.Text" xml:space="preserve">
|
<data name="Duplicate.Text" xml:space="preserve">
|
||||||
<value>Duplicate</value>
|
<value>Duplicate</value>
|
||||||
<comment>Refers to the action of duplicate an existing entry</comment>
|
<comment>Refers to the action of duplicate an existing entry</comment>
|
||||||
|
@ -153,6 +153,19 @@ namespace Hosts.ViewModels
|
|||||||
_entries.Move(oldIndex, newIndex);
|
_entries.Move(oldIndex, newIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
public void DeleteEntry(Entry entry)
|
||||||
|
{
|
||||||
|
if (entry is not null)
|
||||||
|
{
|
||||||
|
var address = entry.Address;
|
||||||
|
var hosts = entry.SplittedHosts;
|
||||||
|
_entries.Remove(entry);
|
||||||
|
|
||||||
|
FindDuplicates(address, hosts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public void ReadHosts()
|
public void ReadHosts()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user