mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 02:09:05 +00:00
Implement RecycleBinPanel #1610
This commit is contained in:
@@ -8,11 +8,5 @@
|
||||
FontSize="14"
|
||||
UseLayoutRounding="True"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<TextBlock x:Name="UnsupportedTextBlock"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="Collapsed" />
|
||||
<!-- EMPTY -->
|
||||
</Grid>
|
||||
<ContentPresenter Content="{Binding Content}" />
|
||||
</UserControl>
|
@@ -24,6 +24,7 @@ public partial class CLSIDInfoPanel : UserControl
|
||||
{
|
||||
public CLSIDInfoPanel()
|
||||
{
|
||||
DataContext = this;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -31,13 +32,21 @@ public partial class CLSIDInfoPanel : UserControl
|
||||
{
|
||||
switch (path.ToUpper())
|
||||
{
|
||||
case "::{645FF040-5081-101B-9F08-00AA002F954E}" // Recycle Bin
|
||||
or "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}": // This PC
|
||||
case CLSIDRegister.RecycleBin:
|
||||
Content = new RecycleBinPanel();
|
||||
break;
|
||||
|
||||
case CLSIDRegister.ThisPC:
|
||||
Content = new ThisPCPanel();
|
||||
break;
|
||||
|
||||
default:
|
||||
UnsupportedTextBlock.Text = $"Unsupported for {path}";
|
||||
UnsupportedTextBlock.Visibility = Visibility.Visible;
|
||||
Content = new TextBlock()
|
||||
{
|
||||
Text = $"Unsupported for {path}",
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,9 @@ namespace QuickLook.Plugin.CLSIDViewer;
|
||||
|
||||
internal static class CLSIDRegister
|
||||
{
|
||||
public const string RecycleBin = "::{645FF040-5081-101B-9F08-00AA002F954E}";
|
||||
public const string ThisPC = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
|
||||
|
||||
public static string GetName(string clsid)
|
||||
{
|
||||
try
|
||||
@@ -31,10 +34,10 @@ internal static class CLSIDRegister
|
||||
string displayName = Registry.GetValue($@"HKEY_CLASSES_ROOT\CLSID\{clsid.Replace(":", string.Empty)}", string.Empty, null)?.ToString();
|
||||
return displayName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine("Error reading registry: " + ex.Message);
|
||||
Debug.WriteLine("Error reading registry: " + e.Message);
|
||||
}
|
||||
return string.Empty;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -47,7 +47,12 @@ public class Plugin : IViewer
|
||||
|
||||
public void Prepare(string path, ContextObject context)
|
||||
{
|
||||
context.PreferredSize = new Size { Width = 520, Height = 192 };
|
||||
context.PreferredSize = path switch
|
||||
{
|
||||
CLSIDRegister.RecycleBin => new Size { Width = 520, Height = 192 },
|
||||
CLSIDRegister.ThisPC => new Size { Width = 900, Height = 800 },
|
||||
_ => new Size { Width = 520, Height = 192 },
|
||||
};
|
||||
}
|
||||
|
||||
public void View(string path, ContextObject context)
|
||||
@@ -59,7 +64,7 @@ public class Plugin : IViewer
|
||||
_ip.Tag = context;
|
||||
|
||||
context.ViewerContent = _ip;
|
||||
context.Title = $"{CLSIDRegister.GetName(path)}";
|
||||
context.Title = $"{CLSIDRegister.GetName(path) ?? path}";
|
||||
context.IsBusy = false;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,24 @@
|
||||
<UserControl x:Class="QuickLook.Plugin.CLSIDViewer.RecycleBinPanel"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:QuickLook.Plugin.CLSIDViewer"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<TextBlock x:Name="EmptyRecycleBinText"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="Recycle Bin is empty" />
|
||||
<Grid>
|
||||
<Button x:Name="EmptyRecycleBinButton"
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Click="OnEmptyRecycleBinClick"
|
||||
Content="Empty Recycle Bin" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -0,0 +1,105 @@
|
||||
// Copyright © 2017-2025 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace QuickLook.Plugin.CLSIDViewer;
|
||||
|
||||
public partial class RecycleBinPanel : UserControl
|
||||
{
|
||||
public RecycleBinPanel()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += OnRecycleBinPanelLoaded;
|
||||
}
|
||||
|
||||
private void OnRecycleBinPanelLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
private void OnEmptyRecycleBinClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// TODO: Use async to avoid blocking the UI thread
|
||||
if (RecycleBinHelper.EmptyRecycleBin())
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateState()
|
||||
{
|
||||
bool hasTrash = RecycleBinHelper.HasTrash();
|
||||
|
||||
EmptyRecycleBinButton.Visibility = hasTrash ? Visibility.Visible : Visibility.Collapsed;
|
||||
EmptyRecycleBinText.Visibility = hasTrash ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
file static class RecycleBinHelper
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct SHQUERYRBINFO
|
||||
{
|
||||
public uint cbSize;
|
||||
public ulong i64Size;
|
||||
public ulong i64NumItems;
|
||||
}
|
||||
|
||||
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern int SHQueryRecycleBin(string pszRootPath, ref SHQUERYRBINFO pSHQueryRBInfo);
|
||||
|
||||
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern int SHEmptyRecycleBin(nint hwnd, string pszRootPath, RecycleFlags dwFlags);
|
||||
|
||||
[Flags]
|
||||
private enum RecycleFlags : uint
|
||||
{
|
||||
SHERB_NOCONFIRMATION = 0x00000001,
|
||||
SHERB_NOPROGRESSUI = 0x00000002,
|
||||
SHERB_NOSOUND = 0x00000004,
|
||||
}
|
||||
|
||||
public static bool HasTrash()
|
||||
{
|
||||
var info = new SHQUERYRBINFO()
|
||||
{
|
||||
cbSize = (uint)Marshal.SizeOf(typeof(SHQUERYRBINFO))
|
||||
};
|
||||
|
||||
int result = SHQueryRecycleBin(null, ref info);
|
||||
|
||||
if (result == 0) // S_OK
|
||||
{
|
||||
return info.i64NumItems > 0;
|
||||
}
|
||||
|
||||
// Fallback
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool EmptyRecycleBin()
|
||||
{
|
||||
int result = SHEmptyRecycleBin(IntPtr.Zero, null,
|
||||
RecycleFlags.SHERB_NOCONFIRMATION | RecycleFlags.SHERB_NOPROGRESSUI | RecycleFlags.SHERB_NOSOUND);
|
||||
|
||||
return result == 0;
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
<UserControl x:Class="QuickLook.Plugin.CLSIDViewer.ThisPCPanel"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:QuickLook.Plugin.CLSIDViewer"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<TextBlock HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="ThisPCPanel" />
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -0,0 +1,28 @@
|
||||
// Copyright © 2017-2025 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace QuickLook.Plugin.CLSIDViewer;
|
||||
|
||||
public partial class ThisPCPanel : UserControl
|
||||
{
|
||||
public ThisPCPanel()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user