Skip to content

Commit 432b3b0

Browse files
committed
Add cross-plugin 'Reopen as' menu for SVG and HTML
Introduces 'Reopen as source code' and 'Reopen as image preview' options in the MoreMenu for SVG and HTML files, enabling users to switch between ImageViewer and TextViewer plugins. Updates translation files to support new menu items in multiple languages and refactors related plugin code for extensibility.
1 parent f7c029f commit 432b3b0

9 files changed

Lines changed: 193 additions & 32 deletions

File tree

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,21 @@
2121
using System.Collections.Generic;
2222
using System.IO;
2323
using System.Reflection;
24-
using System.Windows.Input;
2524

2625
namespace QuickLook.Plugin.HtmlViewer;
2726

2827
public partial class Plugin
2928
{
30-
public ICommand ViewSourceCodeCommand { get; }
31-
32-
public Plugin()
33-
{
34-
ViewSourceCodeCommand = new RelayCommand(ViewSourceCode);
35-
}
36-
3729
public IEnumerable<IMenuItem> GetMenuItems()
3830
{
3931
string translationFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Translations.config");
4032

33+
// HTML <=> HTML TEXT
4134
yield return new MoreMenuItem()
4235
{
4336
Icon = "\uE943",
4437
Header = TranslationHelper.Get("MW_ReopenAsSourceCode", translationFile),
45-
Command = ViewSourceCodeCommand,
38+
Command = new RelayCommand(() => PluginHelper.InvokePluginPreview("QuickLook.Plugin.TextViewer", _currentPath)),
4639
};
4740
}
48-
49-
public void ViewSourceCode()
50-
{
51-
PluginHelper.InvokePluginPreview("QuickLook.Plugin.TextViewer", _currentPath);
52-
}
5341
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
25+
namespace QuickLook.Plugin.ImageViewer;
26+
27+
public partial class Plugin
28+
{
29+
public IEnumerable<IMenuItem> GetMenuItems()
30+
{
31+
string translationFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Translations.config");
32+
string extension = Path.GetExtension(_currentPath).ToLower();
33+
34+
var reopen = extension switch
35+
{
36+
// SVG IMAGE <=> XML TEXT
37+
".svg" => new MoreMenuItem()
38+
{
39+
Icon = "\uE943",
40+
Header = TranslationHelper.Get("MW_ReopenAsSourceCode", translationFile),
41+
Command = new RelayCommand(() => PluginHelper.InvokePluginPreview("QuickLook.Plugin.TextViewer", _currentPath)),
42+
},
43+
_ => null,
44+
};
45+
46+
if (reopen is not null)
47+
yield return reopen;
48+
}
49+
}

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
using QuickLook.Common.Helpers;
1919
using QuickLook.Common.Plugin;
20+
using QuickLook.Common.Plugin.MoreMenu;
2021
using QuickLook.Plugin.ImageViewer.AnimatedImage.Providers;
2122
using QuickLook.Plugin.ImageViewer.Webview;
2223
using System;
@@ -28,7 +29,7 @@
2829

2930
namespace QuickLook.Plugin.ImageViewer;
3031

31-
public class Plugin : IViewer
32+
public partial class Plugin : IViewer, IMoreMenu
3233
{
3334
private static readonly HashSet<string> WellKnownExtensions = new(
3435
[
@@ -56,13 +57,16 @@ public class Plugin : IViewer
5657
]);
5758

5859
private ImagePanel _ip;
60+
private string _currentPath;
5961
private MetaProvider _meta;
6062

6163
private IWebImagePanel _ipWeb;
6264
private IWebMetaProvider _metaWeb;
6365

6466
public int Priority => 0;
6567

68+
public IEnumerable<IMenuItem> MenuItems => GetMenuItems();
69+
6670
public void Init()
6771
{
6872
// Option of UseColorProfile:
@@ -137,6 +141,8 @@ public void Prepare(string path, ContextObject context)
137141

138142
public void View(string path, ContextObject context)
139143
{
144+
_currentPath = path;
145+
140146
if (WebHandler.TryView(path, context, _metaWeb, out _ipWeb))
141147
return;
142148

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/QuickLook.Plugin.ImageViewer.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,10 @@
138138
</Compile>
139139
</ItemGroup>
140140

141+
<ItemGroup>
142+
<None Update="Translations.config">
143+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
144+
</None>
145+
</ItemGroup>
146+
141147
</Project>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<Translations>
4+
<ca>
5+
<MW_ReopenAsSourceCode>Torna a obrir com a codi font</MW_ReopenAsSourceCode>
6+
</ca>
7+
<he>
8+
<MW_ReopenAsSourceCode>פתח מחדש כקוד מקור</MW_ReopenAsSourceCode>
9+
</he>
10+
<hi>
11+
<MW_ReopenAsSourceCode>सोर्स कोड के रूप में पुनः खोलें</MW_ReopenAsSourceCode>
12+
</hi>
13+
<hu-HU>
14+
<MW_ReopenAsSourceCode>Újranyitás forráskódként</MW_ReopenAsSourceCode>
15+
</hu-HU>
16+
<id-ID>
17+
<MW_ReopenAsSourceCode>Buka ulang sebagai kode sumber</MW_ReopenAsSourceCode>
18+
</id-ID>
19+
<mr>
20+
<MW_ReopenAsSourceCode>स्रोत कोड म्हणून पुन्हा उघडा</MW_ReopenAsSourceCode>
21+
</mr>
22+
<nb-NO>
23+
<MW_ReopenAsSourceCode>Åpne på nytt som kildekode</MW_ReopenAsSourceCode>
24+
</nb-NO>
25+
<nl-NL>
26+
<MW_ReopenAsSourceCode>Opnieuw openen als broncode</MW_ReopenAsSourceCode>
27+
</nl-NL>
28+
<pt-BR>
29+
<MW_ReopenAsSourceCode>Reabrir como código-fonte</MW_ReopenAsSourceCode>
30+
</pt-BR>
31+
<pt-PT>
32+
<MW_ReopenAsSourceCode>Reabrir como código-fonte</MW_ReopenAsSourceCode>
33+
</pt-PT>
34+
<ru-RU>
35+
<MW_ReopenAsSourceCode>Открыть заново как исходный код</MW_ReopenAsSourceCode>
36+
</ru-RU>
37+
<sk>
38+
<MW_ReopenAsSourceCode>Znovu otvoriť ako zdrojový kód</MW_ReopenAsSourceCode>
39+
</sk>
40+
<tr-TR>
41+
<MW_ReopenAsSourceCode>Kaynak kod olarak yeniden aç</MW_ReopenAsSourceCode>
42+
</tr-TR>
43+
<vi>
44+
<MW_ReopenAsSourceCode>Mở lại dưới dạng mã nguồn</MW_ReopenAsSourceCode>
45+
</vi>
46+
<en>
47+
<MW_ReopenAsSourceCode>Reopen as source code</MW_ReopenAsSourceCode>
48+
</en>
49+
<ko>
50+
<MW_ReopenAsSourceCode>소스 코드로 다시 열기</MW_ReopenAsSourceCode>
51+
</ko>
52+
<de>
53+
<MW_ReopenAsSourceCode>Als Quellcode erneut öffnen</MW_ReopenAsSourceCode>
54+
</de>
55+
<fr>
56+
<MW_ReopenAsSourceCode>Rouvrir en tant que code source</MW_ReopenAsSourceCode>
57+
</fr>
58+
<ja>
59+
<MW_ReopenAsSourceCode>ソースコードとして再度開く</MW_ReopenAsSourceCode>
60+
</ja>
61+
<zh-CN>
62+
<MW_ReopenAsSourceCode>以源代码方式重新打开</MW_ReopenAsSourceCode>
63+
</zh-CN>
64+
<zh-TW>
65+
<MW_ReopenAsSourceCode>以原始碼方式重新開啟</MW_ReopenAsSourceCode>
66+
</zh-TW>
67+
<es>
68+
<MW_ReopenAsSourceCode>Reabrir como código fuente</MW_ReopenAsSourceCode>
69+
</es>
70+
<it>
71+
<MW_ReopenAsSourceCode>Riapri come codice sorgente</MW_ReopenAsSourceCode>
72+
</it>
73+
<ar>
74+
<MW_ReopenAsSourceCode>إعادة الفتح كرمز مصدر</MW_ReopenAsSourceCode>
75+
</ar>
76+
<pl>
77+
<MW_ReopenAsSourceCode>Otwórz ponownie jako kod źródłowy</MW_ReopenAsSourceCode>
78+
</pl>
79+
<el>
80+
<MW_ReopenAsSourceCode>Επαναάνοιγμα ως πηγαίος κώδικας</MW_ReopenAsSourceCode>
81+
</el>
82+
<uk-UA>
83+
<MW_ReopenAsSourceCode>Відкрити знову як вихідний код</MW_ReopenAsSourceCode>
84+
</uk-UA>
85+
<sv>
86+
<MW_ReopenAsSourceCode>Öppna igen som källkod</MW_ReopenAsSourceCode>
87+
</sv>
88+
</Translations>

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,39 @@
2121
using System.Collections.Generic;
2222
using System.IO;
2323
using System.Reflection;
24-
using System.Windows.Input;
2524

2625
namespace QuickLook.Plugin.TextViewer;
2726

2827
public partial class Plugin
2928
{
30-
public ICommand ReopenAsHtmlPreviewCommand { get; }
31-
32-
public Plugin()
33-
{
34-
ReopenAsHtmlPreviewCommand = new RelayCommand(ReopenAsHtmlPreview);
35-
}
36-
3729
public IEnumerable<IMenuItem> GetMenuItems()
3830
{
3931
string translationFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Translations.config");
4032
string extension = Path.GetExtension(_currentPath).ToLower();
4133

4234
var reopen = extension switch
4335
{
36+
// HTML <=> HTML TEXT
4437
// \QuickLook\QuickLook.Plugin\QuickLook.Plugin.TextViewer\Syntax\Light\zzz-After-JavaScript-HTML.xshd
4538
// .html;.htm;.xhtml;.shtml;.shtm;.xht;.hta
4639
".html" or ".htm" or ".xhtml" or ".shtml" or ".shtm" or ".xht" or ".hta" => new MoreMenuItem()
4740
{
4841
Icon = "\uE774",
4942
Header = TranslationHelper.Get("MW_ReopenAsHtmlPreview", translationFile),
50-
Command = ReopenAsHtmlPreviewCommand,
43+
Command = new RelayCommand(() => PluginHelper.InvokePluginPreview("QuickLook.Plugin.HtmlViewer", _currentPath)),
5144
},
52-
_ => null
45+
46+
// SVG IMAGE <=> XML TEXT
47+
".svg" => new MoreMenuItem()
48+
{
49+
Icon = "\uE774",
50+
Header = TranslationHelper.Get("MW_ReopenAsImagePreview", translationFile),
51+
Command = new RelayCommand(() => PluginHelper.InvokePluginPreview("QuickLook.Plugin.ImageViewer", _currentPath)),
52+
},
53+
_ => null,
5354
};
5455

5556
if (reopen is not null)
5657
yield return reopen;
5758
}
58-
59-
public void ReopenAsHtmlPreview()
60-
{
61-
PluginHelper.InvokePluginPreview("QuickLook.Plugin.HtmlViewer", _currentPath);
62-
}
6359
}

QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Dark/XML.xshd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

3-
<SyntaxDefinition name="XML" extensions=".xml;.xsl;.xslt;.xsd;.syn;.lang;.manifest;.config;.addin;.xshd;.wxs;.wxi;.wxl;.proj;.csproj;.vbproj;.resx;.user;.ilproj;.booproj;.build;.xfrm;.targets;.axaml;.xaml;.xpt;.xft;.map;.wsdl;.disco;.ascx;.atom;.bpmn;.cpt;.csl;.props;.dotsettings;.slnx">
3+
<SyntaxDefinition name="XML" extensions=".xml;.xsl;.xslt;.xsd;.syn;.lang;.manifest;.config;.addin;.xshd;.wxs;.wxi;.wxl;.proj;.csproj;.vbproj;.resx;.user;.ilproj;.booproj;.build;.xfrm;.targets;.axaml;.xaml;.xpt;.xft;.map;.wsdl;.disco;.ascx;.atom;.bpmn;.cpt;.csl;.props;.dotsettings;.slnx;.svg">
44

55
<Environment>
66
<Default color="#D4D4D4" bgcolor="#1E1E1E"/>

QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/XML.xshd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

3-
<SyntaxDefinition name="XML" extensions=".xml;.xsl;.xslt;.xsd;.syn;.lang;.manifest;.config;.addin;.xshd;.wxs;.wxi;.wxl;.proj;.csproj;.vbproj;.resx;.user;.ilproj;.booproj;.build;.xfrm;.targets;.axaml;.xaml;.xpt;.xft;.map;.wsdl;.disco;.ascx;.atom;.bpmn;.cpt;.csl;.props;.dotsettings;.slnx">
3+
<SyntaxDefinition name="XML" extensions=".xml;.xsl;.xslt;.xsd;.syn;.lang;.manifest;.config;.addin;.xshd;.wxs;.wxi;.wxl;.proj;.csproj;.vbproj;.resx;.user;.ilproj;.booproj;.build;.xfrm;.targets;.axaml;.xaml;.xpt;.xft;.map;.wsdl;.disco;.ascx;.atom;.bpmn;.cpt;.csl;.props;.dotsettings;.slnx;.svg">
44

55
<Environment>
66
<Default color="Black" bgcolor="#FFFFFF"/>

0 commit comments

Comments
 (0)