Assuming I want to create a code snippet for ToString(), I have created the following snippet:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>To String VB</Title>
<Author>John Doe</Author>
<Description>Shortcut for ToString()</Description>
<Shortcut>ts</Shortcut>
</Header>
<Snippet>
<Code Language="VB">
<![CDATA[toString()]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
When I write the code myObject.ts and then press tab to invoke the code snippet, visual studio does this:
myObject.
toString()
instead of this:
myObject.toString()
How can I keep the snippet completion on the same line that I invoked it from? I came across a page that mentioned using $end$ to mark the position the cursor should go when the snippet is inserted, but that has done nothing for me besides including the $end$ in the snippet.
Related
I'm trying to repurpose the built in font selector for my own objects in PowerPoint (vsto add-in). I repurpose regular commands (bold, italic etc.) successfully using the ribbon xml.
I have a test that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab idMso="TabAddIns" label="Test">
<group id="MyGroup"
label="My Group">
<comboBox idMso="Font" label="ComboBox1" onChange="ChangeCallback"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
If I have a regular is instead of the idMso this callback works fine:
ChangeCallback(Office.IRibbonControl control, string text)
{
Debug.WriteLine("Changed");
}
The callback stops working when I use idMso="Font", but the comboBox works and I can use it to select font like normal.
I have tried the following callback with no luck.
ChangeCallback(Office.IRibbonControl control, string text, ref bool cancelDefault)
{
Debug.WriteLine("Changed");
}
When I repurpose commands I put it in the commands section of the xml instead of the ribbon, but having a comboBox element there is not allowed.
Any ideas on how to get this to work?
I am trying to add a new tab to an actionscript TabBar control at runtime. When I use addChild() to add a tab to the tab bar I get an exception at runtime:
Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.
However, when I tried using addElement() instead I get an error at compile time:
1061: Call to a possibly undefined method addElement through a reference with static type spark.components:TabBar.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="100%"
height="100%">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private var _lastAddedNumber:int = 1;
protected function btnAddNewTab_clickHandler(event:MouseEvent):void
{
tabby.dataProvider.addItem('New '+_lastAddedNumber);
_lastAddedNumber++;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:Button id="btnSave"
click="btnAddNewTab_clickHandler(event)"
label="Add New Tab"/>
<mx:Form top="50">
<mx:FormItem label="tabWidth:">
<s:HSlider id="slider"
minimum="40"
maximum="120"
value="100"/>
</mx:FormItem>
</mx:Form>
<s:TabBar id="tabby"
horizontalCenter="0"
verticalCenter="0">
<s:layout>
<s:HorizontalLayout gap="-1"
columnWidth="{slider.value}"
variableColumnWidth="false"/>
</s:layout>
<s:dataProvider>
<s:ArrayList source="[red,orange,yellow,green,blue]"/>
</s:dataProvider>
</s:TabBar></s:Application>
may this will help you!!!
Is there any way to prevent the addition of an extra line below a multi-line snippet in VB.NET?
(hit tab key to expand snippet...)
I've double checked that the snippet itself does not have an extra line at the end. Also, this seems to be VB-specific.
Just close the ]] after the end of your snipped. The ¿end¿ part sets the caret at this position after inserting the snipped.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>tryt</Title>
<Author>[USERNAME]</Author>
<Description>
</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>tryt</Shortcut>
</Header>
<Snippet>
<Code Language="vb" Delimiter="¿"><![CDATA[Try
¿end¿
Catch ex As Exception
Throw New Exception(ex) 'or do some other stuff
End Try]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Below is my SQL snippet that is used to surround existing SQL. After highlighting some SQL and inserting this snippet, I want ALL the selected text to be indented by a tab or several spaces. My snippet currently will indent just the first line of highlighted code.
How can I make is indent all the selected text?
Here is my SQL snippet.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Insert a comment header for SQL</Title>
<Shortcut>header</Shortcut>
<Description>SQL Snippet will add comment area for header to break up code</Description>
<Author>Mike Adams</Author>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>headerText</ID>
<ToolTip>Header Text</ToolTip>
<Default></Default>
<Function></Function>
</Literal>
</Declarations>
<Code Language="sql">
<![CDATA[
-- $headerText$
---------------------------------------------------------
$selected$
$end$
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
In Visual Studio 2010, for VB.NET, the "Property" + Tab + Tab inserts a full property implementation. Is there another snippet for inserting an autoproperty?
Just put this in a file called C:\Users\\Documents\Visual Studio 2010\Code Snippets\Visual Basic\My Code Snippets\DefaultProperty.snippet and restart VS... or put it in that file but not in that dir, then in VS click Tools, Code Snippets Manager, and Select Visual Basic as the language... the click on the Import button. Select your new file, and then choose the top folder "My Snippets". Now in the IDE just type PropDefAuto and tab tab. Feel free to modify the file.
<?xml version="1.0" encoding="UTF-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Define a Auto-Implemented Default Property</Title>
<Author>Some Guy On SO</Author>
<Description>Defines an Auto-Implemented default property or index property.</Description>
<Keywords>
<Keyword>PropAuto</Keyword>
</Keywords>
<Shortcut>PropDefAuto</Shortcut>
</Header>
<Snippet>
<Imports>
<Import>
<Namespace>System</Namespace>
</Import>
</Imports>
<Declarations>
<Literal>
<ID>propertyName</ID>
<Type>
</Type>
<ToolTip>Rename to descriptive name for the property.</ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>indexType</ID>
<Type>
</Type>
<ToolTip>Replace with the type of the index</ToolTip>
<Default>Integer</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<Type>
</Type>
<ToolTip>Replace with the type returned by the property.</ToolTip>
<Default>String</Default>
</Literal>
<Literal>
<ID>IndexIsValid</ID>
<Type>Boolean</Type>
<ToolTip>Replace with an expression to test if index is valid.</ToolTip>
<Default>True</Default>
</Literal>
</Declarations>
<Code Language="VB" Kind="method decl"><![CDATA[Public Property $propertyName$ As $PropertyType$
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
The closest you can currently get in VB is typing out
Property Name as string
You can find more information in this blog post by The Gu