mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 02:09:05 +00:00
load syntax files from plugin directory
This commit is contained in:
@@ -15,9 +15,14 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// 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 System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Xml;
|
||||||
using ICSharpCode.AvalonEdit.Highlighting;
|
using ICSharpCode.AvalonEdit.Highlighting;
|
||||||
|
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
|
||||||
using QuickLook.Common.Plugin;
|
using QuickLook.Common.Plugin;
|
||||||
|
|
||||||
namespace QuickLook.Plugin.TextViewer
|
namespace QuickLook.Plugin.TextViewer
|
||||||
@@ -30,6 +35,26 @@ namespace QuickLook.Plugin.TextViewer
|
|||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
|
HighlightingManager hlm = HighlightingManager.Instance;
|
||||||
|
|
||||||
|
string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||||
|
if (string.IsNullOrEmpty(assemblyPath)) return;
|
||||||
|
|
||||||
|
string syntaxPath = Path.Combine(assemblyPath, "Syntax");
|
||||||
|
if (!Directory.Exists(syntaxPath)) return;
|
||||||
|
|
||||||
|
foreach (string file in Directory.EnumerateFiles(syntaxPath, "*.xshd"))
|
||||||
|
{
|
||||||
|
string lang = Path.GetFileNameWithoutExtension(file);
|
||||||
|
using (Stream s = File.OpenRead(Path.GetFullPath(file)))
|
||||||
|
using (XmlTextReader reader = new XmlTextReader(s))
|
||||||
|
{
|
||||||
|
XshdSyntaxDefinition xshd = HighlightingLoader.LoadXshd(reader);
|
||||||
|
IHighlightingDefinition highlightingDefinition = HighlightingLoader.Load(xshd, hlm);
|
||||||
|
if (xshd.Extensions.Count > 0)
|
||||||
|
hlm.RegisterHighlighting(lang, xshd.Extensions.ToArray(), highlightingDefinition);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanHandle(string path)
|
public bool CanHandle(string path)
|
||||||
|
@@ -65,6 +65,7 @@
|
|||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xaml" />
|
<Reference Include="System.Xaml" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="UtfUnknown, Version=1.0.0.0, Culture=neutral, PublicKeyToken=90217ce7a23260d4, processorArchitecture=MSIL">
|
<Reference Include="UtfUnknown, Version=1.0.0.0, Culture=neutral, PublicKeyToken=90217ce7a23260d4, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\UTF.Unknown.1.0.0-beta1\lib\net40\UtfUnknown.dll</HintPath>
|
<HintPath>..\..\packages\UTF.Unknown.1.0.0-beta1\lib\net40\UtfUnknown.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
Reference in New Issue
Block a user