Skip to content
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

Fix: Cherry-pick recent changes into servicing #12197

Merged
merged 2 commits into from
Apr 25, 2023
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
7 changes: 1 addition & 6 deletions src/Files.App/Dialogs/CreateArchiveDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
x:Class="Files.App.Dialogs.CreateArchiveDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:local="using:Files.App.Dialogs"
Expand All @@ -21,10 +20,6 @@
Style="{StaticResource DefaultContentDialogStyle}"
mc:Ignorable="d">

<ContentDialog.Resources>
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
</ContentDialog.Resources>

<StackPanel Width="440" Spacing="4">

<!-- Archive Name -->
Expand Down Expand Up @@ -53,7 +48,7 @@
<TeachingTip
x:Name="InvalidNameWarning"
Title="{helpers:ResourceString Name=InvalidFilename/Text}"
IsOpen="{x:Bind ViewModel.IsNameValid, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}"
IsOpen="{x:Bind ViewModel.ShowNameWarning, Mode=OneWay}"
PreferredPlacement="Bottom"
Target="{x:Bind FileNameBox}" />
</TextBox.Resources>
Expand Down
11 changes: 10 additions & 1 deletion src/Files.App/Dialogs/CreateArchiveDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,20 @@ private class DialogViewModel : ObservableObject
{
public bool IsNameValid => FilesystemHelpers.IsValidForFilename(fileName);

public bool ShowNameWarning => !string.IsNullOrEmpty(fileName) && !IsNameValid;

private string fileName = string.Empty;
public string FileName
{
get => fileName;
set => SetProperty(ref fileName, value, nameof(IsNameValid));
set
{
if (SetProperty(ref fileName, value))
{
OnPropertyChanged(nameof(IsNameValid));
OnPropertyChanged(nameof(ShowNameWarning));
}
}
}

private FileFormatItem fileFormat;
Expand Down
7 changes: 1 addition & 6 deletions src/Files.App/Dialogs/CreateShortcutDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
x:Class="Files.App.Dialogs.CreateShortcutDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand All @@ -16,10 +15,6 @@
Style="{StaticResource DefaultContentDialogStyle}"
mc:Ignorable="d">

<ContentDialog.Resources>
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
</ContentDialog.Resources>

<Border Width="400">
<Grid
x:Name="DestinationPathGrid"
Expand Down Expand Up @@ -59,7 +54,7 @@
<TeachingTip
x:Name="InvalidPathWarning"
Title="{helpers:ResourceString Name=InvalidLocation}"
IsOpen="{x:Bind ViewModel.IsLocationValid, Mode=OneWay, Converter={StaticResource BoolNegationConverter}, FallbackValue=False}"
IsOpen="{x:Bind ViewModel.ShowWarningTip, Mode=OneWay}"
PreferredPlacement="Bottom" />
</TextBox.Resources>
</TextBox>
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/CloudDrivesDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static Task<IEnumerable<ICloudProvider>> DetectGenericCloudDrive()
using var clsidKey = Registry.ClassesRoot.OpenSubKey(@"CLSID");
using var namespaceKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace");

foreach (var subKeyName in namespaceKey.GetSubKeyNames())
foreach (var subKeyName in namespaceKey?.GetSubKeyNames() ?? Array.Empty<string>())
{
using var clsidSubKey = SafetyExtensions.IgnoreExceptions(() => clsidKey.OpenSubKey(subKeyName));
if (clsidSubKey is not null && (int?)clsidSubKey.GetValue("System.IsPinnedToNameSpaceTree") is 1)
Expand Down
3 changes: 1 addition & 2 deletions src/Files.App/Helpers/DynamicDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static DynamicDialog GetFor_RenameDialog()
inputText.TextChanged += (textBox, args) =>
{
var isInputValid = FilesystemHelpers.IsValidForFilename(inputText.Text);
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = !isInputValid;
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = !string.IsNullOrEmpty(inputText.Text) && !isInputValid;
dialog!.ViewModel.DynamicButtonsEnabled = isInputValid
? DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
: DynamicDialogButtons.Cancel;
Expand All @@ -99,7 +99,6 @@ public static DynamicDialog GetFor_RenameDialog()
{
// dispatching to the ui thread fixes an issue where the primary dialog button would steal focus
_ = inputText.DispatcherQueue.EnqueueAsync(() => inputText.Focus(FocusState.Programmatic));
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = true;
};

dialog = new DynamicDialog(new DynamicDialogViewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public string DestinationItemPath
if (!SetProperty(ref _destinationItemPath, value))
return;

OnPropertyChanged(nameof(ShowWarningTip));
if (string.IsNullOrWhiteSpace(DestinationItemPath))
{
IsLocationValid = false;
Expand Down Expand Up @@ -65,9 +66,11 @@ public string DestinationItemPath
public bool IsLocationValid
{
get => _isLocationValid;
set => SetProperty(ref _isLocationValid, value);
set => SetProperty(ref _isLocationValid, value, nameof(ShowWarningTip));
}

public bool ShowWarningTip => !string.IsNullOrEmpty(DestinationItemPath) && !_isLocationValid;

// Command invoked when the user clicks the 'Browse' button
public ICommand SelectDestinationCommand { get; private set; }

Expand Down Expand Up @@ -110,10 +113,10 @@ private async Task CreateShortcut()
if (string.IsNullOrEmpty(destinationName))
{
var destinationPath = DestinationItemPath.Replace('/', '\\');

if (destinationPath.EndsWith('\\'))
destinationPath = destinationPath.Substring(0, destinationPath.Length - 1);

destinationName = destinationPath.Substring(destinationPath.LastIndexOf('\\') + 1);
}
}
Expand Down
19 changes: 14 additions & 5 deletions src/Files.App/ViewModels/Settings/TagsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Files.App.ViewModels.Settings
{
public class TagsViewModel : ObservableObject
{
{
private readonly IFileTagsSettingsService fileTagsSettingsService = Ioc.Default.GetRequiredService<IFileTagsSettingsService>();

private bool isBulkOperation = true;
Expand Down Expand Up @@ -116,8 +116,11 @@ public string Name
get => name;
set
{
if (SetProperty(ref name, value))
SetProperty(ref name, value);
{
OnPropertyChanged(nameof(CanCommit));
OnPropertyChanged(nameof(IsNameValid));
}
}
}

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

private bool isNameValid;
private bool isNameValid = true;
public bool IsNameValid
{
get => isNameValid;
set => SetProperty(ref isNameValid, value);
set
{
if (SetProperty(ref isNameValid, value))
OnPropertyChanged(nameof(CanCommit));
}
}

public bool CanCommit => !string.IsNullOrEmpty(name) && IsNameValid;

public void Reset()
{
Name = string.Empty;
IsNameValid = false;
IsNameValid = true;
Color = ColorHelpers.RandomColor();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/Settings/TagsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<Button
Command="{x:Bind ViewModel.SaveNewTagCommand, Mode=OneWay}"
Content="{helpers:ResourceString Name=Create}"
IsEnabled="{x:Bind ViewModel.NewTag.IsNameValid, Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.NewTag.CanCommit, Mode=OneWay}"
Style="{StaticResource AccentButtonStyle}" />
</StackPanel>
</Grid>
Expand Down
7 changes: 4 additions & 3 deletions src/Files.App/Views/Settings/TagsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ private void RemoveTag_Click(object sender, RoutedEventArgs e)
private void RenameTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var text = ((TextBox)sender).Text;
editingTag!.IsNameValid = IsNameValid(text) && !ViewModel.Tags.Any(tag => tag.Tag.Name == text && editingTag!.Tag.Name != text);
editingTag!.CanCommit = editingTag!.IsNameValid && (
var isNullOrEmpty = string.IsNullOrEmpty(text);
editingTag!.IsNameValid = isNullOrEmpty || (IsNameValid(text) && !ViewModel.Tags.Any(tag => tag.Tag.Name == text && editingTag!.Tag.Name != text));
editingTag!.CanCommit = !isNullOrEmpty && editingTag!.IsNameValid && (
text != editingTag!.Tag.Name ||
editingTag!.NewColor != editingTag!.Tag.Color
);
Expand All @@ -114,7 +115,7 @@ private void NewTagTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var text = ((TextBox)sender).Text;
ViewModel.NewTag.Name = text;
ViewModel.NewTag.IsNameValid = IsNameValid(text) && !ViewModel.Tags.Any(tag => text == tag.Tag.Name);
ViewModel.NewTag.IsNameValid = string.IsNullOrEmpty(text) || (IsNameValid(text) && !ViewModel.Tags.Any(tag => text == tag.Tag.Name));
}

private void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
Expand Down