Can I define custom "surround with" templates in Visual Studio 2008?
Here you go, this is an example to set everything selected inside {}
In tools, codesnipet manager.
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>{}</Title>
<Shortcut>{}</Shortcut>
<Description>Code snippet for {}</Description>
<Author>Sérgio</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language="csharp"><![CDATA[{
$selected$ $end$
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
In the event anyone else visits this question searching for more examples, here's my snippet to surround the block of code with a stopwatch:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Stopwatch</Title>
<Shortcut>SW</Shortcut>
<Description>Code snippet for Stopwatch</Description>
<Author>Bernhard Hofmann</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language="csharp"><![CDATA[var tacho = new System.Diagnostics.Stopwatch();
tacho.Start();
$selected$ $end$
tacho.Stop();
System.Diagnostics.Trace.WriteLine(string.Format("Elapsed: {0}", tacho.Elapsed));
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Also, if you save it as Stopwatch.snippet in My Documents\Visual Studio ????\Code Snippets\Visual C#\My Code Snippets, then it'll automagically appear in Visual Studio without needing to visit the Tools menu.
I have an example for you. This snippet will surround the selected text with <![CDATA[...]]>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Surround in CDATA</Title>
<Author>Sten Hougaard, 2010 - http://www.netsi.dk/wordpress</Author>
<Shortcut>shortcut</Shortcut>
<Description>Surrounds selected data in CDATA</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<Default>value</Default>
</Literal>
</Declarations>
<Code Language="XML">
<![CDATA[<![CDATA[$selected$]]><![CDATA[]]]><![CDATA[]]]><![CDATA[>]]>
</Code>
</Snippet>
</CodeSnippet>
The steps to make this example are this:
Copy and paste these into a new XML file in Visual Studio
Save it anywhere as for instance: "SnippetXML_SurroundWithCDATA.snippet"
Open "Tools > Code Snippet Manager"
Click "Import..." and locate the file you just saved, choose it and click "open"
You now have the option to choose where it should be possible to "run" the snippet. Choose one or more "scenarios"
The snippet is now ready for use. Try it using a relevant scenario, for instance a XML file. Select some data and click Ctrl+K and Ctrl+S (or go through the menu). Locate the snippet and voila - your data has been surrounded with CDATA.
Related
How I should create asp classic snippets and use they in visual studio? I follow some tutorials on the internet but doesn't work at all:
This is a sample from my snippet:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Total de registros a serem exportados.</Title>
<Author>Lucas Luan de Melo Pereira</Author>
<Description>Implementa a busca ao parametro de limite de linhas a serem exportadas.</Description>
<Shortcut>snpTot</Shortcut>
</Header>
<Snippet>
<Code Language="VBScript">
<![CDATA[
'---------Total de registros a serem exportados---------------
response.write("Awesome feature!")
'-------------------------------------------------------------
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
In VS, I'm importing inside VB option (Code Snippets Manager). But when try to use don't work also another question, this will be called by Intellisense? There's no option of snippets im my *.asp files.
I am using a code snippet inside Visual Studio (Community 2015) to automate the line Debug.LogFormat("");. The snippet is working but it adds a extra empty line (enter) at the start so using the snippet with logtabtab will result in the following code:
// blank line
Debug.LogFormat("");
instead of
Debug.LogFormat("");
Here is the XML of the snippet I use:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Unity LogFormat</Title>
<Author>Faas</Author>
<Shortcut>log</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>Message</ID>
<ToolTip>Message</ToolTip>
<Default></Default>
</Literal>
</Declarations>
<Code Language="CSharp"><![CDATA[Debug.LogFormat("$Message$");]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
I can fix the problem by placing a $end$ in the Code element. I don't know the root cause. Just have a try.
<Code Language="csharp"><![CDATA[Debug.LogFormat("$Message$");$end$]]>
See more document about Code element here.
I'm trying to add a overlay to the preferences of the browser from my extension without success. Nothing is displayed when my plugin is installed. Other xul files show correctly (for example a preferences dialog of the plugin. I tried to adapt this tutorial to my needs.
I register the overlay in chrome.manifest:
content smime chrome/content/
overlay chrome://browser/content/preferences/preferences.xul chrome://smime/content/preferences.xul
The preferences.xul:
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!-- Merge with the BrowserPreferences Window -->
<prefwindow id="BrowserPreferences">
<!-- Create a new pane (tab) for HP Scheduler. -->
<prefpane id="hpschedPane" label="&prefpane.label;"
image="chrome://smime/content/sogo-48.png">
<!-- Intermediary between GUI and preferences system -->
<preferences>
<preference id="sodgeItSmimeKeyfile" name="extensions.sodgeItSmime.keyfile" type="text"/>
</preferences>
<!-- GUI Elements... -->
<groupbox>
<caption label="Settings"/>
<grid>
<columns>
<column flex="4"/>
<column flex="1"/>
</columns>
<rows>
<row>
<label control="keyfile" value="Keyfile"/>
<textbox id="keyfile" preference="sodgeItSmimeKeyfile"/>
</row>
</rows>
</grid>
</groupbox>
</prefpane>
</prefwindow>
</overlay>
This is what I want to do - add a tab in the Firefox settings dialog.
Edit: added image to describe what I'm trying to do
It's trickier to get this to work than it should be. You might try the following approach, which we use in our FireTorrent extension:
Overlay the Firefox preference window as shown:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://firetorrent/skin/firetorrent-prefs.css" type="text/css"?>
<overlay id="FiretorrentPaneOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<prefwindow id="BrowserPreferences">
<prefpane id="paneFiretorrent" label="FireTorrent"
src="chrome://firetorrent/content/optionsOverlay.xul"/>
</prefwindow>
</overlay>
Add the following to your CSS file (firetorrent-prefs.css in the example):
#BrowserPreferences radio[pane="paneFiretorrent"] {
list-style-image: url("chrome://firetorrent/skin/firetorrent-icon-32.png");
}
Contents of optionsOverlay.xul as follows:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
<?xml-stylesheet href="chrome://global/skin/preferences.css" type="text/css"?>
<?xml-stylesheet href="chrome://firetorrent/skin/options.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://firetorrent/locale/optionsOverlay.dtd">
<overlay id="firetorrentOptionsOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<prefpane id="paneFiretorrent" onpaneload="loadOptions();" flex="1">
<preferences>
<preference id="firetorrent.options.port" name="extensions.firetorrent.port" type="int"/>
...etc...
</preferences>
<script type="application/x-javascript" src="chrome://firetorrent/content/optionsOverlay.js"/>
...all your prefpane XUL here...
</prefpane>
</overlay>
It's been a long time since I wrote this, but I believe the important things to note are that the overlay for preferences.xul (point 1 in my example) references another XUL overlay that contains the actual prefpane (optionsOverlay.xul) and that you need to use the list-style-image style in CSS to specify the icon for your new tab.
I am doing a joomla 2.5 project
I put this <jdoc:include type="modules" name="izquierdo" style="none"/> and it shows me nothing.
The positions in my template is this:
<positions>
<position>izquierdo</position>
<position>extranet</position>
<position>menuPrincipal</position>
The status of this module is public.
Any ideas, am I miss something?
I found something strange.
if I put my route and at the end add ?tp=1 it shows me all my postions and it shows me my module (I see the image and other thinks), but with the normal router (without ?tp=1) I don't see anything.
This is my xml template:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE install PUBLIC "-//Joomla! 1.6//DTD template 1.0//EN" "http://www.joomla.org/xml/dtd/1.6/template-install.dtd">
<extension version="2.5" type="template" client="site">
<name>arquero</name>
<creationDate>10/10/09</creationDate>
<author>Ron Severdia</author>
<authorEmail>mpiedra#edosoftfactory.com</authorEmail>
<authorUrl>http://www.kontentdesign.com</authorUrl>
<copyright>Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>2.5.0</version>
<description>ARQUERO_XML_DESCRIPTION</description>
<files>
<folder>html</folder>
<folder>css</folder>
<folder>images</folder>
<folder>js</folder>
<filename>index.php</filename>
<filename>index.html</filename>
<filename>templateDetails.xml</filename>
<filename>ajax.php</filename>
<filename>component.php</filename>
</files>
<positions>
<position>izquierdo</position>
<position>extranet</position>
<position>menuPrincipal</position>
<position>carrusel</position>
<position>noticias</position>
<position>footer</position>
<position>debug</position>
</positions>
</extension>
It seems to be fine your template. But try style="xhtml" on your jdoc statement.
And another guess is please check again the assignment of pages for your module from the backend. Most probably you might select "No pages" for the module assignment.
Thank you.
I'm developing some code snippet, and I experienced that Visual Studio doesn't automatically add Reference to specified assembly and doesn't import the specified namespace.
My snippet definition is:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MyTryCatch</Title>
<Shortcut>myTryCatch</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>MyAssembly.dll</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>MyNamespace</Namespace>
</Import>
</Imports>
<Declarations>
<Object Editable="true">
<ID>Message</ID>
<Type>String</Type>
<ToolTip>Error message</ToolTip>
<Default>message</Default>
<Function></Function>
</Object>
</Declarations>
<Code Language="csharp" Kind="" Delimiter="$">
<![CDATA[try
{
}
catch (Exception exception)
{
throw new MyNamespace.MyException("$Message$", exception);
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
</CodeSnippets>
Note that I'm referencing a custom MyAssembly.dll that is visible from "Add Reference" popup (.NET Tab).
When I use the above snippet by myTryCatch shortcut, I'm able to see the snippet code but no Reference added and no Import made.
How I can fix or debug this issue?
Thanks in advance!
It sounds like the problem is your choice of language. Only VB.Net supports reference assemblies and importing of namespaces from a code snippet. The C# engine will ignore these elements.
Reference: http://msdn.microsoft.com/en-us/library/ms171438.aspx