I have a VS2010 VSIP package with several commands,Those commands are added to the javascript editor's context menu,and i am using
<Group guid="guidPrettyJsCmdSet" id="ContextMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
</Group>
but it work only C# file,how to make it work for .js file?
The HTML/CSS/JS code editors actually show different context menus than the main code editor. Unfortunately, the Guid/ID pairs for these context menus aren't published or defined in the Visual Studio SDK.
However, there is a debug hook (since VS 2005 SP1) that lets you identify the Guid/ID of almost any menu item you could be interested in. See this blog post for how to do that.
Using the technique described in that post, if I CTRL+SHIFT+RIGHTCLICK in the Javascript editor, I get the following dialog:
In the <Symbols> section of my VSCT file, I can put the following:
<GuidSymbol name="htmlEditorCommandSet" value="{D7E8C5E1-BDB8-11D0-9C88-0000F8040A53}">
<IDSymbol name="jsContextMenu" value="0x0034"/> <!-- 52 in hex is 0x0034 -->
</GuidSymbol>
Then, it's just a matter of parenting to that Guid/ID:
<Group guid="guidPrettyJsCmdSet" id="ContextMenuGroup" priority="0x0600">
<Parent guid="htmlEditorCommandSet" id="jsContextMenu"/>
</Group>
Related
I'm creating an extension for Visual Studio 2010.
The extension is made available to the user via a button in the Debug-menu of VS.
The button is defined as follows in the VSCT file:
<Button guid="guidRTKDebuggerCmdSet" id="cmdidRtkDebug" priority="0x0300" type="Button">
<Parent guid="guidVSDebugGroup" id="IDG_EXECUTION" />
<Icon guid="guidImages" id="bmpPic1" />
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidRtkDebug</CommandName>
<ButtonText>My Debug Extension</ButtonText>
</Strings>
</Button>
How would I make the button disappear when the debugger starts? All other debug buttons in Visual Studio show exactly this behavior, but my button remains visible all the time.
You need to use VisibilityConstraints (see http://msdn.microsoft.com/en-us/library/bb166229.aspx) and list all needed contexts except UICONTEXT_Debugging (see http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vsconstants.aspx).
<VisibilityConstraints>
<VisibilityItem guid="guidRTKDebuggerCmdSet" id="cmdidRtkDebug"
context="UICONTEXT_SolutionHasSingleProject" />
<VisibilityItem guid="guidRTKDebuggerCmdSet" id="cmdidRtkDebug"
context="UICONTEXT_SolutionHasMultipleProjects" />
</VisibilityConstraints>
I'm creating an Activity Library in Visual Studio 11 Beta (although I've repeated all my steps in VS2010 with the same result), targeting the .NET 4.0 framework.
As I started entering arguments via the Workflow Designer, I noticed the "Enter a VB Expression" message in the Default Value box. I'm not sure how to change the language context from VB to C#.
To create the project, I followed these steps:
Go to File> New and select Project...
In the Installed> Templates section of the New Project dialog window, select Visual C#> Workflow> Activity Library
Name the project, as usual, and click OK
And that's basically it. I noticed then that the default Activity1.xaml file was expecting VB in the default values fields. I deleted it and then followed these steps to create a new Activity:
Right-click on the project and select Add> New Item...
In the Add New Item dialog window, navigate to Installed> Visual C# Items> Workflow> Activity
Name the Activity and click OK
It was the same result, the Default Value fields are expecting a VB expression.
When I look at the XAML code, I can clearly see the Microsoft.VisualBasic.Activities namespace listed and a VisualBasic.Settings element, but I'm not sure what to do to change it; everytime I try, I just end up screwing things up. Here's the XAML code being generated:
<Activity mc:Ignorable="sads sap" x:Class="THINKImport.CustomerAddOrderAdd"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:local="clr-namespace:THINKImport.THINKWebReference"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
xmlns:s="clr-namespace:System;assembly=System.Core"
xmlns:s1="clr-namespace:System;assembly=System"
xmlns:s2="clr-namespace:System;assembly=System.ServiceModel"
xmlns:s3="clr-namespace:System;assembly=mscorlib"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:t="clr-namespace:THINKImport"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Members>
<x:Property Name="user_login_data" Type="InArgument(local:user_login_data)" />
<!--Removed the other properties for brevity-->
</x:Members>
<sap:VirtualizedContainerService.HintSize>440,440</sap:VirtualizedContainerService.HintSize>
<mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings>
</Activity>
I was able to figure out the issue.
First, though, I was able to discover the root cause here. In a nutshell, it says VB.NET must be used in the Expression Editor even if the program is in C#.
So, I was kinda bummed about that, but I decided to take another crack at the XAML code because, in working through the WF tutorials, there was most definitely an activity I was working on in the designer that would accept Expressions in C#. I opened up that project and went through the XAML code.
It's then that I noticed this line:
<sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>
I searched the MSDN library and found the documentation for the ExpressionActivityEditor class. As best as I can tell, this is new to .NET 4.5. In my particular case, there isn't any reason I can't target .NET 4.5 in my project, so I changed it. Once the solution reopened, right away, all the Expression Editor text fields and boxes would accept C#. In order to "start fresh", I deleted the activity file I had been working on and created a new one. If anyone's interested, here's that generated XAML code:
<Activity mc:Ignorable="sap sap2010 sads" x:Class="THINKImport.CustomerAddOrderAdd"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:THINKWebReference="clr-namespace:THINKImport.THINKWebReference">
<x:Members>
<x:Property Name="user_login_data" Type="InArgument(THINKWebReference:user_login_data)">
<x:Property.Attributes>
<RequiredArgumentAttribute />
</x:Property.Attributes>
</x:Property>
<x:Property Name="customer_data" Type="InArgument(THINKWebReference:customer_data)" />
<!--Remainder of Properties removed for brevity-->
</x:Members>
<sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>
<TextExpression.NamespacesForImplementation>
<sco:Collection x:TypeArguments="x:String">
<x:String>System</x:String>
<x:String>System.Collections.Generic</x:String>
<x:String>System.Data</x:String>
<x:String>System.Linq</x:String>
<x:String>System.Text</x:String>
</sco:Collection>
</TextExpression.NamespacesForImplementation>
<TextExpression.ReferencesForImplementation>
<sco:Collection x:TypeArguments="AssemblyReference">
<AssemblyReference>mscorlib</AssemblyReference>
<AssemblyReference>System</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
<AssemblyReference>System.Data</AssemblyReference>
<AssemblyReference>System.ServiceModel</AssemblyReference>
<AssemblyReference>System.Xml</AssemblyReference>
</sco:Collection>
</TextExpression.ReferencesForImplementation>
<sap2010:WorkflowViewState.IdRef>
THINKImport.CustomerAddOrderAdd_1
</sap2010:WorkflowViewState.IdRef>
<sap2010:WorkflowViewState.ViewStateManager>
<sap2010:ViewStateManager>
<sap2010:ViewStateData Id="THINKImport.CustomerAddOrderAdd_1" sap:VirtualizedContainerService.HintSize="440,440" />
</sap2010:ViewStateManager>
</sap2010:WorkflowViewState.ViewStateManager>
</Activity>
So, quite a bit different (to me, anyways) but I can use C# now, so I'm happy.
C# Expressions
Previously, all expressions in workflows can only be written in Visual
Basic. In .NET Framework 4.5 RC, Visual Basic expressions are only
used for projects created using Visual Basic. Visual C# projects now
use C# for expressions. A fully functional C# expression editor is
provided which capabilities such as grammar highlighting and
intellisense. C# workflow projects created in previous versions that
use Visual Basic expressions will continue to work.
As of Beta 1, C# expressions are validated at design-time. Errors in
C# expressions will be marked with a red wavy underline.
More: What's New in Windows Workflow Foundation in .NET 4.5
i'm developing a Visual Studio 2010 extension, i already have a toolbar inside my window. on that toolbar i have a button that i want to give an icon - my own icon!
I've read this article and it is great but... it explains how to replace the icons.
i want to add an additional icon.
how do i achieve that?
First, add the bitmap and set its build action to Resource
Remember, shocking pink = transparent (damn you, old school!)
Then, in your vsct file, add the image to the bitmaps section
<Bitmaps>
<Bitmap guid="AddSampleData.bmpGuid"
href="..\Button Bitmaps\AddSampleData.bmp"
usedList="AddSampleData.bmpId" />
<Bitmap guid="ApplySampleData.bmpGuid"
href="..\Button Bitmaps\ApplySampleData.bmp"
usedList="ApplySampleData.bmpId" />
</Bitmaps>
and assign it a guid in the symbols node
<Symbols>
<!-- snip -->
<GuidSymbol name="AddSampleData.bmpGuid"
value="{dcae7c84-8e91-4f8a-907b-95ccb0f52e6e}">
<IDSymbol name="AddSampleData.bmpId"
value="1" />
</GuidSymbol>
<GuidSymbol name="ApplySampleData.bmpGuid"
value="{9f555245-2430-4e6f-992b-b49ce87a31a2}">
<IDSymbol name="ApplySampleData.bmpId"
value="1" />
</GuidSymbol>
</Symbols>
and apply it to a button
<Buttons>
<!-- snip -->
<Button guid="guidEditorExtensionCommandSet"
id="setDesignTimeDataOnPage"
priority="0x0100">
<Icon guid="ApplySampleData.bmpGuid"
id="ApplySampleData.bmpId" />
<Strings>
<!-- snip -->
</Strings>
</Button>
</Buttons>
Of course, its always easier to use the available tools, including the excellent VSPackage Builder extension.
A workaround for this is to create a PNG and rename the extension as *.bmp. VS will accept it as an icon image and it will also have transparency (from Visual Studio Extensibility > Toolbox Icons -- Is transparency supported?)
We have an add in for VS that currently is launched from the tools menu, the add-in consists of a a UI offering the user a few option buttons, which I now want to convert to a top-level menu that would offer the same functionality.
I've read this tutorial, which helped me add a new top-level menu, but couldn't really understand the logic behind all the steps. The guide doesn't really clear what each of the steps create or how can your change the output.
What the steps create is a new top-level menu with a single item underneath it. I'm trying to create some hierarchy in my menu (i.e. Top Level -> Sub category -> Commands) but got abit lost with all the groups/menus/IDs structure.
Is there any clear explanation for the structure of these files? A documentation or a tutorial? If anyone had experience in the subject and could help clear things up I would much appreciate it...
I haven't tried doing hierarchical menu items, but I have had similar problems with the Visual SDK .vcst file. It is a pain. A couple of things you can do.
Install the VS Package Editor to Visual Studio Blog Entry for it: http://blogs.msdn.com/b/visualstudio/archive/2010/09/08/introducing-the-vspackage-builder.aspx
Download source code (open source so you can see how they do it) for an add-in that does similar things. Example is AnkhSVN which is a Subversion Repository Add-in to Visual Studio. Here is the source code: http://ankhsvn.open.collab.net/source/browse/ankhsvn/
I assume that nowadays by "add-in" you mean an extension that is a VS package (using the VS SDK) because an "add-in" was an older form of extension for VS 2013 and lower. (If you really mean an "add-in" then see my sample HOWTO: Adding buttons, commandbars and toolbars to Visual Studio .NET from an add-in)
Packages use .vsct files. To answer your question, see the .vsct files of my samples here:
CommandTopMenu
CommandSubMenu
(and to learn see also the other ones for context menus, toolbars, etc.). In the .vcst file they use "CommandPlacements" to separate the definition of an item from its "placement", and comments to explain the relationship between the 3 kinds of items:
Menus (Main-menu/Top-menus/Sub-menus/Context menus) and Toolbars.
Groups: a group is a container for other groups and also for commands and sub-menus.
Commands
Remember the rules:
The parent of a top-menu is always the Main menu of VS, never a group
The parent of a sub-menu is always a group, never directly a toolbar or any kind of menu.
The parent of a command is always a group, never directly a toolbar or any kind of menu (same rule that for sub-menus)
The parent of a group can be a menu, a toolbar, a context menu, etc. and it can be also another group.
A menu (any kind) or toolbar can be either created by your extension (except the main menu of VS) or an existing one of VS, identified by prefix "IDM_". See GUIDs and IDs of Visual Studio menus and GUIDs and IDs of Visual Studio toolbars.
A group can be either new (created by your extension) or an existing group of Visual Studio, identified by prefix "IDG_". You have some built-in Visual Studio groups in the links above, but for a more exhaustive list install the ExtensionTools extension (Mads Kristensen) that provides intellisense in the .vsct file or check the source code of its VsctBuiltInCache.cs file.
Code example
<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="...">
<!-- Extern section unchanged -->
<Commands package="guidHowToPackagePkg">
<Menus>
<!-- New menu added -->
<Menu guid="guidBasicVSCTSampleCmdSet" id="SubMenu" priority="0x200"
type="Menu">
<Parent guid="guidBasicVSCTSampleCmdSet" id="TopLevelMenuGroup" />
<Strings>
<ButtonText>Other Commands</ButtonText>
<CommandName>Other Commands</CommandName>
</Strings>
</Menu>
</Menus>
<Groups>
<!-- Group changed to SubMenuGroup and attached to SubMenu -->
<Group guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup"
priority="0x0600">
<Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenu"/>
</Group>
</Groups>
<Buttons>
<!-- We attached these two buttons to SubMenuGroup -->
<Button guid="guidBasicVSCTSampleCmdSet" id="ThirdCommand" priority="0x0100"
type="Button">
<Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup" />
<Icon guid="guidImages" id="bmpPicX" />
<Strings>
<CommandName>ThirdCommand</CommandName>
<ButtonText>Third Command</ButtonText>
</Strings>
</Button>
<Button guid="guidBasicVSCTSampleCmdSet" id="FourthCommand"
priority="0x0101" type="Button">
<Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup" />
<Icon guid="guidImages" id="bmpPicArrows" />
<Strings>
<CommandName>FourthCommand</CommandName>
<ButtonText>Fourth Command</ButtonText>
</Strings>
</Button>
</Buttons>
</Commands>
<Symbols>
<!-- We add a SubMenu and changed SubMenuGroup -->
<GuidSymbol name="guidBasicVSCTSampleCmdSet" value="...">
<IDSymbol name="SubMenu" value="0x0101" />
<IDSymbol name="SubMenuGroup" value="0x0201" />
</GuidSymbol>
</Symbols>
</CommandTable>
This provides you with the following top-level menu:
Here's a full chapter on the topic. This pretty much explains everything there is to know on (hierarchical) menu's.
http://dotneteers.net/blogs/divedeeper/archive/2010/05/23/vs-2010-package-development-chapter-2-commands-menus-and-toolbars.aspx
This seems like the most basic question in the world, but damned if I can find an answer.
Is there a keyboard shortcut, either native to Visual Studio or through Code Rush or other third-party plug-in, to wrap the current selection with an HTML tag? I'm tired of typing the opening tag, cutting the misplaced closing tag to the clipboard, moving the cursor, and pasting it at the end where it belongs.
Update: This is how TextMate handles surrounding a selection with a tag. Frankly, I'm stunned that Visual Studio doesn't seem to have a similar feature. Creating a macro or snippet for every conceivable tag I might want to use seems absurd.
Visual Studio 2015 comes with a new shortcut, Shift+Alt+W, that wraps the current selection with a div. This shortcut leaves the text "div" selected, making it seamlessly changeable to any desired tag. This coupled with the automatic end tag replacement makes for a quick solution.
UPDATE
This shortcut is available in Visual Studio 2017 as well, but you must have the "ASP.NET and Web Development" workload installed.
Example
Shift+Alt+W > p > Enter
I know this is old and you have probably found the answer by now but I would just like to add for the sake of those who might not know it that this is possible in VS 2010:
Select the code you would like to surround.
Do ctrl-k ctrl-s (or right-click and select Surround with....
There are a variety of HTML snippets to choose from.
You can create your own SurroundsWith snippets if you do not find what you are looking for:
Click File and then click New, and choose a file type of XML.
On the File menu, click Save .
In the Save as box, select All Files (*.*).
In the File name box, enter a file name with the .snippet file name extension.
Click Save.
Enter something like the following sample in the XML file:
<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>ul-div</Title>
<Author>Microsoft Corporation</Author>
<Shortcut>ul>li</Shortcut>
<Description>Wrap in a ul and then an li</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>selected</ID>
<ToolTip>content</ToolTip>
<Default>content</Default>
</Literal>
</Declarations>
<Code Language="html"><![CDATA[<ul><li>$selected$</li></ul>$end$]]></Code>
</Snippet>
</CodeSnippet>
Open Tools > Code Snippets Manager.
Click Import and browse to the snippet you just created.
Check My HTML Snippets and click Finish and then OK.
You will then have your shiny new HTML snippet available for wrapping stuff in!
Ctrl-X -> Type tags -> Ctrl-V is still the fastest solution I've seen as mentioned in this answer: https://stackoverflow.com/a/5109994/486325.
If you have Web Essentials installed, you can use Shift+Alt+W to surround a selection with a tag.
For those who use Visual Studio 2017: Right click on an html/cshtml area, or select some elements to wrap, there is a Wrap With <div> button on the list.
I know this is an ancient thread but having come up against the issue I finally got round to making my own and as this is one of the first results in Google I figured people might find this useful.
Actually it was pretty easy, I just copied from an existing HTML snippet and moved around the literals. The following snippet will surround with a generic HTML tag, it prompts for the tag and will put it in both the opening and closing tags.
<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<!-- Generic HTML Snippet -->
<Header>
<Title>Html</Title>
<Author>Liam Slater</Author>
<Shortcut>h</Shortcut>
<Description>Markup snippet for HTML</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>tag</ID>
<ToolTip>tag</ToolTip>
<Default></Default>
</Literal>
<Literal>
<ID>selected</ID>
<ToolTip>content</ToolTip>
<Default>content</Default>
</Literal>
</Declarations>
<Code Language="html"><![CDATA[<$tag$>$selected$</$tag$>$end$]]></Code>
</Snippet>
</CodeSnippet>
When faced with this situation, I often type the closing tag first, then the opening tag. This prevents the IDE from "helping" by inserting the closing tag where I don't want it. I'm also interested in a better solution, though.
Nothing I'm aware of, but writing a macro to wrap it in whatever tag you want shouldn't be hard. I have a similar one that will wrap my selection in a region block.
I know this is an old question but I was just struggling with the same thing. You can install the Emmet Keybindings extension by Andrés Gutiérrez. Once installed you can highlight text then use control + MW to wrap with any tag you'd like. To give each line an opening and closing tag include an * after the tag.