Support Reopen as HTML preview #1690

This commit is contained in:
ema
2025-10-08 01:24:23 +08:00
parent 3e4052ae77
commit f7c029f127
4 changed files with 123 additions and 33 deletions

View File

@@ -0,0 +1,63 @@
// 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 QuickLook.Common.Commands;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin.MoreMenu;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows.Input;
namespace QuickLook.Plugin.TextViewer;
public partial class Plugin
{
public ICommand ReopenAsHtmlPreviewCommand { get; }
public Plugin()
{
ReopenAsHtmlPreviewCommand = new RelayCommand(ReopenAsHtmlPreview);
}
public IEnumerable<IMenuItem> GetMenuItems()
{
string translationFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Translations.config");
string extension = Path.GetExtension(_currentPath).ToLower();
var reopen = extension switch
{
// \QuickLook\QuickLook.Plugin\QuickLook.Plugin.TextViewer\Syntax\Light\zzz-After-JavaScript-HTML.xshd
// .html;.htm;.xhtml;.shtml;.shtm;.xht;.hta
".html" or ".htm" or ".xhtml" or ".shtml" or ".shtm" or ".xht" or ".hta" => new MoreMenuItem()
{
Icon = "\uE774",
Header = TranslationHelper.Get("MW_ReopenAsHtmlPreview", translationFile),
Command = ReopenAsHtmlPreviewCommand,
},
_ => null
};
if (reopen is not null)
yield return reopen;
}
public void ReopenAsHtmlPreview()
{
PluginHelper.InvokePluginPreview("QuickLook.Plugin.HtmlViewer", _currentPath);
}
}

View File

