Snippets Documentation? [message #98933] |
Wed, 04 May 2005 16:58  |
Eclipse User |
|
|
|
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 02:06  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03175 seconds