Skip to content

Commit 0525252

Browse files
committed
Fix potential crash from Recent Items list
1 parent 8b67f35 commit 0525252

File tree

5 files changed

+122
-97
lines changed

5 files changed

+122
-97
lines changed

Files UWP/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public App()
6868

6969
private void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
7070
{
71-
e.Handled = true;
71+
e.Handled = true;
7272
Frame rootFrame = Window.Current.Content as Frame;
7373
rootFrame.Navigate(typeof(UnhandledExceptionDisplay), e.Exception);
7474
}

Files UWP/PhotoAlbum.xaml

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
xmlns:navigation="using:Files.Navigation"
1414
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
1515
Name="PhotoAlbumViewer"
16-
PointerReleased="PhotoAlbumViewer_PointerReleased">
16+
PointerReleased="PhotoAlbumViewer_PointerReleased" PointerPressed="PhotoAlbumViewer_PointerPressed">
1717

1818
<Page.Resources>
1919
<Style x:Key="MenuFlyoutFluentThemeResources" TargetType="MenuFlyoutPresenter">
@@ -372,6 +372,9 @@
372372
</Setter.Value>
373373
</Setter>
374374
</Style>
375+
<ItemsPanelTemplate x:Key="GridViewItemsPanel1">
376+
<ItemsWrapGrid Orientation="Horizontal"/>
377+
</ItemsPanelTemplate>
375378
</Page.Resources>
376379

377380
<Grid Tag="{x:Bind Tag, Mode=OneWay}" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Padding="0,0,0,0" VerticalAlignment="Stretch">
@@ -400,76 +403,76 @@
400403
<ProgressBar Name="ProgBar" Height="10" VerticalAlignment="Top" IsIndeterminate="True"/>
401404
<TextBlock Visibility="{x:Bind TextState.isVisible, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Name="EmptyText" HorizontalAlignment="Center" Text="This folder is empty." TextWrapping="Wrap" VerticalAlignment="Top" Margin="0,125,0,0" Grid.Row="3" Canvas.ZIndex="0"/>
402405

