|Published (Last):||16 May 2008|
|PDF File Size:||20.87 Mb|
|ePub File Size:||15.99 Mb|
|Price:||Free* [*Free Regsitration Required]|
The Addin infrastructure is LGPL-licensed, and so can be used in arbitrarily-licensed applications, ranging from GPL to commercial closed-source solutions. It has proven to scale for a KLOC project such as SharpDevelop, so take a look at it to see if it fits your needs too. Most of the applications use some sort of AddIn architecture. But most of the time AddIns are limited to do only a few specific jobs - like extending a certain menu or handling a new file format.
The goal of the SharpDevelop AddIn architecture is to make it easy to provide "extension points" in the application that can be extended. In fact, we wanted to make it so easy that you could use it all the time, thus allowing AddIns to extend nearly everything. In this article, we'll build a small text editor application. Here is a screenshot of the finished application:. The core uses log4net for logging in the class LoggingService.
If you want to use a different logging engine, you only need to modify the file LoggingService. Core , and also reference Base except for AddIns that don't need to interact with the host application. AddIns can reference each other and they can also come with additional libraries. The core is responsible for loading the AddIns and storing a list of extension points and the AddIns extending them. The extension points are stored in a tree structure called AddIn tree. Base is the base AddIn of the application.
To the Core, it's just a normal AddIn, but it provides all the essential functionalities so all other AddIns need references to it. In this article's example application, Base contains a Notepad-like application. AddInManager allows the user to install packaged AddIns. The AddIn tree is structured like a file system. A path represents an extension point of the application. A node is some behavior added to the extension point by an AddIn or the base application.
Nodes can have sub-nodes, as presented in this example path. The most common use of the AddIn tree is to extend menus and tool bars. When some part of the application wants to create a menu or toolbar, it uses a path in the AddIn tree. Where did this toolbar get loaded from? Every node has a Codon associated to it. A Codon is the in-memory representation of an AddIn tree node.
When the AddIn tree is loaded, an instance of the Codon class is created. The other attributes are put into a " Properties " container works like a Hashtable. The icon attribute refers to an image stored in the ResourceService; the tooltip attribute is parsed using the "StringParser" service to insert localized strings. It has to implement the interface ICommand. But these are just the special cases for the "ToolbarItem", you can use the AddInTree to store any information.
For example, the HtmlHelp2. You can see that AddIns can add new items into the existing paths and use the special attributes insertafter and insertbefore to specify the location of the inserted elements. You can also see that Codons can have conditions assigned to them; I'll explain the conditions in detail in a later article. Creates object instances by invocating a type's parameterless constructor via System.
Includes one or multiple items from another location in the addin tree. You can use the attribute " item " to include a single item or the attribute " path " to include all items from the target path. Of course, AddIns or your base project can create new element types for other data by adding custom doozers.
Doozers are the classes that create the objects from the Codons. Core contains the doozer classes for the Codon types mentioned in the table. Custom doozers will be covered in another article.
However, using Class will be sufficient in most cases. It allows you to put absolutely any object in the AddIn tree. If all of the classes put into a path implement a specific interface e. IMyInterface , you can use:. This makes it possible to use the AddInTree to define things like file type handlers or a set of commands being run on some action. The main form is called "Workbench" and shows the main menu, a toolbar and the ViewContent.
A ViewContent can be anything that can behave remotely like a document. Our example application can only display one ViewContent at a time. The "Edit" and "Format" menus are intentionally missing: in the next article, we'll add them as AddIn. The application is just meant to demonstrate what you can do with ICSharpCode.
Core ; it is not usable as a full-blown text editor because it doesn't support encodings only UTF Let us take a look at the Startup code file Start. Main and the features of ICSharpCode.
Core used in it:. The Workbench class in the "Base" project is the main window of our application. In its constructor called by Workbench. InitializeWorkbench , it uses the MenuService and ToolbarService to create the content of the main window.
It makes use of the PropertyService to load and store the location of the main window. The Core contains a class called " PropertyService " that can be used to store application settings. Take a look at the code used to save and restore the location of a Form to get an idea of how easy it is to use:. The Get and Set methods of the PropertyService are generic methods:. The C compiler infers the type from GetDefaultBounds , which just returns the bounds of the Form centered on the active screen, and reads the property.
The Validate method ensures that the position is valid; we do not want to show the Form on a no-longer-existing secondary monitor. When the Form is closed, the new location is saved. PropertyService supports the types providing a TypeConverter, so you can use it with most of the. NET's built-in types and adding support for custom types is also easy. Additionally, the PropertyService supports storing one-dimensional arrays if the array element type has a TypeConverter.
You have already seen that menu commands are declared in the. Here are the commands specific to our text editor application:. The first parameter is the owner of the toolstrip, all commands created for the toolbar will have their Owner property set to the owner passed while creating the tool strip.
This is useful while creating context menus for items. Now move on to opening the existing files. We do not know what kind of file the user will try to open, and we want to give AddIn authors the possibility to add support for more file types. Therefore, the file filter used in the OpenFileDialog must be extensible, and the AddIns should be able to create custom view contents for the file chosen by the user:.
As you can see, the BuildItems method returns an ArrayList of strings in this case. The FileFilter doozer returns strings in the form "name extensions"; this is used to concatenate the complete filter string. Now we'll take a look at the creation of the view content. As already said in the "Features" section, the Core does not provide you with predefined classes for this task, but the DisplayBindingManager is easy to write.
Our DisplayBindingManager constructs those objects and asks each of them to create a view content for the file. The first object that is able to open the file will be used. As you can see, we are simply constructing all the DisplayBinding classes from the AddIn tree. The first display binding that is able to open the file will be used. The AddIn definition from the "Base" project, Base.
If we don't use " insertbefore ", the base text editor would display the rich text source code, and our rich text editor would never be asked to open the file. This approach will cause all the display binding AddIns to be loaded when a file is opened for the first time; in a later article, I will show you a better approach by moving the file extension check into the XML.
The core supports localization using resource files for the different languages. The ResourceService reads the resources from multiple locations:. However, it is also possible that AddIns supply their own localized string resources.
Both are set to "EmbeddedResource", so the English resources are included in the AddIn assembly and the German resources are put into a satellite assembly. The ResourceService will load the string resources from the AddIn assembly and it will look for a satellite assembly for the current language.
GetString will probe all the registered resources and return the string for the current language. However, we cannot simply call a method in the XML files, so we have to use something different there.
The StringParser is used for all labels of menu items in the AddIn tree, so you can use it to include translated strings or other variables.
Additional variables can be set using StringParser. Moreover, you can register new prefixes by using PropertyService. A property object can be any object — the members are accessed using Reflection.
In short, you can use the libraries in commercial projects, but you have to publish the source code for any modifications done to the libraries.
Building Applications with the SharpDevelop Core
GitHub is home to over 50 million developers working together. Join them to grow your own development teams, manage permissions, and collaborate on projects. NET platform. C Convert code from C to VB. NET and vice versa using Roslyn. Global type inference for C 8 nullable reference types.
SharpDevelop also styled as develop is a discontinued  free and open source integrated development environment IDE   for the. SharpDevelop was designed as a free and lightweight alternative to Microsoft Visual Studio , and contains an equivalent feature for almost every essential Visual Studio Express feature and features very similar to those found in Borland Kylix and Delphi , including advanced project management, code editing, application compiling and debugging functionality. NET Framework applications,  a "New Project" wizard , toolbars, menus, panels and a docking system,  : 7    and built-in code refactoring tools,   and it has an integrated debugger  that allows for stepping, viewing values of objects in memory, and breakpoints. To allow for easy project migration, SharpDevelop works natively with Visual Studio project and code files.
SharpDevelop: An Alternative IDE to Visual Studio Express
The Addin infrastructure is LGPL-licensed, and so can be used in arbitrarily-licensed applications, ranging from GPL to commercial closed-source solutions. It has proven to scale for a KLOC project such as SharpDevelop, so take a look at it to see if it fits your needs too. Most of the applications use some sort of AddIn architecture. But most of the time AddIns are limited to do only a few specific jobs - like extending a certain menu or handling a new file format. The goal of the SharpDevelop AddIn architecture is to make it easy to provide "extension points" in the application that can be extended.