Command Image Changing Extension

Command Image Changing Extension

Rate This
  • Comments 35

  Hi, I’m Ryan Molden, a developer on the Shell team.  Due to popular feedback from users I have been reassigned to a top-secret UI project.  I can’t say much about it, just give you a quick sneak peek.

ClippyInVS 
  No wait, that’s not right, I mean I set aside some of my free time and wrote an extension for Visual Studio 2010 that allows users to change the images on the command UI as many customers had complained of the pain of not being able to do this in the RTM version of the product.  The extension is freely available on the Visual Studio Gallery and has the following awesome features:

  1. Allows users to change the image associated with any piece of command UI (toolbar buttons & menu items) in Visual Studio.

  2. Contains all images that are used in the Ultimate edition of Visual Studio indexed with search text to make locating an icon easier.

  3. Allows copy/paste (keyboard and context menu) as well as drag & drop within the tool window to change the images on command UI.

  4. Allows pasting from the Windows Clipboard and automatically performs low color conversion (Near Green and Magenta are mapped to Transparent) and size conversion (to 16x16).

  5. Allows users to load an image off their disk (supported formats:  jpg, png, gif, tiff, bmp) and use it in their Visual Studio command UI.

  The interaction model with the extension is slightly different than command image customization in Visual Studio 2008 since I couldn’t change already shipped assemblies in an out of band extension.  This article aims to be a walk-through of the extension and how it works.

Getting Started

First off, you can get the extension here.

After installing the extension there is a new item on the Tools menu with the text Customize Command Images (as shown below)

ToolsMenuAfterInstall

When you invoke the item it brings up a tool window that looks like this

CommandingImageToolWindow

The UI Explained

  Since I wrote this extension in my free time, and I am not a UX designer, apologies if you consider the UI to be terrible.  All flaming arrows can be directed at me and not my teammates.  That apology out of the way, let’s dig into what is here and what you can do with it.  To start, let’s think of a scenario where you would WANT to change command UI.  The most common scenario would be that you have created a custom toolbar and filled it with macros you wrote and you want to make it go from this

CustomToolBar-Before 
to this

CustomToolBar-After 
  Since I couldn’t change already shipped assemblies I couldn’t support drag & drop onto the existing UI nor could I integrate the image swapping with the existing customization dialog.  To that end we have a tool window with two distinct areas.  At the top is the hierarchical command view area, and at the bottom is the available images area. 

The Hierarchical Command View Area

  The area outlined in red in the picture below is the hierarchical view of the command UI in Visual Studio. 

HierarchicalViewArea

This consists of a few main parts; I will tackle each one in turn.  First up is the search text box.  In this area you can type text, and the tree view will be filtered down to only show nodes   which contain the typed text.  One caveat to share, the hierarchy is built up by recursively enumerating the DTE models for all menus/toolbars/context menus in Visual Studio.  Since there are a very large number of them (there are over 11,000 ‘buttons’ in the Visual Studio command UI) this is done as lazily and asynchronously as possible.  This means that before the hierarchy nodes are expanded their children have not been calculated and search can’t really match against anything, since there is nothing to match against.  If you type in the textbox before the hierarchy has been built, the UI will show a warning icon in place of the search icon.  This will look like the picture below (imagine your cursor was hovering over the warning icon, which is where the tooltip is coming from)

HierarchyWarning

This is just warning you that any filtering that is done may be incorrect since the entire hierarchy has not been constructed.  You are of course safe to ignore this if the filtering results in what you want.  If it doesn’t there are two approaches.  One approach is to click the button highlighted below

ForceBuildHierarchy

