Abstracttexteditor is the base class of the text editor in eclipse. It class it and implements the corresponding abstract method to get the text editor with the general text editor function, but it is far more than that.
First, let's take a look at what interfaces It implements. The following is the source code of the declaration part:
Public abstract class abstracttexteditor extends editorpart implements itexteditor, ireusableeditor, itexteditorextension, itexteditorextension2, region, inavigationlocationprovider, isaveablessource, ipersistableeditor
Wow, it's so long. Let's see it one by one.
Itexteditor
Itexteditor defines general editor interfaces, including opening, saving, selecting, and highlighting text.
Ireusableeditor
This interface is used by the editor to respond to input changes. For example, you are editing a Java file, but you have used other editors to change and save the content of this file, in this case, the files in your editor are different from those in the file system. The General editor will not respond. However, in eclipse, this change can be handled by notifying ireusableeditor through the file system listener.
Itexteditorextension
It mainly provides the ruler context menu management.
Itexteditorextension2
Query the status of the text editor, editable, and valid.
Itexteditorextension3
Insert mode and overwrite mode status management, and smart insert function status.
Itexteditorextension4
Fast jump between comments
Itexteditorextension5
Block Selection supports Status Management
Inavigationlocationprovider,
Provides the navigation function, that is, you can remember the location of the Editor (using the forward and backward reading code function on the toolbar)
Isaveablessource
Manage saved sources (files, URLs, or others)
Ipersistableeditor
Indicates that the editor can be saved, so that the editor can be restored to the closed state when it is opened next time.
Eclipse, in order to make the Editor (not necessarily a text editor) suitable for multiple inputs (such as files, FTP, HTTP, databases ......), Abstract Input to ieditorinput
The specific resource type can implement different ieditorinput, so that the same editor can edit different types of resources. Ieditorinput does not contain resource content, but is only a description of the resource. When you call setinput () in abstracttexteditor to set input, the editor must first create a documentprovider with the so-called input.
Documentprovider is responsible for loading and saving specific resources.
After a resource is loaded (or a new document is created, the memory actually uses an idocument object to represent the document)
Idocuent provides many methods to access documents, which seem to be based on text, but we know that binary files can be converted to text for processing without special restrictions.
With the above knowledge, we can analyze how texteditor works.
When the editor is created in step 1, you need to specify an input (here I think it can be translated as a location). If not, the editor is automatically closed. That is to say, the eclipse editor cannot open files without a location. Note, the file is not required to exist, but to have a location.
Step 2 editor uses this input to create the corresponding documentprovider, call the documentprovider's connect and other methods to make it related to the resource, and then call the documentprovider's getdocument method to obtain a document that can be operated by the editor.
Step 3 the editor continues to operate the document until the response user saves or closes the file. At this time, the savedocument method of documentprovider is called to save the file.
Operations in abstracttexteditor
The operations in the editor are added by setaction when the editor is initialized. The added actions can be used after the editor is initialized, for example, CTRL + C.
Others
Abstracttexteditor has other functions, such as determining whether it can be saved. You can refer to the source code.
In the next article, I will study the source code of the editor related to specific languages in jdt or CDT.