mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
Remove redundant code
This commit is contained in:
@@ -16,11 +16,14 @@ internal static class ContextMenuHelper
|
|||||||
{
|
{
|
||||||
internal static List<CommandContextItem> GetContextMenuResults(in WindowWalkerListItem listItem)
|
internal static List<CommandContextItem> GetContextMenuResults(in WindowWalkerListItem listItem)
|
||||||
{
|
{
|
||||||
if (listItem?.Window is not Window windowData)
|
ArgumentNullException.ThrowIfNull(listItem);
|
||||||
|
|
||||||
|
if (listItem.Window is null)
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var windowData = listItem.Window;
|
||||||
var contextMenu = new List<CommandContextItem>
|
var contextMenu = new List<CommandContextItem>
|
||||||
{
|
{
|
||||||
new(new CloseWindowCommand(windowData))
|
new(new CloseWindowCommand(windowData))
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ internal sealed class OpenWindows
|
|||||||
/// <param name="lParam">Value being passed from the caller (we don't use this but might come in handy
|
/// <param name="lParam">Value being passed from the caller (we don't use this but might come in handy
|
||||||
/// in the future</param>
|
/// in the future</param>
|
||||||
/// <returns>true to make sure to continue enumeration</returns>
|
/// <returns>true to make sure to continue enumeration</returns>
|
||||||
internal bool WindowEnumerationCallBack(IntPtr hwnd, IntPtr lParam)
|
private bool WindowEnumerationCallBack(IntPtr hwnd, IntPtr lParam)
|
||||||
{
|
{
|
||||||
var tokenHandle = GCHandle.FromIntPtr(lParam);
|
var tokenHandle = GCHandle.FromIntPtr(lParam);
|
||||||
var target = (CancellationToken?)tokenHandle.Target ?? CancellationToken.None;
|
var target = (CancellationToken?)tokenHandle.Target ?? CancellationToken.None;
|
||||||
|
|||||||
@@ -35,10 +35,6 @@ internal static class ResultHelper
|
|||||||
for (var i = 0; i < list.Count; i++)
|
for (var i = 0; i < list.Count; i++)
|
||||||
{
|
{
|
||||||
var window = list[i].Item;
|
var window = list[i].Item;
|
||||||
if (window?.Process is null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.Equals(window.Process.Name, "explorer.exe", StringComparison.OrdinalIgnoreCase) && window.Process.IsShellProcess)
|
if (string.Equals(window.Process.Name, "explorer.exe", StringComparison.OrdinalIgnoreCase) && window.Process.IsShellProcess)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ internal sealed class Window
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether the window is minimized
|
/// Gets a value indicating whether the window is minimized
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal bool Minimized => GetWindowSizeState() == WindowSizeState.Minimized;
|
private bool Minimized => GetWindowSizeState() == WindowSizeState.Minimized;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Window"/> class.
|
/// Initializes a new instance of the <see cref="Window"/> class.
|
||||||
@@ -159,7 +159,7 @@ internal sealed class Window
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper function to close the window
|
/// Helper function to close the window
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal void CloseThisWindowHelper()
|
private void CloseThisWindowHelper()
|
||||||
{
|
{
|
||||||
_ = NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_SYSCOMMAND, Win32Constants.SC_CLOSE, 0, 0x0000, 5000, out _);
|
_ = NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_SYSCOMMAND, Win32Constants.SC_CLOSE, 0, 0x0000, 5000, out _);
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ internal sealed class Window
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal void CloseThisWindow()
|
internal void CloseThisWindow()
|
||||||
{
|
{
|
||||||
Thread thread = new(new ThreadStart(CloseThisWindowHelper));
|
Thread thread = new(CloseThisWindowHelper);
|
||||||
thread.Start();
|
thread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,24 +188,24 @@ internal sealed class Window
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try WM_GETICON with SendMessageTimeout
|
// Try WM_GETICON with SendMessageTimeout
|
||||||
if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, (UIntPtr)Win32Constants.ICON_BIG, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out var result) != 0 && result != 0)
|
if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, Win32Constants.ICON_BIG, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out var result) != 0 && result != 0)
|
||||||
{
|
{
|
||||||
icon = System.Drawing.Icon.FromHandle((IntPtr)result);
|
icon = System.Drawing.Icon.FromHandle(result);
|
||||||
NativeMethods.DestroyIcon((IntPtr)result);
|
NativeMethods.DestroyIcon(result);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, (UIntPtr)Win32Constants.ICON_SMALL, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out result) != 0 && result != 0)
|
if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, Win32Constants.ICON_SMALL, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out result) != 0 && result != 0)
|
||||||
{
|
{
|
||||||
icon = System.Drawing.Icon.FromHandle((IntPtr)result);
|
icon = System.Drawing.Icon.FromHandle(result);
|
||||||
NativeMethods.DestroyIcon((IntPtr)result);
|
NativeMethods.DestroyIcon(result);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, (UIntPtr)Win32Constants.ICON_SMALL2, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out result) != 0 && result != 0)
|
if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, Win32Constants.ICON_SMALL2, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out result) != 0 && result != 0)
|
||||||
{
|
{
|
||||||
icon = System.Drawing.Icon.FromHandle((IntPtr)result);
|
icon = System.Drawing.Icon.FromHandle(result);
|
||||||
NativeMethods.DestroyIcon((IntPtr)result);
|
NativeMethods.DestroyIcon(result);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ internal sealed class Window
|
|||||||
if (iconHandle != IntPtr.Zero)
|
if (iconHandle != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
icon = System.Drawing.Icon.FromHandle(iconHandle);
|
icon = System.Drawing.Icon.FromHandle(iconHandle);
|
||||||
NativeMethods.DestroyIcon((IntPtr)iconHandle);
|
NativeMethods.DestroyIcon(iconHandle);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ internal sealed class Window
|
|||||||
if (iconHandle != IntPtr.Zero)
|
if (iconHandle != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
icon = System.Drawing.Icon.FromHandle(iconHandle);
|
icon = System.Drawing.Icon.FromHandle(iconHandle);
|
||||||
NativeMethods.DestroyIcon((IntPtr)iconHandle);
|
NativeMethods.DestroyIcon(iconHandle);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,8 +242,8 @@ internal sealed class Window
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns what the window size is
|
/// Returns what the window size is
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The state (minimized, maximized, etc..) of the window</returns>
|
/// <returns>The state (minimized, maximized, etc...) of the window</returns>
|
||||||
internal WindowSizeState GetWindowSizeState()
|
private WindowSizeState GetWindowSizeState()
|
||||||
{
|
{
|
||||||
NativeMethods.GetWindowPlacement(Hwnd, out var placement);
|
NativeMethods.GetWindowPlacement(Hwnd, out var placement);
|
||||||
|
|
||||||
@@ -369,7 +369,7 @@ internal sealed class Window
|
|||||||
{
|
{
|
||||||
new Task(() =>
|
new Task(() =>
|
||||||
{
|
{
|
||||||
var callbackptr = new EnumWindowsProc((IntPtr hwnd, IntPtr lParam) =>
|
var callbackptr = new EnumWindowsProc((hwnd, _) =>
|
||||||
{
|
{
|
||||||
// Every uwp app main window has at least three child windows. Only the one we are interested in has a class starting with "Windows.UI.Core." and is assigned to the real app process.
|
// Every uwp app main window has at least three child windows. Only the one we are interested in has a class starting with "Windows.UI.Core." and is assigned to the real app process.
|
||||||
// (The other ones have a class name that begins with the string "ApplicationFrame".)
|
// (The other ones have a class name that begins with the string "ApplicationFrame".)
|
||||||
|
|||||||
Reference in New Issue
Block a user