403-
<controls:AdaptiveGridView RightTapped="FileList_RightTapped" StretchContentForSingleRow="False" DesiredWidth="150" VerticalContentAlignment="Stretch" ItemHeight="150" animations:ReorderGridAnimation.Duration="300" ShowsScrollingPlaceholders="True" Margin="24,24,24,0" Grid.Row="3" SelectionMode="Extended" IsRightTapEnabled="True" IsDoubleTapEnabled="True" Name="FileList" Padding="0, 0, 0, 0" >
404-
<controls:AdaptiveGridView.ItemTemplate>
405-
<DataTemplate>
406-
<StackPanel Tag="{Binding RowIndex}" RightTapped="StackPanel_RightTapped" Orientation="Vertical" Padding="0" ToolTipService.ToolTip="{Binding FileName}" Background="Transparent" IsRightTapEnabled="True" Margin="0, 0, 0, 0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
407-
<StackPanel.ContextFlyout>
408-
<MenuFlyout x:Name="RightClickContextMenu" MenuFlyoutPresenterStyle="{StaticResource MenuFlyoutFluentThemeResources}">
409-
<MenuFlyout.Items>
410-
<MenuFlyoutItem Click="OpenItem_Click" Text="Open With..." Name="OpenItem">
411-
<MenuFlyoutItem.Icon>
412-
<FontIcon Glyph="&#xE7AC;"/>
413-
</MenuFlyoutItem.Icon>
414-
</MenuFlyoutItem>
415-
<MenuFlyoutItem Click="ShareItem_Click" Text="Share" Name="ShareItem">
416-
<MenuFlyoutItem.Icon>
417-
<FontIcon Glyph="&#xE72D;"/>
418-
</MenuFlyoutItem.Icon>
419-
</MenuFlyoutItem>
420-
<MenuFlyoutSeparator/>
421-
<MenuFlyoutItem Click="DeleteItem_Click" Text="Delete" Name="DeleteItem" >
422-
<MenuFlyoutItem.Icon>
423-
<FontIcon Glyph="&#xE74D;"/>
424-
</MenuFlyoutItem.Icon>
425-
</MenuFlyoutItem>
426-
<MenuFlyoutItem Click="RenameItem_Click" Text="Rename" Name="RenameItem" >
427-
<MenuFlyoutItem.Icon>
428-
<FontIcon Glyph="&#xE8AC;"/>
429-
</MenuFlyoutItem.Icon>
430-
</MenuFlyoutItem>
431-
<MenuFlyoutSeparator/>
432-
<MenuFlyoutItem Click="CutItem_Click" Text="Cut" Name="CutItem" >
433-
<MenuFlyoutItem.Icon>
434-
<FontIcon Glyph="&#xE8C6;"/>
435-
</MenuFlyoutItem.Icon>
436-
</MenuFlyoutItem>
437-
<MenuFlyoutItem Click="CopyItem_Click" Text="Copy" Name="CopyItem" >
438-
<MenuFlyoutItem.Icon>
439-
<FontIcon Glyph="&#xE8C8;"/>
440-
</MenuFlyoutItem.Icon>
441-
</MenuFlyoutItem>
406+
<GridView ContextRequested="FileList_ContextRequested" Background="Transparent" ItemsSource="{x:Bind instanceViewModel.FilesAndFolders}" RightTapped="FileList_RightTapped" VerticalContentAlignment="Stretch" animations:ReorderGridAnimation.Duration="300" ShowsScrollingPlaceholders="True" Margin="24,24,24,0" Grid.Row="3" SelectionMode="Extended" IsRightTapEnabled="True" IsDoubleTapEnabled="True" Name="FileList" Padding="0, 0, 0, 0" >
407+
<GridView.ContextFlyout>
408+
<MenuFlyout x:Name="RightClickContextMenu" MenuFlyoutPresenterStyle="{StaticResource MenuFlyoutFluentThemeResources}">
409+
<MenuFlyout.Items>
410+
<MenuFlyoutItem Click="OpenItem_Click" Text="Open With..." Name="OpenItem">
411+
<MenuFlyoutItem.Icon>
412+
<FontIcon Glyph="&#xE7AC;"/>
413+
</MenuFlyoutItem.Icon>
414+
</MenuFlyoutItem>
415+
<MenuFlyoutItem Click="ShareItem_Click" Text="Share" Name="ShareItem">
416+
<MenuFlyoutItem.Icon>
417+
<FontIcon Glyph="&#xE72D;"/>
418+
</MenuFlyoutItem.Icon>
419+
</MenuFlyoutItem>
420+
<MenuFlyoutSeparator/>
421+
<MenuFlyoutItem Click="DeleteItem_Click" Text="Delete" Name="DeleteItem" >
422+
<MenuFlyoutItem.Icon>
423+
<FontIcon Glyph="&#xE74D;"/>
424+
</MenuFlyoutItem.Icon>
425+
</MenuFlyoutItem>
426+
<MenuFlyoutItem Click="RenameItem_Click" Text="Rename" Name="RenameItem" >
427+
<MenuFlyoutItem.Icon>
428+
<FontIcon Glyph="&#xE8AC;"/>
429+
</MenuFlyoutItem.Icon>
430+
</MenuFlyoutItem>
431+
<MenuFlyoutSeparator/>
432+
<MenuFlyoutItem Click="CutItem_Click" Text="Cut" Name="CutItem" >
433+
<MenuFlyoutItem.Icon>
434+
<FontIcon Glyph="&#xE8C6;"/>
435+
</MenuFlyoutItem.Icon>
436+
</MenuFlyoutItem>
437+
<MenuFlyoutItem Click="CopyItem_Click" Text="Copy" Name="CopyItem" >
438+
<MenuFlyoutItem.Icon>
439+
<FontIcon Glyph="&#xE8C8;"/>
440+
</MenuFlyoutItem.Icon>
441+
</MenuFlyoutItem>
442442

443-
<MenuFlyoutSeparator/>
444-
<MenuFlyoutItem Click="PropertiesItem_Click" Text="Properties" Name="PropertiesItem">
445-
<MenuFlyoutItem.Icon>
446-
<FontIcon Glyph="&#xE946;"/>
447-
</MenuFlyoutItem.Icon>
448-
</MenuFlyoutItem>
449-
</MenuFlyout.Items>
443+
<MenuFlyoutSeparator/>
444+
<MenuFlyoutItem Click="PropertiesItem_Click" Text="Properties" Name="PropertiesItem">
445+
<MenuFlyoutItem.Icon>
446+
<FontIcon Glyph="&#xE946;"/>
447+
</MenuFlyoutItem.Icon>
448+
</MenuFlyoutItem>
449+
</MenuFlyout.Items>
450450

