Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Snippets Documentation?
Snippets Documentation? [message #98933] Wed, 04 May 2005 20:58 Go to next message
Eclipse UserFriend
Originally posted by: jfirebau.us.ibm.com

Is there any available documentation on how to make a plugin interface
with the snippets feature?

From looking at the source code it looks as though it may be difficult
to get Snippets to contribute to a Text component instead of a full
fledged Editor. Does someone have a sample of getting a snippet to
insert into a form field instead of a StructuredTextEditor ?

Thanks,
Joe
Re: Snippets Documentation? [message #99862 is a reply to message #98933] Fri, 06 May 2005 06:06 Go to previous message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4474
Registered: July 2009
Senior Member

Joseph Firebaugh wrote:
> Is there any available documentation on how to make a plugin interface
> with the snippets feature?
>
> From looking at the source code it looks as though it may be difficult
> to get Snippets to contribute to a Text component instead of a full
> fledged Editor. Does someone have a sample of getting a snippet to
> insert into a form field instead of a StructuredTextEditor ?

Eclipse's text editors don't support dropping text into them by
default, and the "double-click to insert" method from the Snippets
view only targets the active editor in the window. There's no API
for doing otherwise at this time, but it can be done using
unsupported internals. Snippets could/will undergo significant
changes in the future--compatibility is not assured until Snippets'
API is declared and documented, most likely post-R1. Dropping
snippets into non-text editors isn't one of our main use cases right
now, but feedback from users/clients of the view will guide us in
defining how things work in the future. For example, we already
have plans to remove the dependency on SSE editors altogether.

I haven't tried it, but I don't think the SWT API prevents you from
registering a DropTarget on a Text control, although providing
appropriate dragOver feedback should be an interesting problem to
solve. The Snippets view defaults to using the
org.eclipse.wst.common.snippets.internal.dnd.VariableTextTra nsfer in
the DND events for most plugin-contributed and user-created
snippets, so supporting that transfer type would be required. For
situations where a text editor is not involved, two steps are needed:

1) You need to reconstitute the ISnippetItem object from the drop
event. For VariableTextTransfers only, the snippet dragged out of
the view is serialized into a UTF-16 XML stream and stored in the
event data as a byte array. Converting it back can be done by calling:
ISnippetItem item = (ISnippetItem)
org.eclipse.wst.common.snippets.internal.ui.EntryDeserialize r.getInstance().fromXML((byte[])
event.data);

2) Use the
org.eclipse.wst.common.snippets.internal.VariableItemHelper class to
launch the insertion dialog for that ISnippetItem. The dialog will
prompt the user for any variable values and return the completed
String on success and null if the user cancels:
String s =
org.eclipse.wst.common.snippets.internal.VariableItemHelper. getInsertString(Shell,
ISnippetItem);

At that point you can use the string to update your form accordingly.

--
- Nitin


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Previous Topic:Debug
Next Topic:WTP and JBoss IDE
Goto Forum:
  


Current Time: Wed Jul 17 01:31:01 GMT 2024

Powered by FUDForum. Page generated in 0.03532 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top