CodeFoldingChanges201302

(Difference between revisions)
m
m
Line 31: Line 31:
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 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.
The pseudo-API is documented in arch document of ''editor.lib'' module.
 +
 +
= Overview of new features =
 +
 +
== FoldTypes ==
 +
FoldTypes were extended to act like ''extensible enum''. Each FoldType has a ''code'', a String which can be used to lookup the FoldType, or represent it (mainly in settings/preferences).
 +
 +
To further support modularization, the extension was enabled not only for 1 provider per language (MIME type), but multiple parties can define FoldTypes for a language. This allows to build a base support, usually tied to syntax structure of the language, and possibly enhance with an additional module e.g. for more advanced constructs.
 +
 +
Since FoldTypes can now be defined in an uncontrolled way (each language support can define whatever it needs), a single-parent '''hierarchy''' can be defined among FoldTypes. For example, large field initializers and methods are both ''members''; so an action "Collapse all members" will work on all of them.
 +
 +
The hierarchy also allows individual new FoldTypes to be preconfigured from the general settings: if the user configures auto-folding for ''NESTED' type folds, inner classes (in java), classes (in PHP) and other derived fold types will become autofolded, unless they have a specific override in the target language.
 +
 +
== Folding options ==
 +
Support for folding options was centralized. It is no longer needed to assign initial collapsed state to a Fold, when it is created. For special cases and backward compatibility, the assignment can be still made by the FoldManager, but
 +
in the case FoldManager does not set collapsed or expanded state, the infrastructure is capable to determine the auto-folding option status.
 +
 +
UI for folding options was extended to allow specific options for each language.

Revision as of 13:50, 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.

Overview of new features

FoldTypes

FoldTypes were extended to act like extensible enum. Each FoldType has a code, a String which can be used to lookup the FoldType, or represent it (mainly in settings/preferences).

To further support modularization, the extension was enabled not only for 1 provider per language (MIME type), but multiple parties can define FoldTypes for a language. This allows to build a base support, usually tied to syntax structure of the language, and possibly enhance with an additional module e.g. for more advanced constructs.

Since FoldTypes can now be defined in an uncontrolled way (each language support can define whatever it needs), a single-parent hierarchy can be defined among FoldTypes. For example, large field initializers and methods are both members; so an action "Collapse all members" will work on all of them.

The hierarchy also allows individual new FoldTypes to be preconfigured from the general settings: if the user configures auto-folding for NESTED' type folds, inner classes (in java), classes (in PHP) and other derived fold types will become autofolded, unless they have a specific override in the target language.

Folding options

Support for folding options was centralized. It is no longer needed to assign initial collapsed state to a Fold, when it is created. For special cases and backward compatibility, the assignment can be still made by the FoldManager, but in the case FoldManager does not set collapsed or expanded state, the infrastructure is capable to determine the auto-folding option status.

UI for folding options was extended to allow specific options for each language.

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