Skip to content

Commit 1eb8a2d

Browse files
d2dyno1tsvietOK
andauthored
Implemented the ability to rename files/folders from the properties window (#1781)
Co-authored-by: Vladyslav <[email protected]>
1 parent 2405b73 commit 1eb8a2d

File tree

9 files changed

+43
-10
lines changed

9 files changed

+43
-10
lines changed

Files/Interacts/Interaction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ public async Task<bool> RenameFileItem(ListedItem item, string oldName, string n
971971
{
972972
return false;
973973
}
974-
974+
975975
CurrentInstance.NavigationToolbar.CanGoForward = false;
976976
return true;
977977
}
@@ -1652,4 +1652,4 @@ public async Task<string> GetHashForFile(ListedItem fileItem, string nameOfAlg,
16521652
return CryptographicBuffer.EncodeToHexString(hash.GetValueAndReset()).ToLower();
16531653
}
16541654
}
1655-
}
1655+
}

Files/View Models/Properties/DriveProperties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ public override void GetSpecialProperties()
6060
}
6161
}
6262
}
63-
}
63+
}

Files/View Models/Properties/FileProperties.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public override void GetBaseProperties()
3939
if (Item != null)
4040
{
4141
ViewModel.ItemName = Item.ItemName;
42+
ViewModel.OriginalItemName = Item.ItemName;
4243
ViewModel.ItemType = Item.ItemType;
4344
ViewModel.ItemPath = Path.IsPathRooted(Item.ItemPath) ? Path.GetDirectoryName(Item.ItemPath) : Item.ItemPath;
4445
ViewModel.ItemModifiedTimestamp = Item.ItemDateModified;

Files/View Models/Properties/FolderProperties.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public override void GetBaseProperties()
3535
if (Item != null)
3636
{
3737
ViewModel.ItemName = Item.ItemName;
38+
ViewModel.OriginalItemName = Item.ItemName;
3839
ViewModel.ItemType = Item.ItemType;
3940
ViewModel.ItemPath = Path.IsPathRooted(Item.ItemPath) ? Path.GetDirectoryName(Item.ItemPath) : Item.ItemPath;
4041
ViewModel.ItemModifiedTimestamp = Item.ItemDateModified;

Files/View Models/SelectedItemsPropertiesViewModel.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ public string ItemName
8080
}
8181
}
8282

83+
private string _OriginalItemName;
84+
85+
public string OriginalItemName
86+
{
87+
get => _OriginalItemName;
88+
set
89+
{
90+
ItemNameVisibility = Visibility.Visible;
91+
SetProperty(ref _OriginalItemName, value);
92+
}
93+
}
94+
8395
private Visibility _ItemNameVisibility = Visibility.Collapsed;
8496

8597
public Visibility ItemNameVisibility

Files/Views/Pages/Properties.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
Grid.Column="1"
7575
MinWidth="100"
7676
HorizontalAlignment="Right"
77-
Click="Button_Click"
77+
Click="OKButton_Click"
7878
Content="OK"
7979
Style="{ThemeResource ButtonRevealStyle}" />
8080
</Grid>

Files/Views/Pages/Properties.xaml.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public sealed partial class Properties : Page
2727

2828
private object navParameter;
2929

30+
private ListedItem listedItem;
31+
3032
public SettingsViewModel AppSettings => App.AppSettings;
3133

3234
public Properties()
@@ -38,6 +40,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
3840
{
3941
this.navParameter = e.Parameter;
4042
this.TabShorcut.Visibility = e.Parameter is ShortcutItem ? Visibility.Visible : Visibility.Collapsed;
43+
this.listedItem = e.Parameter as ListedItem;
4144
this.SetBackground();
4245
base.OnNavigatedTo(e);
4346
}
@@ -157,8 +160,13 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
157160
});
158161
}
159162

160-
private async void Button_Click(object sender, RoutedEventArgs e)
163+
private async void OKButton_Click(object sender, RoutedEventArgs e)
161164
{
165+
if (contentFrame.Content is PropertiesGeneral)
166+
{
167+
(contentFrame.Content as PropertiesGeneral).SaveChanges(listedItem);
168+
}
169+
162170
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
163171
{
164172
await ApplicationView.GetForCurrentView().TryConsolidateAsync();

Files/Views/Pages/PropertiesGeneral.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,15 @@
101101
Source="{x:Bind ViewModel.FileIconSource, Mode=OneWay}" />
102102
</Grid>
103103
<TextBox
104-
x:Name="itemFileName"
104+
x:Name="ItemFileName"
105105
x:Uid="PropertiesItemFileName"
106106
Grid.Row="0"
107107
Grid.Column="1"
108108
Margin="20,0"
109109
HorizontalAlignment="Stretch"
110110
VerticalAlignment="Center"
111111
BorderThickness="1"
112-
IsReadOnly="True"
113-
Text="{x:Bind ViewModel.ItemName, Mode=OneWay}"
112+
Text="{x:Bind ViewModel.ItemName, Mode=TwoWay}"
114113
Visibility="{x:Bind ViewModel.ItemNameVisibility, Mode=OneWay}" />
115114

116115
<MenuFlyoutSeparator

Files/Views/Pages/PropertiesGeneral.xaml.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using Files.Filesystem;
1+
using Files.Filesystem;
22
using Files.View_Models;
33
using Files.View_Models.Properties;
44
using System.Collections.Generic;
55
using Windows.Storage;
66
using Windows.UI.Xaml;
77
using Windows.UI.Xaml.Controls;
88
using Windows.UI.Xaml.Navigation;
9+
using Windows.ApplicationModel.Core;
10+
using Microsoft.Toolkit.Uwp.Helpers;
911

1012
// Il modello di elemento Pagina vuota è documentato all'indirizzo https://go.microsoft.com/fwlink/?LinkId=234238
1113

@@ -61,5 +63,15 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
6163

6264
base.OnNavigatedTo(e);
6365
}
66+
67+
public async void SaveChanges(ListedItem item)
68+
{
69+
if (ViewModel.OriginalItemName != null)
70+
{
71+
await CoreApplication.MainView.ExecuteOnUIThreadAsync(() => App.CurrentInstance.InteractionOperations.RenameFileItem(item,
72+
ViewModel.OriginalItemName,
73+
ViewModel.ItemName));
74+
}
75+
}
6476
}
65-
}
77+
}

0 commit comments

Comments
 (0)