Skip to content

Commit 157a817

Browse files
Fix: FIxed some changes in the properties window cannot be canceled
1 parent bb026d9 commit 157a817

File tree

6 files changed

+91
-20
lines changed

6 files changed

+91
-20
lines changed

src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,18 @@ public string ShortcutItemType
558558
public string ShortcutItemPath
559559
{
560560
get => shortcutItemPath;
561-
set => SetProperty(ref shortcutItemPath, value);
561+
set
562+
{
563+
SetProperty(ref shortcutItemPath, value);
564+
ShortcutItemPathUserEditableValue = value;
565+
}
566+
}
567+
568+
private string shortcutItemPathUserEditableValue;
569+
public string ShortcutItemPathUserEditableValue
570+
{
571+
get => shortcutItemPathUserEditableValue;
572+
set => SetProperty(ref shortcutItemPathUserEditableValue, value);
562573
}
563574

564575
private bool isShortcutItemPathReadOnly;
@@ -572,7 +583,18 @@ public bool IsShortcutItemPathReadOnly
572583
public string ShortcutItemWorkingDir
573584
{
574585
get => shortcutItemWorkingDir;
575-
set => SetProperty(ref shortcutItemWorkingDir, value);
586+
set
587+
{
588+
SetProperty(ref shortcutItemWorkingDir, value);
589+
ShortcutItemWorkingDirUserEditableValue = value;
590+
}
591+
}
592+
593+
private string shortcutItemWorkingDirUserEditableValue;
594+
public string ShortcutItemWorkingDirUserEditableValue
595+
{
596+
get => shortcutItemWorkingDirUserEditableValue;
597+
set => SetProperty(ref shortcutItemWorkingDirUserEditableValue, value);
576598
}
577599

578600
private bool shortcutItemWorkingDirVisibility = false;
@@ -589,6 +611,17 @@ public string ShortcutItemArguments
589611
set
590612
{
591613
SetProperty(ref shortcutItemArguments, value);
614+
ShortcutItemArgumentsUserEditableValue = value;
615+
}
616+
}
617+
618+
private string shortcutItemArgumentsUserEditableValue;
619+
public string ShortcutItemArgumentsUserEditableValue
620+
{
621+
get => shortcutItemArgumentsUserEditableValue;
622+
set
623+
{
624+
SetProperty(ref shortcutItemArgumentsUserEditableValue, value);
592625
}
593626
}
594627

@@ -648,6 +681,18 @@ public bool IsReadOnly
648681
{
649682
IsReadOnlyEnabled = true;
650683
SetProperty(ref isReadOnly, value);
684+
IsReadOnlyUserEditableValue = value;
685+
}
686+
}
687+
688+
private bool isReadOnlyUserEditableValue;
689+
public bool IsReadOnlyUserEditableValue
690+
{
691+
get => isReadOnlyUserEditableValue;
692+
set
693+
{
694+
IsReadOnlyEnabled = true;
695+
SetProperty(ref isReadOnlyUserEditableValue, value);
651696
}
652697
}
653698

@@ -662,7 +707,18 @@ public bool IsReadOnlyEnabled
662707
public bool IsHidden
663708
{
664709
get => isHidden;
665-
set => SetProperty(ref isHidden, value);
710+
set
711+
{
712+
SetProperty(ref isHidden, value);
713+
IsHiddenUserEditableValue = value;
714+
}
715+
}
716+
717+
private bool isHiddenUserEditableValue;
718+
public bool IsHiddenUserEditableValue
719+
{
720+
get => isHiddenUserEditableValue;
721+
set => SetProperty(ref isHiddenUserEditableValue, value);
666722
}
667723

668724
private bool runAsAdmin;
@@ -673,6 +729,18 @@ public bool RunAsAdmin
673729
{
674730
RunAsAdminEnabled = true;
675731
SetProperty(ref runAsAdmin, value);
732+
RunAsAdminUserEditableValue = value;
733+
}
734+
}
735+
736+
private bool runAsAdminUserEditableValue;
737+
public bool RunAsAdminUserEditableValue
738+
{
739+
get => runAsAdminUserEditableValue;
740+
set
741+
{
742+
RunAsAdminEnabled = true;
743+
SetProperty(ref runAsAdminUserEditableValue, value);
676744
}
677745
}
678746

