Skip to content

Commit 165c5c7

Browse files
committed
Merge branch 'SaveSessionWhenException' of https://github.com/hishitetsu/Files into pr/12005
2 parents 1324658 + 574c99e commit 165c5c7

File tree

7 files changed

+94
-21
lines changed

7 files changed

+94
-21
lines changed

src/Files.App/Dialogs/CreateArchiveDialog.xaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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"
56
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
67
xmlns:helpers="using:Files.App.Helpers"
78
xmlns:local="using:Files.App.Dialogs"
@@ -13,12 +14,17 @@
1314
Closing="ContentDialog_Closing"
1415
CornerRadius="{StaticResource OverlayCornerRadius}"
1516
DefaultButton="Primary"
16-
IsPrimaryButtonEnabled="True"
17+
IsPrimaryButtonEnabled="{x:Bind ViewModel.IsNameValid, Mode=OneWay}"
1718
Loaded="ContentDialog_Loaded"
1819
PrimaryButtonText="{helpers:ResourceString Name=Create}"
1920
RequestedTheme="{x:Bind helpers:ThemeHelper.RootTheme}"
2021
Style="{StaticResource DefaultContentDialogStyle}"
2122
mc:Ignorable="d">
23+
24+
<ContentDialog.Resources>
25+
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
26+
</ContentDialog.Resources>
27+
2228
<StackPanel Width="440" Spacing="4">
2329

2430
<!-- Archive Name -->
@@ -42,7 +48,16 @@
4248
Grid.Column="1"
4349
Width="260"
4450
PlaceholderText="{helpers:ResourceString Name=EnterName}"
45-
Text="{x:Bind ViewModel.FileName, Mode=TwoWay}" />
51+
Text="{x:Bind ViewModel.FileName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
52+
<TextBox.Resources>
53+
<TeachingTip
54+
x:Name="InvalidNameWarning"
55+
Title="{helpers:ResourceString Name=InvalidFilename/Text}"
56+
IsOpen="{x:Bind ViewModel.IsNameValid, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}"
57+
PreferredPlacement="Bottom"
58+
Target="{x:Bind FileNameBox}" />
59+
</TextBox.Resources>
60+
</TextBox>
4661
</Grid>
4762

