Skip to content

Commit fd96bc1

Browse files
hishitetsuheftymouseferrariofilippo
authored
Fix: Cherry-pick recent changes into servicing (#12197)
Co-authored-by: Nikhil B <[email protected]> Co-authored-by: Filippo Ferrario <[email protected]>
1 parent de2d8ef commit fd96bc1

File tree

9 files changed

+39
-28
lines changed

9 files changed

+39
-28
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
@@ -103,11 +103,20 @@ private class DialogViewModel : ObservableObject
103103
{
104104
public bool IsNameValid => FilesystemHelpers.IsValidForFilename(fileName);
105105

106+
public bool ShowNameWarning => !string.IsNullOrEmpty(fileName) && !IsNameValid;
107+
106108
private string fileName = string.Empty;
107109
public string FileName
108110
{
109111
get => fileName;
110-
set => SetProperty(ref fileName, value, nameof(IsNameValid));
112+
set
113+
{
114+
if (SetProperty(ref fileName, value))
115+
{
116+
OnPropertyChanged(nameof(IsNameValid));
117+
OnPropertyChanged(nameof(ShowNameWarning));
118+
}
119+
}
111120
}
112121

113122
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/CloudDrivesDetector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private static Task<IEnumerable<ICloudProvider>> DetectGenericCloudDrive()
6464
using var clsidKey = Registry.ClassesRoot.OpenSubKey(@"CLSID");
6565
using var namespaceKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace");
6666

67-
foreach (var subKeyName in namespaceKey.GetSubKeyNames())
67+
foreach (var subKeyName in namespaceKey?.GetSubKeyNames() ?? Array.Empty<string>())
6868
{
6969
using var clsidSubKey = SafetyExtensions.IgnoreExceptions(() => clsidKey.OpenSubKey(subKeyName));
7070
if (clsidSubKey is not null && (int?)clsidSubKey.GetValue("System.IsPinnedToNameSpaceTree") is 1)

src/Files.App/Helpers/DynamicDialogFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static DynamicDialog GetFor_RenameDialog()
8787
inputText.TextChanged += (textBox, args) =>
8888
{
8989
var isInputValid = FilesystemHelpers.IsValidForFilename(inputText.Text);
90-
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = !isInputValid;
90+
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = !string.IsNullOrEmpty(inputText.Text) && !isInputValid;
9191
dialog!.ViewModel.DynamicButtonsEnabled = isInputValid
9292
? DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
9393
: DynamicDialogButtons.Cancel;
@@ -99,7 +99,6 @@ public static DynamicDialog GetFor_RenameDialog()
9999
{
100100
// dispatching to the ui thread fixes an issue where the primary dialog button would steal focus
101101
_ = inputText.DispatcherQueue.EnqueueAsync(() => inputText.Focus(FocusState.Programmatic));
102-
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = true;
103102
};
104103

105104
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
@@ -34,6 +34,7 @@ public string DestinationItemPath
3434
if (!SetProperty(ref _destinationItemPath, value))
3535
return;
3636

37+
OnPropertyChanged(nameof(ShowWarningTip));
3738
if (string.IsNullOrWhiteSpace(DestinationItemPath))
3839
{
3940
IsLocationValid = false;
@@ -65,9 +66,11 @@ public string DestinationItemPath
6566
public bool IsLocationValid
6667
{
6768
get => _isLocationValid;
68-
set => SetProperty(ref _isLocationValid, value);
69+
set => SetProperty(ref _isLocationValid, value, nameof(ShowWarningTip));
6970
}
7071

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

@@ -110,10 +113,10 @@ private async Task CreateShortcut()
110113
if (string.IsNullOrEmpty(destinationName))
111114
{
112115
var destinationPath = DestinationItemPath.Replace('/', '\\');
113-
116+
114117
if (destinationPath.EndsWith('\\'))
115118
destinationPath = destinationPath.Substring(0, destinationPath.Length - 1);
116-
119+
117120
destinationName = destinationPath.Substring(destinationPath.LastIndexOf('\\') + 1);
118121
}
119122
}

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Files.App.ViewModels.Settings
1313
{
1414
public class TagsViewModel : ObservableObject
15-
{
15+
{
1616
private readonly IFileTagsSettingsService fileTagsSettingsService = Ioc.Default.GetRequiredService<IFileTagsSettingsService>();
1717

1818
private bool isBulkOperation = true;
@@ -116,8 +116,11 @@ public string Name
116116
get => name;
117117
set
118118
{
119-
if (SetProperty(ref name, value))
119+
SetProperty(ref name, value);
120+
{
121+
OnPropertyChanged(nameof(CanCommit));
120122
OnPropertyChanged(nameof(IsNameValid));
123+
}
121124
}
122125
}
123126

@@ -128,17 +131,23 @@ public string Color
128131
set => SetProperty(ref color, value);
129132
}
130133

131-
private bool isNameValid;
134+
private bool isNameValid = true;
132135
public bool IsNameValid
133136
{
134137
get => isNameValid;
135-
set => SetProperty(ref isNameValid, value);
138+
set
139+
{
140+
if (SetProperty(ref isNameValid, value))
141+
OnPropertyChanged(nameof(CanCommit));
142+
}
136143
}
137144

145+
public bool CanCommit => !string.IsNullOrEmpty(name) && IsNameValid;
146+
138147
public void Reset()
139148
{
140149
Name = string.Empty;
141-
IsNameValid = false;
150+
IsNameValid = true;
142151
Color = ColorHelpers.RandomColor();
143152
}
144153
}

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
@@ -92,8 +92,9 @@ private void RemoveTag_Click(object sender, RoutedEventArgs e)
9292
private void RenameTextBox_TextChanged(object sender, TextChangedEventArgs e)
9393
{
9494
var text = ((TextBox)sender).Text;
95-
editingTag!.IsNameValid = IsNameValid(text) && !ViewModel.Tags.Any(tag => tag.Tag.Name == text && editingTag!.Tag.Name != text);
96-
editingTag!.CanCommit = editingTag!.IsNameValid && (
95+
var isNullOrEmpty = string.IsNullOrEmpty(text);
96+
editingTag!.IsNameValid = isNullOrEmpty || (IsNameValid(text) && !ViewModel.Tags.Any(tag => tag.Tag.Name == text && editingTag!.Tag.Name != text));
97+
editingTag!.CanCommit = !isNullOrEmpty && editingTag!.IsNameValid && (
9798
text != editingTag!.Tag.Name ||
9899
editingTag!.NewColor != editingTag!.Tag.Color
99100
);
@@ -114,7 +115,7 @@ private void NewTagTextBox_TextChanged(object sender, TextChangedEventArgs e)
114115
{
115116
var text = ((TextBox)sender).Text;
116117
ViewModel.NewTag.Name = text;
117-
ViewModel.NewTag.IsNameValid = IsNameValid(text) && !ViewModel.Tags.Any(tag => text == tag.Tag.Name);
118+
ViewModel.NewTag.IsNameValid = string.IsNullOrEmpty(text) || (IsNameValid(text) && !ViewModel.Tags.Any(tag => text == tag.Tag.Name));
118119
}
119120

120121
private void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)

0 commit comments

Comments
 (0)