Skip to content

Commit f7c029f

Browse files
committed
Support Reopen as HTML preview #1690
1 parent 3e4052a commit f7c029f

4 files changed

Lines changed: 123 additions & 33 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 QuickLook.Common.Commands;
19+
using QuickLook.Common.Helpers;
20+
using QuickLook.Common.Plugin.MoreMenu;
21+
using System.Collections.Generic;
22+
using System.IO;
23+
using System.Reflection;
24+
using System.Windows.Input;
25+
26+
namespace QuickLook.Plugin.TextViewer;
27+
28+
public partial class Plugin
29+
{
30+
public ICommand ReopenAsHtmlPreviewCommand { get; }
31+
32+
public Plugin()
33+
{
34+
ReopenAsHtmlPreviewCommand = new RelayCommand(ReopenAsHtmlPreview);
35+
}
36+
37+
public IEnumerable<IMenuItem> GetMenuItems()
38+
{
39+
string translationFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Translations.config");
40+
string extension = Path.GetExtension(_currentPath).ToLower();
41+
42+
var reopen = extension switch
43+
{
44+
// \QuickLook\QuickLook.Plugin\QuickLook.Plugin.TextViewer\Syntax\Light\zzz-After-JavaScript-HTML.xshd
45+
// .html;.htm;.xhtml;.shtml;.shtm;.xht;.hta
46+
".html" or ".htm" or ".xhtml" or ".shtml" or ".shtm" or ".xht" or ".hta" => new MoreMenuItem()
47+
{
48+
Icon = "\uE774",
49+
Header = TranslationHelper.Get("MW_ReopenAsHtmlPreview", translationFile),
50+
Command = ReopenAsHtmlPreviewCommand,
51+
},
52+
_ => null
53+
};
54+
55+
if (reopen is not null)
56+
yield return reopen;
57+
}
58+
59+
public void ReopenAsHtmlPreview()
60+
{
61+
PluginHelper.InvokePluginPreview("QuickLook.Plugin.HtmlViewer", _currentPath);
62+
}
63+
}

QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

1818
using QuickLook.Common.Plugin;
19+
using QuickLook.Common.Plugin.MoreMenu;
1920
using System;
2021
using System.Collections.Generic;
2122
using System.IO;
@@ -27,17 +28,20 @@
2728

2829
namespace QuickLook.Plugin.TextViewer;
2930

