~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/docs/Mono.Addins/ConditionType.xml

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<Type Name="ConditionType" FullName="Mono.Addins.ConditionType">
 
2
  <TypeSignature Language="C#" Value="public abstract class ConditionType" />
 
3
  <AssemblyInfo>
 
4
    <AssemblyName>Mono.Addins</AssemblyName>
 
5
    <AssemblyVersion>0.4.0.0</AssemblyVersion>
 
6
    <AssemblyVersion>1.0.0.0</AssemblyVersion>
 
7
  </AssemblyInfo>
 
8
  <Base>
 
9
    <BaseTypeName>System.Object</BaseTypeName>
 
10
  </Base>
 
11
  <Interfaces />
 
12
  <Docs>
 
13
    <summary>A condition evaluator.</summary>
 
14
    <remarks>Add-ins may use conditions to register nodes in an extension point which are only visible under some contexts.
 
15
 
 
16
<para>
 
17
For example, an add-in registering a custom menu option to the main menu of a sample text editor might want to make that option visible only for some kind of files. To allow add-ins to do this kind of check, the host application needs to define a new condition. Conditions are defined like this: 
 
18
</para><example><code lang="XML">
 
19
&lt;Addin namespace="TextEditor" id="Core" version="1.0"&gt;
 
20
        ...
 
21
        &lt;ConditionType id="Openfile" type="TextEditor.OpenFileCondition" /&gt;
 
22
        ...
 
23
&lt;/Addin&gt;
 
24
</code></example><para>This condition defined in the add-in host can be referenced by add-ins like this:</para><example><code lang="XML">
 
25
&lt;Addin namespace="TextEditor" id="Xml"&gt;
 
26
        ...
 
27
        &lt;Extension path = "/TextEditor/MainMenu/Edit"&gt;
 
28
                &lt;Condition id="OpenFile" extension="xml,config"&gt;
 
29
                        &lt;MenuSeparator insertafter="Paste" /&gt;
 
30
                        &lt;MenuItem label="Format XML" commandType="TextEditor.Xml.FormatXmlCommand" /&gt;
 
31
                &lt;/Condition&gt;
 
32
        &lt;/Extension&gt;
 
33
        ...
 
34
&lt;/Addin&gt;
 
35
</code></example><para>Meaning that a separator and new "Format XML" command will be added after the "Paste" command, but only if the current open file has the extension ".xml" or ".config".</para><para>Extension points are dynamically updated when the status of a condition changes. Nodes matching the new condition status will be added, and nodes which do not match the condition will be removed.</para><para>Conditions are implemented using a subclass of <see cref="T:Mono.Addins.ConditionType" />. For example, OpenFileCondition might be implemented like this:</para><example><code lang="C#">
 
36
namespace TextEditor
 
37
{
 
38
        public class OpenFileCondition: ConditionType
 
39
        {
 
40
                public OpenFileCondition ()
 
41
                {
 
42
                        // It's important to notify changes in the status of a condition,
 
43
                        // to make sure the extension points are properly updated.
 
44
                        TextEditorApp.OpenFileChanged += delegate {
 
45
                                // The NotifyChanged method must be called when the status
 
46
                                // of a condition changes.
 
47
                                NotifyChanged ();
 
48
                        };
 
49
                }
 
50
                
 
51
                public override bool Evaluate (NodeElement conditionNode)
 
52
                {
 
53
                        // Get the required extension value from an attribute,
 
54
                        // and check againts the extension of the currently open document
 
55
                        string val = conditionNode.GetAttribute ("extension");
 
56
                        if (val.Length &gt; 0) {
 
57
                                string ext = Path.GetExtension (TextEditorApp.OpenFileName);
 
58
                                foreach (string requiredExtension in val.Split (','))
 
59
                                        if (ext == "." + requiredExtension)
 
60
                                                return true;
 
61
                        }
 
62
                        return false;
 
63
                }
 
64
        }
 
65
}
 
66
  </code></example><para>The add-in engine will create an instance of OpenFileCondition when needed, and will call Evaluate to get the result for a specific condition node. </para></remarks>
 
67
  </Docs>
 
68
  <Members>
 
69
    <Member MemberName=".ctor">
 
70
      <MemberSignature Language="C#" Value="protected ConditionType ();" />
 
71
      <MemberType>Constructor</MemberType>
 
72
      <Parameters />
 
73
      <Docs>
 
74
        <summary>Creates a new instance.</summary>
 
75
        <remarks />
 
76
      </Docs>
 
77
      <AssemblyInfo>
 
78
        <AssemblyVersion>0.4.0.0</AssemblyVersion>
 
79
      </AssemblyInfo>
 
80
    </Member>
 
81
    <Member MemberName="Evaluate">
 
82
      <MemberSignature Language="C#" Value="public abstract bool Evaluate (Mono.Addins.NodeElement conditionNode);" />
 
83
      <MemberType>Method</MemberType>
 
84
      <ReturnValue>
 
85
        <ReturnType>System.Boolean</ReturnType>
 
86
      </ReturnValue>
 
87
      <Parameters>
 
88
        <Parameter Name="conditionNode" Type="Mono.Addins.NodeElement" />
 
89
      </Parameters>
 
90
      <Docs>
 
91
        <param name="conditionNode">Condition node information.</param>
 
92
        <summary>Evaluates the condition.</summary>
 
93
        <returns>'true' if the condition is satisfied.</returns>
 
94
        <remarks>This method must be overriden to evaluate the condition for the provided node, and should return 'true' if the condition is satisfied.</remarks>
 
95
      </Docs>
 
96
      <AssemblyInfo>
 
97
        <AssemblyVersion>0.4.0.0</AssemblyVersion>
 
98
      </AssemblyInfo>
 
99
    </Member>
 
100
    <Member MemberName="NotifyChanged">
 
101
      <MemberSignature Language="C#" Value="public void NotifyChanged ();" />
 
102
      <MemberType>Method</MemberType>
 
103
      <ReturnValue>
 
104
        <ReturnType>System.Void</ReturnType>
 
105
      </ReturnValue>
 
106
      <Parameters />
 
107
      <Docs>
 
108
        <summary>Notifies that the condition has changed, and that it has to be re-evaluated.</summary>
 
109
        <remarks>This method must be called when there is a change in the state that determines the result of the evaluation. When this method is called, all node conditions depending on it are reevaluated and the corresponding events for adding or removing extension nodes are fired.
 
110
</remarks>
 
111
      </Docs>
 
112
      <AssemblyInfo>
 
113
        <AssemblyVersion>0.4.0.0</AssemblyVersion>
 
114
      </AssemblyInfo>
 
115
    </Member>
 
116
  </Members>
 
117
</Type>