Contents tagged with English
-
How to Determine the Localized Name of the Scope for a Key Binding (Dirty Hack)
Here’s a tip I actually wanted to share some time ago, but kind of forgot about it until I got reminded by a recent post by Thomas Müller who I had nice contact with some months ago.
In order to assign a keyboard shortcut to a Visual Studio command from code (e.g. in an add-in), one has to specify a binding consisting of the shortcut’s scope (e.g. “Global”, or “Text Editor”) and the actual keys to be pressed (e.g. “ctrl+shift+d”). For example in C#:
DTE2 objApplication;
...
Command cmd=objApplication.Commands.Item("TheNamespace.TheClass.TheCommand", -1);
cmd.Bindings="Text Editor::Ctrl+Shift+D";(The example shows how to assign a single shortcut. Multiple shortcuts can be assigned, please see this entry in the MSDN libary for more details)
When Microsoft released the international versions of Visual Studio 2005, I received a lot of feedback from users of my add-in GhostDoc who ran into problems during setup with the creation of the hotkey for the “Document This” command. Debugging GhostDoc on a German version of Visual Studio 2005 (which by the way was a strange experience as I never had used a developer tool in my native language before), I found out the following:
- When you read a binding of a command (in C# by casting the
Bindings
property of aCommand
instance toobject[]
, and casting an array item tostring
), you get the localized text (e.g. “Text-Editor::Strg+Umschalt+D” in German Visual Studio 2005) - When you define a binding using the localized text, you get an error (hmm…).
- When you define a binding using the non-localized text, you get an error (huh?).
- You have to define a binding using the localized scope and the non-localized key names (…mkay).
But where to get the localized name of the scope from? I couldn’t find anything on the web, and posting a question in the MSDN Extensibility Forum didn’t help either.
What I did in the end must be considered a dirty hack and should be used with caution:
- In my case, I needed the localized name for “Text Editor” (“Text-Editor” in German, “Editor de Texto” in Spanish).
- I chose a command that – at least with a high probability – never would be assigned to an other scope than “Text Editor” (
Edit.DeleteBackwards
) and read the first entry of its bindings. - The sub-string up to the “::” was the desired localized name of the scope.
Here's the C# code to do that (all error handling stripped):
Command cmd=objApplication.Commands.Item("Edit.DeleteBackwards", -1);
object[] arrBindings = (object[]) cmd.Bindings;
string strBinding = (string)arrBindings[0];
string strScope = strBinding.Substring(0, strBinding.IndexOf("::"));By now, every professional developer should have bad feeling about this solution – there are just too many coding catastrophes in the history of computing that started with “it should be safe to do that, nobody will ever…”. So if you have a better solution, please let me know. If you do chose to go that route and need the localized name of an other scope than “Text Editor”, make sure you chose the command veeeery wisely.
- When you read a binding of a command (in C# by casting the
-
Three Years of Blogging
Three years ago on this day I started this blog… Originally, I had planned to write a blog entry looking back at some of the stuff that happened since my “Two years of Blogging” post. But suddenly outside the wind died down completely, so I took my little electric R/C plane (which doesn’t like any wind at all) to the next football (soccer) field.
The weather was just incredible (not a single cloud to be seen!) and with the moon up in the sky, I just had to take a picture. Unfortunately I didn’t have my digital camera with me, so – in true geek style – I used my XDA Neo (aka HTC Prophet). Taking a picture and controlling the plane at the same time proved to be a bit difficult, so I made only one attempt, but that turned out pretty well:
A little closer:
-
GhostDoc 1.9.4 (for Visual Studio 2005) Released
A couple of issues were found shortly after the release of version 1.9.3 yesterday, so here’s version 1.9.4 of GhostDoc for Visual Studio 2005 (download on the GhostDoc website)
- Fixed: Installation "for everyone" not working in 1.9.3 (since preview 3).
- Fixed: Configuration dialog using huge amounts of CPU time when clicking certain parts.
- Fixed: Inherited documentation in VB.Net sometimes being garbled.
Here’s my usual disclaimer: VB.Net support is regarded as "experimental", it is turned off by default and you have to turn it on in the configuration dialog.
For a list of what was new in 1.9.3 see this blog post.
-
GhostDoc 1.9.3 (for Visual Studio 2005) Released
Version 1.9.3 is a bugfix release of GhostDoc for Visual Studio 2005 (download on the GhostDoc website) dealing mostly with installation problems.
- Fixed: GhostDoc not appearing in Visual Studio on systems that had Extensibility.DLL missing in the GAC (caused by uninstallation of other add-ins with buggy installers).
- Fixed: GhostDoc not working on international (i.e. non-US) versions of Visual Studio:
- Assignment of keyboard shortcuts not working on non-US versions
- "Tools" menu not found on "Chinese Simplified" systems
- Fixed: Problems with multiple users on a single machine.
- Fixed: Problems with users working under non-admin accounts (MSI installation still requires admin permissions).
- Fixed: Documentation of indexers in VB.Net (remaining known issue: VB.Net indexers are treated like C# indexers - no explicit <param> tag for the parameter, only the first parameter is mentioned)
- Changed: Summaries of VB.Net properties in interfaces now start with "Gets or sets ..." (remaining known issue: ReadOnly properties are not handled correctly, but that's not easy to correct right now)
Because of the known issues mentioned above, VB.Net support will still remain "experimental" in this release, so it is turned off by default and you have to turn it on in the configuration dialog.
-
Speeding up the C# Source Code Editor
Sometimes, the C# source code editor feels a bit sluggish, even on pretty fast systems. One way to speed it up a little is by turning off the navigation bar (the drop down lists above the code window).
- “Tools” menu -> “Options”
- “Text Editor” -> “C#”
- Uncheck “Navigation bar” under “Display”
Of course, the navigation bar is there for a reason and some people just can not live without it. But if you’re like me, and don’t use all the time, you may find the following macro for toggling the navigation bar helpful:
Sub ToggleCSharpNavigationBar()
Dim objShowNavigationBar As EnvDTE.Property
objShowNavigationBar = DTE.Properties("TextEditor", "CSharp").Item("ShowNavigationBar")
objShowNavigationBar.Value = Not objShowNavigationBar.Value
End SubInstallation:
- Open the Macros IDE (“Tools” -> “Macros” -> “Macros IDE”)
- Either create a new module or use an existing one (e.g. I have a module “Misc” where I collect all my small macros) and paste the code into it.
You could assign the macro to a hotkey (Tools -> Options -> Keyboard), but even though I use hotkeys a lot, for this macro I prefer an icon in a toolbar near the navigation bar:
- Right click the toolbar area -> “Customize”
- The “Customize” dialog opens
- On the “Toolbars” tab: Create a new toolbar (e.g. "My Macros")
- Drag the (floating) toolbar to the toolbar area and move it somewhere near the navigation bar.
- On the “Commands” tab: Click the category "Macros"
- Choose the macro (e.g. "MyMacros.Misc.ToggleCSharpNavigationBar") from the “Commands” list and drag it to the toolbar
The toolbar will look something like this:
- Copy the following image
to the clipboard
- Back in Visual Studio, right click the macro name -> “Paste Button Image”
- Right click the macro name -> “Default Style”
- Right click the macro name -> “Name” -> Enter "Toggle Navigation Bar"
- Close the “Customize” dialog
The button on the toolbar is now ready to use and will look like this:
-
"Advent and Evolution of WPF" on Channel 9
No demos, no cool effects. But yet Michael Wallent talking about the road from DHTML to WPF was one of the most interesting Channel 9 videos I’ve seen recently.
-
GhostDoc: Looking for International Beta Testers
I’m in the process of getting GhostDoc 1.9.3 out the door. This is mainly a bugfix release adding support for international versions of Visual Studio 2005. If you are using a different combination than
- Visual Studio 2005 (English) on any language version of Windows
- Visual Studio 2005 (German) on a German Windows version
and if you are interested in trying an installation of version 1.9.3, please send an email to
gd193beta@roland-weigelt.de, I’ll get back to you in the next days.Please include the following information in your email:
- Language of your OS
- Language of your Visual Studio 2005
Please note that the preview version sent out to testers does not contain any hot new features, so if 1.9.2 is running on your system just fine, you won’t miss anything.
Update: The new version has been released, the email address is now disabled (too much spam).
-
A Sneak Peek at GhostDoc 2.0
In order to be able to generate better documentation comments, the next major version of GhostDoc not only looks at identifier names, but also performs some in-depth code analysis. Here are some screenshots:
Update 2006–04–02: Ok, ok, just kidding… just a little April Fool’s joke…
-
Code Snippet for Throwing an ArgumentNullException
Name: ArgumentNullException Description: Inserts code for throwing an ArgumentNullException. Shortcut: ane Result: if (parameter == null)
throw new ArgumentNullException( "parameter" );Download: ArgumentNullException.snippet -
Code Snippet for a Divider Comment
Name: Divider Description: Inserts a Divider Comment. Shortcut: div Result: //===================================================
// text
//===================================================Download: Divider.snippet
Funny, this wildly unspectacular snippet is one of my most-used. For previous versions of Visual Studio, I had a macro for inserting this comment, but code snippets are much better, as they disturb the natural flow of typing much less.