diff options
author | Mikayla Hutchinson <m.j.hutchinson@gmail.com> | 2019-01-19 13:32:42 +0300 |
---|---|---|
committer | Mikayla Hutchinson <m.j.hutchinson@gmail.com> | 2019-01-19 13:36:06 +0300 |
commit | 7d99dbf29f04d037c9877d53928ae2b8816759eb (patch) | |
tree | f76977984135fd61e7b7bde462358caadb9acd75 /main/src | |
parent | fd97c718944fd978b5526a4708705dc47b107657 (diff) |
Replace IMimeToContentTypeRegistryService usage with MimeTypeCatalog
Diffstat (limited to 'main/src')
7 files changed, 95 insertions, 304 deletions
diff --git a/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor/TextViewContent.cs b/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor/TextViewContent.cs index 13a1a87f05..782802e211 100644 --- a/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor/TextViewContent.cs +++ b/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor/TextViewContent.cs @@ -34,7 +34,7 @@ using MonoDevelop.Projects; namespace MonoDevelop.TextEditor { - abstract partial class TextViewContent<TView,TImports> : ViewContent, INavigable + abstract partial class TextViewContent<TView, TImports> : ViewContent, INavigable where TView : ITextView where TImports : TextViewImports
{ @@ -60,15 +60,13 @@ namespace MonoDevelop.TextEditor this.fileName = fileName; this.mimeType = mimeType; this.ownerProject = ownerProject; - this.sourceEditorOptions = Ide.Editor.DefaultSourceEditorOptions.Instance; - - // FIXME: move this to the end of the .ctor after fixing margin options responsiveness - HandleSourceEditorOptionsChanged (this, EventArgs.Empty); - - //TODO: this can change when the file is renamed - var contentType = mimeType == null - ? Imports.TextBufferFactoryService.InertContentType - : GetContentTypeFromMimeType (fileName, mimeType); + this.sourceEditorOptions = Ide.Editor.DefaultSourceEditorOptions.Instance;
+
+ // FIXME: move this to the end of the .ctor after fixing margin options responsiveness
+ HandleSourceEditorOptionsChanged (this, EventArgs.Empty);
+
+ //TODO: this can change when the file is renamed
+ var contentType = GetContentTypeFromMimeType (fileName, mimeType); TextDocument = Imports.TextDocumentFactoryService.CreateAndLoadTextDocument (fileName, contentType); TextBuffer = TextDocument.TextBuffer; @@ -90,7 +88,7 @@ namespace MonoDevelop.TextEditor commandService = Imports.EditorCommandHandlerServiceFactory.GetService (TextView); contentProviders = new List<IEditorContentProvider> (Imports.EditorContentProviderService.GetContentProvidersForView (TextView)); - TextView.Properties [GetType ()] = this; + TextView.Properties[GetType ()] = this; ContentName = fileName; SubscribeToEvents (); @@ -197,28 +195,9 @@ namespace MonoDevelop.TextEditor static readonly string[] textContentType = { "text" }; IContentType GetContentTypeFromMimeType (string filePath, string mimeType) - { - if (filePath != null) { - var contentTypeFromPath = Imports.FileToContentTypeService.GetContentTypeForFilePath (filePath); - if (contentTypeFromPath != null && - contentTypeFromPath != Imports.ContentTypeRegistryService.UnknownContentType) { - return contentTypeFromPath; - } - } - - IContentType contentType = Imports.MimeToContentTypeRegistryService.GetContentType (mimeType); - if (contentType == null) { - // fallback 1: see if there is a content tyhpe with the same name - contentType = Imports.ContentTypeRegistryService.GetContentType (mimeType); - if (contentType == null) { - // No joy, create a content type that, by default, derives from text. This is strictly an error - // (there should be mappings between any mime type and any content type). - contentType = Imports.ContentTypeRegistryService.AddContentType (mimeType, textContentType); - } - } - - return contentType; - } + => Ide.MimeTypeCatalog.Instance.GetContentTypeForMimeType (mimeType)
+ ?? (fileName != null ? null : Ide.Composition.CompositionManager.GetExportedValue<IFileToContentTypeService> ().GetContentTypeForFilePath (fileName))
+ ?? Microsoft.VisualStudio.Platform.PlatformCatalog.Instance.ContentTypeRegistryService.UnknownContentType; void CaretPositionChanged (object sender, CaretPositionChangedEventArgs e) { diff --git a/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor/TextViewImports.cs b/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor/TextViewImports.cs index 62fd26a5b0..0dd13ca365 100644 --- a/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor/TextViewImports.cs +++ b/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor/TextViewImports.cs @@ -46,9 +46,6 @@ namespace MonoDevelop.TextEditor [Import] public IContentTypeRegistryService ContentTypeRegistryService { get; set; } - [Import] - public IMimeToContentTypeRegistryService MimeToContentTypeRegistryService { get; set; } - [ImportMany] public List<Lazy<ITextViewModelProvider, IContentTypeAndTextViewRoleMetadata>> TextViewModelProviders { get; set; } diff --git a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/Document/TextDocument.cs b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/Document/TextDocument.cs index a9787fb53a..8182dc4fa4 100644 --- a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/Document/TextDocument.cs +++ b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/Document/TextDocument.cs @@ -28,24 +28,21 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using Mono.TextEditor.Highlighting; -using Mono.TextEditor.Utils; +using System.IO; using System.Linq; -using System.ComponentModel; using System.Text; -using System.Threading.Tasks; using System.Threading; -using MonoDevelop.Ide.Composition;
+using System.Threading.Tasks; +using Microsoft.VisualStudio.Platform; +using Microsoft.VisualStudio.Text.Utilities; +using Microsoft.VisualStudio.Utilities;
+using Mono.TextEditor.Utils; +using MonoDevelop.Core; using MonoDevelop.Core.Text; +using MonoDevelop.Ide;
using MonoDevelop.Ide.Editor; -using MonoDevelop.Core; -using System.IO; using MonoDevelop.Ide.Editor.Highlighting; -using Microsoft.VisualStudio.Platform; -using Microsoft.VisualStudio.Text.Tagging; -using Microsoft.VisualStudio.Utilities;
-using Microsoft.VisualStudio.Text.Utilities; - +
namespace Mono.TextEditor {
class TextDocument : ITextDocument, IDisposable
@@ -54,59 +51,25 @@ namespace Mono.TextEditor public Microsoft.VisualStudio.Text.ITextBuffer TextBuffer { get { return this.VsTextDocument.TextBuffer; } }
Microsoft.VisualStudio.Text.ITextSnapshot currentSnapshot;
- bool lineEndingMismatch;
-
//HACK ImmutableText buffer;
//HACK readonly ILineSplitter splitter;
ISyntaxHighlighting syntaxMode = null;
-
- //HACK TextSourceVersionProvider versionProvider = new TextSourceVersionProvider ();
-
- bool readOnly;
- ReadOnlyCheckDelegate readOnlyCheckDelegate;
+ string mimeType;
public string MimeType {
get {
- var snapshot = this.TextBuffer.CurrentSnapshot;
- return PlatformCatalog.Instance.MimeToContentTypeRegistryService.GetMimeType(snapshot.ContentType) ?? snapshot.ContentType.TypeName;
+ return mimeType ?? MimeTypeCatalog.TextPlain;
}
set {
- var newContentType = value != null ? GetContentTypeFromMimeType(null, value) : PlatformCatalog.Instance.ContentTypeRegistryService.UnknownContentType; -
- if (this.TextBuffer.CurrentSnapshot.ContentType != newContentType) {
- this.TextBuffer.ChangeContentType(newContentType, null);
- }
- }
- }
-
- private static IContentType GetContentTypeFromMimeType(string filePath, string mimeType)
- {
- if (filePath != null) - {
- var fileToContentTypeService = CompositionManager.GetExportedValue<IFileToContentTypeService> ();
- var contentTypeFromPath = fileToContentTypeService.GetContentTypeForFilePath (filePath);
- if (contentTypeFromPath != null && - contentTypeFromPath != PlatformCatalog.Instance.ContentTypeRegistryService.UnknownContentType) - {
- return contentTypeFromPath;
+ var newContentType = MimeTypeCatalog.Instance.GetContentTypeForMimeType (value) ?? PlatformCatalog.Instance.ContentTypeRegistryService.UnknownContentType;
+ if (TextBuffer.CurrentSnapshot.ContentType != newContentType) {
+ TextBuffer.ChangeContentType (newContentType, null);
}
- }
-
- IContentType contentType = PlatformCatalog.Instance.MimeToContentTypeRegistryService.GetContentType (mimeType); - if (contentType == null)
- {
- // fallback 1: see if there is a content tyhpe with the same name
- contentType = PlatformCatalog.Instance.ContentTypeRegistryService.GetContentType(mimeType);
- if (contentType == null)
- {
- // No joy, create a content type that, by default, derives from text. This is strictly an error
- // (there should be mappings between any mime type and any content type).
- contentType = PlatformCatalog.Instance.ContentTypeRegistryService.AddContentType(mimeType, new string[] { "text" });
+ if (mimeType != value) {
+ MimeTypeChanged?.Invoke (this, EventArgs.Empty);
}
}
-
- return contentType;
}
public event EventHandler MimeTypeChanged;
@@ -216,14 +179,7 @@ namespace Mono.TextEditor set;
}
- public bool HasLineEndingMismatchOnTextSet {
- get {
- return lineEndingMismatch;
- }
- set {
- lineEndingMismatch = value;
- }
- }
+ public bool HasLineEndingMismatchOnTextSet { get; set; }
protected void Initialize()
{
@@ -273,7 +229,7 @@ namespace Mono.TextEditor var textChange = new TextChangeEventArgs(changes); InterruptFoldWorker(); - TextChanging?.Invoke(this, textChange); + TextChanging?.Invoke (this, textChange); // After TextChanging notification has been sent, we can update the cached snapshot
this.currentSnapshot = args.After; }
@@ -332,34 +288,34 @@ namespace Mono.TextEditor { if (e.Node.IsCollapsed) foldedSegments.Remove (e.Node); - } - - public TextDocument (string fileName, string mimeType)
- {
- var contentType = (mimeType == null) ? PlatformCatalog.Instance.TextBufferFactoryService.InertContentType : GetContentTypeFromMimeType(fileName, mimeType);
- Encoding enc;
- var text = TextFileUtility.GetText (fileName, out enc);
- var buffer = PlatformCatalog.Instance.TextBufferFactoryService.CreateTextBuffer (text ?? string.Empty, - contentType); - - this.VsTextDocument = PlatformCatalog.Instance.TextDocumentFactoryService.CreateTextDocument (buffer, fileName); - this.VsTextDocument.Encoding = enc; -
- this.Initialize();
}
+ public TextDocument (string fileName, string mimeType) : this (
+ TextFileUtility.GetText (fileName, out var enc),
+ fileName,
+ mimeType
+ ) {}
+
public TextDocument (string text = null, string fileName = null, string mimeType = null)
{
- var contentType = (mimeType == null) ? PlatformCatalog.Instance.TextBufferFactoryService.InertContentType : GetContentTypeFromMimeType(fileName, mimeType);
- var buffer = PlatformCatalog.Instance.TextBufferFactoryService.CreateTextBuffer (text ?? string.Empty,
- contentType);
+ VsTextDocument = PlatformCatalog.Instance.TextDocumentFactoryService.CreateTextDocument (
+ PlatformCatalog.Instance.TextBufferFactoryService.CreateTextBuffer (
+ text ?? string.Empty,
+ GetContentTypeFromMimeType (fileName, mimeType)
+ ),
+ fileName ?? string.Empty
+ );
- this.VsTextDocument = PlatformCatalog.Instance.TextDocumentFactoryService.CreateTextDocument(buffer, fileName ?? string.Empty);
- this.VsTextDocument.Encoding = TextFileUtility.DefaultEncoding;
+ VsTextDocument.Encoding = TextFileUtility.DefaultEncoding;
- this.Initialize();
+ Initialize();
}
+ IContentType GetContentTypeFromMimeType (string fileName, string mimeType) + => MimeTypeCatalog.Instance.GetContentTypeForMimeType (mimeType)
+ ?? (fileName != null ? null : MonoDevelop.Ide.Composition.CompositionManager.GetExportedValue<IFileToContentTypeService> ().GetContentTypeForFilePath (fileName))
+ ?? PlatformCatalog.Instance.ContentTypeRegistryService.UnknownContentType;
+
public static TextDocument CreateImmutableDocument (string text, bool suppressHighlighting = true) { return new TextDocument (text) { @@ -1856,25 +1812,15 @@ namespace Mono.TextEditor get { return updateRequests; } - } - // Use CanEdit (int lineNumber) instead for getting a request - // if a part of a document can be read. ReadOnly should generally not be used - // for deciding, if a document is readonly or not. - public bool IsReadOnly { - get { - return readOnly; - } - set { - readOnly = value; - } - } - - public ReadOnlyCheckDelegate ReadOnlyCheckDelegate { - get { return readOnlyCheckDelegate; } - set { readOnlyCheckDelegate = value; } - } - - + }
+ // Use CanEdit (int lineNumber) instead for getting a request
+ // if a part of a document can be read. ReadOnly should generally not be used
+ // for deciding, if a document is readonly or not.
+ public bool IsReadOnly { get; set; }
+
+ public ReadOnlyCheckDelegate ReadOnlyCheckDelegate { get; set; }
+
+
public void RequestUpdate (DocumentUpdateRequest request) { lock (syncObject) { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/PlatformCatalog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/PlatformCatalog.cs index 80b307cd7b..c4b938643d 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/PlatformCatalog.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/PlatformCatalog.cs @@ -30,7 +30,8 @@ using Microsoft.VisualStudio.Utilities; namespace Microsoft.VisualStudio.Platform
{
[Export]
- public class PlatformCatalog
+ // TODO: editor obsolete
+ internal class PlatformCatalog
{
static PlatformCatalog instance;
public static PlatformCatalog Instance {
@@ -52,9 +53,6 @@ namespace Microsoft.VisualStudio.Platform internal ITextDocumentFactoryService TextDocumentFactoryService { get; private set; }
[Import]
- internal IMimeToContentTypeRegistryService MimeToContentTypeRegistryService { get; private set; }
-
- [Import]
internal IContentTypeRegistryService ContentTypeRegistryService { get; private set; }
[Import]
@@ -67,82 +65,9 @@ namespace Microsoft.VisualStudio.Platform internal IViewClassifierAggregatorService ViewClassifierAggregatorService { get; private set; }
}
- public interface IMimeToContentTypeRegistryService
- {
- string GetMimeType(IContentType type);
- IContentType GetContentType(string type);
-
- void LinkTypes(string mimeType, IContentType contentType);
- }
-
- [Export(typeof(IMimeToContentTypeRegistryService))]
- public class MimeToContentTypeRegistryService : IMimeToContentTypeRegistryService, IPartImportsSatisfiedNotification
- {
- [Import]
- IContentTypeRegistryService ContentTypeRegistryService { get; set; }
-
- [Export]
- [Name ("csharp")]
- [BaseDefinition ("code")]
- public ContentTypeDefinition codeContentType;
-
- public string GetMimeType(IContentType type)
- {
- string mimeType;
- if (this.maps.Item2.TryGetValue(type, out mimeType))
- {
- return mimeType;
- }
-
- return (ContentTypeRegistryService as IContentTypeRegistryService2).GetMimeType (type);
- }
-
- public IContentType GetContentType(string type)
- {
- IContentType contentType;
- if (this.maps.Item1.TryGetValue(type, out contentType))
- {
- return contentType;
- }
-
- return (ContentTypeRegistryService as IContentTypeRegistryService2).GetContentTypeForMimeType (type);
- }
-
- public void LinkTypes(string mimeType, IContentType contentType)
- {
- var oldMap = Volatile.Read(ref this.maps);
- while (true)
- {
- if (oldMap.Item1.ContainsKey(mimeType) || oldMap.Item2.ContainsKey(contentType))
- break;
-
- var newMap = Tuple.Create(oldMap.Item1.Add(mimeType, contentType), oldMap.Item2.Add(contentType, mimeType));
- var result = Interlocked.CompareExchange(ref this.maps, newMap, oldMap);
- if (result == oldMap)
- {
- break;
- }
-
- oldMap = result;
- }
- }
-
- void LinkTypes (string mimeType, string contentType)
- {
- LinkTypes (mimeType, ContentTypeRegistryService.GetContentType (contentType));
- }
-
- void IPartImportsSatisfiedNotification.OnImportsSatisfied ()
- {
- LinkTypes ("text/plain", "text");
- LinkTypes ("text/x-csharp", "csharp");
- }
-
- Tuple<ImmutableDictionary<string, IContentType>, ImmutableDictionary<IContentType, string>> maps = Tuple.Create(ImmutableDictionary<string, IContentType>.Empty, ImmutableDictionary<IContentType, string>.Empty);
- }
-
// Fold back into Text.Def.TextData.TextSnapshotToTextReader
- public sealed class NewTextSnapshotToTextReader : TextReader
+ // TODO: editor obsolete
+ internal sealed class NewTextSnapshotToTextReader : TextReader
{
#region TextReader methods
/// <summary>
@@ -324,69 +249,4 @@ namespace Microsoft.VisualStudio.Platform int _end;
}
-
-#if false
- [Export(typeof(ITaggerProvider))]
- [ContentType("text")]
- [TagType(typeof(IClassificationTag))]
- public class TestClassifierProvider : ITaggerProvider
- {
- [Import]
- internal IClassificationTypeRegistryService ClassificationTypeRegistryService { get; private set; }
-
- [Export]
- [Name("keyword")]
- public ClassificationTypeDefinition textClassificationType;
-
- public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
- {
- return buffer.Properties.GetOrCreateSingletonProperty(typeof(TestClassifier), () => new TestClassifier(this)) as ITagger<T>;
- }
- }
-
- public class TestClassifier : ITagger<IClassificationTag>
- {
- private ClassificationTag _keyword { get; }
-
- public TestClassifier(TestClassifierProvider provider)
- {
- _keyword = new ClassificationTag(provider.ClassificationTypeRegistryService.GetClassificationType("keyword"));
- }
-
- public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanCollection spans)
- {
- foreach (var span in spans)
- {
- int start = -1;
- for (int i = span.Start; (i < span.End); ++i)
- {
- var c = span.Snapshot[i];
- if ((c == 'a') || (c == 'A'))
- {
- if (start == -1)
- {
- start = i;
- }
- }
- else if (start != -1)
- {
- yield return new TagSpan<ClassificationTag>(
- new SnapshotSpan(span.Snapshot, start, i - start),
- _keyword);
- start = -1;
- }
- }
-
- if (start != -1)
- {
- yield return new TagSpan<ClassificationTag>(
- new SnapshotSpan(span.Snapshot, start, span.End - start),
- _keyword);
- }
- }
- }
-
- public event EventHandler<SnapshotSpanEventArgs> TagsChanged;
- }
-#endif
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj index 6269e01745..2125705f3f 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj @@ -4281,6 +4281,7 @@ <InternalsVisibleTo Include="MonoDevelop.Refactoring.Tests" /> <InternalsVisibleTo Include="MonoDevelop.SourceEditor" /> <InternalsVisibleTo Include="MonoDevelop.SourceEditor2" /> + <InternalsVisibleTo Include="MonoDevelop.TextEditor" /> <InternalsVisibleTo Include="MonoDevelop.TextEditor.Tests" /> <InternalsVisibleTo Include="MonoDevelop.UnitTesting" /> <InternalsVisibleTo Include="MonoDevelop.VBNetBinding" /> diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/DesktopService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/DesktopService.cs index e1ffc4319a..ddf38b4be9 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/DesktopService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/DesktopService.cs @@ -26,14 +26,15 @@ using System; using System.Collections.Generic; -using Mono.Addins; -using MonoDevelop.Ide.Desktop; -using MonoDevelop.Core; using System.IO; +using System.Threading.Tasks; +using Microsoft.VisualStudio.Utilities;
+using Mono.Addins; using MonoDevelop.Components; using MonoDevelop.Components.MainToolbar; +using MonoDevelop.Core; +using MonoDevelop.Ide.Desktop; using MonoDevelop.Ide.Fonts; -using System.Threading.Tasks; namespace MonoDevelop.Ide { @@ -163,13 +164,13 @@ namespace MonoDevelop.Ide public static string GetRoslynLanguageForMimeType (string mimeType) => MimeTypeCatalog.Instance.GetRoslynLanguageForMimeType (mimeType); - public static string GetMimeTypeForContentType (string contentType) + public static string GetMimeTypeForContentType (IContentType contentType) => MimeTypeCatalog.Instance.GetMimeTypeForContentType (contentType); - public static IEnumerable<string> GetMimeTypeInheritanceChainForContentType (string contentType) + public static IEnumerable<string> GetMimeTypeInheritanceChainForContentType (IContentType contentType) => MimeTypeCatalog.Instance.GetMimeTypeInheritanceChainForContentType (contentType); - public static string GetContentTypeForMimeType (string mimeType) + public static IContentType GetContentTypeForMimeType (string mimeType) => MimeTypeCatalog.Instance.GetContentTypeForMimeType (mimeType); public static string GetMimeTypeForUri (string uri) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/MimeTypeCatalog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/MimeTypeCatalog.cs index 8359fc833d..f788ad6a8a 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/MimeTypeCatalog.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/MimeTypeCatalog.cs @@ -24,6 +24,8 @@ using System;
using System.Collections.Generic; +using Microsoft.VisualStudio.Platform;
+using Microsoft.VisualStudio.Utilities;
using Mono.Addins; using MonoDevelop.Core;
using MonoDevelop.Ide.Extensions; @@ -34,9 +36,8 @@ namespace MonoDevelop.Ide {
public static MimeTypeCatalog Instance { get; } = new MimeTypeCatalog ();
- 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);
-
+ readonly MimeTypeNode textPlainNode = new MimeTypeNode (TextPlain, null, GettextCatalog.GetString ("Text document"), null, true, "text");
+ readonly MimeTypeNode xmlNode = new MimeTypeNode (ApplicationXml, null, GettextCatalog.GetString ("XML document"), null, true, null);
List<MimeTypeNode> mimeTypeNodes = new List<MimeTypeNode> ();
MimeTypeCatalog ()
@@ -60,6 +61,10 @@ namespace MonoDevelop.Ide }
}
+ public const string TextPlain = "text/plain";
+ public const string ApplicationXml = "application/xml";
+ public const string OctetStream = "application/octet-stream";
+
public MimeTypeNode FindMimeType (string type)
{
foreach (MimeTypeNode mt in mimeTypeNodes) {
@@ -95,15 +100,15 @@ namespace MonoDevelop.Ide { yield return mimeType; - while (mimeType != null && mimeType != "text/plain" && mimeType != "application/octet-stream") { + while (mimeType != null && mimeType != TextPlain && mimeType != OctetStream) { MimeTypeNode mt = FindMimeType (mimeType); if (mt != null && !string.IsNullOrEmpty (mt.BaseType)) mimeType = mt.BaseType; else { if (mimeType.EndsWith ("+xml", StringComparison.Ordinal)) - mimeType = "application/xml"; + mimeType = ApplicationXml; else if (mimeType.StartsWith ("text/", StringComparison.Ordinal)) - mimeType = "text/plain"; + mimeType = TextPlain; else break; } @@ -126,7 +131,7 @@ namespace MonoDevelop.Ide while (node != null) {
yield return node; - if (node.Id == "application/octet-stream" || node.Id == "text/plain") {
+ if (node.Id == OctetStream || node.Id == TextPlain) {
yield break;
} @@ -180,18 +185,20 @@ namespace MonoDevelop.Ide return null;
}
- public string GetMimeTypeForContentType (string contentType)
- => GetMimeTypeNodeForContentType (contentType)?.Id;
+ public string GetMimeTypeForContentType (IContentType contentType)
+ => GetMimeTypeNodeForContentType (contentType.TypeName)?.Id;
- public IEnumerable<string> GetMimeTypeInheritanceChainForContentType (string contentType)
- => GetMimeTypeInheritanceChain (GetMimeTypeNodeForContentType (contentType));
+ public IEnumerable<string> GetMimeTypeInheritanceChainForContentType (IContentType contentType)
+ => GetMimeTypeInheritanceChain (GetMimeTypeNodeForContentType (contentType.TypeName));
- public string GetContentTypeForMimeType (string mimeType)
+ public IContentType GetContentTypeForMimeType (string mimeType)
{
- var node = FindMimeType (mimeType);
- foreach (var mt in GetMimeTypeNodeInheritanceChain (node)) {
- if (node.ContentType != null) {
- return node.ContentType;
+ if (mimeType != null) {
+ var node = FindMimeType (mimeType);
+ foreach (var mt in GetMimeTypeNodeInheritanceChain (node)) {
+ if (node.ContentType != null) {
+ return PlatformCatalog.Instance.ContentTypeRegistryService.GetContentType (node.ContentType);
+ }
}
}
return null;
|