Skip to content

Commit 7cbf02f

Browse files
authored
Fix: Fixed COMException when renaming files (#15686)
1 parent 141aa4a commit 7cbf02f

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

src/Files.App/Data/Models/AppModel.cs

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Microsoft.UI.Xaml.Controls;
5+
using System.Runtime.InteropServices;
56
using Windows.ApplicationModel.DataTransfer;
67

78
namespace Files.App.Data.Models
@@ -35,11 +36,18 @@ public int TabStripSelectedIndex
3536
{
3637
SetProperty(ref _TabStripSelectedIndex, value);
3738

38-
if (value >= 0 && value < MainPageViewModel.AppInstances.Count)
39+
try
3940
{
40-
var rootFrame = (Frame)MainWindow.Instance.Content;
41-
var mainView = (MainPage)rootFrame.Content;
42-
mainView.ViewModel.SelectedTabItem = MainPageViewModel.AppInstances[value];
41+
if (value >= 0 && value < MainPageViewModel.AppInstances.Count)
42+
{
43+
var rootFrame = (Frame)MainWindow.Instance.Content;
44+
var mainView = (MainPage)rootFrame.Content;
45+
mainView.ViewModel.SelectedTabItem = MainPageViewModel.AppInstances[value];
46+
}
47+
}
48+
catch (COMException)
49+
{
50+
4351
}
4452
}
4553
}

src/Files.App/Views/Layouts/BaseGroupableLayoutPage.cs

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.UI.Xaml.Controls;
99
using Microsoft.UI.Xaml.Controls.Primitives;
1010
using Microsoft.UI.Xaml.Input;
11+
using System.Runtime.InteropServices;
1112
using Windows.System;
1213
using Windows.UI.Core;
1314
using Windows.Win32;
@@ -276,12 +277,19 @@ protected virtual async Task CommitRenameAsync(TextBox textBox)
276277

277278
protected virtual async void RenameTextBox_LostFocus(object sender, RoutedEventArgs e)
278279
{
279-
// This check allows the user to use the text box context menu without ending the rename
280-
if (!(FocusManager.GetFocusedElement(MainWindow.Instance.Content.XamlRoot) is AppBarButton or Popup))
280+
try
281281
{
282-
TextBox textBox = (TextBox)e.OriginalSource;
283-
await CommitRenameAsync(textBox);
282+
// This check allows the user to use the text box context menu without ending the rename
283+
if (!(FocusManager.GetFocusedElement(MainWindow.Instance.Content.XamlRoot) is AppBarButton or Popup))
284+
{
285+
TextBox textBox = (TextBox)e.OriginalSource;
286+
await CommitRenameAsync(textBox);
287+
}
284288
}
289+
catch (COMException)
290+
{
291+
292+
}
285293
}
286294

287295
// Methods

src/Files.App/Views/Shells/BaseShellPage.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.UI.Xaml.Media.Animation;
1010
using Microsoft.UI.Xaml.Navigation;
1111
using System.Runtime.CompilerServices;
12+
using System.Runtime.InteropServices;
1213
using Windows.Foundation.Metadata;
1314
using Windows.System;
1415
using Windows.UI.Core;
@@ -756,10 +757,17 @@ protected void SelectSidebarItemFromPath(Type incomingSourcePageType = null)
756757

757758
protected void SetLoadingIndicatorForTabs(bool isLoading)
758759
{
759-
var multitaskingControls = ((MainWindow.Instance.Content as Frame).Content as MainPage).ViewModel.MultitaskingControls;
760+
try
761+
{
762+
var multitaskingControls = ((MainWindow.Instance.Content as Frame).Content as MainPage).ViewModel.MultitaskingControls;
760763

761-
foreach (var x in multitaskingControls)
762-
x.SetLoadingIndicatorStatus(x.Items.FirstOrDefault(x => x.TabItemContent == PaneHolder), isLoading);
764+
foreach (var x in multitaskingControls)
765+
x.SetLoadingIndicatorStatus(x.Items.FirstOrDefault(x => x.TabItemContent == PaneHolder), isLoading);
766+
}
767+
catch (COMException)
768+
{
769+
770+
}
763771
}
764772

765773
// WINUI3

0 commit comments

Comments
 (0)