Skip to content

Fix: Cancel tag edit when pressing esc & Tags duplicate names #11297

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
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
3 changes: 3 additions & 0 deletions src/Files.App/Views/SettingsPages/Advanced.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@
<ListView.ItemTemplate>
<DataTemplate xmlns:vm="using:Files.Backend.ViewModels.FileTags" x:DataType="vm:ListedTagViewModel">
<Grid ColumnSpacing="16">
<Grid.KeyboardAccelerators>
<KeyboardAccelerator Key="Escape" Invoked="KeyboardAccelerator_Invoked" />
</Grid.KeyboardAccelerators>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
Expand Down
32 changes: 25 additions & 7 deletions src/Files.App/Views/SettingsPages/Advanced.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using System.Linq;
using Windows.System;

namespace Files.App.SettingsPages
Expand Down Expand Up @@ -74,19 +75,14 @@ private void RenameTextBox_TextChanged(object sender, TextChangedEventArgs e)

private void CommitRenameTag_Click(object sender, RoutedEventArgs e)
{
var editingTag = (ListedTagViewModel)((Button)sender).DataContext;
var item = TagsList.ContainerFromItem(editingTag) as ListViewItem;

CommitChanges(item.FindDescendant("TagNameTextBox") as TextBox);
}

private void CancelRenameTag_Click(object sender, RoutedEventArgs e)
{
var editingTag = (ListedTagViewModel)((Button)sender).DataContext;
var item = TagsList.ContainerFromItem(editingTag) as ListViewItem;
editingTag.NewColor = editingTag.Tag.Color;

EndEditing(item.FindDescendant("TagNameTextBox") as TextBox);
CloseEdit();
}

private void RemoveTag_Click(object sender, RoutedEventArgs e)
Expand All @@ -103,7 +99,29 @@ private void NewTagTextBox_TextChanged(object sender, TextChangedEventArgs e)

private bool IsNameValid(string name)
{
return !(string.IsNullOrWhiteSpace(name) || name.EndsWith('.') || name.StartsWith('.'));
return !(
string.IsNullOrWhiteSpace(name) ||
name.StartsWith('.') ||
name.EndsWith('.') ||
ViewModel.Tags.Any(tag => name == tag.Tag.Name)
);
}

private void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
{
if (args.KeyboardAccelerator.Key is VirtualKey.Escape)
{
CloseEdit();
args.Handled = true;
}
}

private void CloseEdit()
{
var item = TagsList.ContainerFromItem(editingTag) as ListViewItem;
editingTag.NewColor = editingTag.Tag.Color;

EndEditing(item.FindDescendant("TagNameTextBox") as TextBox);
}
}
}