which will force an asynchronous build-out of the entire command hierarchy.  This can take a while and use up a decent amount of memory as it constructs in memory-models for all the command UI that exists in all of Visual Studio.  I wouldn’t recommend doing this, but if you know that some command exists that you want to associate an image with, but you don’t remember the exact location it exists in this can be helpful.  The second way you can get the filtering to see the nodes you want to modify is to expand the nodes that lead to the command(s) you are interested in. 

  You may be asking “why would I need to filter if I already know where the command is and have to expand nodes leading up to it anyways?”  Good question, astute reader!  One possible scenario is that you want to have a less cluttered area to prepare for the image switching or perhaps you know the command exists in a couple of locations and you want to change the image in each location.  An example of the second scenario can be shown below

FilterNodes

Another place this is useful is in culling down the list of context menus.  Since there are many context menus in Visual Studio expanding that node and finding one of interest among the children can be an adventure.  One way to make that a bit easier is to expand the Context Menus node in the tree view then enter text into the search box that would narrow it down to the context menu you are interested in.  An example of that is shown below.

FilterCM

  Now that I have explained the search textbox and the Force Build Hierarchy button, I guess the next obvious bit is the tree view itself.  As one can see the tree view simply shows the hierarchical arrangement of command UI in Visual Studio under some ‘grouping’ nodes (MenuBar/ToolBars/Context Menus).  The MenuBar node is the main menu in Visual Studio.  The Toolbars node contains all non-tool window toolbars in Visual Studio and the Context Menus node contains all Context Menus in Visual Studio.  The nodes in this tree view serve as the ‘targets’ of the image replacement actions.  The only nodes that will accept image replacement are leaf nodes (the ones representing individual commands).  Each leaf node has a context menu that looks like so

CommandNodeCM

This is a standard Visual Studio context menu and supports the Copy and Paste commands.  Copy will be enabled anytime the node in question already has an image associated with it.  If invoked it will copy the image into an internal storage location that can be used for subsequent Paste operations.  Copy does not place the image in the Windows Clipboard due to concerns about icon licensing, ownership and potential reuse outside Visual Studio.  The Paste command will replace the image that is associated with the target node (if any) with the one from the internal storage location.  The Paste command will be enabled in the following three scenarios

  1. You have copied an image from a leaf node in the tree view via the Copy command.

  2. You have copied an image from the image list in the lower half of the tool window (discussed later) via the Copy command

  3. You have data in the Windows Clipboard that WPF recognizes as being image data.  NOTE:  When pasting from external programs we will auto-convert the image size 16x16 and mask Near-Green (RGB: 00FE00) and Magenta (RGB: FF00FF) colors to transparent since the Windows Clipboard has very spotty support for transparency information and previous versions of Visual Studio have treated those colors as being transparent.

The context menu is accessible in the ‘usual ways’ (i.e. right click, context menu key, shift-F10).  Also note that the regular keyboard shortcuts for Copy/Paste should work as well, so there is no need to bring up the context menu if you don’t want to.

  The only thing about the hierarchy view area that is left to explain is the Refresh Button and the ‘Show only visible items’ checkbox.  Since the Refresh Button is only enabled and only makes sense when the ‘Show only visible items is checked’ I will explain it (and why it is needed) after explaining the checkbox. 

  The checkbox controls whether the tree view will show all items under a specific container (toolbar/menu/context menu) or just the ones currently visible in the UI.  By default it is checked meaning we will only show command UI that is currently visible in the Visual Studio UI.  One exception is for the Context Menus node.  Since it would be impossible for a Visual Studio context menu to actually be visible while you are interacting with the tool window we obviously won’t hide them as they would then never be available for customization.  The Refresh button deals with the fact that there is no DTE event (or other type of event) that would alert us when the visibility of a piece of command UI has changed.  This means if you say load a project and new menus become visible, or you show a toolbar that wasn’t previously shown, the tree view can’t update automatically as there is no way for it to be notified this has happened.  The ‘hacky fix’ is the Refresh button which will cause the tree view to re-process the controls visibility state which will show/hide ones based on the most up to date information.

The Images View Area

  The area outlined in red below is the view of images available for use in the command UI in Visual Studio. 

ImagesViewArea

