Repository navigation
Expand file tree
/
Copy pathPlugin.MoreMenu.cs
More file actions
100 lines (91 loc) · 3.76 KB
/
Copy pathPlugin.MoreMenu.cs
File metadata and controls
100 lines (91 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright © 2017-2026 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.Controls;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin.MoreMenu;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
namespace QuickLook.Plugin.TextViewer;
public sealed partial class Plugin
{
public IEnumerable<IMenuItem> GetMenuItems()
{
string translationFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Translations.config");
string extension = string.Empty;
try
{
// Get the file extension in lowercase for comparison
extension = Path.GetExtension(_currentPath).ToLower();
}
catch (Exception)
{
}
if (extension == ".txt" && _tvp is { } viewer)
{
var checkMark = new TextBlock
{
Text = "✓",
Visibility = viewer.ShowLineNumbers ? Visibility.Visible : Visibility.Hidden,
};
yield return new MoreMenuItem
{
Header = TranslationHelper.Get("Editor_ShowLineNumbers", translationFile),
Icon = checkMark,
Command = new RelayCommand(() =>
{
if (!ReferenceEquals(_tvp, viewer)) return;
viewer.ToggleLineNumbers();
checkMark.Visibility = viewer.ShowLineNumbers ? Visibility.Visible : Visibility.Hidden;
}),
};
}
var reopen = extension switch
{
// HTML <=> HTML TEXT
// \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 = FontSymbols.Globe,
Header = TranslationHelper.Get("MW_ReopenAsHtmlPreview", translationFile),
Command = new RelayCommand(() => PluginHelper.InvokePluginPreview("QuickLook.Plugin.HtmlViewer", _currentPath)),
},
// SVG IMAGE <=> XML TEXT
".svg" => new MoreMenuItem()
{
Icon = FontSymbols.Picture,
Header = TranslationHelper.Get("MW_ReopenAsImagePreview", translationFile),
Command = new RelayCommand(() => PluginHelper.InvokePluginPreview("QuickLook.Plugin.ImageViewer", _currentPath)),
},
// CSV, TSV, PSV <=> CSV viewer
".csv" or ".tsv" or ".psv" => new MoreMenuItem()
{
Icon = FontSymbols.Code,
Header = TranslationHelper.Get("MW_ReopenAsCsvPreview", translationFile),
Command = new RelayCommand(() => PluginHelper.InvokePluginPreview("QuickLook.Plugin.CsvViewer", _currentPath)),
},
_ => null,
};
if (reopen is not null)
yield return reopen;
}
}