Snippets are frequently
used strings that can be quickly inserted into the current document. For
example, repetitive sections of code or standard comments can be stored
within a snippet. Snippets have advanced properties; they support the use of
Tab Stops and
Interpolation
Shortcuts, can
be assigned to Key Bindings, and allow for
the specification of indentation context and cursor position.
Snippets are stored in the
Project Manager or the
Toolbox.
|
|
To create a code snippet, select the desired block of text in the Editor
Pane. Then drag and drop the selected section onto the
Toolbox tab or into a project
on the Projects tab.
Alternatively, select the desired text, then right-click and select
Add as Snippet in the Toolbox.
Alternatively, right-click a folder in the Toolbox or on a project or folder
name on the Projects tab, and select New
Snippet. If you use this method, you must manually enter the contents
of the snippet; text selected in the Editor Pane is not automatically added to
the Snippet dialog box.
To configure snippet properties, right-click the snippet on either the
Toolbox tab or the
Projects tab,
and select Properties. The following configuration properties
are available:
- Snippet Name: Enter the text that should display in the
Project Manager or Toolbox for this code snippet. If the snippet was created
by dragging a text selection from the Editor Pane, the snippet is named
after the text in the snippet.
- Snippet Contents: If the snippet was created by dragging
a text selection from the Editor Pane, the contents of the selected text
are displayed in the Snippet Contents field. Otherwise, enter
the contents of the snippet manually. Add or edit snippet content as desired.
- Snippet Shortcuts: Add Interpolation
Shortcuts or Tab Stop/Replace
markers to a snippet by clicking the arrow button to the right of
the Snippets Contents field, and selecting a shortcut from the
drop-down menu. Interpolation shortcuts in snippets are not executed
when the snippet is inserted in the Editor Pane via dragging and
dropping.
- Maintain selected text or cursor position after insertion:
Within the snippet contents field, either select a portion of the
snippet (by dragging the mouse pointer over the desired selection) or
position the editing cursor within the string. If this check box is selected,
when the snippet is inserted into the Editor Pane, the selected text or the
cursor position is displayed in the same manner.
- Maintain indentation context after insertion: If the
snippet is inserted into the Editor Pane when the editing cursor is in an
indented position, select this check box to use the indentation point as an
indentation "prefix". The indentation structure of the snippet is
preserved at the position of insertion.
To insert the contents of a snippet at the current cursor
position in the Editor Pane, double-click it, or
right-click the snippet and select Insert Snippet.
Although you can also drag and drop snippets onto the Editor
Pane, the cursor position and indentation check box options explained above in
Configuring Snippets
will only take effect if the snippet is added using the double-click or
Insert Snippet method.
To access options for the selected snippet, do one of the following:
- Toolbox|snippet_name|option or
Project|snippet_name|option: When a snippet
is selected in the Project
Manager or Toolbox tab,
use the Project or Toolbox drop-down menus
to access the list of options. The name of the snippet currently selected in a
project or the Toolbox is displayed on the drop-down menu.
- Context Menu: Right-click a snippet in a
project or the Toolbox and select the desired option.
The following options are available:
- Insert Snippet: Use this option to insert the
snippet at the current cursor position in the editor, as described above in
Using Snippets.
- Cut/Copy/Paste: These options are used to remove the
snippet from a project or the Toolbox, or to move snippets between
the project and the Toolbox (and vice versa).
- Export as Project File: When this option is invoked, a
new project file is created that
contains the snippet from which the option is invoked. You are prompted to
provide the name of the new project file and the directory where it will be
stored. To open the new project file, select
File|Open|Project.
- Export Package: Snippets can be archived and distributed
among multiple Komodo users via Packages. Packages are
compressed archive files that contain the snippet from which the
Export Package option was invoked. Packages are stored in
files with a ".kpz" extension, and can be opened by any archiving utility that
supports
libz (for example WinZip). The Export
Package option differs from the Export as Project
File option in that copies of filesystem-based components (such as
files and dialog projects) are included in the archive. Conversely,
Export as Project File creates a project with a reference to
the component's original location and does not create copies of the components.
When Export Package is invoked, you are prompted for a name
and file location for the package. Exported packages can only be imported into
"container" objects in Komodo, such as projects, the Toolbox, and folders
within projects and the Toolbox. See Toolbox - Exporting and Importing
Toolbox Contents, Projects - Importing and
Exporting Projects via Packages, or Folders - Import Contents
from Package for more information.
- Rename: To change the name of a snippet, select this
option and enter a new name.
- Delete: To remove a snippet from a project or the
Toolbox, select this option. The snippet is permanently deleted.
Snippet properties are used to alter or rename snippets (as described in Configuring Snippets, above). The Properties dialog
box is also used to assign a custom icon to a snippet or to assign a custom key
binding. To access the Properties dialog box, right-click the snippet and select
Properties.
The default snippet icons can be replaced with custom icons. Komodo
includes more than 600 icons; alternatively, select a custom image
stored on a local or network drive (use 16x16-pixel images for best results).
To assign a custom icon to a snippet:
- On the Projects tab or Toolbox tab, right-click the desired snippet
and select Properties. Alternatively, click the icon
in the Projects tab or Toolbox tab, then select
Projects|snippet_name|Properties or
Toolboxsnippet_name|Properties.
- In the Properties dialog box, click Change Icon.
- In the Pick an Icon dialog box, select a new icon and click
OK. Alternatively, click Choose Other,
and browse to the desired image file.
- In the Properties dialog box for the snippet, click OK.
The custom icon is displayed next to the snippet.
To revert to the default icon for a selected snippet:
- On the Projects tab or Toolbox tab, right-click the desired snippet
and select Properties.
- Click Reset, then click OK. The default
icon is displayed next to the snippet.
To assign a key binding to a snippet, right-click the snippet on either the
Toolbox tab or the
Projects tab,
and select Properties. Select the Key Bindings
tab, and configure the desired binding. See
Key Bindings
for Custom Components for more information.
|