[
Advertise | Submit Code | About us | Contact us | Link us
]
Go!
Membership Services
Login
Register

Home
C# General

General

C# Language

Design & Architecture

Algorithms

Database

Security

Active Directory

COM Interop

Remoting
C# Windows Forms

General

Combo and List boxes

Miscellaneous Controls

Button Controls

Edit Controls
Cutting Edge

ASP.NET 2.0

Visual Studio 2005

Windows Longhorn

SQL Server 2005
C# Multimedia and GDI+

General

DirectX

GDI+

Audio
Internet & Web

General

Images and multimedia

Database

Utilities

Security

ASP.NET Controls

Design and Architecture

Webservices
.NET

General

Design & Architecture

Algorithms

Database

Security

Active Directory

COM Interop

Remoting

ADO.NET

XML.NET

Tools

Enterprise

IDE
Visual Basic .NET

VB.NET General

VB.NET Controls
General Reading

.NET Books Review

Product Showcase

Book Chapters

Business Design & Strategy
Community

Discuss

Job Board

Discussion

CodeXchange
DeveloperLand

Advertise

Submit Code

About us

Contact us

Link us
Miscellaneous

Favorite Links

Downloads

Programming Sites

Top Stories
Regular Expressions

E-Mail

Date/Time
Home > C# Windows Forms > General
Writing an Addin for SharpDevelop 1.0+ with Visual Studio 2003
Posted by on Thursday, June 23, 2005 (EST)

Creating a simple SharpDevelop Pad Content with Visual Studio 2003

This article has been viewed: 6,486 times
Technology: General.

SharpDevelop CodeXchange Plugin ALL.zip (75.11 KB)
SharpDevelop CodeXchange Plugin Binary.zip (27.90 KB)
SharpDevelop CodeXchange Plugin Source.zip (51.06 KB)

Contents

Please by indulgent since this is my first article on DeveloperLand. And please; send me feedback, comments, advice, anything you want. I'm here to learn!



Introduction

Any modern application theses days is designed with extensibility in mind. This allows developers and even the end user to replace existing pieces or add their own custom functionality.

When extending an existing application we have basically two ways of doing this : Macros and plug-ins. Macros are small interpreted programs created with scripting languages that run within applications such as Excel and PowerPoint while Plug-ins are compiled applications created against the application plug-in mechanism and have access to a rich set of APIs that enables developers to develop and explore new tools quickly, without having to start from scratch.

Which approach is the best? Well, It depends on the situation. Macros are usually very easy to create by end users but have a limited access to the application API while Plug-ins require strong programming skills to make something useful but are usually far more efficient and powerful. Plug-ins are compiled code; so there are no performance losses caused by the script engine virtual machine.

IDEs (Integrated development environment) are no exception. They provide a very rich object model. The big ones like Visual Studio or Eclipse are basically a container where developers can connect their code. Even the compilers are plug-ins!

Top Go to Table of Contents

CodeXchange

For those of you who don't know CodeXchange you can visit its website and learn what is all about. All software is free so this is not some kind of cheap commercial.

In the above website you will find also a Visual Studio version of the client software but if you are a SharpDevelop user you are out of luck, so we will write our own SharpDevelop CodeXchange client (Good excuse to learn something new about this IDE!) .

Our simple SharpDevelop CodeXchange client will be based on its public web services located at
http://www.codexchange.net/CodeXchangeservice.asmx [^]

Top Go to Table of Contents

What’s a Plug-in/Addin?

The word plug-in is often used by software developers to describe a third party application that "hooks" into a main application to extend its functionality.

An Addin is a small compiled piece of software that, once registered and installed, extends the functionality of the host application (in our sample the SharpDevelop IDE).The only limit from here is the host application exposed functionality and your imagination.

Top Go to Table of Contents

The SharpDevelop object model

There is a detailed PDF available at SharpDevelop’s website
here [^] that you will want to read for a full understanding of the entire system and possibilities. This is intended as a simple and quick overview.

Top Go to Table of Contents

The Addin Assembly

A SharpDevelop Addin is a regular class library which imports some SharpDevelop namespaces. We are creating a project browser or output pad like Addin. In SharpDevelop this kind of plug-ins are called Pads. Creating your own SharpDevelopPad is really simple, just create a new class an inherit form the AbstractPadContent class.

The most important property of this class is a virtual property called “Control”. This property as his name says holds a Windows Forms control reference (our control) that will be the graphical representation of our plug-in because this is the control that will be added to the SharpDevelop environment inside the newly created Pad.

Import common .NET framework namespaces

using System;
using System.IO;
using System.Collections;
using System.Windows.Forms;
using System.Drawing;

Import SharpDevelop specific namespaces
using ICSharpCode.Core.Services;
using ICSharpCode.Core.Properties;
using ICSharpCode.Core.AddIns.Codons;
using ICSharpCode.Core.AddIns.Conditions;
using ICSharpCode.Core.AddIns;
using ICSharpCode.SharpDevelop.Services;
using ICSharpCode.SharpDevelop.Gui

