SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Christian Hornung

ResourceToolkit addin

The ResourceToolkit addin has been added to SharpDevelop 2.1 ("Serralongue") in revision 1866.

It is intended to be used in development of localizable applications and helps the developer with managing string resources by providing tool tips on resource keys and code completion. These features are currently working in most cases when the .NET framework resource accessing classes (System.Resources.ResourceManager or derived classes) are used. String resource access using ICSharpCode.Core ("${res:...}" or ResourceService.GetString) is also supported. The following screenshot shows the resource code completion window:

Resource code completion window

The documentation of the previous (discontinued) stand-alone version of this addin is still available on my website:
http://dev.hornung.dynalias.com/
There you can find some more detailed information especially on the exact coding requirements for the addin to detect the resource references. 

If you already had the stand-alone version installed, and are now upgrading to a newer SharpDevelop build, you should uninstall the stand-alone version using the AddIn Manager to avoid problems and duplicate menu items. 

 

New features

The integrated version of the addin has some new major features that were not present in any previous version.

First, "Find references" and "Rename" commands are now available for resource keys:

Resource refactoring menu 

They operate on the whole solution and can be used like the similar commands for classes, methods etc.
"Rename" will rename all occurrences of the resource key in code, the resource key itself in the resource file and also in all localized resource files with the same name, as long as these are in the same directory as the main resource file.

Two other new commands are available through the tools menu:

 

These commands also operate on the whole solution. Their performance is quite bad at the moment because they need to resolve all resource references in all source code files, but I have already some ideas how to improve that.

"Find missing resource keys" looks for resource keys that are referenced in code but cannot be found in the resource file. The results are displayed in the search results panel:

Here I ran this command on a copy of the SharpDevelop source code (this took about 72 seconds in debug mode, by the way). The one item it has found here is not actually a missing key. The addin has found the string "${res:" as an indication of an ICSharpCode.Core resource reference, but of course it cannot find this key because it is concatenated at runtime with a variable, and so this key is reported as missing.
 

"Find unused resource keys" looks for keys that are present in a resource file but not referenced anywhere in code. The results are displayed in a new view:

 

Here I ran this command on the SharpDevelop solution as well.

Note that you have to be very careful with the list you get here. The addin cannot detect all kinds of resource references, especially not ones that are outside the scope of the open solution. So this list most probably always shows some keys that are in fact used somewhere. For example, all the "Templates." keys are listed here although they are used, because the are only referenced in the external template files which the addin knows nothing about.
Because of this problem, I plan to add some filtering capabilities to this view so that you can filter out the "false positives" more easily.

Resource keys can be deleted directly from this view by using the context menu or the delete button in the SharpDevelop toolbar after selecting one or more rows in the list. The keys are also deleted from the localized resource files if these are in the same directory as the main resource file. 

Comments

 

Blue Ninja said:

It seems that the code completion and tooltips are triggered by "GetString("${res:", but not simply by "GetString(". So, I am having trouble figuring out how to make use of this handy functionality from VB.NET. Is it possible, and if so, any tips on how to do it? Thanks!

October 22, 2006 7:25 PM
 

Christian Hornung said:

It should be possible, but there may well be cases where the references are not detected correctly.

Could you show some code that makes clear what you are actually trying to do?

I'm only guessing here, but are you perhaps referring to a GetString method you have written yourself? The addin cannot detect user-defined GetString methods, only the predefined ones (ICSharpCode.Core.ResourceService.GetString and System.Resources.ResourceManager.GetString).

"${res:" works independently of that because it is not tied to a specific method call.

October 22, 2006 8:51 PM
 

Blue Ninja said:

I think the "${res:" thing is C# only, as I don't know of an equivalent in VB (if there is one, let me know!)

In my project, I have a StringResources.resx file and I have declared:

   Public StringResources As New Resources.ResourceManager(My.Application.Info.AssemblyName & ".StringResources", My.Application.GetType().Assembly)

I expected that when I typed "StringResources.GetString(" that I'd get the auto-completion list of values, but I don't. I had not created an indexed accessor to see if that would work by allowing "StringResources[" to bring up the list.

Thanks for the info so far - this looks like an extremely handy tool, I just hope I can make good use of it in VB as well as C#!

October 23, 2006 7:21 AM
 

Christian Hornung said:

First, "${res:" is not specific to any programming language, but to the ICSharpCode.Core framework. If you are using the ICSharpCode.Core resource access methods (like StringParser.Parse), you can use "${res" in all languages.

I think I see the problem now. The name of the resources in the ResourceManager constructor must be specified as a single string literal because the addin cannot evaluate expressions. So it should work as expected if you replaced

My.Application.Info.AssemblyName & ".StringResources"

with

"YourAssemblyNameHere.StringResources".

October 23, 2006 11:38 AM
 

Blue Ninja said:

You, sir, are a scholar and a gentleman! That worked perfectly, thank you. I'll play around with the ICSharpCode.Core methods and see what I can dig up there as well.

October 23, 2006 5:56 PM
 

Matt Ward said:

Here is the list of features that have been added to SharpDevelop 2.1. Feature Description Code Analysis

March 5, 2007 7:28 PM
 

vioxx celebrex pennsylvania said:

vioxx celebrex pennsylvania

October 4, 2007 7:01 AM
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.