Skip to content

Commit 1a6d5f8

Browse files
committed
Merge branch 'file-jumping' into folder-properties
2 parents c483b53 + 382de39 commit 1a6d5f8

File tree

9 files changed

+1469
-18
lines changed

9 files changed

+1469
-18
lines changed

Files UWP/GenericFileBrowser.xaml

Lines changed: 356 additions & 0 deletions
Large diffs are not rendered by default.

Files UWP/GenericFileBrowser.xaml.cs

Lines changed: 508 additions & 0 deletions
Large diffs are not rendered by default.

Files UWP/PhotoAlbum.xaml.cs

Lines changed: 459 additions & 0 deletions
Large diffs are not rendered by default.

Files/BaseLayout.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Runtime.InteropServices.WindowsRuntime;
88
using Windows.Foundation;
99
using Windows.Foundation.Collections;
10+
using Windows.UI.Core;
1011
using Windows.UI.Xaml;
1112
using Windows.UI.Xaml.Controls;
1213
using Windows.UI.Xaml.Controls.Primitives;
@@ -25,6 +26,7 @@ public class BaseLayout : Page
2526
{
2627
public ItemViewModel AssociatedViewModel = null;
2728
public Interaction AssociatedInteractions = null;
29+
public bool isRenamingItem = false;
2830
public List<ListedItem> selectedItems
2931
{
3032
get
@@ -53,6 +55,8 @@ public BaseLayout()
5355
protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
5456
{
5557
base.OnNavigatedTo(eventArgs);
58+
// Add item jumping handler
59+
Window.Current.CoreWindow.CharacterReceived += Page_CharacterReceived;
5660
var parameters = (string)eventArgs.Parameter;
5761
if (App.FormFactor == Enums.FormFactorMode.Regular)
5862
{
@@ -121,6 +125,8 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
121125
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
122126
{
123127
base.OnNavigatingFrom(e);
128+
// Remove item jumping handler
129+
Window.Current.CoreWindow.CharacterReceived -= Page_CharacterReceived;
124130
if (App.OccupiedInstance.instanceViewModel._fileQueryResult != null)
125131
{
126132
App.OccupiedInstance.instanceViewModel._fileQueryResult.ContentsChanged -= App.OccupiedInstance.instanceViewModel.FileContentsChanged;
@@ -205,5 +211,15 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
205211
}
206212
}
207213
}
214+
215+
protected virtual void Page_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
216+
{
217+
var focusedElement = FocusManager.GetFocusedElement(XamlRoot) as FrameworkElement;
218+
if (focusedElement is TextBox)
219+
return;
220+
221+
char letterPressed = Convert.ToChar(args.KeyCode);
222+
App.OccupiedInstance.instanceInteraction.PushJumpChar(letterPressed);
223+
}
208224
}
209225
}

Files/Filesystem/ItemViewModel.cs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public class ItemViewModel : INotifyPropertyChanged
4747
private const int _step = 250;
4848
public event PropertyChangedEventHandler PropertyChanged;
4949

50+
private string _jumpString = "";
51+
private DispatcherTimer jumpTimer = new DispatcherTimer();
52+
5053
private SortOption _directorySortOption = SortOption.Name;
5154
private SortDirection _directorySortDirection = SortDirection.Ascending;
5255

@@ -170,6 +173,66 @@ public bool IsSortedDescending
170173
}
171174
}
172175

