Skip to content

Commit d791cd2

Browse files
authored
Merge branch 'master' into sort
2 parents 1692c0a + 2e93cfb commit d791cd2

File tree

6 files changed

+236
-475
lines changed

6 files changed

+236
-475
lines changed

Files UWP/GenericFileBrowser.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
</Grid.ContextFlyout>
213213
<ProgressBar x:Name="progBar" Height="10" VerticalAlignment="Top" IsIndeterminate="True"/>
214214
<TextBlock Visibility="{x:Bind Mode=TwoWay, Path=TextState.isVisible, UpdateSourceTrigger=PropertyChanged}" x:Name="EmptyText" HorizontalAlignment="Center" Text="This folder is empty." TextWrapping="Wrap" VerticalAlignment="Top" Margin="0,125,0,0"/>
215-
<controls:DataGrid ItemsSource="{x:Bind viewModelInstance.FilesAndFolders}" ScrollViewer.IsScrollInertiaEnabled="True" ClipboardCopyMode="None" RowDetailsVisibilityMode="Collapsed" AllowDrop="True" Drop="AllView_DropAsync" DragLeave="AllView_DragLeave" DragStarting="AllView_DragStarting" SelectionChanged="AllView_SelectionChanged" Margin="24,24,0,0" Grid.Row="3" CellEditEnded="AllView_CellEditEnded" FocusVisualPrimaryThickness="0" SelectionMode="Extended" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" AutoGenerateColumns="False" CanDrag="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" CanUserSortColumns="True" Sorting="AllView_Sorting" IsReadOnly="True" HorizontalAlignment="Left">
215+
<controls:DataGrid ItemsSource="{x:Bind viewModelInstance.FilesAndFolders}" PreviewKeyDown="AllView_PreviewKeyDown" ScrollViewer.IsScrollInertiaEnabled="True" ClipboardCopyMode="None" RowDetailsVisibilityMode="Collapsed" AllowDrop="True" Drop="AllView_DropAsync" DragLeave="AllView_DragLeave" DragStarting="AllView_DragStarting" SelectionChanged="AllView_SelectionChanged" Margin="24,24,0,0" Grid.Row="3" PreparingCellForEdit="AllView_PreparingCellForEdit" CellEditEnding="AllView_CellEditEnding" FocusVisualPrimaryThickness="0" SelectionMode="Extended" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" AutoGenerateColumns="False" CanDrag="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" CanUserSortColumns="True" Sorting="AllView_Sorting" HorizontalAlignment="Left">
216216
<controls:DataGrid.Resources>
217217
<SolidColorBrush x:Key="DataGridCellFocusVisualPrimaryBrush" Color="Transparent"/>
218218
<SolidColorBrush x:Key="DataGridCellFocusVisualSecondaryBrush" Color="Transparent"/>
@@ -339,7 +339,7 @@
339339
</DataTemplate>
340340
</controls:DataGridTemplateColumn.CellTemplate>
341341
</controls:DataGridTemplateColumn>
342-
<controls:DataGridTextColumn DisplayIndex="1" x:Name="nameColumn" IsReadOnly="True" Header="Name" Width="275" Binding="{Binding FileName}" Tag="Name"/>
342+
<controls:DataGridTextColumn DisplayIndex="1" x:Name="nameColumn" Header="Name" Width="275" Binding="{Binding FileName}" Tag="Name"/>
343343
<controls:DataGridTextColumn DisplayIndex="2" x:Name="dateColumn" IsReadOnly="True" Header="Date modified" Width="Auto" Binding="{Binding FileDate}" Tag="Date"/>
344344
<controls:DataGridTextColumn DisplayIndex="3" x:Name="typeColumn" IsReadOnly="True" Header="Type" Width="150" Binding="{Binding FileType}" Tag="Type"/>
345345
<controls:DataGridTextColumn DisplayIndex="4" x:Name="sizeColumn" IsReadOnly="True" Header="Size" Width="Auto" MinWidth="100" Binding="{Binding FileSize}" Tag="Size"/>

Files UWP/GenericFileBrowser.xaml.cs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using Files.Interacts;
1313
using System.IO;
1414
using System.Runtime.CompilerServices;
15+
using Windows.System;
16+
using Windows.UI.Xaml.Input;
1517

1618
namespace Files
1719
{
@@ -26,6 +28,7 @@ public sealed partial class GenericFileBrowser : Page
2628
public Page GFBPageName;
2729
public ContentDialog AddItemBox;
2830
public ContentDialog NameBox;
31+
public string previousFileName;
2932
public TextBox inputFromRename;
3033
public string inputForRename;
3134
public Flyout CopiedFlyout;
@@ -152,11 +155,6 @@ private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e
152155
}
153156
}
154157

155-
private void AddItem_Click(object sender, RoutedEventArgs e)
156-
{
157-
//await AddDialog.ShowAsync();
158-
}
159-
160158
private void Clipboard_ContentChanged(object sender, object e)
161159
{
162160
try
@@ -199,7 +197,6 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
199197

200198
Clipboard_ContentChanged(null, null);
201199
tabInstance.AlwaysPresentCommands.isEnabled = true;
202-
tabInstance.AddItemButton.Click += AddItem_Click;
203200

204201
TextState.isVisible = Visibility.Collapsed;
205202

@@ -298,37 +295,32 @@ private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialo
298295
this.progressBar.Visibility = Visibility.Collapsed;
299296
}
300297

301-
private async void AllView_CellEditEnded(object sender, DataGridCellEditEndedEventArgs e)
298+
private void AllView_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
302299
{
303-
var newCellText = (data.SelectedItem as ListedItem)?.FileName;
304-
var selectedItem = tabInstance.instanceViewModel.FilesAndFolders[e.Row.GetIndex()];
305-
if(selectedItem.FileType == "Folder")
306-
{
307-
StorageFolder FolderToRename = await StorageFolder.GetFolderFromPathAsync(selectedItem.FilePath);
308-
if(FolderToRename.Name != newCellText)
309-
{
310-
await FolderToRename.RenameAsync(newCellText);
311-
AllView.CommitEdit();
312-
}
313-
else
314-
{
315-
AllView.CancelEdit();
316-
}
317-
}
318-
else
300+
var textBox = e.EditingElement as TextBox;
301+
var selectedItem = data.SelectedItem as ListedItem;
302+
int extensionLength = selectedItem.DotFileExtension?.Length ?? 0;
303+
304+
previousFileName = selectedItem.FileName;
305+
textBox.Focus(FocusState.Programmatic); // Without this, cannot edit text box when renaming via right-click
306+
textBox.Select(0, selectedItem.FileName.Length - extensionLength);
307+
}
308+
309+
private async void AllView_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
310+
{
311+
if (e.EditAction == DataGridEditAction.Cancel)
312+
return;
313+
314+
var selectedItem = data.SelectedItem as ListedItem;
315+
string currentName = previousFileName;
316+
string newName = (e.EditingElement as TextBox).Text;
317+
318+
bool successful = await tabInstance.instanceInteraction.RenameFileItem(selectedItem, currentName, newName);
319+
if (!successful)
319320
{
320-
StorageFile fileToRename = await StorageFile.GetFileFromPathAsync(selectedItem.FilePath);
321-
if (fileToRename.Name != newCellText)
322-
{
323-
await fileToRename.RenameAsync(newCellText);
324-
AllView.CommitEdit();
325-
}
326-
else
327-
{
328-
AllView.CancelEdit();
329-
}
321+
selectedItem.FileName = currentName;
322+
((sender as DataGrid).Columns[1].GetCellContent(e.Row) as TextBlock).Text = currentName;
330323
}
331-
//Navigation.NavigationActions.Refresh_Click(null, null);
332324
}
333325

334326
private void ContentDialog_Loaded(object sender, RoutedEventArgs e)
@@ -408,8 +400,17 @@ private void AllView_Sorting(object sender, DataGridColumnEventArgs e)
408400
else if (e.Column != iconColumn)
409401
SortedColumn = e.Column;
410402
}
403+
404+
private void AllView_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
405+
{
406+
if (e.Key == VirtualKey.Enter)
407+
{
408+
tabInstance.instanceInteraction.List_ItemClick(null, null);
409+
e.Handled = true;
410+
}
411+
}
411412
}
412-
413+
413414
public class EmptyFolderTextState : INotifyPropertyChanged
414415
{
415416
public Visibility _isVisible;

0 commit comments

Comments
 (0)