CodeFoldingChanges201302

(Difference between revisions)
(Created page with '== Separation from Editor == For legacy reasons, part of the Code Folding (sidebar, bindings to caret) was placed in the ''editor.lib'' module. This complicates dependencies, and…')
m
Line 6: Line 6:
* '''CustomFoldManager'''
* '''CustomFoldManager'''
Classes are moved between modules, with ''editor.lib'' injecting dependency on ''editor.fold'' module, so existing clients continue to compile and run.
Classes are moved between modules, with ''editor.lib'' injecting dependency on ''editor.fold'' module, so existing clients continue to compile and run.
 +
 +
=== CodeFoldingSidebar ===
 +
The class resides in a public package, but exposes a lot of its internals. It's typically used just to create an instance of SideBar for the editor. Potential other use could be a different presentation of folding signs, but that is severely impaired by design of the class, where useful methods are private, leading to copy-paste or reflection programming.
 +
 +
I've decided to provide ''factories'' for the sidebar, both for code and XML layer usage, and deprecate the whole class. It could be redesigned in the future and published in a codefolding API package.
 +
 +
The moved class (in the original package) is left public and unchanged for backwards compatibility.
 +
 +
=== CustomFoldManager ===
 +
The CustomFoldManager handles in-comments user-defined folds, such as those used by Form module:
 +
<code><pre>
 +
// <editor-fold collapsed=true">
 +
</pre></code>
 +
it has to be instantiated for every MIME type, which want to support user comments. The use-cases require only the creation to be public, not the entire class. XML layer - usable creation API was added into FoldingSupport utility class.
 +
 +
=== Additional hooks between editor.lib and editor.fold ===
Two hooks between ''editor.lib'' and ''editor.fold'' are needed to integrate folding with the caret operations. New method
Two hooks between ''editor.lib'' and ''editor.fold'' are needed to integrate folding with the caret operations. New method

Revision as of 13:26, 19 February 2013

Contents

Separation from Editor

For legacy reasons, part of the Code Folding (sidebar, bindings to caret) was placed in the editor.lib module. This complicates dependencies, and puts an add-on feature into the base editor module. Instead of moving the parts of folding code to editor.lib2, they will be merged with the data layer in editor.fold.

Several legacy classes are moved and deprecated:

  • CodeFoldingSidebar
  • CustomFoldManager

Classes are moved between modules, with editor.lib injecting dependency on editor.fold module, so existing clients continue to compile and run.

CodeFoldingSidebar

The class resides in a public package, but exposes a lot of its internals. It's typically used just to create an instance of SideBar for the editor. Potential other use could be a different presentation of folding signs, but that is severely impaired by design of the class, where useful methods are private, leading to copy-paste or reflection programming.

I've decided to provide factories for the sidebar, both for code and XML layer usage, and deprecate the whole class. It could be redesigned in the future and published in a codefolding API package.

The moved class (in the original package) is left public and unchanged for backwards compatibility.

CustomFoldManager

The CustomFoldManager handles in-comments user-defined folds, such as those used by Form module:

// <editor-fold collapsed=true">

it has to be instantiated for every MIME type, which want to support user comments. The use-cases require only the creation to be public, not the entire class. XML layer - usable creation API was added into FoldingSupport utility class.

Additional hooks between editor.lib and editor.fold

Two hooks between editor.lib and editor.fold are needed to integrate folding with the caret operations. New method

public void refresh(boolean retainInView)

is introduced, so fold support can refresh caret position on the screen.

The 2nd hook is used by BaseCaret handling of mouse clicks, which needs an immediate info on whether the current visual position falls into a folded view, since the behaviour is then different. Since the mouse support is quite mixed with BaseCaret with no points for extension, I decided to use a pseudo-API: register a Callable<Boolean> as org.netbeans.api.fold.expander property on the text component. Base caret calls the Callable to obtain the necessary information. The pseudo-API is documented in arch document of editor.lib module.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo