State driven menuitem in Visual Studio 2012 extension - visual-studio-2012

I am writing a Visual Studio 2012 extension that defines several sub-menus to go in two existing Visual Studio context menus. The sub-menu items appear to work correctly except for one thing:
Until the first menu item in my package is clicked, the state of each menu item is its default state depending on its definition in the VSCT file. That works fine for menu items that are always enabled, but some menu items should be enabled or disabled based on certain changing conditions. After the package is sited, their states are set correctly, but how can I get the states to be set correctly before the first item is clicked?
There is no default state that works in my solution. The conditions might be true or false the first time my menus appear.
If you have a solution for this, or know where this has been addressed in a tutorial somewhere, I would appreciate your help.

I finally discovered the answer to my question at MSDN in an article called How to: Autoload a VSPackage. The "trick" is to set the ProvideAutoLoadAttribute on the package class that's created for the project. Here is the declaration for one of the projects I am working on:
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideAutoLoad("{f1536ef8-92ec-443c-9ed7-fdadf150da82}")]
[Guid(GuidList.guidXamlHelpmeetPkgString)]
public sealed class XamlHelpmeetPackage : Package
{ ...
The third line is all that I added to make the otherwise working extension load early rather than on demand.

Related

Shipment's page customization removes UpdateIN Action

I noticed that customizing the Shipment's page "Confirm Shipment" action, removes the "Update IN" action from the dropdown list. This is occurring even without actual logic in the overriden method - as soon as it's created and published, the action disappears.
Below is the list of steps that I have followed:
The Actions dropdown options for the Shipments page are:
Then, the following customization is created
Which - without any changes - generates the following result:
After publishing the customization, the Actions dropdown is now shown with the UpdateIN action removed:
I noticed that the UpdateIN action is not selectable in the Override Method option of the customization project - that could have some relation with the error:
The action definition however, can be found in the CodeRepository directory (with Visible = False):
Any ideas? Thanks
If I'm not mistaken, this issue has been fixed in 2017 R2 Update 3 (build #17.230.0029). Could you please update your developer instance to 2017 R2 Update 3 or more recent build and check if the issue gets resolved?

Determining which Visual Studio context menu was selected?

I'm writing a VS2012 add-in, adding a command to Build Explorer context menu (see related question). The command gets added to 2 different context menus:
Build Explorer
Team Explorer, Builds page, My Builds section
When my one callback is called, how do I know which of these it is?
I tried get the focused control (using P/Invoke as this question suggests). However, it gets me a Tabs container for (1), and null for (2). I could try to cast the control to the tabbed container, but that sounds pretty bad...
Any better alternative?
My new/other idea - it is similar to yours:
You should try to monitor which window was activated lastly.
If you create an eventhandler for your command, then you may be able to check which window is active when your command fired. A simple evenent handler for a command:
void cmdEvents_BeforeExecute( string guid, int ID, object customIn, object customOut, ref bool cancelDefault )
{
Window2 teamExplorer = _applicationObject.Windows.Item("Team Explorer") as Window2;
if (_applicationObject.ActiveWindow.Caption == teamExplorer.Caption)
{
//You are called from Team Explorer
}
else
{
//Somewhere else
}
}
And the way you can subscribe:
static _dispCommandEvents_BeforeExecuteEventHandler _myHandler;
static CommandEvents _cmdEvents;
public void OnConnection(...)
{
Command command = ...; // Init your command
int ID = command.ID;
string GUID = command.Guid;
CommandEvents _cmdEvents = _applicationObject.Events.get_CommandEvents(GUID, ID);
_myHandler = new _dispCommandEvents_BeforeExecuteEventHandler(cmdEvents_BeforeExecute);
_cmdEvents.BeforeExecute += _myHandler;
}
You may find a better way to identify the window(s) by GUID. You should keep at least _cmdEvents as static because when it will be desroyed, your event handler could vanish (least for internal commands).
In OnDisconnection you should unsubscribe.
Reworked by the comment, and founded links:
As the menu item is shown every place it seems there is no way to distinct between them from an Add-In, you should add two command and distinct them by their context.
The way instead of converting the Add-In to a VS-Package MZ-Tools HOWTO: Controlling the state of command in a Visual Studio add-in, try MZ-Tools HOWTO: Use the IVsMonitorSelection ... you can also get it from an Add-In.
But:
Neither the AddNamedCommand nor the QueryStatus methods honor the
invisible state: the button that must be invisible ...
remains disabled rather than invisible.
I think this makes it impossible to do it from an Add-In on a suitable way, but maybe you can check the contexts.
Other way you could get further, if you try to migrate your command/menu into a VSPackage and create a custom UIContext for the menu items or find a suitable predefined one. I have no access to a Studio enhanced with Build Explorer so I can't try it.
The following discussion is about custom contexts for vs-packages:
http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/
Sadly the links are broken from the post, and I can't reach Part 1. and Part 2. which is about the discussion of the problem from the beginning.
But there is no guarantee you can create a context which suits you.
Only context ID I found for Team Explorer is the guidTeamProjectCmdUIContext.
It is placed at vsshilds.h in Visual Studio 2010 SDK, vsshell*.h are also contain several others.
MSDN: Vsct files to define command, menus, ect. from packages.
Condition attribute for items:
http://msdn.microsoft.com/en-us/library/bb491718.aspx
http://msdn.microsoft.com/en-us/library/bb166515.aspx
MSDN: VisibilityItem element for commands and toolbars.
VisibilityItem element determines the static visibility of commands and toolbars.
... After the VSPackage is loaded, Visual Studio expects command visibility to be determined by the VSPackage rather than the VisibilityItem.
And finally about predefined Context Guids:
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.uicontextguids80.aspx
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.uicontextguids.aspx

In VS2012 how do I filter the Object Browser to display objects in my Project?

In VS2012 how do I filter the Object Browser to display objects accessible from my Project?
As far as I can make out from the UI it can be configured to show either
1) Everything installed on the machine.
2) A manually selected subset of everything installed on the machine.
3) Everything referenced by the entire Solution.
So where is the most useful view of all, namely the view of everything referenced by the current Project?
The MSDN even states that you can use it to view what can be referenced by the Project
http://msdn.microsoft.com/en-us/library/vstudio/exy1facf%28v=vs.100%29.aspx
"The Object Browser lets you select and examine the namespaces, classes, methods, and other programming symbols available for use in your project."
But I can't see how to do it.
You can use the Class View (Ctrl + Shift + C) to see the references available per project.
Look in the Projects References section of each project in the Class View.
Example: Class Library in Solution
Here, I am looking at the System.Collections classes.
Example: WPF Project in Solution
Here I am looking a the System.Diagnostics classes
To view the class in Object Browser, right click and choose, "Browse Definition".