Create our own SharpDevelop Pad inheriting from AbstractPadContent and adding our custom control to it

namespace Sand.Services.CodeXchange.SharpDevelopAddin
{
 public class CodeXchangeViewContent : AbstractPadContent
 {
  public static CodeXchangeControl MyControl = null;
  
  public CodeXchangeViewContent () : base ("CodeXchange Addin")
  {
   MyControl = new CodeXchangeControl ();
   MyControl.Dock = DockStyle.Fill;
  }
  /// 
  /// This is the Windows.Forms control for the view.
  /// 
  public override Control Control 
  {
   get 
   {
    return MyControl;
   }
  }
  
  /// 
  /// Reinitializes the content. (Re-initializes all add-in tree stuff)
  /// and redraws the content. Call this not directly unless you know
  /// what you do.
  /// 
  public override void RedrawContent()
  {
   
  }
  public override void Dispose()
  {
   MyControl = null;
  }
 }
}

Top Go to Table of Contents

Debugging our SharpDevelop Addin with Visual Studio.NET

Our Addin is no more than a standard DLL, so we can use the same procedure used when debugging other class libraries.

Debugging our newly created SharpDevelop Addin should be very easy if we setup the “Start Program” setting of our project to the SharpDevelop image path. Every time we run the DLL project Visual Studio will load a new instance of SharpDevelop and attach the debugger to it so we can debug our code.



Top Go to Table of Contents

The .addin.xml file

Once we have our code ready and compiled into one or more assemblies we must tell SharpDevelop how to load it and how to configure the environment, for example, If you pay attention to the “Extension” tags you will see the new menus my Addin requires and how I’m telling SharpDevelop where to place these application or contextual menus and how to connect them to our code thru commands.

The Addin xml file is almost self explaining:

<AddIn name        = "CodeXchangeAddin"
       author      = "Marc Piulachs"
       copyright   = "GPL"
       url         = "http://www.codexchange.net"
       description = "SharpDevelop CodeXchange Client"
       version     = "0.1.0">
 
 <Runtime>
  <Import assembly="Sand.Services.CodeXchange.SharpDevelopAddin.dll"/>
 </Runtime>
 
 <Extension path = "/SharpDevelop/Workbench/Views">
     <Class id = "CodeXchange" 
       insertafter = "HelpBrowser"
       class = "Sand.Services.CodeXchange.SharpDevelopAddin.CodeXchangeViewContent"/>
 </Extension>
 
 <Extension path = "/SharpDevelop/Workbench/MainMenu/Tools">
  <MenuItem id = "CodeXchangeAddin"
          insertafter = "Separator3" insertbefore = "Separator4"
          label = "CodeXchange" 
          class = "Sand.Services.CodeXchange.SharpDevelopAddin.CodeXchangeCommand"/>
 </Extension>
            
            
 <Extension path = "/SharpDevelop/ViewContent/DefaultTextEditor/ContextMenu">
   <Conditional action="Disable">
      <Or>
        <Condition activeextension = ".vb"/>
        <Condition activeextension = ".cs"/>
      </Or>              
      <MenuItem id = "InsertFromCodeXchange"
         label = "Search snippet on CodeXchange"
         insertafter = "Separator4"
         class ="Sand.Services.CodeXchange.SharpDevelopAddin.InsertCodeXchangeSnippetCommand" />
   </Conditional>
  </Extension>
            
            
  <Extension path = "/SharpDevelop/ViewContent/DefaultTextEditor/ContextMenu">
    <Conditional action="Disable">
      <Or>
        <Condition activeextension = ".vb"/>
        <Condition activeextension = ".cs"/>
      </Or>              
      <MenuItem id = "ContributeToCodeXchange"
        label = "Contribute snippet to CodeXchange"
        insertafter = "Separator4"
        class ="Sand.Services.CodeXchange.SharpDevelopAddin.ContributeSnippetCommand" />
    </Conditional>
   </Extension>
</AddIn>

Top Go to Table of Contents

Building and installing

• Create a new folder named “CodeXchange” in your SharpDevelop Addins folder in my setup “\SharpDevelop\AddIns\AddIns\Misc\CodeXchange” .
• Compile your code as usual and place the generated dlls together with the .Addin manifest file to the newly created folder
• Start SharpDevelop as normal.
Conclusions
The CodeXchange sample client included with this article does not pretend to implement the complete command set providing instead support for the basic features. You can use this code to create your own customized client or use it as reference and guide for your own projects. Have Fun!

Top Go to Table of Contents

Credits and Errata

Article reviewed by Ernesto Giralt

Top Go to Table of Contents

References

