<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Dynamic Menu Commands in Visual Studio Packages &#8211; Part 3</title>
	<atom:link href="http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 22 Sep 2011 22:12:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: JSLint in Visual Studio Part 2 &#124; Scott Logic</title>
		<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-72</link>
		<dc:creator>JSLint in Visual Studio Part 2 &#124; Scott Logic</dc:creator>
		<pubDate>Mon, 25 Oct 2010 12:40:57 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.rev-net.com/ddewinter/index.php/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-72</guid>
		<description>[...] David DeWinter &#8211; Dynamic Menu Commands in Visual Studio Packages – Part 3 &#8211; Explains how to dynamically turn on and off menu commands. We needed this because the XML used to attach commands was sometimes not specific enough &#8211; for instance all web site files are web item nodes, where as a javascript file embedded in a project is a javascript item node.. [...] </description>
		<content:encoded><![CDATA[<p>[...] David DeWinter &#8211; Dynamic Menu Commands in Visual Studio Packages – Part 3 &#8211; Explains how to dynamically turn on and off menu commands. We needed this because the XML used to attach commands was sometimes not specific enough &#8211; for instance all web site files are web item nodes, where as a javascript file embedded in a project is a javascript item node.. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xavi</title>
		<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-71</link>
		<dc:creator>Xavi</dc:creator>
		<pubDate>Wed, 26 May 2010 14:55:10 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.rev-net.com/ddewinter/index.php/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-71</guid>
		<description>Hi Tom, 

this is a great tutorial. But i have a doubt. I have changed the the location of the commands to the menu tables of Server Explorer. And now the problem, how can i get the selected node in MenuItemCallback?

thank you very much</description>
		<content:encoded><![CDATA[<p>Hi Tom, </p>
<p>this is a great tutorial. But i have a doubt. I have changed the the location of the commands to the menu tables of Server Explorer. And now the problem, how can i get the selected node in MenuItemCallback?</p>
<p>thank you very much</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David DeWinter</title>
		<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-70</link>
		<dc:creator>David DeWinter</dc:creator>
		<pubDate>Sat, 24 Apr 2010 02:06:55 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.rev-net.com/ddewinter/index.php/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-70</guid>
		<description>Hi Tom, thanks for the info! I haven&#039;t done VS package development in a while but I&#039;ll definitely use this code if I run into the same situation. Thanks again!</description>
		<content:encoded><![CDATA[<p>Hi Tom, thanks for the info! I haven&#8217;t done VS package development in a while but I&#8217;ll definitely use this code if I run into the same situation. Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom M</title>
		<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-69</link>
		<dc:creator>Tom M</dc:creator>
		<pubDate>Fri, 23 Apr 2010 19:05:10 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.rev-net.com/ddewinter/index.php/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-69</guid>
		<description>David,

   First, thanks for the article - it&#039;s been very informative!  I was trying to implement a toolbar that would only enable commands when a specific window was open, and since your &quot;BeforeQueryStatus&quot; from Part 2 worked so well for my menu items I tried again.  The problem that I discovered is that toolbar buttons don&#039;t fire the BeforeQueryStatus event, so you can not disable them that way.  I went back to looking at the VisibilityItem and custom Context approach that you outlined here and I think I discovered how to avoid the problem that Kilpatrick described above (losing control when you add it to the IMenuCommandService).

   Instead of using the IMenuCommandService and &quot;Adding&quot; commands to it, you can implement the IOleCommandTarget interface on your package class itself.  Doing that doesn&#039;t invalidate your contexts and the IDE will continue to enable/disable your commands when the context changes.  (The toolbar buttons will not disappear, but menu commands do!)

  To implement this interface, you only need to add two methods as outlined here:
int IOleCommandTarget.Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
{
	 //If it&#039;s not your GUID, then say so.
    if (pguidCmdGroup != GuidList.guidDynamicMenuDevelopmentCmdSetPart2)
    {
    	return (int)Constants.OLECMDERR_E_UNKNOWNGROUP;
    }
    //If it&#039;s not one of your comamnds, then say so.
    if (nCmdID != PkgCmdIDList.cmdidCustomUIContext) 
    { 
    	return (int)Constants.OLECMDERR_E_NOTSUPPORTED;
    }
    //This returns an error if someone requests &quot;Help&quot; for this command, but you have not implemented it.
    if (nCmdexecopt == (uint)OLECMDEXECOPT.OLECMDEXECOPT_SHOWHELP)
    {
    	return (int)Constants.OLECMDERR_E_NOHELP;
    }
    if (nCmdID == PkgCmdIDList.cmdidCustomUIContext)
    {
    	//Add your code here to handle the command
    }
    return VSConstants.S_OK;
}

int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
{
	 //If it&#039;s not your GUID, then say so.
    if (pguidCmdGroup != GuidList.guidDynamicMenuDevelopmentCmdSetPart2)
    {
    	return (int)Constants.OLECMDERR_E_UNKNOWNGROUP;
    }
    //If it&#039;s not one of your comamnds, then say so.
    if (prgCmds[0].cmdID != PkgCmdIDList.cmdidCustomUIContext) 
    { 
    	return (int)Constants.OLECMDERR_E_NOTSUPPORTED;
    }
    //Additional code can be added here to more finely control the display
    //See OLECMDF enumeration for more details.
    return VSConstants.S_OK;
}

(NOTE: The IOleCommandTarget. prefix is added to the methods because the Package already implements IOleCommandTarget, but this forces the package to override that implementation.)

Now you can remove all references to the IMenuCommandService and the code associated with &quot;Adding&quot; your commands from the package initialization.

Thanks again for the great article, and I hope this helps!</description>
		<content:encoded><![CDATA[<p>David,</p>
<p>   First, thanks for the article &#8211; it&#8217;s been very informative!  I was trying to implement a toolbar that would only enable commands when a specific window was open, and since your &#8220;BeforeQueryStatus&#8221; from Part 2 worked so well for my menu items I tried again.  The problem that I discovered is that toolbar buttons don&#8217;t fire the BeforeQueryStatus event, so you can not disable them that way.  I went back to looking at the VisibilityItem and custom Context approach that you outlined here and I think I discovered how to avoid the problem that Kilpatrick described above (losing control when you add it to the IMenuCommandService).</p>
<p>   Instead of using the IMenuCommandService and &#8220;Adding&#8221; commands to it, you can implement the IOleCommandTarget interface on your package class itself.  Doing that doesn&#8217;t invalidate your contexts and the IDE will continue to enable/disable your commands when the context changes.  (The toolbar buttons will not disappear, but menu commands do!)</p>
<p>  To implement this interface, you only need to add two methods as outlined here:<br />
int IOleCommandTarget.Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)<br />
{<br />
	 //If it&#8217;s not your GUID, then say so.<br />
    if (pguidCmdGroup != GuidList.guidDynamicMenuDevelopmentCmdSetPart2)<br />
    {<br />
    	return (int)Constants.OLECMDERR_E_UNKNOWNGROUP;<br />
    }<br />
    //If it&#8217;s not one of your comamnds, then say so.<br />
    if (nCmdID != PkgCmdIDList.cmdidCustomUIContext)<br />
    {<br />
    	return (int)Constants.OLECMDERR_E_NOTSUPPORTED;<br />
    }<br />
    //This returns an error if someone requests &#8220;Help&#8221; for this command, but you have not implemented it.<br />
    if (nCmdexecopt == (uint)OLECMDEXECOPT.OLECMDEXECOPT_SHOWHELP)<br />
    {<br />
    	return (int)Constants.OLECMDERR_E_NOHELP;<br />
    }<br />
    if (nCmdID == PkgCmdIDList.cmdidCustomUIContext)<br />
    {<br />
    	//Add your code here to handle the command<br />
    }<br />
    return VSConstants.S_OK;<br />
}</p>
<p>int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)<br />
{<br />
	 //If it&#8217;s not your GUID, then say so.<br />
    if (pguidCmdGroup != GuidList.guidDynamicMenuDevelopmentCmdSetPart2)<br />
    {<br />
    	return (int)Constants.OLECMDERR_E_UNKNOWNGROUP;<br />
    }<br />
    //If it&#8217;s not one of your comamnds, then say so.<br />
    if (prgCmds[0].cmdID != PkgCmdIDList.cmdidCustomUIContext)<br />
    {<br />
    	return (int)Constants.OLECMDERR_E_NOTSUPPORTED;<br />
    }<br />
    //Additional code can be added here to more finely control the display<br />
    //See OLECMDF enumeration for more details.<br />
    return VSConstants.S_OK;<br />
}</p>
<p>(NOTE: The IOleCommandTarget. prefix is added to the methods because the Package already implements IOleCommandTarget, but this forces the package to override that implementation.)</p>
<p>Now you can remove all references to the IMenuCommandService and the code associated with &#8220;Adding&#8221; your commands from the package initialization.</p>
<p>Thanks again for the great article, and I hope this helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David DeWinter</title>
		<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-68</link>
		<dc:creator>David DeWinter</dc:creator>
		<pubDate>Thu, 16 Apr 2009 00:50:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.rev-net.com/ddewinter/index.php/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-68</guid>
		<description>Gil, are you saying to launch a dialog when someone clicks on file to select it in the Solution Explorer? (Not when a context menu item is chosen?) To answer your question, I&#039;m not sure how to do this; it&#039;s unrelated to what I have discussed in this series of posts.

Also, just my 2 cents, but I don&#039;t think launching a dialog is a great experience for the end user in this case.</description>
		<content:encoded><![CDATA[<p>Gil, are you saying to launch a dialog when someone clicks on file to select it in the Solution Explorer? (Not when a context menu item is chosen?) To answer your question, I&#8217;m not sure how to do this; it&#8217;s unrelated to what I have discussed in this series of posts.</p>
<p>Also, just my 2 cents, but I don&#8217;t think launching a dialog is a great experience for the end user in this case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gil Ballesca</title>
		<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-67</link>
		<dc:creator>Gil Ballesca</dc:creator>
		<pubDate>Wed, 15 Apr 2009 08:03:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.rev-net.com/ddewinter/index.php/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-67</guid>
		<description>Hi David, 

I would like to ask for your help about how can I override the command when the user clicks an item/file in the solution explorer. 

For example:

    the user click the Sample.vb code file then a dialog will be opened. 

Thank you, 
Gil Ballesca.</description>
		<content:encoded><![CDATA[<p>Hi David, </p>
<p>I would like to ask for your help about how can I override the command when the user clicks an item/file in the solution explorer. </p>
<p>For example:</p>
<p>    the user click the Sample.vb code file then a dialog will be opened. </p>
<p>Thank you,<br />
Gil Ballesca.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kilpatrick</title>
		<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-66</link>
		<dc:creator>Kilpatrick</dc:creator>
		<pubDate>Wed, 07 Jan 2009 23:03:39 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.rev-net.com/ddewinter/index.php/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-66</guid>
		<description>Hi David,

Thanks for the clarification and it looks like you&#039;re right. When I implement the technique in Part 2 the command will be dynamic and I can also hook it up to a callback event. It&#039;s a shame that I couldn&#039;t use the technique as defined in Part 3. This would&#039;ve worked well when dynamically displaying commands and menus based on the same criteria. Although I&#039;m sure that I will find a way of doing the same using the technique in Part 2.

Thanks for the speedy reply as well!

Cheers!
Craig Wilson</description>
		<content:encoded><![CDATA[<p>Hi David,</p>
<p>Thanks for the clarification and it looks like you&#8217;re right. When I implement the technique in Part 2 the command will be dynamic and I can also hook it up to a callback event. It&#8217;s a shame that I couldn&#8217;t use the technique as defined in Part 3. This would&#8217;ve worked well when dynamically displaying commands and menus based on the same criteria. Although I&#8217;m sure that I will find a way of doing the same using the technique in Part 2.</p>
<p>Thanks for the speedy reply as well!</p>
<p>Cheers!<br />
Craig Wilson</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David DeWinter</title>
		<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-65</link>
		<dc:creator>David DeWinter</dc:creator>
		<pubDate>Wed, 07 Jan 2009 13:23:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.rev-net.com/ddewinter/index.php/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-65</guid>
		<description>Kilpatrick,

Yes I do. Perhaps this info from the docs can help:

 The VisibilityItem element determines the static visibility of commands and toolbars. Each entry identifies a command or menu and an associated command user interface (UI) context. The visibility is first controlled by the Visual Studio integrated development environment (IDE) without loading the VSPackage.

&lt;strong&gt;After your VSPackage is loaded, the IDE relies on your commands to determine their visibility instead of the static visibility defined in VisibilityItem.&lt;/strong&gt; In an unmanaged VSPackage, implement QueryStatus; in a managed VSPackage, handle the BeforeQueryStatus event.

http://msdn.microsoft.com/en-us/library/bb491710.aspx

Looks as though we&#039;ll have to use the technique in Part 2 for true dynamic menus...

Regards,
David</description>
		<content:encoded><![CDATA[<p>Kilpatrick,</p>
<p>Yes I do. Perhaps this info from the docs can help:</p>
<p> The VisibilityItem element determines the static visibility of commands and toolbars. Each entry identifies a command or menu and an associated command user interface (UI) context. The visibility is first controlled by the Visual Studio integrated development environment (IDE) without loading the VSPackage.</p>
<p><strong>After your VSPackage is loaded, the IDE relies on your commands to determine their visibility instead of the static visibility defined in VisibilityItem.</strong> In an unmanaged VSPackage, implement QueryStatus; in a managed VSPackage, handle the BeforeQueryStatus event.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/bb491710.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb491710.aspx</a></p>
<p>Looks as though we&#8217;ll have to use the technique in Part 2 for true dynamic menus&#8230;</p>
<p>Regards,<br />
David</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kilpatrick</title>
		<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-64</link>
		<dc:creator>Kilpatrick</dc:creator>
		<pubDate>Wed, 07 Jan 2009 06:19:43 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.rev-net.com/ddewinter/index.php/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-64</guid>
		<description>Hi David,

In addition to your response to Manish&#039;s question. When I add the command to the IMenuCommandService (to handle the commands &#039;click&#039; event&#039;) the dynamic showing and hiding of the command ceases to function (it&#039;s always displayed regardless). Do you experience this as well?

Cheers!
Kilpatrick</description>
		<content:encoded><![CDATA[<p>Hi David,</p>
<p>In addition to your response to Manish&#8217;s question. When I add the command to the IMenuCommandService (to handle the commands &#8216;click&#8217; event&#8217;) the dynamic showing and hiding of the command ceases to function (it&#8217;s always displayed regardless). Do you experience this as well?</p>
<p>Cheers!<br />
Kilpatrick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fantasyer</title>
		<link>http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-63</link>
		<dc:creator>fantasyer</dc:creator>
		<pubDate>Mon, 05 Jan 2009 06:41:03 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.rev-net.com/ddewinter/index.php/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/#comment-63</guid>
		<description>It really help me a lot.
Thanks very much!!</description>
		<content:encoded><![CDATA[<p>It really help me a lot.<br />
Thanks very much!!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

