Posted 18 years ago by Devin Grant - Novi
Avatar
Dose Syntax Editor support Xml & VJSharp snippets like VS2005, or is it limited to C# & VB languages only?

[Modified at 01/08/2006 08:51 PM]

Comments (11)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Devin,

Yes, actually we place no restriction on language type so you could even use them for a completely custom language if you wanted.


Actipro Software Support

Posted 18 years ago by Devin Grant - Novi
Avatar
I am unable to get the Xml snippets to work.

The code below is called when the user Ctrl+J in the editor. Is there something special I have to do in the language file to enable snippets?
editor.IntelliPrompt.CodeSnippets.ShowInsertSnippetPopup(
editor.Caret.Offset,
"Insert Snippet:",
new CodeSnippetFolder("XML", Global.SnippetDir + "XML"),
CodeSnippetTypes.Expansion);
}
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Devin,

Maybe check to make sure the CodeSnippetFolder you're loading is actually pulling in snippets. Check the Count on it before calling ShowInsertSnippetPopup. See if that is the problem.

Another thing is that maybe with the XML in your snippet isn't being interpreted correctly. This would cause it to silently not load into the CodeSnippetFolder. You might even try doing CodeSnippet.LoadFromXml on a sample snippet because that will throw an exception if there is a problem.

I haven't tried an XML snippet but I would imagine you'd need to escape the special XML characters in your code since the snippet itself is XML. So like < chars would probably need to be &lt;, etc.

If none of these are the issues, can you send us an email with a sample XML snippet and I'll try debugging it here? If you do find the issue yourself, please post what you find. Thanks!

[Modified at 01/09/2006 09:33 AM]


Actipro Software Support

Posted 18 years ago by Devin Grant - Novi
Avatar
I am using the exact snippet that VS2005 is supplying (i.e. C:\Program Files\Microsoft Visual Studio 8\xml\1033\Snippets\Parent.snippet).

Calling the code below doesn't throw any exceptions.

ActiproSoftware.SyntaxEditor.CodeSnippet.LoadFromXml(_xmlSnippetFolder.Path + "\\Parent.snippet")

Can you verify that you are able to use an Xml snippet in your environment?
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok I found the problem... in that snippet, they left out the CodeSnippets root tag that appears in all their C# and VB ones. Therefore it wasn't getting loaded by our code. I changed code for the next maintenance release to allow for that scenario.

However I also encountered another issue which is easily resolved. Since they have that snippet's shortcut as "element" and when you insert it, default text "element" is highlighted, if you press Tab it inserts the snippet template again as a new snippet since it thinks a new shortcut is found.

So to work around that, in the KeyTyping code, modify this line so that we add a check to ensure that code snippet mode is not already active when checking for a shortcut:
if ((e.KeyData == Keys.Tab) && (editor.SelectedView.Selection.EndOffset > 0) &&
(!editor.IntelliPrompt.CodeSnippets.IsActive)) {


Actipro Software Support

Posted 18 years ago by Devin Grant - Novi
Avatar
It now works as expacted!

Thanks,
Posted 18 years ago by Devin Grant - Novi
Avatar
How do you clear the existing CodeSnippets that are in memory? For example, I loaded the Parent.snippet for the first time, than I changed the shortcut key to be something else. When I saved the snippet file with the new changes and than create a new _xmlSnippetFolder object, my changes does appear even if I create a new form.

It seems that you are caching these snippets, is that true?

[Modified at 01/09/2006 11:57 AM]
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Well in our sample app we load the CodeSnippetFolder when the sample app. So in the sample, yes, it is cached. However internally in SyntaxEditor, we don't cache anything. You are probably caching it in your own app.

You can call the Refresh method on a CodeSnippetFolder to refresh its contents. It does a recursive refresh.


Actipro Software Support

Posted 18 years ago by Devin Grant - Novi
Avatar
I am not caching it in my code.

Here is a simple check:
string folder = @"C:\Program Files\Microsoft Visual Studio 8\xml\1033\Snippets\Xml";

_xmlSnippetFolder = new CodeSnippetFolder("XML", folder);
Debug.WriteLine(_xmlSnippetFolder.CodeSnippets[0].Shortcut);

// Change the shortcut from "element" to "elem" than save the file

_xmlSnippetFolder = new CodeSnippetFolder("XML", folder);
Debug.WriteLine(_xmlSnippetFolder.CodeSnippets[0].Shortcut);
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
While first running this I made a simple mistake which I think is what you did too. I changed the <Default>element</Default> instead of the shortcut one since they both contain the text "element". When I noticed this and re-ran, changing the shortcut element, it worked fine.


Actipro Software Support

Posted 18 years ago by Devin Grant - Novi
Avatar
Oops, you are right!

Thanks,
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.