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: Fixed issue where certain changes in the Properties Window couldn't be canceled #14661

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 71 additions & 3 deletions src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,18 @@ public string ShortcutItemType
public string ShortcutItemPath
{
get => shortcutItemPath;
set => SetProperty(ref shortcutItemPath, value);
set
{
SetProperty(ref shortcutItemPath, value);
ShortcutItemPathEditedValue = value;
}
}

private string shortcutItemPathEditedValue;
public string ShortcutItemPathEditedValue
{
get => shortcutItemPathEditedValue;
set => SetProperty(ref shortcutItemPathEditedValue, value);
}

private bool isShortcutItemPathReadOnly;
Expand All @@ -572,7 +583,18 @@ public bool IsShortcutItemPathReadOnly
public string ShortcutItemWorkingDir
{
get => shortcutItemWorkingDir;
set => SetProperty(ref shortcutItemWorkingDir, value);
set
{
SetProperty(ref shortcutItemWorkingDir, value);
ShortcutItemWorkingDirEditedValue = value;
}
}

private string shortcutItemWorkingDirEditedValue;
public string ShortcutItemWorkingDirEditedValue
{
get => shortcutItemWorkingDirEditedValue;
set => SetProperty(ref shortcutItemWorkingDirEditedValue, value);
}

private bool shortcutItemWorkingDirVisibility = false;
Expand All @@ -589,6 +611,17 @@ public string ShortcutItemArguments
set
{
SetProperty(ref shortcutItemArguments, value);
ShortcutItemArgumentsEditedValue = value;
}
}

private string shortcutItemArgumentsEditedValue;
public string ShortcutItemArgumentsEditedValue
{
get => shortcutItemArgumentsEditedValue;
set
{
SetProperty(ref shortcutItemArgumentsEditedValue, value);
}
}

Expand Down Expand Up @@ -648,6 +681,18 @@ public bool IsReadOnly
{
IsReadOnlyEnabled = true;
SetProperty(ref isReadOnly, value);
IsReadOnlyEditedValue = value;
}
}

private bool isReadOnlyEditedValue;
public bool IsReadOnlyEditedValue
{
get => isReadOnlyEditedValue;
set
{
IsReadOnlyEnabled = true;
SetProperty(ref isReadOnlyEditedValue, value);
}
}

Expand All @@ -662,7 +707,18 @@ public bool IsReadOnlyEnabled
public bool IsHidden
{
get => isHidden;
set => SetProperty(ref isHidden, value);
set
{
SetProperty(ref isHidden, value);
IsHiddenEditedValue = value;
}
}

private bool isHiddenEditedValue;
public bool IsHiddenEditedValue
{
get => isHiddenEditedValue;
set => SetProperty(ref isHiddenEditedValue, value);
}

private bool runAsAdmin;
Expand All @@ -673,6 +729,18 @@ public bool RunAsAdmin
{
RunAsAdminEnabled = true;
SetProperty(ref runAsAdmin, value);
RunAsAdminEditedValue = value;
}
}

