orion.edit.outliner

An orion.edit.outliner service provides an overview of a file being edited. The result returned by this service is a tree, which is rendered in the left-hand pane in the Orion editor. Items in the tree can be links that take you to the appropriate point in the file, or to another URL entirely.

Service methods

Implementations of orion.edit.outliner must define the following function:

getOutline(contents, title)
contents String The contents of the file being edited.
title String The path and filename of the file being edited.

Returns an Array giving the top-level elements to be shown in the outline. Each element of the returned array must have the properties:

label String Text to be shown in the UI for this element.
className String Optional A space-separated list of CSS class names to be applied to this element in the UI.
children Array Optional Array of child elements of this element. Children may be nested to an arbitrary depth.
line Number Optional The line number within the file to use as the link for this element in the UI. Line numbers begin counting from 1.
The optional properties column, start, end, text may be used for finer-grained control. (Consult the orion.util.hashFromPosition() documentation in the Client API reference for details about these parameters.)
href String Optional When line is omitted, the href property provides a URL to use as the link.

Service attributes

Implementations of orion.edit.outliner must define the following attributes:

pattern
String A regex pattern matching the names of files this outliner can provide an outline for.
id
String A unique identifier for this outline provider.
name
String A user-readable name for this outline provider.

Examples

This example shows an outline provider that runs on .txt files. It finds Mediawiki-style =Section Headings= and generates a flat outline from them. (A more elaborate implementation might also find subsections and include them as children of the top-level sections.)

var provider = new eclipse.PluginProvider();
provider.registerServiceProvider("orion.edit.outliner", {
  getOutline: function(contents, title) {
    var outline = [];
    var lines = contents.split(/\r?\n/);
    for (var i=0; i < lines.length; i++) {
      var line = lines[i];
      var match = /^=\s*(.+?)\s*=$/.exec(line);
      if (match) {
        outline.push({
           label: match[1],
           line: i+1  // lines are numbered from 1
        });
      }
    }
    return outline;
  }
}, {
  pattern: "\.txt$",
  name: "Headings",
  id: "orion.outliner.example.headings"
});
provider.connect();