Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / September 2005

Tip: Looking for answers? Try searching our database.

Latching Commands

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RR - 28 Sep 2005 21:04 GMT
I'm creating an Add-in and have a top-level menu item (command popup) next to
the Tools menu item in VS IDE. Under that top-level menu, I have a few more
command popup items. Then under one of those command popup items, I have a
submenu with 5 commands.  When a user clicks on one of those commands, I want
to latch it (show a check mark next to it) and any other of the 4 commands on
that submenu to NOT be latched. In other words, I want only one of the 5
commands to be latched at one time.  I'm having a hard time figuring out how
to manage this in the QueryStatus method since I can't figure out which one
was actually clicked. The QueryStatus method gets called for each of the
items even when the menu appears, much less when an item is clicked.  I was
hoping someone else has faced this situation already and could point me in
the right direction?  Any code examples would be a great help.  

TIA,
RR
RR - 29 Sep 2005 21:59 GMT
I received an answer from another newgroup and thought I would include it
here for the sake of completion:

=================================================

Perhaps not the most elegant solution but the working example below
does do what you expect - Steve.

namespace MyAddin1
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using EnvDTE;

[GuidAttribute("12795A44-2D50-448D-8A4B-7829E5E38BED"), ProgId
("MyAddin1.Connect")]
public class Connect : Object,
Extensibility.IDTExtensibility2, IDTCommandTarget
{
public Connect() {}

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
applicationObject = (_DTE)application;
addInInstance = (AddIn)addInInst;

object []contextGUIDS = new object[] { };
Commands commands =
applicationObject.Commands;
_CommandBars commandBars =
applicationObject.CommandBars;

try
{
Command command =
commands.AddNamedCommand
(addInInstance, "MyAddin1", "MyAddin1", "Executes the command for
MyAddin1", true, 59, ref contextGUIDS, (int)
vsCommandStatus.vsCommandStatusSupported+(int)
vsCommandStatus.vsCommandStatusEnabled);
Command command2 =
commands.AddNamedCommand
(addInInstance, "MyAddin2", "MyAddin2", "Executes the command for
MyAddin2", true, 59, ref contextGUIDS, (int)
vsCommandStatus.vsCommandStatusSupported+(int)
vsCommandStatus.vsCommandStatusEnabled);
CommandBar commandBar = (CommandBar)
commandBars["Tools"];
CommandBarControl commandBarControl =
command.AddControl(commandBar, 1);
CommandBarControl commandBarControl2
= command2.AddControl(commandBar, 2);
}
catch(System.Exception /*e*/)
{
}
}

public void OnDisconnection
(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array
custom) {}

public void OnAddInsUpdate(ref System.Array custom) {}

public void OnStartupComplete(ref System.Array
custom) {}

public void OnBeginShutdown(ref System.Array custom)
{}

public void QueryStatus(string commandName,
EnvDTE.vsCommandStatusTextWanted neededText, ref
EnvDTE.vsCommandStatus status, ref object commandText)
{
if(neededText ==
EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
{
if(commandName.StartsWith
("MyAddin1.Connect"))
{
status = (vsCommandStatus)
vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStat
usEnabled;
if (commandName ==
_justLatched)
status |=
vsCommandStatus.vsCommandStatusLatched;
}
}
}

public void Exec(string commandName,
EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref
object varOut, ref bool handled)
{
handled = false;
if(executeOption ==
EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if(commandName.StartsWith
("MyAddin1.Connect"))
{
_justLatched = commandName;
handled = true;
return;
}
}
}
private _DTE applicationObject;
private AddIn addInInstance;
private string _justLatched = string.Empty;
}
}

> I'm creating an Add-in and have a top-level menu item (command popup) next to
> the Tools menu item in VS IDE. Under that top-level menu, I have a few more
[quoted text clipped - 11 lines]
> TIA,
> RR

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.