Skip to content

Commit e0f581e

Browse files
committed
Implement RecycleBinPanel #1610
1 parent a0a4683 commit e0f581e

File tree

8 files changed

+199
-16
lines changed

8 files changed

+199
-16
lines changed

QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDInfoPanel.xaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,5 @@
88
FontSize="14"
99
UseLayoutRounding="True"
1010
mc:Ignorable="d">
11-
<Grid>
12-
<TextBlock x:Name="UnsupportedTextBlock"
13-
HorizontalAlignment="Center"
14-
VerticalAlignment="Center"
15-
Visibility="Collapsed" />
16-
<!-- EMPTY -->
17-
</Grid>
11+
<ContentPresenter Content="{Binding Content}" />
1812
</UserControl>

QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDInfoPanel.xaml.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,29 @@ public partial class CLSIDInfoPanel : UserControl
2424
{
2525
public CLSIDInfoPanel()
2626
{
27+
DataContext = this;
2728
InitializeComponent();
2829
}
2930

3031
public void DisplayInfo(string path)
3132
{
3233
switch (path.ToUpper())
3334
{
34-
case "::{645FF040-5081-101B-9F08-00AA002F954E}" // Recycle Bin
35-
or "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}": // This PC
35+
case CLSIDRegister.RecycleBin:
36+
Content = new RecycleBinPanel();
37+
break;
38+
39+
case CLSIDRegister.ThisPC:
40+
Content = new ThisPCPanel();
3641
break;
3742

3843
default:
39-
UnsupportedTextBlock.Text = $"Unsupported for {path}";
40-
UnsupportedTextBlock.Visibility = Visibility.Visible;
44+
Content = new TextBlock()
45+
{
46+
Text = $"Unsupported for {path}",
47+
HorizontalAlignment = HorizontalAlignment.Center,
48+
VerticalAlignment = VerticalAlignment.Center,
49+
};
4150
break;
4251
}
4352
}

QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDRegister.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace QuickLook.Plugin.CLSIDViewer;
2323

2424
internal static class CLSIDRegister
2525
{
26+
public const string RecycleBin = "::{645FF040-5081-101B-9F08-00AA002F954E}";
27+
public const string ThisPC = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
28+
2629
public static string GetName(string clsid)
2730
{
2831
try
@@ -31,10 +34,10 @@ public static string GetName(string clsid)
3134
string displayName = Registry.GetValue($@"HKEY_CLASSES_ROOT\CLSID\{clsid.Replace(":", string.Empty)}", string.Empty, null)?.ToString();
3235
return displayName;
3336
}
34-
catch (Exception ex)
37+
catch (Exception e)
3538
{
36-
Debug.WriteLine("Error reading registry: " + ex.Message);
39+
Debug.WriteLine("Error reading registry: " + e.Message);
3740
}
38-
return string.Empty;
41+
return null;
3942
}
4043
}

QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/Plugin.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ public bool CanHandle(string path)
4747

4848
public void Prepare(string path, ContextObject context)
4949
{
50-
context.PreferredSize = new Size { Width = 520, Height = 192 };
50+
context.PreferredSize = path switch
51+
{
52+
CLSIDRegister.RecycleBin => new Size { Width = 520, Height = 192 },
53+
CLSIDRegister.ThisPC => new Size { Width = 900, Height = 800 },
54+
_ => new Size { Width = 520, Height = 192 },
55+
};
5156
}
5257

5358
public void View(string path, ContextObject context)
@@ -59,7 +64,7 @@ public void View(string path, ContextObject context)
5964
_ip.Tag = context;
6065