451-
</MenuFlyout>
452-
</StackPanel.ContextFlyout>
451+
</MenuFlyout>
452+
</GridView.ContextFlyout>
453+
<GridView.ItemTemplate>
454+
<DataTemplate x:DataType="local2:ListedItem">
455+
<StackPanel Width="150" Height="150" Tag="{x:Bind RowIndex}" Orientation="Vertical" Padding="0" ToolTipService.ToolTip="{Binding FileName}" Background="Transparent" Margin="0, 0, 0, 0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
453456
<Grid Width="150" Height="100">
454-
<Grid Padding="12" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Name="Picture" Visibility="{Binding FileIconVis}">
455-
<Image Stretch="Uniform" Source="{Binding FileImg}"/>
457+
<Grid Padding="12" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Name="Picture" Visibility="{x:Bind FileIconVis}">
458+
<Image Stretch="Uniform" Source="{x:Bind FileImg}"/>
456459
</Grid>
457-
<Grid Name="Album" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{Binding FolderImg}">
460+
<Grid Name="Album" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{x:Bind FolderImg}">
458461
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
459462
<FontIcon FontSize="72" Glyph="&#xE8D5;" FontFamily="Segoe MDL2 Assets" Foreground="#ffe793"/>
460463
</Grid>
461464
</Grid>
462-
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{Binding EmptyImgVis}">
465+
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{x:Bind EmptyImgVis}">
463466
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
464467
<FontIcon FontSize="72" Glyph="&#xE7C3;" FontFamily="Segoe MDL2 Assets"/>
465468
</Grid>
466469
</Grid>
467470
</Grid>
468-
<TextBlock MaxWidth="150" HorizontalTextAlignment="Center" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{Binding FileName}" TextWrapping="Wrap"/>
471+
<TextBlock MaxWidth="150" HorizontalTextAlignment="Center" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{x:Bind FileName}" TextWrapping="Wrap"/>
469472
</StackPanel>
470473

471474
</DataTemplate>
472-
</controls:AdaptiveGridView.ItemTemplate>
473-
</controls:AdaptiveGridView>
475+
</GridView.ItemTemplate>
476+
</GridView>
474477
</Grid>
475478
</Page>

Files UWP/PhotoAlbum.xaml.cs

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
using System.Collections.ObjectModel;
1919
using System.Collections.Generic;
2020
using Windows.UI.Xaml.Data;
21+
using Windows.UI.Xaml.Controls.Primitives;
2122

2223
namespace Files
2324
{
2425

2526
public sealed partial class PhotoAlbum : Page
2627
{
27-
public AdaptiveGridView gv;
28+
public GridView gv;
2829
public Image largeImg;
2930
public MenuFlyout context;
3031
public MenuFlyout gridContext;
@@ -51,7 +52,7 @@ public PhotoAlbum()
5152
Clipboard.ContentChanged += Clipboard_ContentChanged;
5253
instanceViewModel = new ItemViewModel<PhotoAlbum>(this, null);
5354
instanceInteraction = new Interaction<PhotoAlbum>(this);
54-
gv.ItemsSource = instanceViewModel.FilesAndFolders;
55+
//gv.ItemsSource = instanceViewModel.FilesAndFolders;
5556
}
5657

5758
protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
@@ -144,9 +145,8 @@ private void FileList_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEv
144145

145146
private void PhotoAlbumViewer_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
146147
{
147-
FileList.SelectedItem = null;
148-
ItemViewModel<PhotoAlbum>.GetCurrentSelectedTabInstance<ProHome>().HomeItems.isEnabled = false;
149-
ItemViewModel<PhotoAlbum>.GetCurrentSelectedTabInstance<ProHome>().ShareItems.isEnabled = false;
148+
149+
150150
}
151151

152152
private void PhotoAlbumViewer_RightTapped(object sender, Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e)
@@ -225,37 +225,45 @@ private void StackPanel_RightTapped(object sender, RightTappedRoutedEventArgs e)
225225

226226
private void FileList_RightTapped(object sender, RightTappedRoutedEventArgs e)
227227
{
228-
var ItemPressed = Interaction<PhotoAlbum>.FindParent<GridViewItem>(e.OriginalSource as DependencyObject);
229-
List<StackPanel> stackPanels = new List<StackPanel>();
230-
Interaction<PhotoAlbum>.FindChildren<StackPanel>(stackPanels, ItemPressed);
231-
var ObjectPressed = ((ReadOnlyObservableCollection<ListedItem>)FileList.ItemsSource)[(int) stackPanels[0].Tag];
232-
//List<int> indexes = new List<int>();
233-
//foreach (ItemIndexRange range in FileList.SelectedRanges)
234-
//{
235-
// for (int x = range.FirstIndex; x <= range.LastIndex; x++) { indexes.Add(x); }
236-
//}
237-
List<GridViewItem> items = new List<GridViewItem>();
238-
List<GridViewItem> selitems = new List<GridViewItem>();
239-
Interaction<PhotoAlbum>.FindChildren<GridViewItem>(items, FileList);
240-
foreach (GridViewItem gvi in items)
228+
try
241229
{
242-
if (gvi.IsSelected)
230+
Interaction<PhotoAlbum>.FindParent<GridViewItem>(e.OriginalSource as DependencyObject);
231+
var ItemPressed = Interaction<PhotoAlbum>.FindParent<GridViewItem>(e.OriginalSource as DependencyObject);
232+
List<StackPanel> stackPanels = new List<StackPanel>();
233+
Interaction<PhotoAlbum>.FindChildren<StackPanel>(stackPanels, ItemPressed);
234+
var indexOfObjectPressed = FileList.IndexFromContainer(FileList.ContainerFromItem(ItemPressed));
235+
foreach (ListedItem selectedItem in (sender as GridView).SelectedItems)
243236
{
244-
selitems.Add(gvi);
237+
if (selectedItem.RowIndex == indexOfObjectPressed)
238+
{
239+
return;
240+
}
245241
}
242+
243+
// The following code is only reachable when a user RightTapped an unselected row
244+
FileList.SelectedItems.Clear();
245+
FileList.SelectedItems.Add(instanceViewModel.FilesAndFolders[indexOfObjectPressed]);
246246
}
247-
248-
foreach (GridViewItem selectedItem in selitems)
247+
catch (ArgumentException)
249248
{
250-
if (FileList.IndexFromContainer(FileList.ContainerFromItem(selectedItem)) == FileList.IndexFromContainer(FileList.ContainerFromItem(ItemPressed)))
251-
{
252-
return;
253-
}
249+
return;
254250
}
255251

256-
// The following code is only reachable when a user RightTapped an unselected row
257-
FileList.SelectedItems.Clear();
258-
FileList.SelectedItems.Add(ObjectPressed);
252+
}
253+
254+
private void FileList_ContextRequested(UIElement sender, ContextRequestedEventArgs args)
255+
{
256+
257+
}
258+
259+
private void PhotoAlbumViewer_PointerPressed(object sender, PointerRoutedEventArgs e)
260+
{
261+
if (e.GetCurrentPoint(sender as Page).Properties.IsLeftButtonPressed)
262+
{
263+
FileList.SelectedItem = null;
264+
ItemViewModel<PhotoAlbum>.GetCurrentSelectedTabInstance<ProHome>().HomeItems.isEnabled = false;
265+
ItemViewModel<PhotoAlbum>.GetCurrentSelectedTabInstance<ProHome>().ShareItems.isEnabled = false;
266+
}
259267
}
260268
}
261269
}

