mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-10-13 14:29:54 +00:00
Support Reopen as HTML preview
#1690
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
@@ -16,6 +16,7 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using QuickLook.Common.Plugin;
|
||||
using QuickLook.Common.Plugin.MoreMenu;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -27,7 +28,7 @@ using System.Windows.Media;
|
||||
|
||||
namespace QuickLook.Plugin.TextViewer;
|
||||
|
||||
public class Plugin : IViewer
|
||||
public partial class Plugin : IViewer, IMoreMenu
|
||||
{
|
||||
private static readonly HashSet<string> WellKnownExtensions = new(
|
||||
[
|
||||
@@ -35,9 +36,12 @@ public class Plugin : IViewer
|
||||
]);
|
||||
|
||||
private TextViewerPanel _tvp;
|
||||
private string _currentPath;
|
||||
|
||||
public int Priority => -5;
|
||||
|
||||
public IEnumerable<IMenuItem> MenuItems => GetMenuItems();
|
||||
|
||||
public void Init()
|
||||
{
|
||||
}
|
||||
@@ -82,6 +86,7 @@ public class Plugin : IViewer
|
||||
else
|
||||
{
|
||||
_tvp = new TextViewerPanel();
|
||||
_currentPath = path;
|
||||
_tvp.LoadFileAsync(path, context);
|
||||
context.ViewerContent = _tvp;
|
||||
}
|
||||
|
@@ -5,145 +5,168 @@
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>انسخ</Editor_Copy>
|
||||
<Editor_SelectAll>حدد الكل</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>إعادة فتح كمعاينة HTML</MW_ReopenAsHtmlPreview>
|
||||
</ar>
|
||||
<ca>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Copia</Editor_Copy>
|
||||
<Editor_SelectAll>Selecciona-ho tot</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Torna a obrir com a previsualització HTML</MW_ReopenAsHtmlPreview>
|
||||
</ca>
|
||||
<de>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Kopieren</Editor_Copy>
|
||||
<Editor_SelectAll>Alles markieren</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Als HTML-Vorschau erneut öffnen</MW_ReopenAsHtmlPreview>
|
||||
</de>
|
||||
<en>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Copy</Editor_Copy>
|
||||
<Editor_SelectAll>Select All</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Reopen as HTML preview</MW_ReopenAsHtmlPreview>
|
||||
</en>
|
||||
<ar>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>انسخ</Editor_Copy>
|
||||
<Editor_SelectAll>حدد الكل</Editor_SelectAll>
|
||||
</ar>
|
||||
<es>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Copiar</Editor_Copy>
|
||||
<Editor_SelectAll>Seleccionar Todo</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Reabrir como vista previa HTML</MW_ReopenAsHtmlPreview>
|
||||
</es>
|
||||
<fr>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Copie</Editor_Copy>
|
||||
<Editor_SelectAll>Tout sélectionner</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Rouvrir en aperçu HTML</MW_ReopenAsHtmlPreview>
|
||||
</fr>
|
||||
<it>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Copia</Editor_Copy>
|
||||
<Editor_SelectAll>Seleziona tutto</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Riapri come anteprima HTML</MW_ReopenAsHtmlPreview>
|
||||
</it>
|
||||
<ja-JP>
|
||||
<Editor_FontFamily>Consolas,Meiryo UI,MS UI Gothic,MS Gothic</Editor_FontFamily>
|
||||
<Editor_Copy>コピー</Editor_Copy>
|
||||
<Editor_SelectAll>すべて選択</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>HTML プレビューとして再度開く</MW_ReopenAsHtmlPreview>
|
||||
</ja-JP>
|
||||
<ko>
|
||||
<Editor_FontFamily>Consolas,Malgun Gothic,Gulim</Editor_FontFamily>
|
||||
<Editor_Copy>복사</Editor_Copy>
|
||||
<Editor_SelectAll>모두 선택</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>HTML 미리보기로 다시 열기</MW_ReopenAsHtmlPreview>
|
||||
</ko>
|
||||
<nb-NO>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Kopier</Editor_Copy>
|
||||
<Editor_SelectAll>Merk alt</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Åpne på nytt som HTML-forhåndsvisning</MW_ReopenAsHtmlPreview>
|
||||
</nb-NO>
|
||||
<nl-NL>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Kopiëren</Editor_Copy>
|
||||
<Editor_SelectAll>Alles selecteren</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Opnieuw openen als HTML-voorbeeld</MW_ReopenAsHtmlPreview>
|
||||
</nl-NL>
|
||||
<pl>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Kopiuj</Editor_Copy>
|
||||
<Editor_SelectAll>Zaznacz wszystko</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Otwórz ponownie jako podgląd HTML</MW_ReopenAsHtmlPreview>
|
||||
</pl>
|
||||
<pt-BR>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Copiar</Editor_Copy>
|
||||
<Editor_SelectAll>Selecionar tudo</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Reabrir como visualização HTML</MW_ReopenAsHtmlPreview>
|
||||
</pt-BR>
|
||||
<pt-PT>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Copiar</Editor_Copy>
|
||||
<Editor_SelectAll>Selecionar tudo</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Reabrir como pré-visualização HTML</MW_ReopenAsHtmlPreview>
|
||||
</pt-PT>
|
||||
<ru-RU>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Копировать</Editor_Copy>
|
||||
<Editor_SelectAll>Выделить всё</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Переоткрыть как предварительный просмотр HTML</MW_ReopenAsHtmlPreview>
|
||||
</ru-RU>
|
||||
<tr-TR>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Kopyala</Editor_Copy>
|
||||
<Editor_SelectAll>Tümünü seç</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>HTML önizlemesi olarak yeniden aç</MW_ReopenAsHtmlPreview>
|
||||
</tr-TR>
|
||||
<uk-UA>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Копіювати</Editor_Copy>
|
||||
<Editor_SelectAll>Виділити Все</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Перевідкрити як попередній перегляд HTML</MW_ReopenAsHtmlPreview>
|
||||
</uk-UA>
|
||||
<vi>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Sao chép</Editor_Copy>
|
||||
<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>
|
||||
<zh-CN>
|
||||
<Editor_FontFamily>Consolas,Microsoft Yahei UI,Microsoft Yahei,SimSun</Editor_FontFamily>
|
||||
<Editor_Copy>复制</Editor_Copy>
|
||||
<Editor_SelectAll>全选</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>重新作为 HTML 预览打开</MW_ReopenAsHtmlPreview>
|
||||
</zh-CN>
|
||||
<zh-TW>
|
||||
<Editor_FontFamily>Consolas,Microsoft JhengHei UI,Microsoft JhengHei,MingLiU</Editor_FontFamily>
|
||||
<Editor_Copy>複製</Editor_Copy>
|
||||
<Editor_SelectAll>全選</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>重新作為 HTML 預覽開啟</MW_ReopenAsHtmlPreview>
|
||||
</zh-TW>
|
||||
<mr>
|
||||
<Editor_FontFamily>Consolas,Mangal,Nirmala UI</Editor_FontFamily>
|
||||
<Editor_Copy>प्रतिलिपी करा</Editor_Copy>
|
||||
<Editor_SelectAll>सर्व निवडा</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>HTML पूर्वावलोकन म्हणून पुन्हा उघडा</MW_ReopenAsHtmlPreview>
|
||||
</mr>
|
||||
<hi>
|
||||
<Editor_FontFamily>Consolas,Mangal,Nirmala UI</Editor_FontFamily>
|
||||
<Editor_Copy>कॉपी करें</Editor_Copy>
|
||||
<Editor_SelectAll>सभी चुनें</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>HTML पूर्वावलोकन के रूप में फिर से खोलें</MW_ReopenAsHtmlPreview>
|
||||
</hi>
|
||||
<he>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>העתק</Editor_Copy>
|
||||
<Editor_SelectAll>בחר הכל</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>פתח מחדש כתצוגה מקדימה של HTML</MW_ReopenAsHtmlPreview>
|
||||
</he>
|
||||
<hu-HU>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Másolás</Editor_Copy>
|
||||
<Editor_SelectAll>Mindet kijelöl</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Újranyitás HTML előnézetként</MW_ReopenAsHtmlPreview>
|
||||
</hu-HU>
|
||||
<id-ID>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Salin</Editor_Copy>
|
||||
<Editor_SelectAll>Pilih Semua</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Buka ulang sebagai pratinjau HTML</MW_ReopenAsHtmlPreview>
|
||||
</id-ID>
|
||||
<sk>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Kopírovať</Editor_Copy>
|
||||
<Editor_SelectAll>Označiť všetko</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Znova otvoriť ako HTML náhľad</MW_ReopenAsHtmlPreview>
|
||||
</sk>
|
||||
<el>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Aντιγραφή</Editor_Copy>
|
||||
<Editor_SelectAll>Επιλογή όλων</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Επανανοίξτε ως προεπισκόπηση HTML</MW_ReopenAsHtmlPreview>
|
||||
</el>
|
||||
<sv>
|
||||
<Editor_FontFamily>Consolas</Editor_FontFamily>
|
||||
<Editor_Copy>Kopiera</Editor_Copy>
|
||||
<Editor_SelectAll>Markera allt</Editor_SelectAll>
|
||||
<MW_ReopenAsHtmlPreview>Öppna på nytt som HTML-förhandsgranskning</MW_ReopenAsHtmlPreview>
|
||||
</sv>
|
||||
</Translations>
|
||||
|
@@ -201,30 +201,6 @@ public partial class ViewerWindow
|
||||
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();
|
||||
|
||||
// Revert UI changes
|
||||
@@ -263,18 +239,41 @@ public partial class ViewerWindow
|
||||
}
|
||||
|
||||
// Load plugin, do not block UI
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
exceptionHandler(path, ExceptionDispatchInfo.Capture(e));
|
||||
}
|
||||
}),
|
||||
DispatcherPriority.Input);
|
||||
}, DispatcherPriority.Input);
|
||||
}
|
||||
|
||||
private void ClearMoreMenuUnpin()
|
||||
|
Reference in New Issue
Block a user