Skip to content

Code Quality: Removed Vanara from ShellPreviewViewModel #16945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Files.App.CsWin32/Extras.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using Windows.Win32.Foundation;
using Windows.Win32.UI.WindowsAndMessaging;

Expand Down Expand Up @@ -37,4 +38,14 @@ public static unsafe nint SetWindowLongPtr(HWND hWnd, WINDOW_LONG_PTR_INDEX nInd
: _SetWindowLongPtr(hWnd, (int)nIndex, dwNewLong);
}
}

namespace Extras
{
[GeneratedComInterface, Guid("EACDD04C-117E-4E17-88F4-D1B12B0E3D89"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public partial interface IDCompositionTarget
{
[PreserveSig]
int SetRoot(nint visual);
}
}
}
5 changes: 2 additions & 3 deletions src/Files.App.CsWin32/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
LRESULT
WPARAM
LPARAM
WM_LBUTTONUP
WM_RBUTTONUP
WM_DESTROY
WM_*
SetForegroundWindow
GetForegroundWindow
GetCurrentThreadId
Expand All @@ -47,7 +45,7 @@
GetKeyState
CreateDirectoryFromApp
WNetCancelConnection2
NET_USE_CONNECT_FLAGS

Check warning on line 48 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

Method, type or constant "NET_USE_CONNECT_FLAGS" not found

Check warning on line 48 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Release, x64)

Method, type or constant "NET_USE_CONNECT_FLAGS" not found

Check warning on line 48 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

Method, type or constant "NET_USE_CONNECT_FLAGS" not found

Check warning on line 48 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

Method, type or constant "NET_USE_CONNECT_FLAGS" not found
NETRESOURCEW
WNetAddConnection3
CREDENTIALW
Expand Down Expand Up @@ -80,7 +78,7 @@
SetEntriesInAcl
ACL_SIZE_INFORMATION
DeleteAce
EXPLICIT_ACCESS

Check warning on line 81 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

Method, type or constant "EXPLICIT_ACCESS" not found. Did you mean or "EXPLICIT_ACCESS_A" or "EXPLICIT_ACCESS_W"?

Check warning on line 81 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Release, x64)

Method, type or constant "EXPLICIT_ACCESS" not found. Did you mean or "EXPLICIT_ACCESS_A" or "EXPLICIT_ACCESS_W"?

Check warning on line 81 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

Method, type or constant "EXPLICIT_ACCESS" not found. Did you mean or "EXPLICIT_ACCESS_A" or "EXPLICIT_ACCESS_W"?

Check warning on line 81 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

Method, type or constant "EXPLICIT_ACCESS" not found. Did you mean or "EXPLICIT_ACCESS_A" or "EXPLICIT_ACCESS_W"?
ACCESS_ALLOWED_ACE
LookupAccountSid
GetComputerName
Expand Down Expand Up @@ -136,7 +134,7 @@
CoTaskMemFree
QueryDosDevice
DeviceIoControl
GetLastError

Check warning on line 137 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

This API will not be generated. Do not generate GetLastError. Call Marshal.GetLastWin32Error() instead. Learn more from https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshal.getlastwin32error

Check warning on line 137 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Release, x64)

This API will not be generated. Do not generate GetLastError. Call Marshal.GetLastWin32Error() instead. Learn more from https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshal.getlastwin32error

Check warning on line 137 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

This API will not be generated. Do not generate GetLastError. Call Marshal.GetLastWin32Error() instead. Learn more from https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshal.getlastwin32error

Check warning on line 137 in src/Files.App.CsWin32/NativeMethods.txt

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

This API will not be generated. Do not generate GetLastError. Call Marshal.GetLastWin32Error() instead. Learn more from https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshal.getlastwin32error
CreateFile
GetVolumeInformation
COMPRESSION_FORMAT
Expand Down Expand Up @@ -173,3 +171,4 @@
FILE_FILE_COMPRESSION
WM_WINDOWPOSCHANGING
WINDOWPOS
UnregisterClass
23 changes: 14 additions & 9 deletions src/Files.App/UserControls/FilePreviews/ShellPreview.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.ViewModels.Previews;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Vanara.PInvoke;
using Windows.Foundation;
using Windows.Win32.Foundation;

namespace Files.App.UserControls.FilePreviews
{
Expand All @@ -13,13 +16,15 @@ public sealed partial class ShellPreview : UserControl
public ShellPreview(ShellPreviewViewModel model)
{
ViewModel = model;
this.InitializeComponent();

InitializeComponent();
}

private void PreviewHost_Loaded(object sender, RoutedEventArgs e)
{
ViewModel.LoadPreview(contentPresenter);
ViewModel.SizeChanged(GetPreviewSize());

if (XamlRoot.Content is FrameworkElement element)
{
element.SizeChanged += PreviewHost_SizeChanged;
Expand All @@ -38,13 +43,12 @@ private RECT GetPreviewSize()
var physicalSize = contentPresenter.RenderSize;
var physicalPos = source.TransformPoint(new Point(0, 0));
var scale = XamlRoot.RasterizationScale;
var result = new RECT
{
X = (int)(physicalPos.X * scale + 0.5),
Y = (int)(physicalPos.Y * scale + 0.5),
Width = (int)(physicalSize.Width * scale + 0.5),
Height = (int)(physicalSize.Height * scale + 0.5)
};
var result = RECT.FromXYWH(
(int)(physicalPos.X * scale + 0.5),
(int)(physicalPos.Y * scale + 0.5),
(int)(physicalSize.Width * scale + 0.5),
(int)(physicalSize.Height * scale + 0.5));

return result;
}

Expand All @@ -55,6 +59,7 @@ private void PreviewHost_Unloaded(object sender, RoutedEventArgs e)
element.SizeChanged -= PreviewHost_SizeChanged;
element.PointerEntered -= PreviewHost_PointerEntered;
}

ViewModel.UnloadPreview();
}

Expand Down
Loading
Loading