This list is pulled in from an on disk cache that ships with the extension.  This is done because enumerating 11,000 buttons in Visual Studio using DTE and tracking unique images found can take some time and use some memory.  Since this collection of images is fairly static I chose to do it on my development machine and cache the results into an on disk file for quick startup / usability.  I will talk more about the caching below.

  The area has a search/filter textbox like the hierarchal command view area that is usable right away to filter the image list.  You may wonder “Filter on what?”  The answer is that we associate the button text of all buttons we find a given image on with that image and use that as searchable text.  Since some images are used in multiple places some images have multiple, distinct search strings.  The search box will cause the image list to be filtered down to include only images whose search text contains the text from the search box.  This can be helpful in finding images that might work well for buttons that you perhaps created yourself (say that are associated with a macro).  For instance assume you have a macro that sets your office on fire so you can leave early on a Friday, because after all, who among us hasn’t written such a macro? [Note to management:  I haven’t]  Well a great icon to help remember what that macro does would be some kind of fire.  So you could do something like what is shown below

HotImage 

Problem solved!

  You’ll notice there is also a button that looks like the ‘Force Build Hierarchy’ button in the hierarchical view area.  This is the ‘Rebuild Image Cache’ command, and it is shown below

RebuildImageCacheButton 

This will rebuild the on-disk cache using your local install.  This can be useful if there are packages or addins you have installed locally which have images you may want to have available for re-use on your own command UI (or just replacing stock Visual Studio images for commands).  This is done asynchronously and takes a little while (again, the processing of 11k buttons).  Progress will be shown at the bottom of the tool window and you are free to go about doing other things while this is happening.  When it is done the result will be saved to disk so on next launch any images not in the original cache will still be present in your image window.

  The button next to the ‘Rebuild Image Cache’ button is the ‘Add Image(s) From Disk’ command and is shown below

AddImagesFromDisk

This command opens a dialog that lets you choose one (or many) images from your local machine to add to the existing image cache.  The button launches the standard Open File dialog and when the images are chosen it shows a dialog like this (well, except the images will of course be different)

AddImagesFromDiskDlg

It shows each image you have selected, resized to 16x16 and also color converted (Near-Green and Magenta –> Transparent, as talked about in the hierarchal command view area section above).  The textbox next to each image allows you to associate search text with the image and defaults to the image’s file name without extension.

  The ‘Save Added Images in Cache’ checkbox determines if the images you are loading should be saved into the cache (thus available in the image view on future launches of Visual Studio) or if you want them in the image view area just for this session, but not permanently.  What you choose here doesn’t affect your ability to use the images on your command UI, it only affects if they will be available in future customization sessions without having to re-load them again via this same dialog.

  Clicking OK will take you back out to the main tool window with the first image you added selected and scrolled into view in the image view area.  NOTE:  If you have filter text in the search text box, and the search text of the added images doesn’t contain the text the nodes will not be visible in the image view area.  This is by design.  Clicking cancel or the red X to close the dialog window will result in the images not being placed into the image list.

  Now that you know how to load your own images and rebuild the cache locally if you so desire we can tackle the question “How the heck do I get these images onto my UI already?!?!”  There are again a couple of ways you can do this.  First, we assume the node you are targeting is visible in the hierarchical view area of the tool window.  Let’s assume I want to change the icon of File->Exit.  Initially my tool window looks like this

FileExitInitial

Now I have two choices.  I can copy / paste via the keyboard or context menus (the images in the image view area also have a context menu available, but only support Copy).  To do this I invoke the Copy command while the image is selected, I then select the Exit command in the hierarchy view area and choose Paste.  Another method is to drag & drop from the image area up to the tree view area.  Since print screen doesn’t capture cursors I can’t show this ‘in action’ but the cursor is changed to show the image you are dragging and will have a red X over the top if you try to drop it somewhere that isn’t allowed.  If you are over a valid node in the tree view the red X should go away and you are free to drop there.  Once I have done this the tool window will look like this.