30-
public class Plugin : IViewer
31+
public partial class Plugin : IViewer, IMoreMenu
3132
{
3233
private static readonly HashSet<string> WellKnownExtensions = new(
3334
[
3435
".txt", ".rtf",
3536
]);
3637

3738
private TextViewerPanel _tvp;
39+
private string _currentPath;
3840

3941
public int Priority => -5;
4042

43+
public IEnumerable<IMenuItem> MenuItems => GetMenuItems();
44+
4145
public void Init()
4246
{
4347
}
@@ -82,6 +86,7 @@ public void View(string path, ContextObject context)
8286
else
8387
{
8488
_tvp = new TextViewerPanel();
89+
_currentPath = path;
8590
_tvp.LoadFileAsync(path, context);
8691
context.ViewerContent = _tvp;
8792
}

QuickLook.Plugin/QuickLook.Plugin.TextViewer/Translations.config

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,145 +5,168 @@
55
<Editor_FontFamily>Consolas</Editor_FontFamily>
66
<Editor_Copy>انسخ</Editor_Copy>
77
<Editor_SelectAll>حدد الكل</Editor_SelectAll>
8+
<MW_ReopenAsHtmlPreview>إعادة فتح كمعاينة HTML</MW_ReopenAsHtmlPreview>
89
</ar>
910
<ca>
1011
<Editor_FontFamily>Consolas</Editor_FontFamily>
1112
<Editor_Copy>Copia</Editor_Copy>
1213
<Editor_SelectAll>Selecciona-ho tot</Editor_SelectAll>
14+
<MW_ReopenAsHtmlPreview>Torna a obrir com a previsualització HTML</MW_ReopenAsHtmlPreview>
1315
</ca>
1416
<de>
1517
<Editor_FontFamily>Consolas</Editor_FontFamily>
1618
<Editor_Copy>Kopieren</Editor_Copy>
1719
<Editor_SelectAll>Alles markieren</Editor_SelectAll>
20+
<MW_ReopenAsHtmlPreview>Als HTML-Vorschau erneut öffnen</MW_ReopenAsHtmlPreview>
1821
</de>
1922
<en>
2023
<Editor_FontFamily>Consolas</Editor_FontFamily>
2124
<Editor_Copy>Copy</Editor_Copy>
2225
<Editor_SelectAll>Select All</Editor_SelectAll>
26+
<MW_ReopenAsHtmlPreview>Reopen as HTML preview</MW_ReopenAsHtmlPreview>
2327
</en>
24-
<ar>
25-
<Editor_FontFamily>Consolas</Editor_FontFamily>
26-
<Editor_Copy>انسخ</Editor_Copy>
27-
<Editor_SelectAll>حدد الكل</Editor_SelectAll>
28-
</ar>
2928
<es>
3029
<Editor_FontFamily>Consolas</Editor_FontFamily>
3130
<Editor_Copy>Copiar</Editor_Copy>
3231
<Editor_SelectAll>Seleccionar Todo</Editor_SelectAll>
32+
<MW_ReopenAsHtmlPreview>Reabrir como vista previa HTML</MW_ReopenAsHtmlPreview>
3333
</es>
3434
<fr>
3535
<Editor_FontFamily>Consolas</Editor_FontFamily>
3636
<Editor_Copy>Copie</Editor_Copy>
3737
<Editor_SelectAll>Tout sélectionner</Editor_SelectAll>
38+
<MW_ReopenAsHtmlPreview>Rouvrir en aperçu HTML</MW_ReopenAsHtmlPreview>
3839
</fr>
3940
<it>
4041
<Editor_FontFamily>Consolas</Editor_FontFamily>
4142
<Editor_Copy>Copia</Editor_Copy>
4243
<Editor_SelectAll>Seleziona tutto</Editor_SelectAll>
44+
<MW_ReopenAsHtmlPreview>Riapri come anteprima HTML</MW_ReopenAsHtmlPreview>
4345
</it>
4446
<ja-JP>
4547
<Editor_FontFamily>Consolas,Meiryo UI,MS UI Gothic,MS Gothic</Editor_FontFamily>
4648
<Editor_Copy>コピー</Editor_Copy>
4749
<Editor_SelectAll>すべて選択</Editor_SelectAll>
50+
<MW_ReopenAsHtmlPreview>HTML プレビューとして再度開く</MW_ReopenAsHtmlPreview>
4851
</ja-JP>
4952
<ko>
5053
<Editor_FontFamily>Consolas,Malgun Gothic,Gulim</Editor_FontFamily>
5154
<Editor_Copy>복사</Editor_Copy>
5255
<Editor_SelectAll>모두 선택</Editor_SelectAll>
56+
<MW_ReopenAsHtmlPreview>HTML 미리보기로 다시 열기</MW_ReopenAsHtmlPreview>
5357
</ko>
5458
<nb-NO>
5559
<Editor_FontFamily>Consolas</Editor_FontFamily>
5660
<Editor_Copy>Kopier</Editor_Copy>
5761
<Editor_SelectAll>Merk alt</Editor_SelectAll>
62+
<MW_ReopenAsHtmlPreview>Åpne på nytt som HTML-forhåndsvisning</MW_ReopenAsHtmlPreview>
5863
</nb-NO>
5964
<nl-NL>
6065
<Editor_FontFamily>Consolas</Editor_FontFamily>
6166
<Editor_Copy>Kopiëren</Editor_Copy>
6267
<Editor_SelectAll>Alles selecteren</Editor_SelectAll>
68+
<MW_ReopenAsHtmlPreview>Opnieuw openen als HTML-voorbeeld</MW_ReopenAsHtmlPreview>
6369
</nl-NL>
6470
<pl>
6571
<Editor_FontFamily>Consolas</Editor_FontFamily>
6672
<Editor_Copy>Kopiuj</Editor_Copy>
6773
<Editor_SelectAll>Zaznacz wszystko</Editor_SelectAll>
74+
<MW_ReopenAsHtmlPreview>Otwórz ponownie jako podgląd HTML</MW_ReopenAsHtmlPreview>
6875
</pl>
6976
<pt-BR>
7077
<Editor_FontFamily>Consolas</Editor_FontFamily>
7178
<Editor_Copy>Copiar</Editor_Copy>
7279
<Editor_SelectAll>Selecionar tudo</Editor_SelectAll>
80+
<MW_ReopenAsHtmlPreview>Reabrir como visualização HTML</MW_ReopenAsHtmlPreview>
7381
</pt-BR>
7482
<pt-PT>
7583
<Editor_FontFamily>Consolas</Editor_FontFamily>
7684
<Editor_Copy>Copiar</Editor_Copy>
7785
<Editor_SelectAll>Selecionar tudo</Editor_SelectAll>
86+
<MW_ReopenAsHtmlPreview>Reabrir como pré-visualização HTML</MW_ReopenAsHtmlPreview>
7887
</pt-PT>
7988
<ru-RU>
8089
<Editor_FontFamily>Consolas</Editor_FontFamily>
8190
<Editor_Copy>Копировать</Editor_Copy>
8291
<Editor_SelectAll>Выделить всё</Editor_SelectAll>
92+
<MW_ReopenAsHtmlPreview>Переоткрыть как предварительный просмотр HTML</MW_ReopenAsHtmlPreview>
8393
</ru-RU>
8494
<tr-TR>
8595
<Editor_FontFamily>Consolas</Editor_FontFamily>
8696
<Editor_Copy>Kopyala</Editor_Copy>
8797
<Editor_SelectAll>Tümünü seç</Editor_SelectAll>
98+
<MW_ReopenAsHtmlPreview>HTML önizlemesi olarak yeniden aç</MW_ReopenAsHtmlPreview>
8899
</tr-TR>
89100
<uk-UA>
90101
<Editor_FontFamily>Consolas</Editor_FontFamily>
91102
<Editor_Copy>Копіювати</Editor_Copy>
92103
<Editor_SelectAll>Виділити Все</Editor_SelectAll>
104+
<MW_ReopenAsHtmlPreview>Перевідкрити як попередній перегляд HTML</MW_ReopenAsHtmlPreview>
93105
</uk-UA>
94106
<vi>
95107
<Editor_FontFamily>Consolas</Editor_FontFamily>
96108
<Editor_Copy>Sao chép</Editor_Copy>
97109
<Editor_SelectAll>Chọn tất cả</Editor_SelectAll>
110+
<MW_ReopenAsHtmlPreview>Mở lại dưới dạng xem trước HTML</MW_ReopenAsHtmlPreview>
98111
</vi>
99112
<zh-CN>
100113
<Editor_FontFamily>Consolas,Microsoft Yahei UI,Microsoft Yahei,SimSun</Editor_FontFamily>
101114
<Editor_Copy>复制</Editor_Copy>
102115
<Editor_SelectAll>全选</Editor_SelectAll>
116+
<MW_ReopenAsHtmlPreview>重新作为 HTML 预览打开</MW_ReopenAsHtmlPreview>
103117
</zh-CN>
104118
<zh-TW>
105119
<Editor_FontFamily>Consolas,Microsoft JhengHei UI,Microsoft JhengHei,MingLiU</Editor_FontFamily>
106120
<Editor_Copy>複製</Editor_Copy>
107121
<Editor_SelectAll>全選</Editor_SelectAll>
122+
<MW_ReopenAsHtmlPreview>重新作為 HTML 預覽開啟</MW_ReopenAsHtmlPreview>
108123
</zh-TW>
109124
<mr>
110125
<Editor_FontFamily>Consolas,Mangal,Nirmala UI</Editor_FontFamily>
111126
<Editor_Copy>प्रतिलिपी करा</Editor_Copy>
112127
<Editor_SelectAll>सर्व निवडा</Editor_SelectAll>
128+
<MW_ReopenAsHtmlPreview>HTML पूर्वावलोकन म्हणून पुन्हा उघडा</MW_ReopenAsHtmlPreview>
113129
</mr>
114130
<hi>
115131
<Editor_FontFamily>Consolas,Mangal,Nirmala UI</Editor_FontFamily>
116132
<Editor_Copy>कॉपी करें</Editor_Copy>
117133
<Editor_SelectAll>सभी चुनें</Editor_SelectAll>
134+
<MW_ReopenAsHtmlPreview>HTML पूर्वावलोकन के रूप में फिर से खोलें</MW_ReopenAsHtmlPreview>
118135
</hi>
119136
<he>
120137
<Editor_FontFamily>Consolas</Editor_FontFamily>
121138
<Editor_Copy>העתק</Editor_Copy>
122139
<Editor_SelectAll>בחר הכל</Editor_SelectAll>
140+
<MW_ReopenAsHtmlPreview>פתח מחדש כתצוגה מקדימה של HTML</MW_ReopenAsHtmlPreview>
123141
</he>
124142
<hu-HU>
125143
<Editor_FontFamily>Consolas</Editor_FontFamily>
126144
<Editor_Copy>Másolás</Editor_Copy>
127145
<Editor_SelectAll>Mindet kijelöl</Editor_SelectAll>
146+
<MW_ReopenAsHtmlPreview>Újranyitás HTML előnézetként</MW_ReopenAsHtmlPreview>
128147
</hu-HU>
129148
<id-ID>
130149
<Editor_FontFamily>Consolas</Editor_FontFamily>
131150
<Editor_Copy>Salin</Editor_Copy>
132151
<Editor_SelectAll>Pilih Semua</Editor_SelectAll>
152+
<MW_ReopenAsHtmlPreview>Buka ulang sebagai pratinjau HTML</MW_ReopenAsHtmlPreview>
133153
</id-ID>
134154
<sk>
135155
<Editor_FontFamily>Consolas</Editor_FontFamily>
136156
<Editor_Copy>Kopírovať</Editor_Copy>
137157
<Editor_SelectAll>Označiť všetko</Editor_SelectAll>
158+
<MW_ReopenAsHtmlPreview>Znova otvoriť ako HTML náhľad</MW_ReopenAsHtmlPreview>
138159
</sk>
139160
<el>
140161
<Editor_FontFamily>Consolas</Editor_FontFamily>
141162
<Editor_Copy>Aντιγραφή</Editor_Copy>
142163
<Editor_SelectAll>Επιλογή όλων</Editor_SelectAll>
164+
<MW_ReopenAsHtmlPreview>Επανανοίξτε ως προεπισκόπηση HTML</MW_ReopenAsHtmlPreview>
143165
</el>
144166
<sv>
145167
<Editor_FontFamily>Consolas</Editor_FontFamily>
146168
<Editor_Copy>Kopiera</Editor_Copy>
147169
<Editor_SelectAll>Markera allt</Editor_SelectAll>
170+
<MW_ReopenAsHtmlPreview>Öppna på nytt som HTML-förhandsgranskning</MW_ReopenAsHtmlPreview>
148171
</sv>
149172
</Translations>

QuickLook/ViewerWindow.Actions.cs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -201,30 +201,6 @@ internal void BeginShow(IViewer matchedPlugin, string path,
201201
return;
202202
}
203203

204-
// Initial the more menu
205-
ClearMoreMenuUnpin();
206-
foreach (var plugin in
207-
PluginManager.GetInstance().LoadedPlugins
208-
.GroupBy(x => x.ToString()).Select(g => g.First()) // DistinctBy plugin name
209-
.OrderBy(p => p.Priority)) // OrderBy plugin priority
210-
{
211-
if (plugin.ToString() == Plugin.ToString())
212-
{
213-
if (Plugin is IMoreMenu moreMenu && moreMenu.MenuItems is not null)
214-
{
215-
InsertMoreMenu(moreMenu.MenuItems);
216-
}
217-
continue;
218-
}
219-
else
220-
{
221-
if (plugin is IMoreMenuExtended moreMenu && moreMenu.MenuItems is not null)
222-
{
223-
InsertMoreMenu(moreMenu.MenuItems);
224-
}
225-
}
226-
}
227-
228204
SetOpenWithButtonAndPath();
229205

230206
// Revert UI changes
@@ -263,18 +239,41 @@ internal void BeginShow(IViewer matchedPlugin, string path,
263239
}
264240

265241
// Load plugin, do not block UI
266-
Dispatcher.BeginInvoke(new Action(() =>
242+
Dispatcher.BeginInvoke(() =>
267243
{
268244
try
269245
{
270246
Plugin.View(path, ContextObject);
247+
248+
// Initial the more menu
249+
ClearMoreMenuUnpin();
250+
foreach (var plugin in
251+
PluginManager.GetInstance().LoadedPlugins
252+
.GroupBy(x => x.ToString()).Select(g => g.First()) // DistinctBy plugin name
253+
.OrderBy(p => p.Priority)) // OrderBy plugin priority
254+
{
255+
if (plugin.ToString() == Plugin.ToString())
256+
{
257+
if (Plugin is IMoreMenu moreMenu && moreMenu.MenuItems is not null)
258+
{
259+
InsertMoreMenu(moreMenu.MenuItems);
260+
}
261+
continue;
262+
}
263+
else
264+
{
265+
if (plugin is IMoreMenuExtended moreMenu && moreMenu.MenuItems is not null)
266+
{
267+
InsertMoreMenu(moreMenu.MenuItems);
268+
}
269+
}
270+
}
271271
}
272272
catch (Exception e)
273273
{
274274
exceptionHandler(path, ExceptionDispatchInfo.Capture(e));
275275
}
276-
}),
277-
DispatcherPriority.Input);
276+
}, DispatcherPriority.Input);
278277
}
279278

280279
private void ClearMoreMenuUnpin()

0 commit comments

Comments
 (0)