4863
<!-- Archive Options -->

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
22
using Files.App.Extensions;
3+
using Files.App.Filesystem;
34
using Files.App.Filesystem.Archive;
45
using Files.Backend.Models;
56
using Microsoft.UI.Xaml;
@@ -81,6 +82,7 @@ private void ContentDialog_Loaded(object _, RoutedEventArgs e)
8182
}
8283
private void ContentDialog_Closing(ContentDialog _, ContentDialogClosingEventArgs e)
8384
{
85+
InvalidNameWarning.IsOpen = false;
8486
Closing -= ContentDialog_Closing;
8587
ViewModel.PropertyChanged -= ViewModel_PropertyChanged;
8688

@@ -99,11 +101,13 @@ private void ViewModel_PropertyChanged(object? _, PropertyChangedEventArgs e)
99101

100102
private class DialogViewModel : ObservableObject
101103
{
104+
public bool IsNameValid => FilesystemHelpers.IsValidForFilename(fileName);
105+
102106
private string fileName = string.Empty;
103107
public string FileName
104108
{
105109
get => fileName;
106-
set => SetProperty(ref fileName, value);
110+
set => SetProperty(ref fileName, value, nameof(IsNameValid));
107111
}
108112

109113
private FileFormatItem fileFormat;

src/Files.App/Dialogs/CreateShortcutDialog.xaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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"
56
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
67
xmlns:helpers="using:Files.App.Helpers"
78
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -15,6 +16,10 @@
1516
Style="{StaticResource DefaultContentDialogStyle}"
1617
mc:Ignorable="d">
1718

19+
<ContentDialog.Resources>
20+
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
21+
</ContentDialog.Resources>
22+
1823
<Border Width="400">
1924
<Grid
2025
x:Name="DestinationPathGrid"
@@ -49,7 +54,15 @@
4954
Grid.Column="0"
5055
HorizontalAlignment="Stretch"
5156
PlaceholderText="C:\Users\"
52-
Text="{x:Bind ViewModel.DestinationItemPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
57+
Text="{x:Bind ViewModel.DestinationItemPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
58+
<TextBox.Resources>
59+
<TeachingTip
60+
x:Name="InvalidPathWarning"
61+
Title="{helpers:ResourceString Name=InvalidLocation}"
62+
IsOpen="{x:Bind ViewModel.IsLocationValid, Mode=OneWay, Converter={StaticResource BoolNegationConverter}, FallbackValue=False}"
63+
PreferredPlacement="Bottom" />
64+
</TextBox.Resources>
65+
</TextBox>
5366
<Button
5467
x:Name="SelectDestination"
5568
Grid.Row="2"
@@ -58,4 +71,4 @@
5871
Content="{helpers:ResourceString Name=Browse}" />
5972
</Grid>
6073
</Border>
61-
</ContentDialog>
74+
</ContentDialog>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Files.Backend.ViewModels.Dialogs;
33
using Files.Shared.Enums;
44
using Microsoft.UI.Xaml.Controls;
5+
using Microsoft.UI.Xaml.Data;
56
using System;
67
using System.Threading.Tasks;
78

@@ -18,6 +19,18 @@ public CreateShortcutDialogViewModel ViewModel
1819
public CreateShortcutDialog()
1920
{
2021
InitializeComponent();
22+
this.Closing += CreateShortcutDialog_Closing;
23+
24+
InvalidPathWarning.SetBinding(TeachingTip.TargetProperty, new Binding()
25+
{
26+
Source = DestinationItemPath
27+
});
28+
}
29+
30+
private void CreateShortcutDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
31+
{
32+
this.Closing -= CreateShortcutDialog_Closing;
33+
InvalidPathWarning.IsOpen = false;
2134
}
2235

2336
public new async Task<DialogResult> ShowAsync() => (DialogResult)await base.ShowAsync();

src/Files.App/Helpers/DynamicDialogFactory.cs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
using Files.App.ViewModels.Dialogs;
66
using Files.Shared.Enums;
77
using Files.Shared.Extensions;
8+
using Microsoft.UI.Xaml;
89
using Microsoft.UI.Xaml.Controls;
10+
using Microsoft.UI.Xaml.Data;
911
using System;
1012
using System.Collections.Generic;
1113
using System.Linq;
@@ -63,18 +65,29 @@ public static DynamicDialog GetFor_RenameDialog()
6365
PlaceholderText = "EnterAnItemName".GetLocalizedResource()
6466
};
6567

66-
TextBlock tipText = new()
68+
TeachingTip warning = new()
6769
{
68-
Text = "InvalidFilename/Text".GetLocalizedResource(),
69-
Margin = new Microsoft.UI.Xaml.Thickness(0, 0, 4, 0),
70-
TextWrapping = Microsoft.UI.Xaml.TextWrapping.Wrap,
71-
Opacity = 0.0d
70+
Title = "InvalidFilename/Text".GetLocalizedResource(),
71+
PreferredPlacement = TeachingTipPlacementMode.Bottom,
72+
DataContext = new RenameDialogViewModel(),
7273
};
7374

75+
warning.SetBinding(TeachingTip.TargetProperty, new Binding()
76+
{
77+
Source = inputText
78+
});
79+
warning.SetBinding(TeachingTip.IsOpenProperty, new Binding()
80+
{
81+
Mode = BindingMode.OneWay,
82+
Path = new PropertyPath("IsNameInvalid")
83+
});
84+
85+
inputText.Resources.Add("InvalidNameWarningTip", warning);
86+
7487
inputText.TextChanged += (textBox, args) =>
7588
{
7689
var isInputValid = FilesystemHelpers.IsValidForFilename(inputText.Text);
77-
tipText.Opacity = isInputValid ? 0.0d : 1.0d;
90+
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = !isInputValid;
7891
dialog!.ViewModel.DynamicButtonsEnabled = isInputValid
7992
? DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
8093
: DynamicDialogButtons.Cancel;
@@ -85,7 +98,8 @@ public static DynamicDialog GetFor_RenameDialog()
8598
inputText.Loaded += (s, e) =>
8699
{
87100
// dispatching to the ui thread fixes an issue where the primary dialog button would steal focus
88-
_ = inputText.DispatcherQueue.EnqueueAsync(() => inputText.Focus(Microsoft.UI.Xaml.FocusState.Programmatic));
101+
_ = inputText.DispatcherQueue.EnqueueAsync(() => inputText.Focus(FocusState.Programmatic));
102+
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = true;
89103
};
90104

91105
dialog = new DynamicDialog(new DynamicDialogViewModel()
@@ -97,15 +111,7 @@ public static DynamicDialog GetFor_RenameDialog()
97111
MinWidth = 300d,
98112
Children =
99113
{
100-
new StackPanel()
101-
{
102-
Spacing = 4d,
103-
Children =
104-
{
105-
inputText,
106-
tipText
107-
}
108-
}
114+
inputText
109115
}
110116
},
111117
PrimaryButtonAction = (vm, e) =>
@@ -118,6 +124,11 @@ public static DynamicDialog GetFor_RenameDialog()
118124
DynamicButtons = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
119125
});
120126

127+
dialog.Closing += (s, e) =>
128+
{
129+
warning.IsOpen = false;
130+
};
131+
121132
return dialog;
122133
}
123134

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,6 +3166,9 @@
31663166
<data name="CloseTab" xml:space="preserve">
31673167
<value>Closes current tab</value>
31683168
</data>
3169+
<data name="InvalidLocation" xml:space="preserve">
3170+
<value>Invalid location</value>
3171+
</data>
31693172
<data name="CopyFileWithoutProperties" xml:space="preserve">
31703173
<value>Are you sure you want to copy these files without their properties?</value>
31713174
</data>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
3+
namespace Files.App.ViewModels.Dialogs
4+
{
5+
class RenameDialogViewModel : ObservableObject
6+
{
7+
private bool isNameInvalid;
8+
public bool IsNameInvalid
9+
{
10+
get => isNameInvalid;
11+
set => SetProperty(ref isNameInvalid, value);
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)