6166
context.ViewerContent = _ip;
62-
context.Title = $"{CLSIDRegister.GetName(path)}";
67+
context.Title = $"{CLSIDRegister.GetName(path) ?? path}";
6368
context.IsBusy = false;
6469
}
6570

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<UserControl x:Class="QuickLook.Plugin.CLSIDViewer.RecycleBinPanel"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:local="clr-namespace:QuickLook.Plugin.CLSIDViewer"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
d:DesignHeight="450"
8+
d:DesignWidth="800"
9+
mc:Ignorable="d">
10+
<Grid>
11+
<TextBlock x:Name="EmptyRecycleBinText"
12+
HorizontalAlignment="Center"
13+
VerticalAlignment="Center"
14+
Text="Recycle Bin is empty" />
15+
<Grid>
16+
<Button x:Name="EmptyRecycleBinButton"
17+
Grid.Column="0"
18+
HorizontalAlignment="Center"
19+
VerticalAlignment="Center"
20+
Click="OnEmptyRecycleBinClick"
21+
Content="Empty Recycle Bin" />
22+
</Grid>
23+
</Grid>
24+
</UserControl>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright © 2017-2025 QL-Win Contributors
2+
//
3+
// This file is part of QuickLook program.
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
using System;
19+
using System.Runtime.InteropServices;
20+
using System.Windows;
21+
using System.Windows.Controls;
22+
23+
namespace QuickLook.Plugin.CLSIDViewer;
24+
25+
public partial class RecycleBinPanel : UserControl
26+
{
27+
public RecycleBinPanel()
28+
{
29+
InitializeComponent();
30+
Loaded += OnRecycleBinPanelLoaded;
31+
}
32+
33+
private void OnRecycleBinPanelLoaded(object sender, RoutedEventArgs e)
34+
{
35+
UpdateState();
36+
}
37+
38+
private void OnEmptyRecycleBinClick(object sender, RoutedEventArgs e)
39+
{
40+
// TODO: Use async to avoid blocking the UI thread
41+
if (RecycleBinHelper.EmptyRecycleBin())
42+
{
43+
UpdateState();
44+
}
45+
}
46+
47+
private void UpdateState()
48+
{
49+
bool hasTrash = RecycleBinHelper.HasTrash();
50+
51+
EmptyRecycleBinButton.Visibility = hasTrash ? Visibility.Visible : Visibility.Collapsed;
52+
EmptyRecycleBinText.Visibility = hasTrash ? Visibility.Collapsed : Visibility.Visible;
53+
}
54+
}
55+
56+
file static class RecycleBinHelper
57+
{
58+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
59+
public struct SHQUERYRBINFO
60+
{
61+
public uint cbSize;
62+
public ulong i64Size;
63+
public ulong i64NumItems;
64+
}
65+
66+
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
67+
private static extern int SHQueryRecycleBin(string pszRootPath, ref SHQUERYRBINFO pSHQueryRBInfo);
68+
69+
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
70+
private static extern int SHEmptyRecycleBin(nint hwnd, string pszRootPath, RecycleFlags dwFlags);
71+
72+
[Flags]
73+
private enum RecycleFlags : uint
74+
{
75+
SHERB_NOCONFIRMATION = 0x00000001,
76+
SHERB_NOPROGRESSUI = 0x00000002,
77+
SHERB_NOSOUND = 0x00000004,
78+
}
79+
80+
public static bool HasTrash()
81+
{
82+
var info = new SHQUERYRBINFO()
83+
{
84+
cbSize = (uint)Marshal.SizeOf(typeof(SHQUERYRBINFO))
85+
};
86+
87+
int result = SHQueryRecycleBin(null, ref info);
88+
89+
if (result == 0) // S_OK
90+
{
91+
return info.i64NumItems > 0;
92+
}
93+
94+
// Fallback
95+
return false;
96+
}
97+
98+
public static bool EmptyRecycleBin()
99+
{
100+
int result = SHEmptyRecycleBin(IntPtr.Zero, null,
101+
RecycleFlags.SHERB_NOCONFIRMATION | RecycleFlags.SHERB_NOPROGRESSUI | RecycleFlags.SHERB_NOSOUND);
102+
103+
return result == 0;
104+
}
105+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<UserControl x:Class="QuickLook.Plugin.CLSIDViewer.ThisPCPanel"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:local="clr-namespace:QuickLook.Plugin.CLSIDViewer"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
d:DesignHeight="450"
8+
d:DesignWidth="800"
9+
mc:Ignorable="d">
10+
<Grid>
11+
<TextBlock HorizontalAlignment="Center"
12+
VerticalAlignment="Center"
13+
Text="ThisPCPanel" />
14+
</Grid>
15+
</UserControl>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright © 2017-2025 QL-Win Contributors
2+
//
3+
// This file is part of QuickLook program.
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
using System.Windows.Controls;
19+
20+
namespace QuickLook.Plugin.CLSIDViewer;
21+
22+
public partial class ThisPCPanel : UserControl
23+
{
24+
public ThisPCPanel()
25+
{
26+
InitializeComponent();
27+
}
28+
}

0 commit comments

Comments
 (0)