Building a fully functional code editor based on the JFace Text framework: Part 11th

Source: Internet
Author: User

Text Folding

Text folding (folding) In fact, at Eclipse 2.1, there has been a symptom, after Eclipse 3.0, the text collapsed architecture has been redesigned, beginning to become practical. Let's take a look at what JTF does for text folding.

Projectionviewer

Sourceviewer itself does not support text folding, so JTF adds a projectionviewer specifically supports text folding, which is a subclass of Sourceviewer.

Master-Slave Document structure

JTF It is impossible to wonder which texts can be folded, and these things have to be told. In the case of text folding, we can see only a part of the text, but the created IDocument instance contains all the text, how can we know what should not be displayed? So JTF introduces a master/slave (master/detail) document schema, where the main document is a document that contains all the content, while the document contains only what the user can see, and the implementation class from the document is projectiondocument. Since there are two of documents, then there is the problem of synchronization, so the introduction of Projectiondocumentmanager to maintain the master-slave document synchronization. It is important to note that Projectiondocument cannot be created directly, and must be created by the Projectiondocumentmanager Createslavedocument method.

The good news is that we don't have to care about the master-slave document architecture When we implement text folding, because it's all wrapped up in JTF, and at the top we see only one document.

Projectionannotation

As you can see in the Java editor, there is a small icon next to the fold, which shows the current folding state and can be clicked to change the folding state. From the interface, you should be able to think: this is not a callout? Yes, it is, but the callout is displayed on another ruler, which is different from the ruler that displays the error annotation. The implementation class of text folding annotation is projectionannotation, in the process of realizing text folding, it is very important to refresh projectionannotation in time.

I mentioned a lot of concepts related to annotations when I covered the text in part V of this series, and they also apply to text folding annotations. For example, you can customize the appearance of callouts by Idrawingstrategy, which by default is an ellipsis. As shown in the following illustration:

Figure 1. Default text collapse callout appearance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.