Files UWP/ProHome.xaml.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,20 @@
77
using System.Diagnostics;
88
using System.IO;
99
using System.Linq;
10-
using Windows.ApplicationModel.Core;
11-
using Windows.Foundation;
1210
using Windows.Storage;
1311
using Windows.System;
14-
using Windows.UI;
1512
using Windows.UI.Core;
1613
using Windows.UI.Popups;
17-
using Windows.UI.ViewManagement;
18-
using Windows.UI.WindowManagement;
1914
using Windows.UI.Xaml;
2015
using Windows.UI.Xaml.Controls;
21-
using Windows.UI.Xaml.Hosting;
2216
using Windows.UI.Xaml.Input;
2317
using Windows.UI.Xaml.Media;
2418
using Windows.UI.Xaml.Media.Animation;
2519

2620
namespace Files
2721
{
2822
/// <summary>
29-
/// Project Mumbai - Pre-release Dense UI Design
23+
/// Code to accompany Project Mumbai layout
3024
/// </summary>
3125
public sealed partial class ProHome : Page
3226
{

Files UWP/YourHome.xaml.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using Microsoft.Toolkit.Uwp.UI.Controls;
22
using System;
33
using System.Diagnostics;
4-
using System.Drawing;
5-
using Windows.Graphics.Display;
6-
using Windows.UI.ViewManagement;
74
using Windows.UI.Xaml;
85
using Windows.UI.Xaml.Controls;
96
using Files.Filesystem;
@@ -15,6 +12,7 @@
1512
using Windows.UI.Xaml.Navigation;
1613
using System.ComponentModel;
1714
using System.Collections.Generic;
15+
using System.Runtime.InteropServices;
1816

1917
namespace Files
2018
{
@@ -259,6 +257,17 @@ public async void PopulateRecentsList()
259257
Debug.WriteLine("Attempted to delete redundant RecentItem from file when ItemPath was never set.");
260258
}
261259
}
260+
catch (COMException)
261+
{
262+
if (ItemPath != null)
263+
{
264+
RemoveDeletedItemFromList(ItemPath, lines);
265+
}
266+
else
267+
{
268+
Debug.WriteLine("Attempted to delete redundant RecentItem from file when ItemPath was never set.");
269+
}
270+
}
262271
}
263272
else
264273
{
@@ -323,7 +332,18 @@ public async void PopulateRecentsList()
323332
Debug.WriteLine("Attempted to delete redundant RecentItem from file when ItemPath was never set.");
324333
}
325334
}
326-
335+
catch (COMException)
336+
{
337+
if (ItemPath != null)
338+
{
339+
RemoveDeletedItemFromList(ItemPath, lines);
340+
}
341+
else
342+
{
343+
Debug.WriteLine("Attempted to delete redundant RecentItem from file when ItemPath was never set.");
344+
}
345+
}
346+
327347
}
328348
}
329349

0 commit comments

Comments
 (0)