@@ -16,6 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using QuickLook.Common.Plugin; using QuickLook.Common.Plugin;
using QuickLook.Common.Plugin.MoreMenu;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -27,7 +28,7 @@ using System.Windows.Media;
namespace QuickLook.Plugin.TextViewer; namespace QuickLook.Plugin.TextViewer;
public class Plugin : IViewer public partial class Plugin : IViewer, IMoreMenu
{ {
private static readonly HashSet<string> WellKnownExtensions = new( private static readonly HashSet<string> WellKnownExtensions = new(
[ [
@@ -35,9 +36,12 @@ public class Plugin : IViewer
]); ]);
private TextViewerPanel _tvp; private TextViewerPanel _tvp;
private string _currentPath;
public int Priority => -5; public int Priority => -5;
public IEnumerable<IMenuItem> MenuItems => GetMenuItems();
public void Init() public void Init()
{ {
} }
@@ -82,6 +86,7 @@ public class Plugin : IViewer
else else
{ {
_tvp = new TextViewerPanel(); _tvp = new TextViewerPanel();
_currentPath = path;
_tvp.LoadFileAsync(path, context); _tvp.LoadFileAsync(path, context);
context.ViewerContent = _tvp; context.ViewerContent = _tvp;
} }

View File

@@ -5,145 +5,168 @@
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>انسخ</Editor_Copy> <Editor_Copy>انسخ</Editor_Copy>
<Editor_SelectAll>حدد الكل</Editor_SelectAll> <Editor_SelectAll>حدد الكل</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>إعادة فتح كمعاينة HTML</MW_ReopenAsHtmlPreview>
</ar> </ar>
<ca> <ca>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Copia</Editor_Copy> <Editor_Copy>Copia</Editor_Copy>
<Editor_SelectAll>Selecciona-ho tot</Editor_SelectAll> <Editor_SelectAll>Selecciona-ho tot</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Torna a obrir com a previsualització HTML</MW_ReopenAsHtmlPreview>
</ca> </ca>
<de> <de>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Kopieren</Editor_Copy> <Editor_Copy>Kopieren</Editor_Copy>
<Editor_SelectAll>Alles markieren</Editor_SelectAll> <Editor_SelectAll>Alles markieren</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Als HTML-Vorschau erneut öffnen</MW_ReopenAsHtmlPreview>
</de> </de>
<en> <en>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Copy</Editor_Copy> <Editor_Copy>Copy</Editor_Copy>
<Editor_SelectAll>Select All</Editor_SelectAll> <Editor_SelectAll>Select All</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Reopen as HTML preview</MW_ReopenAsHtmlPreview>
</en> </en>
<ar>
<Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>انسخ</Editor_Copy>
<Editor_SelectAll>حدد الكل</Editor_SelectAll>
</ar>
<es> <es>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Copiar</Editor_Copy> <Editor_Copy>Copiar</Editor_Copy>
<Editor_SelectAll>Seleccionar Todo</Editor_SelectAll> <Editor_SelectAll>Seleccionar Todo</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Reabrir como vista previa HTML</MW_ReopenAsHtmlPreview>
</es> </es>
<fr> <fr>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Copie</Editor_Copy> <Editor_Copy>Copie</Editor_Copy>
<Editor_SelectAll>Tout sélectionner</Editor_SelectAll> <Editor_SelectAll>Tout sélectionner</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Rouvrir en aperçu HTML</MW_ReopenAsHtmlPreview>
</fr> </fr>
<it> <it>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Copia</Editor_Copy> <Editor_Copy>Copia</Editor_Copy>
<Editor_SelectAll>Seleziona tutto</Editor_SelectAll> <Editor_SelectAll>Seleziona tutto</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Riapri come anteprima HTML</MW_ReopenAsHtmlPreview>
</it> </it>
<ja-JP> <ja-JP>
<Editor_FontFamily>Consolas,Meiryo UI,MS UI Gothic,MS Gothic</Editor_FontFamily> <Editor_FontFamily>Consolas,Meiryo UI,MS UI Gothic,MS Gothic</Editor_FontFamily>
<Editor_Copy>コピー</Editor_Copy> <Editor_Copy>コピー</Editor_Copy>
<Editor_SelectAll>すべて選択</Editor_SelectAll> <Editor_SelectAll>すべて選択</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>HTML プレビューとして再度開く</MW_ReopenAsHtmlPreview>
</ja-JP> </ja-JP>
<ko> <ko>
<Editor_FontFamily>Consolas,Malgun Gothic,Gulim</Editor_FontFamily> <Editor_FontFamily>Consolas,Malgun Gothic,Gulim</Editor_FontFamily>
<Editor_Copy>복사</Editor_Copy> <Editor_Copy>복사</Editor_Copy>
<Editor_SelectAll>모두 선택</Editor_SelectAll> <Editor_SelectAll>모두 선택</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>HTML 미리보기로 다시 열기</MW_ReopenAsHtmlPreview>
</ko> </ko>
<nb-NO> <nb-NO>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Kopier</Editor_Copy> <Editor_Copy>Kopier</Editor_Copy>
<Editor_SelectAll>Merk alt</Editor_SelectAll> <Editor_SelectAll>Merk alt</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Åpne på nytt som HTML-forhåndsvisning</MW_ReopenAsHtmlPreview>
</nb-NO> </nb-NO>
<nl-NL> <nl-NL>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Kopiëren</Editor_Copy> <Editor_Copy>Kopiëren</Editor_Copy>
<Editor_SelectAll>Alles selecteren</Editor_SelectAll> <Editor_SelectAll>Alles selecteren</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Opnieuw openen als HTML-voorbeeld</MW_ReopenAsHtmlPreview>
</nl-NL> </nl-NL>
<pl> <pl>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Kopiuj</Editor_Copy> <Editor_Copy>Kopiuj</Editor_Copy>
<Editor_SelectAll>Zaznacz wszystko</Editor_SelectAll> <Editor_SelectAll>Zaznacz wszystko</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Otwórz ponownie jako podgląd HTML</MW_ReopenAsHtmlPreview>
</pl> </pl>
<pt-BR> <pt-BR>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Copiar</Editor_Copy> <Editor_Copy>Copiar</Editor_Copy>
<Editor_SelectAll>Selecionar tudo</Editor_SelectAll> <Editor_SelectAll>Selecionar tudo</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Reabrir como visualização HTML</MW_ReopenAsHtmlPreview>
</pt-BR> </pt-BR>
<pt-PT> <pt-PT>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Copiar</Editor_Copy> <Editor_Copy>Copiar</Editor_Copy>
<Editor_SelectAll>Selecionar tudo</Editor_SelectAll> <Editor_SelectAll>Selecionar tudo</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Reabrir como pré-visualização HTML</MW_ReopenAsHtmlPreview>
</pt-PT> </pt-PT>
<ru-RU> <ru-RU>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Копировать</Editor_Copy> <Editor_Copy>Копировать</Editor_Copy>
<Editor_SelectAll>Выделить всё</Editor_SelectAll> <Editor_SelectAll>Выделить всё</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Переоткрыть как предварительный просмотр HTML</MW_ReopenAsHtmlPreview>
</ru-RU> </ru-RU>
<tr-TR> <tr-TR>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Kopyala</Editor_Copy> <Editor_Copy>Kopyala</Editor_Copy>
<Editor_SelectAll>Tümünü seç</Editor_SelectAll> <Editor_SelectAll>Tümünü seç</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>HTML önizlemesi olarak yeniden aç</MW_ReopenAsHtmlPreview>
</tr-TR> </tr-TR>
<uk-UA> <uk-UA>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Копіювати</Editor_Copy> <Editor_Copy>Копіювати</Editor_Copy>
<Editor_SelectAll>Виділити Все</Editor_SelectAll> <Editor_SelectAll>Виділити Все</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Перевідкрити як попередній перегляд HTML</MW_ReopenAsHtmlPreview>
</uk-UA> </uk-UA>
<vi> <vi>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Sao chép</Editor_Copy> <Editor_Copy>Sao chép</Editor_Copy>
<Editor_SelectAll>Chọn tất cả</Editor_SelectAll> <Editor_SelectAll>Chọn tất cả</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Mở lại dưới dạng xem trước HTML</MW_ReopenAsHtmlPreview>
</vi> </vi>
<zh-CN> <zh-CN>
<Editor_FontFamily>Consolas,Microsoft Yahei UI,Microsoft Yahei,SimSun</Editor_FontFamily> <Editor_FontFamily>Consolas,Microsoft Yahei UI,Microsoft Yahei,SimSun</Editor_FontFamily>
<Editor_Copy>复制</Editor_Copy> <Editor_Copy>复制</Editor_Copy>
<Editor_SelectAll>全选</Editor_SelectAll> <Editor_SelectAll>全选</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>重新作为 HTML 预览打开</MW_ReopenAsHtmlPreview>
</zh-CN> </zh-CN>
<zh-TW> <zh-TW>
<Editor_FontFamily>Consolas,Microsoft JhengHei UI,Microsoft JhengHei,MingLiU</Editor_FontFamily> <Editor_FontFamily>Consolas,Microsoft JhengHei UI,Microsoft JhengHei,MingLiU</Editor_FontFamily>
<Editor_Copy>複製</Editor_Copy> <Editor_Copy>複製</Editor_Copy>
<Editor_SelectAll>全選</Editor_SelectAll> <Editor_SelectAll>全選</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>重新作為 HTML 預覽開啟</MW_ReopenAsHtmlPreview>
</zh-TW> </zh-TW>
<mr> <mr>
<Editor_FontFamily>Consolas,Mangal,Nirmala UI</Editor_FontFamily> <Editor_FontFamily>Consolas,Mangal,Nirmala UI</Editor_FontFamily>
<Editor_Copy>प्रतिलिपी करा</Editor_Copy> <Editor_Copy>प्रतिलिपी करा</Editor_Copy>
<Editor_SelectAll>सर्व निवडा</Editor_SelectAll> <Editor_SelectAll>सर्व निवडा</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>HTML पूर्वावलोकन म्हणून पुन्हा उघडा</MW_ReopenAsHtmlPreview>
</mr> </mr>
<hi> <hi>
<Editor_FontFamily>Consolas,Mangal,Nirmala UI</Editor_FontFamily> <Editor_FontFamily>Consolas,Mangal,Nirmala UI</Editor_FontFamily>
<Editor_Copy>कॉपी करें</Editor_Copy> <Editor_Copy>कॉपी करें</Editor_Copy>
<Editor_SelectAll>सभी चुनें</Editor_SelectAll> <Editor_SelectAll>सभी चुनें</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>HTML पूर्वावलोकन के रूप में फिर से खोलें</MW_ReopenAsHtmlPreview>
</hi> </hi>
<he> <he>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>העתק</Editor_Copy> <Editor_Copy>העתק</Editor_Copy>
<Editor_SelectAll>בחר הכל</Editor_SelectAll> <Editor_SelectAll>בחר הכל</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>פתח מחדש כתצוגה מקדימה של HTML</MW_ReopenAsHtmlPreview>
</he> </he>
<hu-HU> <hu-HU>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Másolás</Editor_Copy> <Editor_Copy>Másolás</Editor_Copy>
<Editor_SelectAll>Mindet kijelöl</Editor_SelectAll> <Editor_SelectAll>Mindet kijelöl</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Újranyitás HTML előnézetként</MW_ReopenAsHtmlPreview>
</hu-HU> </hu-HU>
<id-ID> <id-ID>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Salin</Editor_Copy> <Editor_Copy>Salin</Editor_Copy>
<Editor_SelectAll>Pilih Semua</Editor_SelectAll> <Editor_SelectAll>Pilih Semua</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Buka ulang sebagai pratinjau HTML</MW_ReopenAsHtmlPreview>
</id-ID> </id-ID>
<sk> <sk>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Kopírovať</Editor_Copy> <Editor_Copy>Kopírovať</Editor_Copy>
<Editor_SelectAll>Označiť všetko</Editor_SelectAll> <Editor_SelectAll>Označiť všetko</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Znova otvoriť ako HTML náhľad</MW_ReopenAsHtmlPreview>
</sk> </sk>
<el> <el>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Aντιγραφή</Editor_Copy> <Editor_Copy>Aντιγραφή</Editor_Copy>
<Editor_SelectAll>Επιλογή όλων</Editor_SelectAll> <Editor_SelectAll>Επιλογή όλων</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Επανανοίξτε ως προεπισκόπηση HTML</MW_ReopenAsHtmlPreview>
</el> </el>
<sv> <sv>
<Editor_FontFamily>Consolas</Editor_FontFamily> <Editor_FontFamily>Consolas</Editor_FontFamily>
<Editor_Copy>Kopiera</Editor_Copy> <Editor_Copy>Kopiera</Editor_Copy>
<Editor_SelectAll>Markera allt</Editor_SelectAll> <Editor_SelectAll>Markera allt</Editor_SelectAll>
<MW_ReopenAsHtmlPreview>Öppna på nytt som HTML-förhandsgranskning</MW_ReopenAsHtmlPreview>
</sv> </sv>
</Translations> </Translations>

View File

@@ -201,30 +201,6 @@ public partial class ViewerWindow
return; return;
} }
// Initial the more menu
ClearMoreMenuUnpin();
foreach (var plugin in
PluginManager.GetInstance().LoadedPlugins
.GroupBy(x => x.ToString()).Select(g => g.First()) // DistinctBy plugin name
.OrderBy(p => p.Priority)) // OrderBy plugin priority
{
if (plugin.ToString() == Plugin.ToString())
{
if (Plugin is IMoreMenu moreMenu && moreMenu.MenuItems is not null)
{
InsertMoreMenu(moreMenu.MenuItems);
}
continue;
}
else
{
if (plugin is IMoreMenuExtended moreMenu && moreMenu.MenuItems is not null)
{
InsertMoreMenu(moreMenu.MenuItems);
}
}
}
SetOpenWithButtonAndPath(); SetOpenWithButtonAndPath();
// Revert UI changes // Revert UI changes
@@ -263,18 +239,41 @@ public partial class ViewerWindow
} }
// Load plugin, do not block UI // Load plugin, do not block UI
Dispatcher.BeginInvoke(new Action(() => Dispatcher.BeginInvoke(() =>
{ {
try try
{ {
Plugin.View(path, ContextObject); Plugin.View(path, ContextObject);
// Initial the more menu
ClearMoreMenuUnpin();
foreach (var plugin in
PluginManager.GetInstance().LoadedPlugins
.GroupBy(x => x.ToString()).Select(g => g.First()) // DistinctBy plugin name
.OrderBy(p => p.Priority)) // OrderBy plugin priority
{
if (plugin.ToString() == Plugin.ToString())
{
if (Plugin is IMoreMenu moreMenu && moreMenu.MenuItems is not null)
{
InsertMoreMenu(moreMenu.MenuItems);
}
continue;
}
else
{
if (plugin is IMoreMenuExtended moreMenu && moreMenu.MenuItems is not null)
{
InsertMoreMenu(moreMenu.MenuItems);
}
}
}
} }
catch (Exception e) catch (Exception e)
{ {
exceptionHandler(path, ExceptionDispatchInfo.Capture(e)); exceptionHandler(path, ExceptionDispatchInfo.Capture(e));
} }
}), }, DispatcherPriority.Input);
DispatcherPriority.Input);
} }
private void ClearMoreMenuUnpin() private void ClearMoreMenuUnpin()