src/Files.App/ViewModels/Properties/Items/FileProperties.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ private async void ViewModel_PropertyChanged(object sender, System.ComponentMode
266266
{
267267
switch (e.PropertyName)
268268
{
269-
case "IsReadOnly":
269+
case nameof(ViewModel.IsReadOnly):
270270
if (ViewModel.IsReadOnly)
271271
{
272272
NativeFileOperationsHelper.SetFileAttribute(
@@ -284,7 +284,7 @@ private async void ViewModel_PropertyChanged(object sender, System.ComponentMode
284284

285285
break;
286286

287-
case "IsHidden":
287+
case nameof(ViewModel.IsHidden):
288288
if (ViewModel.IsHidden)
289289
{
290290
NativeFileOperationsHelper.SetFileAttribute(
@@ -302,10 +302,10 @@ private async void ViewModel_PropertyChanged(object sender, System.ComponentMode
302302

303303
break;
304304

305-
case "RunAsAdmin":
306-
case "ShortcutItemPath":
307-
case "ShortcutItemWorkingDir":
308-
case "ShortcutItemArguments":
305+
case nameof(ViewModel.RunAsAdmin):
306+
case nameof(ViewModel.ShortcutItemPath):
307+
case nameof(ViewModel.ShortcutItemWorkingDir):
308+
case nameof(ViewModel.ShortcutItemArguments):
309309
if (string.IsNullOrWhiteSpace(ViewModel.ShortcutItemPath))
310310
return;
311311

src/Files.App/Views/Properties/GeneralPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@
704704
HorizontalAlignment="Right"
705705
VerticalAlignment="Center"
706706
AutomationProperties.Name="{helpers:ResourceString Name=ReadOnly}"
707-
IsChecked="{x:Bind ViewModel.IsReadOnly, Mode=TwoWay}"
707+
IsChecked="{x:Bind ViewModel.IsReadOnlyUserEditableValue, Mode=TwoWay}"
708708
IsEnabled="{x:Bind ViewModel.IsReadOnlyEnabled, Mode=OneWay}" />
709709

710710
<!-- (Divider) -->
@@ -731,7 +731,7 @@
731731
HorizontalAlignment="Right"
732732
VerticalAlignment="Center"
733733
AutomationProperties.Name="{helpers:ResourceString Name=Hidden}"
734-
IsChecked="{x:Bind ViewModel.IsHidden, Mode=TwoWay}" />
734+
IsChecked="{x:Bind ViewModel.IsHiddenUserEditableValue, Mode=TwoWay}" />
735735

736736
</Grid>
737737
</Expander.Content>

src/Files.App/Views/Properties/GeneralPage.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() =>
173173
});
174174
}
175175

176+
ViewModel.IsReadOnly = ViewModel.IsReadOnlyUserEditableValue;
177+
ViewModel.IsHidden = ViewModel.IsHiddenUserEditableValue;
178+
176179
if (!GetNewName(out var newName))
177180
return true;
178181

src/Files.App/Views/Properties/ShortcutPage.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
Grid.Column="1"
7676
VerticalAlignment="Center"
7777
IsReadOnly="{x:Bind ViewModel.IsShortcutItemPathReadOnly, Mode=OneWay}"
78-
Text="{x:Bind ViewModel.ShortcutItemPath, Mode=TwoWay}"
78+
Text="{x:Bind ViewModel.ShortcutItemPathUserEditableValue, Mode=TwoWay}"
7979
Visibility="Visible" />
8080
</Grid>
8181

@@ -117,7 +117,7 @@
117117
Grid.Column="1"
118118
VerticalAlignment="Center"
119119
x:Load="{x:Bind ViewModel.ShortcutItemArgumentsVisibility, Mode=OneWay}"
120-
Text="{x:Bind ViewModel.ShortcutItemArguments, Mode=TwoWay}" />
120+
Text="{x:Bind ViewModel.ShortcutItemArgumentsUserEditableValue, Mode=TwoWay}" />
121121

122122
<TextBlock
123123
x:Name="PropertiesShortcutItemWorkingDir"
@@ -134,7 +134,7 @@
134134
Grid.Column="1"
135135
VerticalAlignment="Center"
136136
x:Load="{x:Bind ViewModel.ShortcutItemWorkingDirVisibility, Mode=OneWay}"
137-
Text="{x:Bind ViewModel.ShortcutItemWorkingDir, Mode=TwoWay}" />
137+
Text="{x:Bind ViewModel.ShortcutItemWorkingDirUserEditableValue, Mode=TwoWay}" />
138138
</Grid>
139139

140140
<settingsuc:SettingsBlockControl
@@ -144,7 +144,7 @@
144144
x:Load="{x:Bind ViewModel.RunAsAdminEnabled, Mode=OneWay}">
145145
<ToggleSwitch
146146
AutomationProperties.Name="{helpers:ResourceString Name=RunAsAdministrator}"
147-
IsOn="{x:Bind ViewModel.RunAsAdmin, Mode=TwoWay}"
147+
IsOn="{x:Bind ViewModel.RunAsAdminUserEditableValue, Mode=TwoWay}"
148148
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
149149
</settingsuc:SettingsBlockControl>
150150

src/Files.App/Views/Properties/ShortcutPage.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using CommunityToolkit.WinUI;
5-
using Files.App.Extensions;
6-
using Files.App.Utils;
7-
using Files.App.Helpers;
84
using Files.App.ViewModels.Properties;
9-
using System.Threading.Tasks;
105

116
namespace Files.App.Views.Properties
127
{
@@ -29,6 +24,11 @@ public override async Task<bool> SaveChangesAsync()
2924
if (shortcutItem is null)
3025
return true;
3126

27+
ViewModel.RunAsAdmin = ViewModel.RunAsAdminUserEditableValue;
28+
ViewModel.ShortcutItemPath = ViewModel.ShortcutItemPathUserEditableValue;
29+
ViewModel.ShortcutItemWorkingDir = ViewModel.ShortcutItemWorkingDirUserEditableValue;
30+
ViewModel.ShortcutItemArguments = ViewModel.ShortcutItemArgumentsUserEditableValue;
31+
3232
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() =>
3333
UIFilesystemHelpers.UpdateShortcutItemProperties(shortcutItem,
3434
ViewModel.ShortcutItemPath,

0 commit comments

Comments
 (0)