April 2004 - Posts
Yesterday I was trying to access to the service STrackSelection (in order to change the selection in visual studio), I was very confused because in some cases the GetService failed.
For example when I requested the service in the package initialize the getservice failed.
protected class MyPackage : Package
override void Initialize()
{ base.Initialize();
ITrackSelection track = (ITrackSelection) GetService(typeof(STrackSelection));
}
However If I implement a tool window and call the GetService on the service provider of the toolwindow the GetService call succeed
This behavior was very well explained by Douglas Hodges (Microsoft):
“...ITrackSelection or IVsTrackSelectionEx (“SID_STrackSelection” or “SID_SVsTrackSelectionEx” respectively) are only available from the IServiceProvider that is implemented on the site object of a WindowFrame. Basically selection is tracked on a per-window basis. The site pointer that is used to site the IVsWindowPane object provides these TrackSelection services. You can not get these services from the global IServiceProvider that is passed to your IVsPackage object. So the easiest thing is when you are the IVsWindowPane object sited in an IVsWindowFrame, then you are passed the IServiceProvider to use as part of IVsWindowPane::SetSite. If you are not this object, you can still get to the IServiceProvider of an IVsWindowFrame by calling IVsWindowFrame::GetProperty(VSFPROPID_SPFrame, …). Remember you can only set the selection on a window; there is no notion of a global selection context. Each WindowFrame remembers its selection. When the window is activated, its selection is pushed to the global IVsMonitorSelection service that is used by anyone to get events when the selection changes.”
I fixed some bugs and I added 2 new features:
- Generate Images (Tools/Generate Images)
This command will dump all bitmaps and icons as separated files in a selected folder.
- Generate Resource Class (Tools/Generate Resource Class)
If you have a General.resx file then this command will generate a strongly resource class (I mean with a public property for each icon, bitmap or string in the resource). So that for example you can access to your string with GeneralResources.MyString
If the General.resx is in a C# project then the generated file is added to the project.
In the new code you can find how to use DTE and handle commands in VSIPExtras.
Thanks for your feedback
Download: ResourceEditor.msi
When you are developing a package pretty often you have to add a new command, modify or add a menu, toolbar, etc.
In order to do that you have to edit a CTC file that is really painfully because it is not a xml for example then you don't have any editor that help you.
Yesterday in then night I developed a language service for ctc files, then now I have syntax coloring for ctc files (Keywords, Flags, Packages, macros, strings, comments). Now I feel better editing CTC files :)
A CTC file looks like this
CTC with syntax coloring

Additionally you can change the default colors for CTC tokens in VS using the Tools/Options dialog
Installation:
- Download the binary files here CTCEditor
- Open Command Prompt
- If you have VSIP installed then:
"SET ENVSDK_REGKEY=7.1 " (if you have VSIP installed the current value
is 7.1exp)
"SET ENVSDK_ROOTSUFFIX= " (the default value is exp)
4. Extract the zip file and after register both dll in the previous command prompt session( regsvr32 <dll name> )
5. In the command prompt run Devenv /setup
Sources:
The editor was done using VSIPExtras in particular using the babel package.
You can download the sources here: CTCSource
For more info about CTC check ms-help://MS.VSCC.2003/MS.VSIP.2003/vsenvsdk/html/vsgrfCommandTableFormat.htm
Luckly in Whidbey there is a Resource Editor for Editing Resx Files files essentially with the same features that my Resource Editor, then you don't need my resource editor anymore !! (maybe you can use it only for explore dll and exe resources)
But the cool thing about using resources in Whidbey is that you are going to have a "codebehind" for your Editing Resx Files file.
For example if you have a MyResources.resx file you are going to have a MyResources.cs file, bassically this file is a helper class in order to get your resources.
Then if you have an image in your resources called Sunset, then in your code you can use
Image img = MyResources.Sunset;
If you don't know what DeKlarit is take a look of the key features http://www.deklarit.com/hdkfeatures.aspx
Take a look of Key New Features in 3.0 version
http://www.deklarit.com/version
More Posts