176+
public string JumpString
177+
{
178+
get
179+
{
180+
return _jumpString;
181+
}
182+
set
183+
{
184+
// If current string is "a", and the next character typed is "a",
185+
// search for next file that starts with "a" (a.k.a. _jumpString = "a")
186+
if (_jumpString.Length == 1 && value == _jumpString + _jumpString)
187+
{
188+
value = _jumpString;
189+
}
190+
if (value != "")
191+
{
192+
ListedItem jumpedToItem = null;
193+
ListedItem previouslySelectedItem = null;
194+
var candidateItems = _filesAndFolders.Where(f => f.FileName.Length >= value.Length && f.FileName.Substring(0, value.Length).ToLower() == value);
195+
if (App.OccupiedInstance.ItemDisplayFrame.CurrentSourcePageType == typeof(GenericFileBrowser))
196+
{
197+
previouslySelectedItem = (App.OccupiedInstance.ItemDisplayFrame.Content as GenericFileBrowser).AllView.SelectedItem as ListedItem;
198+
}
199+
else if (App.OccupiedInstance.ItemDisplayFrame.CurrentSourcePageType == typeof(PhotoAlbum))
200+
{
201+
previouslySelectedItem = (App.OccupiedInstance.ItemDisplayFrame.Content as PhotoAlbum).FileList.SelectedItem as ListedItem;
202+
}
203+
204+
// If the user is trying to cycle through items
205+
// starting with the same letter
206+
if (value.Length == 1 && previouslySelectedItem != null)
207+
{
208+
// Try to select item lexicographically bigger than the previous item
209+
jumpedToItem = candidateItems.FirstOrDefault(f => f.FileName.CompareTo(previouslySelectedItem.FileName) > 0);
210+
}
211+
if (jumpedToItem == null)
212+
jumpedToItem = candidateItems.FirstOrDefault();
213+
214+
if (jumpedToItem != null)
215+
{
216+
if (App.OccupiedInstance.ItemDisplayFrame.CurrentSourcePageType == typeof(GenericFileBrowser))
217+
{
218+
(App.OccupiedInstance.ItemDisplayFrame.Content as GenericFileBrowser).AllView.SelectedItem = jumpedToItem;
219+
(App.OccupiedInstance.ItemDisplayFrame.Content as GenericFileBrowser).AllView.ScrollIntoView(jumpedToItem, null);
220+
}
221+
else if (App.OccupiedInstance.ItemDisplayFrame.CurrentSourcePageType == typeof(PhotoAlbum))
222+
{
223+
(App.OccupiedInstance.ItemDisplayFrame.Content as PhotoAlbum).FileList.SelectedItem = jumpedToItem;
224+
(App.OccupiedInstance.ItemDisplayFrame.Content as PhotoAlbum).FileList.ScrollIntoView(jumpedToItem);
225+
}
226+
227+
}
228+
229+
// Restart the timer
230+
jumpTimer.Start();
231+
}
232+
_jumpString = value;
233+
}
234+
}
235+
173236
public ItemViewModel()
174237
{
175238
_filesAndFolders = new ObservableCollection<ListedItem>();
@@ -181,14 +244,22 @@ public ItemViewModel()
181244
_cancellationTokenSource = new CancellationTokenSource();
182245

183246
Universal.PropertyChanged += Universal_PropertyChanged;
247+
248+
jumpTimer.Interval = TimeSpan.FromSeconds(0.8);
249+
jumpTimer.Tick += JumpTimer_Tick;
250+
}
251+
252+
private void JumpTimer_Tick(object sender, object e)
253+
{
254+
_jumpString = "";
255+
jumpTimer.Stop();
184256
}
185257

186258
/*
187259
* Ensure that the path bar gets updated for user interaction
188260
* whenever the path changes. We will get the individual directories from
189261
* the updated, most-current path and add them to the UI.
190262
*/
191-
192263
private void Universal_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
193264
{
194265
// Clear the path UI

Files/GenericFileBrowser.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
<Grid ContextFlyout="{StaticResource BaseLayoutContextFlyout}" Background="Transparent" x:Name="RootGrid">
147147
<ProgressBar Visibility="{x:Bind AssociatedViewModel.LoadIndicator.isVisible,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" x:Name="progBar" Height="10" VerticalAlignment="Top" IsIndeterminate="True"/>
148148
<TextBlock Visibility="{x:Bind AssociatedViewModel.EmptyTextState.isVisible, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:Name="EmptyText" HorizontalAlignment="Center" Text="This folder is empty." TextWrapping="Wrap" VerticalAlignment="Top" Margin="0,125,0,0"/>
149-
<controls:DataGrid DoubleTapped="{x:Bind local:App.OccupiedInstance.instanceInteraction.List_ItemClick}" RightTapped="{x:Bind local:App.OccupiedInstance.instanceInteraction.AllView_RightTapped}" ItemsSource="{x:Bind AssociatedViewModel.FilesAndFolders}" PreviewKeyDown="AllView_PreviewKeyDown" ScrollViewer.IsScrollInertiaEnabled="True" ClipboardCopyMode="None" RowDetailsVisibilityMode="Collapsed" AllowDrop="True" Drop="AllView_DropAsync" 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">
149+
<controls:DataGrid DoubleTapped="{x:Bind local:App.OccupiedInstance.instanceInteraction.List_ItemClick}" RightTapped="{x:Bind local:App.OccupiedInstance.instanceInteraction.AllView_RightTapped}" ItemsSource="{x:Bind AssociatedViewModel.FilesAndFolders}" PreviewKeyDown="AllView_PreviewKeyDown" ScrollViewer.IsScrollInertiaEnabled="True" ClipboardCopyMode="None" RowDetailsVisibilityMode="Collapsed" AllowDrop="True" Drop="AllView_DropAsync" DragStarting="AllView_DragStarting" SelectionChanged="AllView_SelectionChanged" Margin="24,24,0,0" Grid.Row="3" PreparingCellForEdit="AllView_PreparingCellForEdit" CellEditEnding="AllView_CellEditEnding" 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" HorizontalAlignment="Left">
150150
<controls:DataGrid.Resources>
151151
<SolidColorBrush x:Key="DataGridCellFocusVisualPrimaryBrush" Color="Transparent"/>
152152
<SolidColorBrush x:Key="DataGridCellFocusVisualSecondaryBrush" Color="Transparent"/>

Files/GenericFileBrowser.xaml.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Files.Filesystem;
1111
using Windows.System;
1212
using Windows.UI.Xaml.Input;
13+
using Windows.UI.Core;
1314

1415
namespace Files
1516
{
@@ -153,6 +154,11 @@ private async void AllView_CellEditEnding(object sender, DataGridCellEditEndingE
153154
}
154155
}
155156

157+
private void AllView_CellEditEnded(object sender, DataGridCellEditEndedEventArgs e)
158+
{
159+
isRenamingItem = false;
160+
}
161+
156162
private void GenericItemView_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
157163
{
158164
AllView.SelectedItem = null;
@@ -192,9 +198,22 @@ private void AllView_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
192198
{
193199
if (e.Key == VirtualKey.Enter)
194200
{
195-
App.OccupiedInstance.instanceInteraction.List_ItemClick(null, null);
201+
if (isRenamingItem)
202+
{
203+
AllView.CommitEdit();
204+
}
205+
else
206+
{
207+
App.OccupiedInstance.instanceInteraction.List_ItemClick(null, null);
208+
}
196209
e.Handled = true;
197210
}
198211
}
212+
213+
protected override void Page_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
214+
{
215+
base.Page_CharacterReceived(sender, args);
216+
AllView.Focus(FocusState.Keyboard);
217+
}
199218
}
200219
}