Success

Success!  This change will now be visible on the File menu (as shown below) as well as being persisted and re-applied on subsequent sessions of Visual Studio.

Success2

Okay, what’s the catch?

  Has this extension fulfilled all of your longings around command image customization?  If not please do leave feedback in the comment section.  There are a couple of known issues that customizations like this may expose.  These bugs have since been fixed but the RTM version of the product does have them :(

  1. Bug:  If you customize a given menu/toolbar across multiple sessions the customizations made in the last sessions will be the only ones to ‘stick’ on shutdown.  This means all will likely look well in the UI of Visual Studio after say customizing the image.  If you then restart Visual Studio the customizations made to that menu/toolbar will have reverted, except for the ones made in the last session.

    Work Around:  The work around is to not modify the same toolbar/menu across multiple sessions, which I admit is kind of a sucky work around, but unfortunately due to the bug there isn’t a lot of other choices until we get the fix out there.

  2. Bug:  If you change the styling of a command in the Tools->Customize dialog on the Commands Page via the Modify Selection drop down (i.e. if you change from say ‘Default Style’ to say ‘Image and Text’) AFTER you have done other customizations (such as rename, or changing the image) the only thing that will be remembered on shutdown is the style change, not the rename or image change.

    Work Around:  Do the style change FIRST then make other changes.  This is obnoxious but hopefully not too much so.  The problem is the style flag overwrites a byte we use to track what changes have occurred (as opposed to ORing its value into the existing changes byte).

Conclusion

  I think that covers the extension.  Hopefully for those of your for whom the pain of the changes around the customization space impacted you greatly this extension will help even if just a little.  If there is something I overlooked or something that is unclear or just general feedback/complaints feel free to post in the comment section.  I really do read them and take them to heart (perhaps too much so at times).

 

BlogPic

Ryan Molden – Developer, Visual Studio Platform

Short Bio:  Ryan has been at Microsoft since 2005 when he bought an online diploma graduated from the University Washington with a BSc in Computer Science.  He has been working on the Visual Studio Platform team for the last 2 years.  His destructive tendencies have been primarily focused on the Visual Studio command system and the conversion of the UI layer of said command system to WPF.  When not at work he enjoys long walks on the beach and conversing with extenders of Visual Studio to help them solve their problems and brainstorm future features for Visual Studio.

Leave a Comment
  • Please add 3 and 7 and type the answer here:
  • Post
  • Hello, Ryan.

    Nasty bug:

    · Change icon for the «Cancel» button on the «Build» toolbar.

    · Restart VS

    · Modify the same toolbar with «Tools\Customize» - set «Begin a Group» for the «Build Solution» button.

    · Restart VS

    · The changed icon has reset to original state.

    The same occurs with most buttons/menus (not quite each). In place of «Begin a Group» may be any other modification on the toolbar.

    This makes the extension useless!

  • @Roman

    Yes this is a known issue :(  I talked about it in the article, it is the one explained in bullet point #1 of the 'Okay What's the Catch' section.  It has to do with us not properly recognizing customizations made in previous sessions as customizations, so when we shut down a subsequent session and there are pending customizations from that session we only save those customizations (overwriting the previous sessions customizations :()  It has since been fixed, but unfortunately the only work around in RTM is to not make customizations to the same menu/toolbar across multiple sessions.

    Ryan

  • hi

    do you know why Edit/Find Previous (Selected) and Edit/Find Next (Selected) dont show up in the command view when i search "previous" or similar?

  • @Kai

    I don't see these items on my Edit menu even when I toggle a switch to show all items.  Are these items actually on your edit menu?  Or are they just in the Edit 'category' on the Add Command dialog/keybinding page?  If it is the latter it likely means these commands are marked 'CommandWellOnly' which means they aren't really on the Edit menu, they simply act like they are in order to get a canonical name (Edit.FindPreviousSelected) generated for them.  If you add them explicitly in the customize dialog so they actually appear on your Edit menu then they should also show up in the dialog, if not it is a bug.

    Ryan

  • it works now (no idea what i did wrong :)

    thanks

  • Hi Ryan!

    Thanks for the workaround.  I guess you guys will not have been deaf to the shouts of the dev community: bring back our customization!!

    Meanwhile I installed your extension but the menu item does not show in the Tools menu.  The extension manager shows that CommandingImage is installed.  I also have Resharper, TeamCity and Git installed.  What's going wrong?  Any idea?

  • @Amos

     Nope, I have definitely heard the shouting :)

     Sorry for the slow response, I have been heads down on various and assorted things lately. As for the menu item not showing in the Tools menu, that is odd.  Have you restarted VS since install? It won't show in the same session as it was installed. If you have restarted can you try going to Tools->Customize and seeing if it is shown under the Tools menu entry on the Commands tab?  If it isn't shown there it seems VS has no idea about the command entirely, which is an issue I haven't seen yet. You can try running devenv /setup to try and 'force' it to re-process the menu contributions, but it should have done that first launch after install. If none of that works feel free to post back here (or write me directly at rmolden AT microsoft DOT com) and we can try and figure out what is going wrong.

    Ryan

  • 2. trial

    hi ryan,

    at first I have been very happy to find this solution for the "icon-problem" in vs 2010 but, unfortunately if I expand a toolbar or click on the "Hierarchical command view" button I get this f... error message "visual studio has encountered a problem and needs to close".

    what's wrong, or better, what can I do? I have installed an evaluation version of vs 2010 prof. (english). any idea?

    wolfgang

  • everything's ok now. after reinstallation of vs 2010 command image works fine.

    thx for supplying this solution.

    wolfgang

  • Ryan, I saw your note above about the "wackiness" factor of implementing a drag and drop for changing the tool bar. Wouldn't it be possible to open a tool bar, or multiple tool bars within a modal dialog box, and do all the dragging and dropping within that dialog box? It's not so much that we can't drag and drop to the main window that folks are disappointed with, but that its not possible at all. Changing the tool bars now is so cumbersome, having to open multiple dialog boxes to add a new button, and having to do that every time we need a new button, even if we want to do all the changes at once, most of us are going to avoid it.

    If we could open one window where we could access all the command buttons with a few clicks, and move them to a tool bar within that window, would make things a lot easier. That would make it possible too to drag and drop to tool bars that aren't even loaded within the main window.

  • Ryan, I saw your note above about the "wackiness" factor of implementing a drag and drop for changing the tool bar. Wouldn't it be possible to open a tool bar, or multiple tool bars within a modal dialog box, and do all the dragging and dropping within that dialog box? It's not so much that we can't drag and drop to the main window that folks are disappointed with, but that its not possible at all. Changing the tool bars now is so cumbersome, having to open multiple dialog boxes to add a new button, and having to do that every time we need a new button, even if we want to do all the changes at once, most of us are going to avoid it.

    If we could open one window where we could access all the command buttons with a few clicks, and move them to a tool bar within that window, would make things a lot easier. That would make it possible too to drag and drop to tool bars that aren't even loaded within the main window.

  • Is there a way to use (import) the Office images available by FaceIds while using Visual Studio 2003?

    Some FaceIds are listed here: www.kebabshopblues.co.uk/.../visual-studio-2005-tools-for-office-commandbarbutton-faceid-property

  • @Roger about reverting changes

    I changed some icons by mistake too.

    If they previousy DID have an icon, the only way I've found is to look for the original one and set it again with this extension.

    If they previously did NOT have an icon at all, the only way I've found to "remove" the new icon is to go for tools\customize\commands and then temporarily modify the selected command to "text only" style, then revert back to "default style".

    HTH

  • Where can we vote on the bugs listed in the section "Okay, what’s the catch?"?

  • This trashed my toolbar.  The images i dragged where place on other menu items.

Page 2 of 3 (35 items) 123