TODO tag comments for SSJS in Xpages in Notes Version 9

At one of the Lotusspere sessions in Orlando, the //TODO comment tag was mentioned. I thought that this was an extremely useful feature but sadly in looks to me like it does not work in SSJS?
Task Tags in XSP sources
Any chance this has been fixed in version 9? It does work in 8, but you need to place it outside your SSJS code block.
I am using the Domino Designer 9 beta build from December (the public beta). The Task Tags functionality still does not include TODO tags in SSJS script libraries and SSJS code blocks.
--
Do the following to control what contents the Tasks view shows:
Choose the Configure Contents
Select "On any element in same project"
You can do the same with the Problems view.
It may have been my session. It's standard Eclipse functionality, so only works in certain editors like the XML Editor. You may have hit the same gotcha I hit during preparation. Enabling it in the Tasks view is not enough. You need to enable it in the relevant editors in the Preferences. Open up preferences and type "Task" in the filter box. It should then get picked up from any SSJS in the source pane. It gets updated when the project is built.

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)): ActiveX and C# Console Application

So, I am playing around with ActiveX and C# and ways how both of them can work together. the thing is I have hit the wall right in the beginning with mentioned error. Steps I have followed:
In VS2010 I selected MFC ActiveX Control project. Then I added a method "SHORT Multiply( SHORT a, SHORT b);" by clicking the Add method option in the menu that pops when you right click _DProjectname under ProjectnameLib in solution explorer. The code for the method is as follows:
SHORT CSampleProgramActivex01Ctrl::Multiply(SHORT a, SHORT b)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: Add your dispatch handler code here
return ( a * b);
}
Now I have created a simple C# console application that references the generated COM file and when I try to use the method, the application stops with the above mentioned error. I have searched the error on the internet but no clear solution is mentioned. Any help appreciated. If you guys want clarification, let me know.
I don't know whether this is considered as solving the problem or not but I found a workaround:
First instead of C# console application, I created C# windows form application. After creating the form, I have added the whole ocx as component in the toolbox. You do this by right-clicking the Toolbox types in Toolbox menu. In the new menu, you click Choose Items. This pops up new menu and in that select the COM tab and in that check your COM component and the COM component will be added to the Toolbox menu. Now drag and drop the component on the menu and you should be good to go.
This seems to be workaround that everybody is following. Not neat but that is the norm I think.
look at here: How to use an OLE control as an automation server in Visual C++
http://support.microsoft.com/kb/146120/en-us

Resources