From e19ceb2cdcc4e05e153b4db636a526638e6e6f9c Mon Sep 17 00:00:00 2001 From: WMJ Date: Sun, 16 Dec 2018 19:11:01 +0800 Subject: [PATCH] ! Detected supported files in Output Smart Bar --- Codist/Helpers/ServicesHelper.cs | 3 +++ Codist/SmartBars/OutputSmartBar.cs | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Codist/Helpers/ServicesHelper.cs b/Codist/Helpers/ServicesHelper.cs index 357100f1..380aba4a 100644 --- a/Codist/Helpers/ServicesHelper.cs +++ b/Codist/Helpers/ServicesHelper.cs @@ -28,6 +28,9 @@ private ServicesHelper() { [Import] public IClassificationTypeRegistryService ClassificationTypeRegistry { get; private set; } + [Import] + public Microsoft.VisualStudio.Utilities.IFileExtensionRegistryService FileExtensionRegistry { get; private set; } + [Import] public IEditorFormatMapService EditorFormatMap { get; private set; } diff --git a/Codist/SmartBars/OutputSmartBar.cs b/Codist/SmartBars/OutputSmartBar.cs index 32b6d1bc..3659824e 100644 --- a/Codist/SmartBars/OutputSmartBar.cs +++ b/Codist/SmartBars/OutputSmartBar.cs @@ -31,12 +31,14 @@ protected override void AddCommands(CancellationToken cancellationToken) { Process.Start("Explorer.exe", "/select,\"" + s + "\""); } }); - AddCommand(MyToolBar, KnownImageIds.VisualStudio, "Open file with Visual Studio", ctx => { - var s = TryGetPath(View); - if (s != null) { - CodistPackage.DTE.OpenFile(s, 1, 1); - } - }); + if (IsFileTypeRegisteredInVS(t)) { + AddCommand(MyToolBar, KnownImageIds.VisualStudio, "Open file with Visual Studio", ctx => { + var s = TryGetPath(View); + if (s != null && IsFileTypeRegisteredInVS(s)) { + CodistPackage.DTE.OpenFile(s, 1, 1); + } + }); + } } else if (Directory.Exists(t)) { AddCommand(MyToolBar, KnownImageIds.OpenFolder, "Open folder", ctx => { @@ -72,6 +74,14 @@ void TryRun(string path) { // ignore } } + bool IsFileTypeRegisteredInVS(string fileName) { + try { + return ServicesHelper.Instance.FileExtensionRegistry.GetContentTypeForExtension(Path.GetExtension(fileName)).TypeName != "UNKNOWN"; + } + catch (ArgumentException) { + return false; + } + } } } }