[Hosts]Duplicate an existing entry (#31075)

* clone an existing entry

* addressed feedbacks
This commit is contained in:
Davide Giacometti 2024-01-25 17:08:43 +01:00 committed by GitHub
parent e6a1dd586a
commit 6da7e3ae39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 6 deletions

View File

@ -185,6 +185,17 @@
ScopeOwner="{x:Bind Entries}" />
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem x:Uid="Duplicate" Click="Duplicate_Click">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xF413;" />
</MenuFlyoutItem.Icon>
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator
Key="D"
Modifiers="Control"
ScopeOwner="{x:Bind Entries}" />
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Uid="Ping"
Click="Ping_Click"

View File

@ -44,12 +44,7 @@ namespace Hosts.Views
private async Task OpenNewDialogAsync()
{
var resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
EntryDialog.Title = resourceLoader.GetString("AddNewEntryDialog_Title");
EntryDialog.PrimaryButtonText = resourceLoader.GetString("AddBtn");
EntryDialog.PrimaryButtonCommand = AddCommand;
EntryDialog.DataContext = new Entry(ViewModel.NextId, string.Empty, string.Empty, string.Empty, true);
await EntryDialog.ShowAsync();
await ShowAddDialogAsync();
}
private async Task OpenAdditionalLinesDialogAsync()
@ -113,6 +108,14 @@ namespace Hosts.Views
}
}
private async void Duplicate_Click(object sender, RoutedEventArgs e)
{
if (Entries.SelectedItem is Entry entry)
{
await ShowAddDialogAsync(entry);
}
}
private async void Ping_Click(object sender, RoutedEventArgs e)
{
if (Entries.SelectedItem is Entry entry)
@ -189,6 +192,20 @@ namespace Hosts.Views
ViewModel.Selected = entry;
}
private async Task ShowAddDialogAsync(Entry template = null)
{
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
EntryDialog.Title = resourceLoader.GetString("AddNewEntryDialog_Title");
EntryDialog.PrimaryButtonText = resourceLoader.GetString("AddBtn");
EntryDialog.PrimaryButtonCommand = AddCommand;
EntryDialog.DataContext = template == null
? new Entry(ViewModel.NextId, string.Empty, string.Empty, string.Empty, true)
: new Entry(ViewModel.NextId, template.Address, template.Hosts, template.Comment, template.Active);
await EntryDialog.ShowAsync();
}
private void ContentDialog_Loaded_ApplyMargin(object sender, RoutedEventArgs e)
{
try

View File

@ -193,6 +193,10 @@
<data name="DeleteDialogAreYouSure.Text" xml:space="preserve">
<value>Are you sure you want to delete this entry?</value>
</data>
<data name="Duplicate.Text" xml:space="preserve">
<value>Duplicate</value>
<comment>Refers to the action of duplicate an existing entry</comment>
</data>
<data name="DuplicateEntryIcon.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Duplicate entry</value>
</data>