private bool runAsAdminEditedValue;
public bool RunAsAdminEditedValue
{
get => runAsAdminEditedValue;
set
{
RunAsAdminEnabled = true;
SetProperty(ref runAsAdminEditedValue, value);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Files.App/ViewModels/Properties/Items/FileProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private async void ViewModel_PropertyChanged(object sender, System.ComponentMode
{
switch (e.PropertyName)
{
case "IsReadOnly":
case nameof(ViewModel.IsReadOnly):
if (ViewModel.IsReadOnly)
{
NativeFileOperationsHelper.SetFileAttribute(
Expand All @@ -284,7 +284,7 @@ private async void ViewModel_PropertyChanged(object sender, System.ComponentMode

break;

case "IsHidden":
case nameof(ViewModel.IsHidden):
if (ViewModel.IsHidden)
{
NativeFileOperationsHelper.SetFileAttribute(
Expand All @@ -302,10 +302,10 @@ private async void ViewModel_PropertyChanged(object sender, System.ComponentMode

break;

case "RunAsAdmin":
case "ShortcutItemPath":
case "ShortcutItemWorkingDir":
case "ShortcutItemArguments":
case nameof(ViewModel.RunAsAdmin):
case nameof(ViewModel.ShortcutItemPath):
case nameof(ViewModel.ShortcutItemWorkingDir):
case nameof(ViewModel.ShortcutItemArguments):
if (string.IsNullOrWhiteSpace(ViewModel.ShortcutItemPath))
return;

Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Views/Properties/GeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@
HorizontalAlignment="Right"
VerticalAlignment="Center"
AutomationProperties.Name="{helpers:ResourceString Name=ReadOnly}"
IsChecked="{x:Bind ViewModel.IsReadOnly, Mode=TwoWay}"
IsChecked="{x:Bind ViewModel.IsReadOnlyEditedValue, Mode=TwoWay}"
IsEnabled="{x:Bind ViewModel.IsReadOnlyEnabled, Mode=OneWay}" />

<!-- (Divider) -->
Expand All @@ -731,7 +731,7 @@
HorizontalAlignment="Right"
VerticalAlignment="Center"
AutomationProperties.Name="{helpers:ResourceString Name=Hidden}"
IsChecked="{x:Bind ViewModel.IsHidden, Mode=TwoWay}" />
IsChecked="{x:Bind ViewModel.IsHiddenEditedValue, Mode=TwoWay}" />

</Grid>
</Expander.Content>
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Views/Properties/GeneralPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ async Task<bool> SaveBaseAsync(ListedItem item)
});
}

ViewModel.IsReadOnly = ViewModel.IsReadOnlyEditedValue;
ViewModel.IsHidden = ViewModel.IsHiddenEditedValue;

if (!GetNewName(out var newName))
return true;

Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/Views/Properties/ShortcutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
Grid.Column="1"
VerticalAlignment="Center"
IsReadOnly="{x:Bind ViewModel.IsShortcutItemPathReadOnly, Mode=OneWay}"
Text="{x:Bind ViewModel.ShortcutItemPath, Mode=TwoWay}"
Text="{x:Bind ViewModel.ShortcutItemPathEditedValue, Mode=TwoWay}"
Visibility="Visible" />
</Grid>

Expand Down Expand Up @@ -117,7 +117,7 @@
Grid.Column="1"
VerticalAlignment="Center"
x:Load="{x:Bind ViewModel.ShortcutItemArgumentsVisibility, Mode=OneWay}"
Text="{x:Bind ViewModel.ShortcutItemArguments, Mode=TwoWay}" />
Text="{x:Bind ViewModel.ShortcutItemArgumentsEditedValue, Mode=TwoWay}" />

<TextBlock
x:Name="PropertiesShortcutItemWorkingDir"
Expand All @@ -134,7 +134,7 @@
Grid.Column="1"
VerticalAlignment="Center"
x:Load="{x:Bind ViewModel.ShortcutItemWorkingDirVisibility, Mode=OneWay}"
Text="{x:Bind ViewModel.ShortcutItemWorkingDir, Mode=TwoWay}" />
Text="{x:Bind ViewModel.ShortcutItemWorkingDirEditedValue, Mode=TwoWay}" />
</Grid>

<settingsuc:SettingsBlockControl
Expand All @@ -144,7 +144,7 @@
x:Load="{x:Bind ViewModel.RunAsAdminEnabled, Mode=OneWay}">
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Name=RunAsAdministrator}"
IsOn="{x:Bind ViewModel.RunAsAdmin, Mode=TwoWay}"
IsOn="{x:Bind ViewModel.RunAsAdminEditedValue, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</settingsuc:SettingsBlockControl>

Expand Down
10 changes: 5 additions & 5 deletions src/Files.App/Views/Properties/ShortcutPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.WinUI;
using Files.App.Extensions;
using Files.App.Utils;
using Files.App.Helpers;
using Files.App.ViewModels.Properties;
using System.Threading.Tasks;

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

ViewModel.RunAsAdmin = ViewModel.RunAsAdminEditedValue;
ViewModel.ShortcutItemPath = ViewModel.ShortcutItemPathEditedValue;
ViewModel.ShortcutItemWorkingDir = ViewModel.ShortcutItemWorkingDirEditedValue;
ViewModel.ShortcutItemArguments = ViewModel.ShortcutItemArgumentsEditedValue;

await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() =>
UIFilesystemHelpers.UpdateShortcutItemProperties(shortcutItem,
ViewModel.ShortcutItemPath,
Expand Down