Skip navigation

OpenVista CIS

2 Posts tagged with the mono_addins tag
0

One of the features of OpenVista CIS is that it is extensible. Without modifying the core of CIS, you can drop in additional functionality, such as new application tabs, new image format rendering support, new preferences tabs, etc.

 

In order to make OpenVista CIS extensible, it uses Mono.Addins for a plugin system. This allows developers to dynamically add more functionality to CIS without having to change its internals. Mono.Addins allows developers to specify "extension points" and then inspect and load all extensions that attach to that extension point. Here is a simple example showing one of the CIS extension points, and a simple extension that implements it.

The Extension Point

Let's look at one of the core UI extension points in CIS, the IApplicationTab. This extension point is used to provide tabs visible in the main window of CIS. Here is the relevant code from the definition of that extension point interface:

using Gtk;

[Mono.Addins.TypeExtensionPoint ("/Interface/ApplicationTab")]
public interface IApplicationTab
{
     Widget LabelWidget {
         get;
     }
     Widget Widget {
          get;
     }
     .
     .
     .
}

 

This extension node is found in the Medsphere.OpenVista.Core.UI.dll assembly, and must define an "AddinRoot" in order to let this extension point be used. The following is from the AssemblyInfo.cs file in that assembly:

using Mono.Addins;

[assembly:AddinRoot ("Medsphere.OpenVista.Core.UI", "1.0")]

A Simple Extension

 

We are going to create a new assembly that contains our application tab extension. We need to specify both our addins dependencies, as well as advertise it the addin itself, in the AssemblyInfo.cs file:

using Mono.Addins;

[assembly: Addin]
[assembly: AddinDependency ("Medsphere.OpenVista.Core.UI", "1.0")]

 

Next we will define our simple hello world extension in HelloWorldSheet.cs:

using System;
using Gtk;
using Medsphere.OpenVista.Core.UI;

[Mono.Addins.Extension ("/Interface/ApplicationTab")]
public class HelloWorldSheet : IApplicationTab
{
        public Widget LabelWidget {
                 get { return _label; }
        }

        public Widget Widget {
                 get { return _widget; }
        }
        .
        .
        .
        public HelloWorldSheet ()
        {
                 _label = new Label ("Hello\nWorld");
                 _widget = new Label ("Hello World!");
        }

        Label _label, _widget;
}

We can now compile our addin with the following command line (of course, this could just as easily be done in Visual Studio, MonoDevelop, etc):

gmcs -r:Mono.Addins.dll -r:Medsphere.OpenVista.Core.UI.dll -pkg:gtk-sharp-2.0 \
     -t:library -out:Medsphere.OpenVista.CIS.Demo.dll HelloWorldSheet.cs AssemblyInfo.cs

 

Now when we run CIS, we see that our hello world application tab has been automatically loaded:

 

openvista-cis-hello-world-plugin.png

 

Conclussion

 

For further reading on Mono.Addins, check out the Mono.Addins page on http://www.mono-project.com/. If you want to get started on extending CIS, grab the CIS source code! The full source code for the simple CIS tab plugin is attached to this document, so you can see the full details.

673 Views 0 Comments 0 References Permalink Tags: c#, cis, mono_addins, openvista_cis_internals, openvista_cis, open_source
0

What is Mono.Addins?

Posted by A Oct 11, 2008

.

948 Views 0 Comments Permalink Tags: mono_addins