Skip to content

Commit 7ed84ac

Browse files
Feature: Disable warning when a new name is empty (#12150)
1 parent 07c8540 commit 7ed84ac

File tree

8 files changed

+38
-27
lines changed

8 files changed

+38
-27
lines changed

src/Files.App/Dialogs/CreateArchiveDialog.xaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
x:Class="Files.App.Dialogs.CreateArchiveDialog"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters"
65
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
76
xmlns:helpers="using:Files.App.Helpers"
87
xmlns:local="using:Files.App.Dialogs"
@@ -21,10 +20,6 @@
2120
Style="{StaticResource DefaultContentDialogStyle}"
2221
mc:Ignorable="d">
2322

24-
<ContentDialog.Resources>
25-
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
26-
</ContentDialog.Resources>
27-
2823
<StackPanel Width="440" Spacing="4">
2924

3025
<!-- Archive Name -->
@@ -53,7 +48,7 @@
5348
<TeachingTip
5449
x:Name="InvalidNameWarning"
5550
Title="{helpers:ResourceString Name=InvalidFilename/Text}"
56-
IsOpen="{x:Bind ViewModel.IsNameValid, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}"
51+
IsOpen="{x:Bind ViewModel.ShowNameWarning, Mode=OneWay}"
5752
PreferredPlacement="Bottom"
5853
Target="{x:Bind FileNameBox}" />
5954
</TextBox.Resources>

src/Files.App/Dialogs/CreateArchiveDialog.xaml.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,20 @@ private class DialogViewModel : ObservableObject
106106
{
107107
public bool IsNameValid => FilesystemHelpers.IsValidForFilename(fileName);
108108

109+
public bool ShowNameWarning => !string.IsNullOrEmpty(fileName) && !IsNameValid;
110+
109111
private string fileName = string.Empty;
110112
public string FileName
111113
{
112114
get => fileName;
113-
set => SetProperty(ref fileName, value, nameof(IsNameValid));
115+
set
116+
{
117+
if (SetProperty(ref fileName, value))
118+
{
119+
OnPropertyChanged(nameof(IsNameValid));
120+
OnPropertyChanged(nameof(ShowNameWarning));
121+
}
122+
}
114123
}
115124

116125
private FileFormatItem fileFormat;

src/Files.App/Dialogs/CreateShortcutDialog.xaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
x:Class="Files.App.Dialogs.CreateShortcutDialog"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters"
65
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
76
xmlns:helpers="using:Files.App.Helpers"
87
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -16,10 +15,6 @@
1615
Style="{StaticResource DefaultContentDialogStyle}"
1716
mc:Ignorable="d">
1817

19-
<ContentDialog.Resources>
20-
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
21-
</ContentDialog.Resources>
22-
2318
<Border Width="400">
2419
<Grid
2520
x:Name="DestinationPathGrid"
@@ -59,7 +54,7 @@
5954
<TeachingTip
6055
x:Name="InvalidPathWarning"
6156
Title="{helpers:ResourceString Name=InvalidLocation}"
62-
IsOpen="{x:Bind ViewModel.IsLocationValid, Mode=OneWay, Converter={StaticResource BoolNegationConverter}, FallbackValue=False}"
57+
IsOpen="{x:Bind ViewModel.ShowWarningTip, Mode=OneWay}"
6358
PreferredPlacement="Bottom" />
6459
</TextBox.Resources>
6560
</TextBox>

src/Files.App/Helpers/DynamicDialogFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static DynamicDialog GetFor_RenameDialog()
9090
inputText.TextChanged += (textBox, args) =>
9191
{
9292
var isInputValid = FilesystemHelpers.IsValidForFilename(inputText.Text);
93-
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = !isInputValid;
93+
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = !string.IsNullOrEmpty(inputText.Text) && !isInputValid;
9494
dialog!.ViewModel.DynamicButtonsEnabled = isInputValid
9595
? DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
9696
: DynamicDialogButtons.Cancel;
@@ -102,7 +102,6 @@ public static DynamicDialog GetFor_RenameDialog()
102102
{
103103
// dispatching to the ui thread fixes an issue where the primary dialog button would steal focus
104104
_ = inputText.DispatcherQueue.EnqueueAsync(() => inputText.Focus(FocusState.Programmatic));
105-
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = true;
106105
};
107106

108107
dialog = new DynamicDialog(new DynamicDialogViewModel()

src/Files.App/ViewModels/Dialogs/CreateShortcutDialogViewModel.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public string DestinationItemPath
3232
if (!SetProperty(ref _destinationItemPath, value))
3333
return;
3434

35+
OnPropertyChanged(nameof(ShowWarningTip));
3536
if (string.IsNullOrWhiteSpace(DestinationItemPath))
3637
{
3738
IsLocationValid = false;
@@ -63,9 +64,11 @@ public string DestinationItemPath
6364
public bool IsLocationValid
6465
{
6566
get => _isLocationValid;
66-
set => SetProperty(ref _isLocationValid, value);
67+
set => SetProperty(ref _isLocationValid, value, nameof(ShowWarningTip));
6768
}
6869

70+
public bool ShowWarningTip => !string.IsNullOrEmpty(DestinationItemPath) && !_isLocationValid;
71+
6972
// Command invoked when the user clicks the 'Browse' button
7073
public ICommand SelectDestinationCommand { get; private set; }
7174

@@ -108,10 +111,10 @@ private async Task CreateShortcut()
108111
if (string.IsNullOrEmpty(destinationName))
109112
{
110113
var destinationPath = DestinationItemPath.Replace('/', '\\');
111-
114+
112115
if (destinationPath.EndsWith('\\'))
113116
destinationPath = destinationPath.Substring(0, destinationPath.Length - 1);
114-
117+
115118
destinationName = destinationPath.Substring(destinationPath.LastIndexOf('\\') + 1);
116119
}
117120
}

src/Files.App/ViewModels/Settings/TagsViewModel.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Files.App.ViewModels.Settings
88
{
99
public class TagsViewModel : ObservableObject
10-
{
10+
{
1111
private readonly IFileTagsSettingsService fileTagsSettingsService = Ioc.Default.GetRequiredService<IFileTagsSettingsService>();
1212

1313
private bool isBulkOperation = true;
@@ -111,8 +111,11 @@ public string Name
111111
get => name;
112112
set
113113
{
114-
if (SetProperty(ref name, value))
114+
SetProperty(ref name, value);
115+
{
116+
OnPropertyChanged(nameof(CanCommit));
115117
OnPropertyChanged(nameof(IsNameValid));
118+
}
116119
}
117120
}
118121

@@ -123,17 +126,23 @@ public string Color
123126
set => SetProperty(ref color, value);
124127
}
125128

126-
private bool isNameValid;
129+
private bool isNameValid = true;
127130
public bool IsNameValid
128131
{
129132
get => isNameValid;
130-
set => SetProperty(ref isNameValid, value);
133+
set
134+
{
135+
if (SetProperty(ref isNameValid, value))
136+
OnPropertyChanged(nameof(CanCommit));
137+
}
131138
}
132139

140+
public bool CanCommit => !string.IsNullOrEmpty(name) && IsNameValid;
141+
133142
public void Reset()
134143
{
135144
Name = string.Empty;
136-
IsNameValid = false;
145+
IsNameValid = true;
137146
Color = ColorHelpers.RandomColor();
138147
}
139148
}

src/Files.App/Views/Settings/TagsPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
<Button
159159
Command="{x:Bind ViewModel.SaveNewTagCommand, Mode=OneWay}"
160160
Content="{helpers:ResourceString Name=Create}"
161-
IsEnabled="{x:Bind ViewModel.NewTag.IsNameValid, Mode=OneWay}"
161+
IsEnabled="{x:Bind ViewModel.NewTag.CanCommit, Mode=OneWay}"
162162
Style="{StaticResource AccentButtonStyle}" />
163163
</StackPanel>
164164
</Grid>

src/Files.App/Views/Settings/TagsPage.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ private void RemoveTag_Click(object sender, RoutedEventArgs e)
9494
private void RenameTextBox_TextChanged(object sender, TextChangedEventArgs e)
9595
{
9696
var text = ((TextBox)sender).Text;
97-
editingTag!.IsNameValid = IsNameValid(text) && !ViewModel.Tags.Any(tag => tag.Tag.Name == text && editingTag!.Tag.Name != text);
98-
editingTag!.CanCommit = editingTag!.IsNameValid && (
97+
var isNullOrEmpty = string.IsNullOrEmpty(text);
98+
editingTag!.IsNameValid = isNullOrEmpty || (IsNameValid(text) && !ViewModel.Tags.Any(tag => tag.Tag.Name == text && editingTag!.Tag.Name != text));
99+
editingTag!.CanCommit = !isNullOrEmpty && editingTag!.IsNameValid && (
99100
text != editingTag!.Tag.Name ||
100101
editingTag!.NewColor != editingTag!.Tag.Color
101102
);
@@ -116,7 +117,7 @@ private void NewTagTextBox_TextChanged(object sender, TextChangedEventArgs e)
116117
{
117118
var text = ((TextBox)sender).Text;
118119
ViewModel.NewTag.Name = text;
119-
ViewModel.NewTag.IsNameValid = IsNameValid(text) && !ViewModel.Tags.Any(tag => text == tag.Tag.Name);
120+
ViewModel.NewTag.IsNameValid = string.IsNullOrEmpty(text) || (IsNameValid(text) && !ViewModel.Tags.Any(tag => text == tag.Tag.Name));
120121
}
121122

122123
private void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)

0 commit comments

Comments
 (0)