Files/Interacts/Interaction.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
using System;
1+
using Files.Dialogs;
2+
using Files.Filesystem;
3+
using Files.Navigation;
4+
using Microsoft.Toolkit.Uwp.UI.Controls;
5+
using System;
6+
using System.Collections;
27
using System.Collections.Generic;
38
using System.Collections.ObjectModel;
9+
using System.ComponentModel;
410
using System.Diagnostics;
11+
using System.IO;
12+
using System.IO.Compression;
13+
using System.Linq;
14+
using System.Reflection;
15+
using System.Threading.Tasks;
16+
using Windows.ApplicationModel;
517
using Windows.ApplicationModel.DataTransfer;
18+
using Windows.Foundation;
619
using Windows.Storage;
720
using Windows.System;
21+
using Windows.UI.Popups;
822
using Windows.UI.Xaml;
923
using Windows.UI.Xaml.Controls;
24+
using Windows.UI.Xaml.Controls.Primitives;
1025
using Windows.UI.Xaml.Input;
11-
using Windows.UI.Popups;
1226
using Windows.UI.Xaml.Media;
1327
using Windows.UI.Xaml.Media.Animation;
14-
using Files.Filesystem;
15-
using Microsoft.Toolkit.Uwp.UI.Controls;
16-
using System.Threading.Tasks;
17-
using Windows.ApplicationModel;
18-
using System.Collections;
19-
using Windows.Foundation;
20-
using System.IO;
21-
using System.Reflection;
22-
using Files.Dialogs;
23-
using System.IO.Compression;
24-
using System.Linq;
2528

2629
namespace Files.Interacts
2730
{
@@ -985,5 +988,10 @@ public void ClearAllItems()
985988
(currentInstance.ItemDisplayFrame.Content as BaseLayout).selectedItems.Clear();
986989
}
987990
}
991+
992+
public void PushJumpChar(char letter)
993+
{
994+
App.OccupiedInstance.instanceViewModel.JumpString += letter.ToString().ToLower();
995+
}
988996
}
989997
}

Files/PhotoAlbum.xaml.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Windows.UI.Xaml.Input;
55
using Windows.System;
66
using Interaction = Files.Interacts.Interaction;
7+
using Windows.UI.Core;
78

89
namespace Files
910
{
@@ -81,6 +82,7 @@ public void StartRename()
8182
textBox.LostFocus += RenameTextBox_LostFocus;
8283
textBox.KeyDown += RenameTextBox_KeyDown;
8384
textBox.Select(0, renamingItem.FileName.Length - extensionLength);
85+
isRenamingItem = true;
8486
}
8587

8688
private void RenameTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
@@ -90,11 +92,13 @@ private void RenameTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
9092
TextBox textBox = sender as TextBox;
9193
textBox.LostFocus -= RenameTextBox_LostFocus;
9294
EndRename(textBox);
95+
e.Handled = true;
9396
}
9497
else if (e.Key == VirtualKey.Enter)
9598
{
9699
TextBox textBox = sender as TextBox;
97100
CommitRename(textBox);
101+
e.Handled = true;
98102
}
99103
}
100104

@@ -125,15 +129,25 @@ private void EndRename(TextBox textBox)
125129
textBlock.Visibility = Visibility.Visible;
126130
textBox.LostFocus -= RenameTextBox_LostFocus;
127131
textBox.KeyDown += RenameTextBox_KeyDown;
132+
isRenamingItem = false;
128133
}
129134

130135
private void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
131136
{
132137
if (e.Key == VirtualKey.Enter)
133138
{
134-
App.OccupiedInstance.instanceInteraction.List_ItemClick(null, null);
135-
e.Handled = true;
139+
if (!isRenamingItem)
140+
{
141+
App.OccupiedInstance.instanceInteraction.List_ItemClick(null, null);
142+
e.Handled = true;
143+
}
136144
}
137145
}
146+
147+
protected override void Page_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
148+
{
149+
base.Page_CharacterReceived(sender, args);
150+
FileList.Focus(FocusState.Keyboard);
151+
}
138152
}
139153
}

0 commit comments

Comments
 (0)