@ -13,21 +13,25 @@
< link rel = "stylesheet" type = "text/css" href = "http://www.codeproject.com/styles/global.css" > < / head >
< link rel = "stylesheet" type = "text/css" href = "http://www.codeproject.com/styles/global.css" > < / head >
< body revision = 'acf4w5gbq8vx_bdf8h26kgddn4:106' >
< body revision = 'acf4w5gbq8vx_bdf8h26kgddn4:106' >
< ul class = "download" >
<!-- Article Starts - DO NOT ADD HTML/BODY START TAGS -->
< li > < a href = "LineCounterSharpDevelopAddIn/LineCounterSharpDevelopAddIn.zip" > Download Source Project (C#) - * KB< / a > < / li >
< li > < a href = "LineCounterSharpDevelopAddIn/LineCounter.sdaddin" > Download AddIn Installation Package (.sdaddin) - * KB< / a > < / li >
<!-- Download Links -->
< ul class = download >
< li > < a href = 'LineCounterSDAddIn/LineCounterSDAddIn.zip' > Download source files - 36 Kb< / a > < / li >
< li > < a href = "LineCounterSDAddIn/LineCountersdaddin.zip" > Download AddIn Installation Package (.sdaddin) - 26 Kb< / a > < / li >
< / ul >
< / ul >
< br >
< br >
< p >
< p >
< img src = "LineCounterSharp Develop AddIn/screenshot.png" >
< img src = "LineCounterSDAddIn/screenshot.png" >
< / p >
< / p >
< h2 >
< h2 >
Introduction< br >
Introduction
< / h2 >
< / h2 >
When seeing the article
When seeing the article
< a href = "http://www.codeproject.com/useritems/LineCounterAddin.asp" title = "Line Counter - Writing a Visual Studio 2005 Add-In" > Line
< a href = "http://www.codeproject.com/useritems/LineCounterAddin.asp" title = "Line Counter - Writing a Visual Studio 2005 Add-In" > Line
Counter - Writing a Visual Studio 2005 Add-In< / a >
Counter - Writing a Visual Studio 2005 Add-In< / a >
< a href = "http://www.codeproject.com/useritems/LineCounterAddin.asp" target = "_blank" title = "Line Counter - Writing a Visual Studio 2005 Add-In" > [^]< / a > ,
< a href = "http://www.codeproject.com/useritems/LineCounterAddin.asp" target = "_blank" title = "Line Counter - Writing a Visual Studio 2005 Add-In" > [^]< / a >
written by Jon Rista,
I wanted to show you how to write that AddIn for SharpDevelop.< br >
I wanted to show you how to write that AddIn for SharpDevelop.< br >
In this article I will show you how to create an AddIn, but I will not discuss
In this article I will show you how to create an AddIn, but I will not discuss
the concepts of the SharpDevelop's AddIn architecture here - you can read more
the concepts of the SharpDevelop's AddIn architecture here - you can read more
@ -36,23 +40,24 @@ about that in my article
Applications with the SharpDevelop Core< / a >
Applications with the SharpDevelop Core< / a >
< a href = "http://www.codeproject.com/csharp/ICSharpCodeCore.asp" target = "_blank" title = "Building Applications with the SharpDevelop Core" > [^]< / a > .
< a href = "http://www.codeproject.com/csharp/ICSharpCodeCore.asp" target = "_blank" title = "Building Applications with the SharpDevelop Core" > [^]< / a > .
The line counter code is taken from the VS 2005 AddIn written by Jon Rista; the
The line counter code is taken from the VS 2005 AddIn written by Jon Rista; the
counting algorithm itself is from Oz Solomon.< br >
counting algorithm itself is from Oz Solomon.< br > I will discuss every of my changes to the code in this article - after all, there aren't so many changes required.
< br >
< br >
< h2 >
< h2 >
Creating a new AddIn
Creating a new AddIn
< / h2 >
< / h2 >
Our AddIn will be a menu entry in the "Tools" menu that opens a document window
Our AddIn will be a menu entry in the "Tools" menu that opens a document window
displaying the line counter UI. SharpDevelop already comes with a project
displaying the line counter UI. While it is possible to develop SharpDevelop AddIns in Visual Studio, you can get
template for an AddIn extending the "Tools" menu: "Tools menu entry"< br >
started a lot faster if you use SharpDevelop because it already comes with a project
< img src = "LineCounterSharpDevelopAddIn/templatetype.png" > < br >
template for an AddIn extending the "Tools" menu: "Tools menu entry".< br >
< img src = "LineCounterSDAddIn/templatetype.png" > < br >
< br >
< br >
We create a SharpDevelop Macro with the name "LineCounter". The "SharpDevelop
We create a SharpDevelop AddIn with the name "LineCounter". The "SharpDevelop
AddIn" template could also be used, but it starts with an AddIn defining a pad
AddIn" template could also be used, but it starts with an AddIn defining a pad
(a docked tool window like "Projects", "Properties"); the "Tool menu entry"
(a docked tool window like "Projects", "Properties"); the "Tool menu entry"
AddIn starts with a menu command.< br >
AddIn starts with a menu command.< br >
Now let's look at what SharpDevelop has generated for us:< br >
Now let's look at what SharpDevelop has generated for us:< br >
We have a project with a few files:< br >
We have a project with a few files:< br >
< img src = "LineCounterSharp Develop AddIn/projectbrowser.png" > < br >
< img src = "LineCounterSDAddIn/projectbrowser.png" > < br >
First look at the .addin file:< br >
First look at the .addin file:< br >
The template already defines a menu item in the tools menu, we'll just modify
The template already defines a menu item in the tools menu, we'll just modify
the label. And we'll add a new section to the .addin file: the < Manifest>
the label. And we'll add a new section to the .addin file: the < Manifest>
@ -69,7 +74,7 @@ item inside a <Condition name="SolutionOpen" action="disable"><br>
Here is how the content of LineCounter.addin should look like after these steps:< br >
Here is how the content of LineCounter.addin should look like after these steps:< br >
< pre > < AddIn name = "LineCounter"
< pre > < AddIn name = "LineCounter"
author = "Daniel Grunwald"
author = "Daniel Grunwald"
url = "http://www.codeproject.com/useritems/LineCounterSharp Develop AddIn.asp"
url = "http://www.codeproject.com/useritems/LineCounterSDAddIn.asp"
description = "Advanced line counter AddIn">
description = "Advanced line counter AddIn">
< Manifest>
< Manifest>
@ -92,7 +97,7 @@ Here is how the content of LineCounter.addin should look like after these steps:
< /AddIn>
< /AddIn>
< / pre > Our menu item uses the "class" attribute. When the menu item is
< / pre > Our menu item uses the "class" attribute. When the menu item is
clicked, SharpDevelop will create an instance of this class and call its Run()
clicked, SharpDevelop will create an instance of this class and call its Run()
method. This class is defined the file Command.cs. The example code from the
method. This class is defined in the file Command.cs. The example code from the
template accesses the currently opened text editor and reverses the letters in
template accesses the currently opened text editor and reverses the letters in
the currently selected text. We are not interested in accessing the text editor,
the currently selected text. We are not interested in accessing the text editor,
so we can delete the content of the Run() method and start writing our own.< br >
so we can delete the content of the Run() method and start writing our own.< br >
@ -105,19 +110,20 @@ about missing references. This is because the template is missing the assembly
references to the SharpDevelop libraries - these have to hard-coded paths in
references to the SharpDevelop libraries - these have to hard-coded paths in
most cases, so you should add them manually. Add references to
most cases, so you should add them manually. Add references to
ICSharpCode.Core.dll and ICSharpCode.SharpDevelop.dll from the bin directory of
ICSharpCode.Core.dll and ICSharpCode.SharpDevelop.dll from the bin directory of
your SharpDevelop installation. ICSharpCode.Core contains the AddIn system, we
your SharpDevelop installation. ICSharpCode.Core contains the AddIn system,
need the base class of our menu command from it. ICSharpCode.SharpDevelop is the
and also the base class for our menu command.
largest part of SharpDevelop, we'll use the project system from it.< br >
ICSharpCode.SharpDevelop is the largest part of SharpDevelop, it contains
the project system and many other things.< br >
Make sure you set "Local copy" for the references to
Make sure you set "Local copy" for the references to
< span style = "FONT-WEIGHT: bold" > False< / span > .< br >
< b > False< / b > .< br >
< img src = "LineCounterSharp Develop AddIn/properties.png" > < br >
< img src = "LineCounterSDAddIn/properties.png" > < br >
< br >
< br >
You should now be able to successfully compile the project. If you look into the
You should now be able to successfully compile the project. If you look into the
bin/Debug directory, you will see a copy of LineCounter.addin, the compiled
bin/Debug directory, you will see a copy of LineCounter.addin, the compiled
LineCounter.dll and the debug symbols.< br >
LineCounter.dll and the debug symbols.< br >
If you want to test your AddIn, you need to register it with SharpDevelop. The
If you want to test your AddIn, you need to register it with SharpDevelop. The
best way for testing is to copy these files to the AddIns directory of your
best way for testing is to copy these files to the AddIns directory of your
SharpDevelop installation. Restart SharpDevelop to let it l oad the AddIn. You
SharpDevelop installation. Restart SharpDevelop to load the AddIn. You
should see the "Line Counter" command in the Tools menu, disabled until you open
should see the "Line Counter" command in the Tools menu, disabled until you open
a solution. If you click the menu item, the message box should show up.< br >
a solution. If you click the menu item, the message box should show up.< br >
If you want to update your AddIn, you'll need to shutdown SharpDevelop, copy the
If you want to update your AddIn, you'll need to shutdown SharpDevelop, copy the
@ -130,15 +136,15 @@ Visual Studio to write your AddIn...</font><br>
< / h2 >
< / h2 >
Now to the real work: Implementing the line counter. We want to display the line
Now to the real work: Implementing the line counter. We want to display the line
counter user interface as a document, like the start page. Document views in
counter user interface as a document, like the start page. Document views in
SharpDevelop are called < span style = "FONT-WEIGHT: bold" > ViewContents< / span > .
SharpDevelop are called < b > ViewContents< / b > .
There are two types of view contents: primary and secondary. A primary view
There are two types of view contents: primary and secondary. A primary view
content is capable of displaying something on its own; a secondary view content
content is capable of displaying something on its own; a secondary view content
extends another view content by displaying multiple tabs in the document -
extends another view content by displaying multiple tabs in the document -
SharpDevelop's Windows.Forms designer is a secondary view content. We want to
SharpDevelop's Windows.Forms designer is a secondary view content. We want to
display a simple document view, so we'll use a normal (primary) view
display a simple document view, so we'll use a normal (primary) view
content.< span style = "FONT-STYLE: italic" > < br >
content.< br >
< br >
< br >
< / span > Showing such a view content is easy:< br >
Showing such a view content is easy:< br >
< pre > public override void Run()
< pre > public override void Run()
{
{
WorkbenchSingleton.Workbench.ShowView(new LineCounterViewContent());
WorkbenchSingleton.Workbench.ShowView(new LineCounterViewContent());
@ -274,7 +280,7 @@ m_projIconMappings.Add("{00000001-0000-0000-0000-000000000000}", 5);
< p >
< p >
Although the extension process is very different in SharpDevelop and Visual
Although the extension process is very different in SharpDevelop and Visual
Studio; the API is quite similar - after all, both are modelling MSBuild
Studio; the API is quite similar - after all, both are modelling MSBuild
solutions and after a similar feature set. I hope this shows you that porting
solutions and a similar feature set. I hope this shows you that porting
AddIns from Visual Studio to SharpDevelop isn't very hard and we would like to
AddIns from Visual Studio to SharpDevelop isn't very hard and we would like to
see more SharpDevelop AddIns in the future.
see more SharpDevelop AddIns in the future.
< / p >
< / p >
@ -282,7 +288,7 @@ m_projIconMappings.Add("{00000001-0000-0000-0000-000000000000}", 5);
Here an image showing the AddIn counting itself:
Here an image showing the AddIn counting itself:
< / p >
< / p >
< p >
< p >
< img src = "LineCounterSharp Develop AddIn/screenshot2.png" >
< img src = "LineCounterSDAddIn/screenshot2.png" >
< / p >
< / p >
< h2 >
< h2 >
Possible improvements
Possible improvements
@ -337,7 +343,7 @@ can add SharpDevelop icons to an existing image list.<br>
}
}
}
}
< / pre >
< / pre >
< span style = "FONT-WEIGHT: bold" > < span style = "FONT-WEIGHT: bold" > < / span > < / span > We
We
will use two instances of this class to control the two image lists
will use two instances of this class to control the two image lists
imgProjectTypes and imgFileTypes.< br >
imgProjectTypes and imgFileTypes.< br >
ScanSolution() is getting the icon index from m_projIconMappings - we will
ScanSolution() is getting the icon index from m_projIconMappings - we will
@ -419,7 +425,7 @@ name "LineCountingAlgorithm". Don't be irritated that it's not defined in the
XML schema for .addin files - we are creating a new possible codon name here;
XML schema for .addin files - we are creating a new possible codon name here;
the XML schema is just for code completion when editing the .addin file.< br >
the XML schema is just for code completion when editing the .addin file.< br >
Now how can we define this codon type? Constructing objects from the AddInTree
Now how can we define this codon type? Constructing objects from the AddInTree
is done by the < span style = "FONT-WEIGHT: bold" > doozers< / span > (the name comes
is done by the < b > doozers< / b > (the name comes
from
from
< a href = "http://en.wikipedia.org/wiki/Fraggle_Rock#Doozers" title = "Fraggle Rock: Doozers" > these
< a href = "http://en.wikipedia.org/wiki/Fraggle_Rock#Doozers" title = "Fraggle Rock: Doozers" > these
guys< / a >
guys< / a >
@ -480,8 +486,7 @@ CountingAlgorithmDescriptor. Let's define that class:<br>
}
}
< / pre > < br >
< / pre > < br >
< p >
< p >
Now only the change to LineCounterBrowser to actually use this code is
Now the LineCounterBrowser code has to be changed to use the code we just wrote.
missing.
< / p >
< / p >
We will need a member variable storing the list of existing counting algorithms:< br >
We will need a member variable storing the list of existing counting algorithms:< br >
< pre > List< CountingAlgorithmDescriptor> countingAlgorithms;
< pre > List< CountingAlgorithmDescriptor> countingAlgorithms;
@ -555,7 +560,7 @@ the zip file to "LineCounter.sdaddin". That really was everything you had to do
where you can install the AddIn with just one click. AddIns installed this way
where you can install the AddIn with just one click. AddIns installed this way
will be extracted to %Application Data%\.ICSharpCode\SharpDevelop2\AddIns.< br >
will be extracted to %Application Data%\.ICSharpCode\SharpDevelop2\AddIns.< br >
< br >
< br >
< img src = "LineCounterSharp Develop AddIn/addinmanager.png" title = "AddIn Manager screenshot" > < br >
< img src = "LineCounterSDAddIn/addinmanager.png" title = "AddIn Manager screenshot" > < br >
< h2 >
< h2 >
More AddIn-writing help
More AddIn-writing help
< / h2 >
< / h2 >
@ -589,7 +594,7 @@ will be extracted to %Application Data%\.ICSharpCode\SharpDevelop2\AddIns.<br>
Summary
Summary
< / h2 >
< / h2 >
< p >
< p >
This article shows you how to start writing SharpDevelop AddIns. It is a
This article shows you how to start writing SharpDevelop AddIns. It is a
complete walkthrough from creating a new project to creating the installation
complete walkthrough from creating a new project to creating the installation
package.
package.
< / p >
< / p >
@ -601,9 +606,7 @@ will be extracted to %Application Data%\.ICSharpCode\SharpDevelop2\AddIns.<br>
18< sup > th< / sup > July, 2006: Article published (based on SharpDevelop
18< sup > th< / sup > July, 2006: Article published (based on SharpDevelop
2.0.0.1591).
2.0.0.1591).
< / ul >
< / ul >
< br >
< br >
< br >
< / body >
< br >
< br > < / body >
< / html >
< / html >