• Writing a MonoDevelop Plug-in [
http://www.monodevelop.com/tutorials/plugin.aspx [^]]
• Notes on the Eclipse Plug-in Architecture [http://www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html [^]]
• Getting Started with Windows Forms and SharpDevelop [http://www.developerland.com/CSharpWinForms/General/50.aspx [^]]

Top Go to Table of Contents

About J.Marc Piulachs

Hi! I'm a 23 year old software engineer currently located in a sunny mediterranian city called Barcelona (that's in Europe ;-)).

I enjoy many outdoor activities such as using my laptop computer out to a local cafe or on the beach :P

I consider myself a bit of a geek, but I don't really like Star Wars... is that possible?

Click here if you want to know more about .

Other articles that may interest you

  • Write a Word Add-In – Part 0
  • Write a Word Add-In – Part I
  • Lengthy Operations on Single Thread in .NET Application
  • Learning Draughts
  • Exceptions and Performance
  • Average Rating :

    Discussion Forums
    Got a programming related question? Hopefully someone has the answer... Want to help out other developers? Visit our discussion forums.

    Comments: View: Order:

    Problem.
    By Benjamin Tang on Friday, July 01, 2005 (EST)

    I have downloaded this Add-In and installed under #D 1.1.  When I logged in, nothing listed in the snippets view.  So have I done something wrong?

    Reply to Comment

    RE : Problem
    By J.Marc Piulachs on Sunday, July 03, 2005 (EST)

    Hi , no you haven't done anything wrong (at least not yet :P) . The snippet view does not represent the contents of the repository It reprents the snippets contributed by the logged user (you) . If you want to browse the database you will have to use the search tab.

    Let me know if you have more problems with it. Thanks!

    Reply to Comment

    Not yet implemented!
    By bas jansen on Saturday, July 09, 2005 (EST)
    When I install your Addin in sharpdevelop 1.1 I get the error: Not yet implemented! I downloaded the binaries and installed as explained on this page. Any clues? Bas

    Reply to Comment

    Not yet implemented!
    By bas jansen on Sunday, July 10, 2005 (EST)
    I did try to install your tool as an add-in but failed... I used the binaries on this page. Installed them in the directory as you wrote down and I can see an entry in the SharpDevelop menu. But when I click on it I get: Not yet implemeted! So what am I doing wrong? Bas

    Reply to Comment

    Update
    By Wenderson Teixeira on Thursday, November 09, 2006 (EST)
    Hi, I've made some changes to the project, so it will work under SharpDevelop 2.0. Let me know if you want the changes. Regards, Wenderson Teixeira

    Reply to Comment

    Add Your Comment

    Sponsored by:

    New Articles

  • Exceptions and Performance
    Almost every time exceptions are mentioned in mailing lists and newsgroups, people say they're really expensive.Let's examine that claim, shall we?

  • Creating multilingual websites - Part 1
    Extend the existing globalization capabilities of .NET to create flexible and powerful multilingual web sites. First, create a custom ResourceManager, and then create custom localized-capable server controls to easily deploy multilingual functionality.

  • Parameter passing in C#
    Many people have become fairly confused about how parameters are passed in C#, particularly with regard to reference types. This page should help to clear up some of that confusion

  • Most Popular Articles

  • LDAP, IIS and WinNT Directory Services
    This article explains how to use .NET Directory Services to retrieve and search directory objects, create new directory objects and edit or delete existing directory objects. Describes Active Directory Application Mode (ADAM) and how to use the IIS, WinNT and LDAP directory (ADSI) provider.

  • An in-depth look at WMI and instrumentation, Part II
    WMI stands for Windows Management Instrumentation and, as the name indicates, is about managing your IT infrastructure this article is the second part of a two-part series.

  • An in-depth look at WMI and instrumentation, Part I
    WMI stands for Windows Management Instrumentation and, as the name indicates, is about managing your IT infrastructure this article provides an in-depth look at WMI and MOM 2005

  • New Books

  • Murach's ASP.NET 2.0 Upgrader's Guide: VB Edition
    What’s new and how to use it! That’s what this book delivers if you’re a VB developer who’s interested in upgrading from ASP.NET 1.x to ASP.NET 2.0.

  • C# in easy steps
    Learn to program with Microsoft’s premier programming language. No previous programming knowledge is assumed. With numerous easy-to-follow examples, this title explains the essentials of object-oriented programming with C#.

  • Murach's ASP.NET web programming with VB.NET
    Murach's ASP.NET web programming with VB.NET by Doug Lowe and Anne Prince is a in depth training and reference book for ASP.NET programming using VB.NET. The book builds upon Murach's previous books and covers more advanced concepts for programming ASP.NET pages.

  • Got Code?

    if you have any article , source code , or anything else you'd like to share with this community that you think others might find useful, please submit it here and we will gladly make it available on this site. submit@developerland.com.
    Partners

    All articles are copyrighted by their individual authors unless otherwise specified , everything else Copyright ©2004-2006 DeveloperLand