Skip to content

Commit 8f5a5e4

Browse files
committed
Code Quality: Improved redundant bring to front action
1 parent 6739f4f commit 8f5a5e4

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

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

+16-7
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ protected virtual void FileList_DragItemsCompleted(ListViewBase sender, DragItem
10271027
{
10281028
itemDragging = false;
10291029
MainWindow.Instance.SetCanWindowToFront(true);
1030+
// No need to bring the window to the front
10301031
}
10311032

10321033
private void Item_DragLeave(object sender, DragEventArgs e)
@@ -1158,8 +1159,9 @@ protected void FileList_ContainerContentChanging(ListViewBase sender, ContainerC
11581159
RefreshContainer(args.ItemContainer, args.InRecycleQueue);
11591160
RefreshItem(args.ItemContainer, args.Item, args.InRecycleQueue, args);
11601161

1161-
MainWindow.Instance.SetCanWindowToFront(true);
11621162
itemDragging = false;
1163+
MainWindow.Instance.SetCanWindowToFront(true);
1164+
// No need to bring the window to the front
11631165
}
11641166

11651167
private void RefreshContainer(SelectorItem container, bool inRecycleQueue)
@@ -1215,7 +1217,13 @@ private void RefreshItem(SelectorItem container, object item, bool inRecycleQueu
12151217
protected internal void FileListItem_PointerPressed(object sender, PointerRoutedEventArgs e)
12161218
{
12171219
if (!itemDragging)
1218-
MainWindow.Instance.SetCanWindowToFront(true);
1220+
{
1221+
// No need to bring the window to the front again
1222+
if (MainWindow.Instance.SetCanWindowToFront(true))
1223+
{
1224+
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
1225+
}
1226+
}
12191227

12201228
if (sender is not SelectorItem selectorItem)
12211229
return;
@@ -1243,9 +1251,7 @@ protected internal void FileListItem_PointerPressed(object sender, PointerRouted
12431251
protected internal void FileListItem_PointerEntered(object sender, PointerRoutedEventArgs e)
12441252
{
12451253
if (sender is SelectorItem selectorItem && selectorItem.IsSelected)
1246-
{
12471254
MainWindow.Instance.SetCanWindowToFront(false);
1248-
}
12491255

12501256
if (!UserSettingsService.FoldersSettingsService.SelectFilesOnHover)
12511257
return;
@@ -1295,6 +1301,7 @@ protected internal void FileListItem_PointerExited(object sender, PointerRoutedE
12951301
{
12961302
if (!itemDragging)
12971303
MainWindow.Instance.SetCanWindowToFront(true);
1304+
// No need to bring the window to the front
12981305

12991306
if (!UserSettingsService.FoldersSettingsService.SelectFilesOnHover)
13001307
return;
@@ -1331,9 +1338,11 @@ protected void FileListItem_RightTapped(object sender, RightTappedRoutedEventArg
13311338
{
13321339
if (!itemDragging)
13331340
{
1334-
MainWindow.Instance.SetCanWindowToFront(true);
1335-
// Bring the window to the front agin
1336-
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
1341+
// No need to bring the window to the front again
1342+
if (MainWindow.Instance.SetCanWindowToFront(true))
1343+
{
1344+
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
1345+
}
13371346
}
13381347

13391348
var rightClickedItem = GetItemFromElement(sender);

0 commit comments

Comments
 (0)