Skip to content

Commit 2af849e

Browse files
Copilotemako
andcommitted
Add IMoreMenu support to HtmlViewer with View Source Code option
Co-Authored-By: emako <24737061+emako@users.noreply.github.com>
1 parent 78843d8 commit 2af849e

4 files changed

Lines changed: 95 additions & 1 deletion

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.HtmlViewer;
27+
28+
public partial class Plugin
29+
{
30+
public ICommand ViewSourceCodeCommand { get; }
31+
32+
public Plugin()
33+
{
34+
ViewSourceCodeCommand = new RelayCommand(ViewSourceCode);
35+
}
36+
37+
public IEnumerable<IMenuItem> GetMenuItems()
38+
{
39+
string translationFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Translations.config");
40+
41+
yield return new MoreMenuItem()
42+
{
43+
Icon = "\uE943",
44+
Header = TranslationHelper.Get("MW_ViewSourceCode", translationFile),
45+
MenuItems = null,
46+
Command = ViewSourceCodeCommand,
47+
};
48+
}
49+
50+
public void ViewSourceCode()
51+
{
52+
PluginHelper.InvokePluginPreview("QuickLook.Plugin.TextViewer", _currentPath);
53+
}
54+
}

QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,28 @@
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;
21+
using System.Collections.Generic;
2022
using System.IO;
2123
using System.Linq;
2224
using System.Windows;
2325
using System.Windows.Threading;
2426

2527
namespace QuickLook.Plugin.HtmlViewer;
2628

