Snippets subcomponent
WST Common Snippets subcomponent Overview
 

Last modified April 13, 2005

 

This document is a work in progress. It is an attempt to capture the key concepts of the WTP Snippets subcomponent. Note that the concepts presented here may differ from what is found in the currently released code. This document describes the architecture, or "end goal", of the Snippets subcomponent. Once finalized, the intent is to bring the code and its specifications into line with this document.

 

Core Concepts
 

The Snippets subcomponent provides a simple way for users to drag and drop chunks of text into source editors. The snippets model refers to these insertable chunks as "Items" and their containers as "Category"s. The actual text being inserted can be affected by input from the user during the "drop" part of the drag-and-drop operation and users are free to create categories and items for themselves. Items contributed from plug-ins may also provide customized insertion behavior, for example substituting wizards and custom dialogs for the defaults that are provided. The user interacts with graphical representations of the snippet items directly, but any exposed APIs do not make specific references to the current UI implementation.

User Interface
 

The Snippets view is based on the GEF PaletteViewer, primarily because the Snippets view is a logical counterpart to the built-in palette found in many graphical editors. Snippet Items and Categories are shown as PaletteTemplateEntrys and PaletteDrawers, although this detail is hidden by the ISnippetItem and ISnippetCategory interfaces.

 

The standard PaletteViewer user settings for appearance are available and supported. The user is also given the ability to show and hide individual PaletteDrawers as they wish. While the user has full editing abiities for PaletteTemplateEntrys and PaletteDrawers they created, those originating from plug-in contributions are otherwise unmodifiable. The user or a plug-in contributor may choose for a drawer to have its visibility automatically controlled according to the active editor part's input's platform content type.

Extension Points
 

SnippetContributions

 

The org.eclipse.wst.common.snippets.SnippetContributions extension point allows other plugins to provide new categories and items (made visible as entries and drawers) into the Snippets view. One keen notion to keep in mind is that contributions provide only the attributes for a snippet item or category, not its implementation. Similarly, the insertion class is contributed (as this is a key part of a snippet item's lifecycle) instead of insertion being directly implemented on a provided snippet item implementation. This arrangement was conceived to remove the need and ability for contributions to maintain any information between workbench sessions--the recording of a contributed drawer's visibility, for instance.

 

For more information, see the reference document for this extension point.