# orion.edit.editor

This service declares a new editor. By default, the Orion client UI declares a single editor with id `"orion.editor"` which is used to edit source code. Using this service, you can declare entirely new editors (for example, you could register an editor that provided a paint interface for drawing images).

Contributions to this service do not directly affect the Orion UI. Instead, this service is typically used in conjunction with two other services, which allow new file types to be defined and associated with editors. See:

- orion.file.contenttype: Registers a new content type for files.
- orion.navigate.openWith: Associates a content type (registered via `orion.file.contenttype`) to an editor (registered via `orion.edit.editor`).

## Service methods

None. This service is purely declarative.

## Service attributes

id
  `String` The unique identifier of this editor.
name
  `String` The user-readable name of this editor.
uriTemplate
  `String` Gives a URI template for constructing a URL that can be followed to drive this editor to a particular file. The parameter `Location` is substituted with the URL of the file being edited. The template is specified using the URI Template syntax.
orionTemplate
  `String` Optional. Gives an Orion template for constructing the editor URL. This serves the same purpose as the uriTemplate field. However an Orion template allows a more human-readable parameter encoding scheme than a URI Template. If both fields are provided, the orionTemplate takes priority over the uriTemplate.<br /> NOTE: Orion templates are not yet standardized.

## Examples

This example code declares an editor called "My Great Editor". When My Great Editor is used to edit a file in Orion, the user will be pointed to a URL containing the location of the file they want to edit as `"fileToEdit"` in the query portion of the URL. Presumably myGreatEditor.php would read the string and open the file. Authentication is beyond the scope of this example.

     var provider = new eclipse.PluginProvider();
     provider.registerServiceProvider("orion.edit.editor", {},
       { id: "example.mygreateditor",
         name: "My Great Editor",
         uriTemplate: "http://mysite.com/myGreatEditor.php?fileToEdit={Location}"
       });

The code below shows a complete example of how to use the `orion.editor`, `orion.file.contenttype`, and `orion.navigate.openWith` services in conjunction to declare a new editor, declare new file types, and associate them together. The example is adapted from Orion's own source code.

     // Declare an editor
     provider.registerServiceProvider("orion.edit.editor", {}, {
       id: "orion.editor",
       name: "Orion Editor",
       uriTemplate: "../edit/edit.html#{Location,params*}",
       orionTemplate: "../edit/edit.html#{,Location,params*}"});

     // Declare content types
     provider.registerServiceProvider("orion.file.contenttype", {}, {
       contentTypes:
         [{ id: "text.plain",
            name: "Text",
            extension: ["txt"]
         },
         {  id: "text.html",
            "extends": "text.plain",
            name: "HTML",
            extension: ["html", "htm"]
         }]
       });

     // Associate editor with content types
     provider.registerServiceProvider("orion.navigate.openWith", {}, {
         editor: "orion.editor",
         contentType: ["text.plain", "text.html"]});

     provider.connect();

Note that the order of these registerServiceProvider() calls is not important.