27-
public class Plugin : IViewer
29+
public partial class Plugin : IViewer, IMoreMenu
2830
{
2931
private static readonly string[] _extensions = [".mht", ".mhtml", ".htm", ".html"];
3032
private static readonly string[] _supportedProtocols = ["http", "https"];
3133

3234
private WebpagePanel _panel;
35+
private string _currentPath;
3336

3437
public int Priority => 0;
3538

39+
public IEnumerable<IMenuItem> MenuItems => GetMenuItems();
40+
3641
public void Init()
3742
{
3843
}
@@ -53,6 +58,7 @@ public void Prepare(string path, ContextObject context)
5358
public void View(string path, ContextObject context)
5459
{
5560
_panel = new WebpagePanel();
61+
_currentPath = path;
5662
context.ViewerContent = _panel;
5763
context.Title = Path.IsPathRooted(path) ? Path.GetFileName(path) : path;
5864

QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/QuickLook.Plugin.HtmlViewer.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,10 @@
8585
</Compile>
8686
</ItemGroup>
8787

88+
<ItemGroup>
89+
<None Update="Translations.config">
90+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
91+
</None>
92+
</ItemGroup>
93+
8894
</Project>

QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Translations.config

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,86 +3,114 @@
33
<Translations>
44
<ca>
55
<WEBVIEW2_NOT_AVAILABLE>Cal instal·lar Microsoft Edge WebView2 per veure aquest fitxer.&#10;Feu clic aquí per descarregar-lo.</WEBVIEW2_NOT_AVAILABLE>
6+
<MW_ViewSourceCode>Veure codi font</MW_ViewSourceCode>
67
</ca>
78
<he>
89
<WEBVIEW2_NOT_AVAILABLE>צפייה בקובץ זה דורשת התקנת Microsoft Edge WebView2.&#10;לחץ כאן להורדה.</WEBVIEW2_NOT_AVAILABLE>
10+
<MW_ViewSourceCode>הצג קוד מקור</MW_ViewSourceCode>
911
</he>
1012
<hi>
1113
<WEBVIEW2_NOT_AVAILABLE>इस फ़ाइल को देखने के लिए Microsoft Edge WebView2 इंस्टॉल होना आवश्यक है।&#10;डाउनलोड करने के लिए यहां क्लिक करें.</WEBVIEW2_NOT_AVAILABLE>
14+
<MW_ViewSourceCode>स्रोत कोड देखें</MW_ViewSourceCode>
1215
</hi>
1316
<hu-HU>
1417
<WEBVIEW2_NOT_AVAILABLE>A fájl megtekintéséhez telepíteni kell a Microsoft Edge WebView2-t.&#10;Kattintson ide a letöltéshez.</WEBVIEW2_NOT_AVAILABLE>
18+
<MW_ViewSourceCode>Forráskód megtekintése</MW_ViewSourceCode>
1519
</hu-HU>
1620
<id-ID>
1721
<WEBVIEW2_NOT_AVAILABLE>Melihat file ini memerlukan Microsoft Edge WebView2 terinstal.&#10;Klik di sini untuk mengunduhnya.</WEBVIEW2_NOT_AVAILABLE>
22+
<MW_ViewSourceCode>Lihat Kode Sumber</MW_ViewSourceCode>
1823
</id-ID>
1924
<mr>
2025
<WEBVIEW2_NOT_AVAILABLE>या फाइलचे दृश्य Microsoft Edge WebView2 स्थापित असणे आवश्यक आहे.&#10;डाउनलोडसाठी येथे क्लिक करा.</WEBVIEW2_NOT_AVAILABLE>
26+
<MW_ViewSourceCode>स्रोत कोड पहा</MW_ViewSourceCode>
2127
</mr>
2228
<nb-NO>
2329
<WEBVIEW2_NOT_AVAILABLE>For å vise denne filen må Microsoft Edge WebView2 være installert.&#10;Klikk her for å laste ned.</WEBVIEW2_NOT_AVAILABLE>
30+
<MW_ViewSourceCode>Vis kildekode</MW_ViewSourceCode>
2431
</nb-NO>
2532
<nl-NL>
2633
<WEBVIEW2_NOT_AVAILABLE>Voor het bekijken van dit bestand moet Microsoft Edge WebView2 geïnstalleerd zijn.&#10;Klik hier om te downloaden.</WEBVIEW2_NOT_AVAILABLE>
34+
<MW_ViewSourceCode>Broncode weergeven</MW_ViewSourceCode>
2735
</nl-NL>
2836
<pt-BR>
2937
<WEBVIEW2_NOT_AVAILABLE>Para visualizar este arquivo, é necessário instalar o Microsoft Edge WebView2.&#10;Clique aqui para baixar.</WEBVIEW2_NOT_AVAILABLE>
38+
<MW_ViewSourceCode>Ver Código Fonte</MW_ViewSourceCode>
3039
</pt-BR>
3140
<pt-PT>
3241
<WEBVIEW2_NOT_AVAILABLE>Para visualizar este ficheiro, é necessário instalar o Microsoft Edge WebView2.&#10;Clique aqui para descarregar.</WEBVIEW2_NOT_AVAILABLE>
42+
<MW_ViewSourceCode>Ver Código Fonte</MW_ViewSourceCode>
3343
</pt-PT>
3444
<ru-RU>
3545
<WEBVIEW2_NOT_AVAILABLE>Для просмотра этого файла требуется установка Microsoft Edge WebView2.&#10;Нажмите здесь, чтобы скачать.</WEBVIEW2_NOT_AVAILABLE>
46+
<MW_ViewSourceCode>Посмотреть исходный код</MW_ViewSourceCode>
3647
</ru-RU>
3748
<sk>
3849
<WEBVIEW2_NOT_AVAILABLE>Na zobrazenie tohto súboru je potrebné nainštalovať Microsoft Edge WebView2.&#10;Kliknite sem pre stiahnutie.</WEBVIEW2_NOT_AVAILABLE>
50+
<MW_ViewSourceCode>Zobraziť zdrojový kód</MW_ViewSourceCode>
3951
</sk>
4052
<tr-TR>
4153
<WEBVIEW2_NOT_AVAILABLE>Bu dosyayı görüntülemek için Microsoft Edge WebView2'nin yüklü olması gerekir.&#10;İndirmek için buraya tıklayın.</WEBVIEW2_NOT_AVAILABLE>
54+
<MW_ViewSourceCode>Kaynak Kodu Görüntüle</MW_ViewSourceCode>
4255
</tr-TR>
4356
<vi>
4457
<WEBVIEW2_NOT_AVAILABLE>Để xem tệp này, cần cài đặt Microsoft Edge WebView2.&#10;Nhấn vào đây để tải về.</WEBVIEW2_NOT_AVAILABLE>
58+
<MW_ViewSourceCode>Xem Mã Nguồn</MW_ViewSourceCode>
4559
</vi>
4660
<en>
4761
<WEBVIEW2_NOT_AVAILABLE>Viewing this file requires Microsoft Edge WebView2 to be installed.&#10;Click here to download it.</WEBVIEW2_NOT_AVAILABLE>
62+
<MW_ViewSourceCode>View Source Code</MW_ViewSourceCode>
4863
</en>
4964
<ko>
5065
<WEBVIEW2_NOT_AVAILABLE>이 파일을 보려면 Microsoft Edge WebView2를 설치해야 합니다.&#10;여기를 클릭하여 다운로드하세요.</WEBVIEW2_NOT_AVAILABLE>
66+
<MW_ViewSourceCode>소스 코드 보기</MW_ViewSourceCode>
5167
</ko>
5268
<de>
5369
<WEBVIEW2_NOT_AVAILABLE>Für das Anzeigen dieses Dateityps wird MS Edge WebView2 benötigt.&#10;Hier klicken zum Downloaden.</WEBVIEW2_NOT_AVAILABLE>
70+
<MW_ViewSourceCode>Quellcode anzeigen</MW_ViewSourceCode>
5471
</de>
5572
<fr>
5673
<WEBVIEW2_NOT_AVAILABLE>Microsoft Edge WebView2 est requis pour afficher ce type de fichier.&#10;Cliquez ici pour le télécharger.</WEBVIEW2_NOT_AVAILABLE>
74+
<MW_ViewSourceCode>Voir le code source</MW_ViewSourceCode>
5775
</fr>
5876
<ja>
5977
<WEBVIEW2_NOT_AVAILABLE>このファイルを閲覧するには、Microsoft Edge WebView2 がインストールされている必要があります。&#10;ここをクリックしてダウンロードを開始する。</WEBVIEW2_NOT_AVAILABLE>
78+
<MW_ViewSourceCode>ソースコードを表示</MW_ViewSourceCode>
6079
</ja>
6180
<zh-CN>
6281
<WEBVIEW2_NOT_AVAILABLE>查看此文件需要安装 Microsoft Edge WebView2。&#10;点击这里开始下载。</WEBVIEW2_NOT_AVAILABLE>
82+
<MW_ViewSourceCode>查看源代码</MW_ViewSourceCode>
6383
</zh-CN>
6484
<zh-TW>
6585
<WEBVIEW2_NOT_AVAILABLE>查看此文件需要安裝 Microsoft Edge WebView2。&#10;點擊這裡開始下載。</WEBVIEW2_NOT_AVAILABLE>
86+
<MW_ViewSourceCode>查看原始碼</MW_ViewSourceCode>
6687
</zh-TW>
6788
<es>
6889
<WEBVIEW2_NOT_AVAILABLE>Es necesario tener instalado Microsoft Edge WebView2 para ver este fichero.&#10;Haga clic aquí para descargarlo.</WEBVIEW2_NOT_AVAILABLE>
90+
<MW_ViewSourceCode>Ver código fuente</MW_ViewSourceCode>
6991
</es>
7092
<it>
7193
<WEBVIEW2_NOT_AVAILABLE>Visualizzare questo file richiede che Microsoft Edge WebView2 sia installato.&#10;Clicca qui per scaricarlo.</WEBVIEW2_NOT_AVAILABLE>
94+
<MW_ViewSourceCode>Visualizza codice sorgente</MW_ViewSourceCode>
7295
</it>
7396
<ar>
7497
<WEBVIEW2_NOT_AVAILABLE>مطلوب لعرض هذا الملف. انقر هنا لتحميله Microsoft Edge WebView2</WEBVIEW2_NOT_AVAILABLE>
98+
<MW_ViewSourceCode>عرض الكود المصدري</MW_ViewSourceCode>
7599
</ar>
76100
<pl>
77101
<WEBVIEW2_NOT_AVAILABLE>Wyświetlenie tego pliku wymaga zainstalowania Microsoft Edge WebView2.&#10;Kliknij tutaj, aby go pobrać.</WEBVIEW2_NOT_AVAILABLE>
102+
<MW_ViewSourceCode>Wyświetl kod źródłowy</MW_ViewSourceCode>
78103
</pl>
79104
<el>
80105
<WEBVIEW2_NOT_AVAILABLE>Για την προβολή αυτού του αρχείου απαιτείται εγκατάσταση του Microsoft Edge WebView2.&#10;Κάντε κλικ εδώ για να το κατεβάσετε.</WEBVIEW2_NOT_AVAILABLE>
106+
<MW_ViewSourceCode>Προβολή πηγαίου κώδικα</MW_ViewSourceCode>
81107
</el>
82108
<uk-UA>
83109
<WEBVIEW2_NOT_AVAILABLE>Для перегляду цього файлу потрібно встановити Microsoft Edge WebView2.&#10;Натисніть тут, щоб завантажити його.</WEBVIEW2_NOT_AVAILABLE>
110+
<MW_ViewSourceCode>Переглянути вихідний код</MW_ViewSourceCode>
84111
</uk-UA>
85112
<sv>
86113
<WEBVIEW2_NOT_AVAILABLE>För att visa denna fil krävs att Microsoft Edge WebView2 är installerat.&#10;Klicka här för att ladda ner det.</WEBVIEW2_NOT_AVAILABLE>
114+
<MW_ViewSourceCode>Visa källkod</MW_ViewSourceCode>
87115
</sv>
88116
</Translations>

0 commit comments

Comments
 (0)