1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Text.RegularExpressions;
6
using ICSharpCode.Core;
8
namespace ICSharpCode.SharpDevelop
10
public class DisplayBindingDescriptor
17
/// Gets the IDisplayBinding or ISecondaryDisplayBinding if it is already loaded,
18
/// otherwise returns null.
20
internal object GetLoadedBinding()
25
public IDisplayBinding Binding {
27
if (codon != null && binding == null) {
28
binding = codon.AddIn.CreateObject(codon.Properties["class"]);
30
return binding as IDisplayBinding;
34
public ISecondaryDisplayBinding SecondaryBinding {
36
if (codon != null && binding == null) {
37
binding = codon.AddIn.CreateObject(codon.Properties["class"]);
39
return binding as ISecondaryDisplayBinding;
43
public bool IsSecondary {
44
get { return isSecondary; }
47
public string Id { get; set; }
48
public string Title { get; set; }
49
public string FileNameRegex { get; set; }
51
public DisplayBindingDescriptor(Codon codon)
54
throw new ArgumentNullException("codon");
56
isSecondary = codon.Properties["type"] == "Secondary";
57
if (!isSecondary && codon.Properties["type"] != "" && codon.Properties["type"] != "Primary")
58
MessageService.ShowWarning("Unknown display binding type: " + codon.Properties["type"]);
63
string title = codon.Properties["title"];
64
if (string.IsNullOrEmpty(title))
65
this.Title = codon.Id;
69
this.FileNameRegex = codon.Properties["fileNamePattern"];
72
public DisplayBindingDescriptor(IDisplayBinding binding)
75
throw new ArgumentNullException("binding");
77
this.isSecondary = false;
78
this.binding = binding;
81
public DisplayBindingDescriptor(ISecondaryDisplayBinding binding)
84
throw new ArgumentNullException("binding");
86
this.isSecondary = true;
87
this.binding = binding;
91
/// Gets if the display binding can possibly open the file.
92
/// If this method returns false, it cannot open it; if the method returns
93
/// true, it *might* open it.
94
/// Call Binding.CanCreateContentForFile() to know for sure if the binding
95
/// will open the file.
98
/// This method is used to skip loading addins like the ResourceEditor which cannot
99
/// attach to a certain file name for sure.
101
public bool CanOpenFile(string fileName)
103
string fileNameRegex = StringParser.Parse(this.FileNameRegex);
104
if (fileNameRegex == null || fileNameRegex.Length == 0) // no regex specified
106
if (fileName == null) // regex specified but file has no name
108
return Regex.IsMatch(fileName, fileNameRegex, RegexOptions.IgnoreCase);
111
public override string ToString()
113
return string.Format("[DisplayBindingDescriptor Id={1} Binding={0}]", binding, Id);