Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorMikayla Hutchinson <m.j.hutchinson@gmail.com>2019-01-19 07:04:21 +0300
committerMikayla Hutchinson <m.j.hutchinson@gmail.com>2019-01-19 13:36:04 +0300
commit334d430ff90f9a0683c0cc5e49f2d0a500838346 (patch)
tree3c9eb1284b0dda197ba5b83c5ee7f9e8f3620a5a /main/src
parentb720ddf0c7b70d0e5a25f1dd1b0475ec205c9d5e (diff)
[Ide] Add MimeType<->ContentType lookups
Diffstat (limited to 'main/src')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/MimeTypes.cs53
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Extensions/MimeTypeNode.cs11
2 files changed, 36 insertions, 28 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/MimeTypes.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/MimeTypes.cs
index 18f5d461a7..03757227a5 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/MimeTypes.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/MimeTypes.cs
@@ -28,11 +28,8 @@
using System;
using System.Collections.Generic;
-using Microsoft.VisualStudio.Platform;
-using Microsoft.VisualStudio.Utilities;
using Mono.Addins;
using MonoDevelop.Core;
-using MonoDevelop.Ide.Composition;
using MonoDevelop.Ide.Extensions;
namespace MonoDevelop.Ide.Desktop
@@ -41,8 +38,8 @@ namespace MonoDevelop.Ide.Desktop
{
public static MimeTypes Instance { get; } = new MimeTypes ();
- MimeTypeNode textPlainNode = new MimeTypeNode ("text/plain", null, GettextCatalog.GetString ("Text document"), null, true);
- MimeTypeNode xmlNode = new MimeTypeNode ("application/xml", null, GettextCatalog.GetString ("XML document"), null, true);
+ readonly MimeTypeNode textPlainNode = new MimeTypeNode ("text/plain", null, GettextCatalog.GetString ("Text document"), null, true, "text");
+ readonly MimeTypeNode xmlNode = new MimeTypeNode ("application/xml", null, GettextCatalog.GetString ("XML document"), null, true, null);
List<MimeTypeNode> mimeTypeNodes = new List<MimeTypeNode> ();
@@ -73,29 +70,11 @@ namespace MonoDevelop.Ide.Desktop
if (mt.Id == type)
return mt;
}
-
- return new MimeTypeNode (type, null, null, null, type.StartsWith ("text/", StringComparison.Ordinal));
+ return null;
}
- Lazy<IFileToContentTypeService> fileToContentTypeService = CompositionManager.GetExport<IFileToContentTypeService> ();
-
public MimeTypeNode FindMimeTypeForFile (string fileName)
{
- try {
- IContentType contentType = fileToContentTypeService.Value.GetContentTypeForFilePath (fileName);
- if (contentType != PlatformCatalog.Instance.ContentTypeRegistryService.UnknownContentType) {
- string mimeType = PlatformCatalog.Instance.MimeToContentTypeRegistryService.GetMimeType (contentType);
- if (mimeType != null) {
- MimeTypeNode mt = FindMimeType (mimeType);
- if (mt != null) {
- return mt;
- }
- }
- }
- } catch (Exception ex) {
- LoggingService.LogError ("IFilePathToContentTypeProvider query failed", ex);
- }
-
foreach (MimeTypeNode mt in mimeTypeNodes) {
if (mt.SupportsFile (fileName))
return mt;
@@ -195,5 +174,31 @@ namespace MonoDevelop.Ide.Desktop
}
return null;
}
+
+ MimeTypeNode GetMimeTypeNodeForContentType (string contentType)
+ {
+ foreach (var mt in mimeTypeNodes) {
+ if (mt.ContentType == contentType)
+ return mt;
+ }
+ return null;
+ }
+
+ public string GetMimeTypeForContentType (string contentType)
+ => GetMimeTypeNodeForContentType (contentType)?.Id;
+
+ public IEnumerable<string> GetMimeTypeInheritanceChainForContentType (string contentType)
+ => GetMimeTypeInheritanceChain (GetMimeTypeNodeForContentType (contentType));
+
+ public string GetContentTypeForMimeType (string mimeType)
+ {
+ var node = FindMimeType (mimeType);
+ foreach (var mt in GetMimeTypeNodeInheritanceChain (node)) {
+ if (node.ContentType != null) {
+ return node.ContentType;
+ }
+ }
+ return null;
+ }
}
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Extensions/MimeTypeNode.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Extensions/MimeTypeNode.cs
index b6686066ea..acc8fcbc7e 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Extensions/MimeTypeNode.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Extensions/MimeTypeNode.cs
@@ -32,7 +32,6 @@ using System.Text.RegularExpressions;
using Mono.Addins;
using MonoDevelop.Core;
-
namespace MonoDevelop.Ide.Extensions
{
[ExtensionNodeChild (typeof(MimeTypeFileNode), "File")]
@@ -59,7 +58,10 @@ namespace MonoDevelop.Ide.Extensions
/// The name used by Roslyn to identify this language.
/// </summary>
[NodeAttribute ("roslynName", "The name used by Roslyn to identify this language", Required=false)]
- public string RoslynName { get; private set; }
+ public string RoslynName { get; private set; }
+
+ [NodeAttribute ("contentType", "The content type name used by the Visual Studio editor to identify this language", Required = false)]
+ public string ContentType { get; private set; }
IFileNameEvaluator regex;
@@ -83,13 +85,14 @@ namespace MonoDevelop.Ide.Extensions
//deserialization
MimeTypeNode () { }
- public MimeTypeNode (string id, string baseType, string description, string icon, bool isText)
+ public MimeTypeNode (string id, string baseType, string description, string icon, bool isText, string contentType)
{
overrideId = id;
this.baseType = baseType;
- this.Description = description;
+ Description = description;
this.icon = icon;
this.isText = isText;
+ ContentType = contentType;
}
interface IFileNameEvaluator