BeIDE: Writing an Editor for the BeIDE
Writing an Editor for the BeIDE
If you're writing an editor that you want to be able to call from the BeIDE, here's what you do:
- Include "text/*" in your editor's list of supported types.
You can do this programmatically
(through BAppFileInfo::SetSupportedTypes()),
or you can write the type into a resource file
(created by FileTypes or mwbres)
and then add the resource file to the BeIDE project for your editor.
- Teach your editor to look for and respond to B_REFS_RECEIVED as described in the next section.
You don't have to install your editor anywhere special; the BeIDE looks for all apps that handles text files and adds them to its list of potential editors. Currently, the communication between the BeIDE and your editor is limited to the B_REFS_RECEIVED message--you can't talk back to the BeIDE from your editor. This may change in the future, as the BeIDE defines and supports a scripting suite.
Opening a File
When the BeIDE opens a file, it sends a B_REFS_RECEIVED message to the editor (one file per message). The message tells you which file to open, and whether to create and display a text selection within the open file.
| Field | Type | Meaning |
|---|---|---|
| "refs" | B_REF_TYPE | The file to open. |
| "be:selection_offset"
(optional) |
B_INT32_TYPE | The location of the first character in the selection, measured in bytes from the beginning of the file. |
| "be:selection_length"
(optional) |
B_INT32_TYPE | The number of bytes in the selection. |
| "be:line"
(optional) |
B_INT32_TYPE | The line number of the selection (counting from line 1). |
Your editor should open the file represented in the "refs" fields, and then look in the other fields for information about the selection:
- First, you should look for the "be:selection_offset" and "be:selection_length"
fields.
If the fields are present (they always appear as a pair),
the selection comprises the characters starting at the
offset and running for the designated number of characters.
- If the offset and length fields aren't present, you should look
for and select the entire line given by the "be:line" field.
(The first line in the file is line 1.)
- If none of the selection fields are present, no selection should be made.
Copyright © 1999 Be, Inc. All rights reserved.