|
org.netbeans.modules.editor.settings.storage/1 1.10 | |||||||||
PREV NEXT | FRAMES NO FRAMES |
See:
Description
Editor Settings Storage | |
---|---|
org.netbeans.modules.editor.settings.storage.api |
The editor/settings/storage
module provides friend
EditorSettingsStorageAPI
comprising classes in the org.netbeans.modules.editor.settings.storage.api
package. It also defines the structure of the settings storage and the structure
of XML files with settings. The following XML files are supported.
-//NetBeans//DTD Editor Fonts and Colors settings 1.1//EN
-//NetBeans//DTD Editor KeyBindings settings 1.1//EN
The setting files are stored in MimeLookup
in the folders hierarchy
under the Editors/
folder on the default filesystem. The storage follows
the main principle of MimeLookup
and allows to define mime type
specific settings as well as settings that apply for all editors. This is achieved
by placing the setting files in the appropriate folder (i.e. in the mime type
folder such as Editors/<mime-type>
or in the Editors/
folder itself for the global settings).
No matter whether the files are stored in Editors/
or in a mime type
specific folder their further position relative to that folder and their meaning
is the same.
Both font & colors and key bindings are grouped in so called profiles that allow user switching quickly between predefined sets of colorings or key bindings. An example of profiles can be key bindings for NetBeans, Eclipse and Emacs. Each of those profiles defines keyboard shortcuts for IDE actions that are known from other products. Another example is the profiles defining normal and inverse color schemes. In Netbeans they are called NetBeans and CityLights.
The editor/settings/storage
module dedicates a special folder for
each profile and stores all the profile related files in that folder.
The module provides a special treatment for profiles with names starting with
the "test"
string. These profiles are handled as a temporary in-memory
profiles, which are not persisted to the disk. They are mainly used for 'preview'
purposes in the Options dialog.
The module also recognizes special mime paths, which String
representation
starts with the "test*_"
string (e.g. "test123ed_text/x-java"
)
and provides MimeLookup for those mime paths. The contents of MimeLookup for those
special mime paths is basically the same as MimeLookup for the mime path without the
leading test*_
string, but it contains FontColorsSettings
and KeyBindingSettings
instances specially constructed for the 'test'
mime type. Again this is mainly used for 'preview' purposes by the Options dialog.
Since this functionality is defacto an API it is being tracked as SpecialProfilesAndMimeTypesAPI.
The editor settings storage is organized in the way that allows storing user
changes separately from the default values provided by modules. This is useful
when a users wants to reset their profiles back to the original values shipped
with the product. This is achieved by defining a special subfolder called
Defaults
for every profile. The default colorings and key bindings
provided by modules are then registered in this Defaults
subfolder
while user changes are stored directly in the profile's folder. When restoring the
original values the files with user changes are simply deleted and the profile
is reloaded from the default files.
Since version 1.10 the storage module does not require coloring files to be
called any special name. The coloring profiles and files are expected to be
registered by modules under a special folder called FontsColors
. The
structure below shows an example of registering several different coloring files
for all editors and the text/x-java mime type.
Editors |- FontsColors | |- NetBeans | |- Defaults | |- foo.xml | |- bar.xml |- text |- x-java |- FontsColors |- NetBeans |- Defaults |- xyz.xml |- abc.xml
In order to distinguish files containing token-related colorings from those
with highlight-related colorings the storage module recognizes a special file
attribute called nbeditor-settings-ColoringType
, which value can
either be token
or highlight
. If a coloring file does
not specify this attribute it is automatically expected to contain token-related
colorings.
Generally, the files with default values are stored in Defaults
subfolders while the files with user changes are stored directly in the
profile's folder.
The default profile for font & colors is called 'NetBeans'.
Prior to version 1.10 the storage module expected colorings in the three different types of files. They are still recognized to support backwards compatibility, but modules are suggusted to use the new registration scheme. All of those three files had the same structure, but different purpose.
coloring.xml
- defines colorings used for rendering tokens from
a particular language (i.e. mime type).
defaultColoring.xml
- defines language neutral colorings, which
can be used as fallback for language specific colorings. This file can only
be specified in the Editors/<profile-name>/Defaults
folders.
If specified in a mime type subfolder it will be ignored.
editorColoring.xml
- defines colorings that do not apply for
tokens. These colorings define for example the color for highlighting the row
with a caret, etc. They are not mime type specific and can only be specified
in the Editors/<profile-name>/Defaults
folders.
If specified in a mime type subfolder it will be ignored.
Since version 1.10 modules can provide their keybindings in multiple files
placed under the special folder called Keybindings
and its profiles'
subfolders. Similarily as for colorings the files with default key bindings are stored in Defaults
subfolder and user changes are stored in files directly in the profile's folder.
The example below shows registration of several keybinding files for all editors
and the text/x-java mime type.
Editors |- Keybindings | |- NetBeans | |- Defaults | |- foo.xml | |- bar.xml |- text |- x-java |- Keybindings |- NetBeans |- Defaults |- xyz.xml |- abc.xml
Prior to version 1.10 the default profile for key bindings, called NetBeans,
had not been stored in its own folder. Therefore the default key bindings for
the NetBeans profile used to be stored directly in
Editors/<mime-type>/Defaults/keybindings.xml
and similarily
user changes used to be stored in Editors/<mime-type>/keybindings.xml
.
This has been deprecated, but is still supported for backwards compatibility reasons.
Also the special mime type called text/base
, has been deprecated
and should not be used anymore. It is however still supported to preserve
backwards compatibility.
Since 1.10 it is possible to mark setting files as applicable only on a certain platform (a.k.a. operating system). This was mainly introduced for keybindings, which are generally platform sensitive settings, but can be used for any other setting type supported by the storage module.
Some platforms (eg. Mac) define their own special rules for the use of some
combinations of keystrokes (eg. ctrl+Q closes the app) that applications on that
platform have to obey. NetBeans mitigates this problem by introducing a special
module ide/applemenu, which is only loaded on Mac and which overrides
keybindings.xml
files provided by some Netbeans modules (eg. editor and java).
This approach works albeit some severe limitations. However with introducing
multiple setting files this would no longer be practical, which is why platform
specific settings have been introduced.
The storage module recognizes a special file attribute for marking
platform specific setting files called nbeditor-settings-targetOS
.
The rules for its use follow.
nbeditor-settings-targetOS
is loaded
on all platforms. All such files will be loaded exactly in the same order as
they appear on the system filesystem.
nbeditor-settings-targetOS
attribute, but its
value does not correspond to the current Operating System, the file is ignored.
nbeditor-settings-targetOS
attribute and its
value designates the current Operating System, the file will be loaded.
Furthermore, any such a file will be loaded after other files in the
same folder that do not define this attribute and therefore its settings will
override settings from those other files.
nbeditor-settings-targetOS
attribute and are eligible for loading on the current Operating System,
they will be loaded in the same order as they appear on the system filesystem.
The available values that can be used for the nbeditor-settings-targetOS
attribute are the string names of the OS_*
constants in org.openide.util.Utilities
class. So, for example the following file will only be loaded on MacOS and its settings
will override settings from all other files that do not specify the target OS attribute.
<folder name="Editors"> <folder name="Keybindings"> <folder name="NetBeans"> <folder name="Defaults"> <file name="keybindings-for-mac.xml" url="..."> <attr name="nbeditor-settings-targetOS" stringvalue="OS_MAC"/> </file> </folder> </folder> </folder> </folder>
The phase 1 of the editor settings enhancements, please see issue 90403 for details. Briefly, the changes involve introducing a special folder for each setting type, profiles are always stored in their own folder, modules are allowed to register multiple settings files, platform specific settings, the use of 'text/base' for all-editors settings has been deprecated in favor of the hierarchy root (ie. 'Editors' folder), etc.
The changes are documented in the Architecture Description document and marked with the module version.
Adding EditorSettings.getAllMimeTypes()
method, which
lists all top-level mime types registered in MimeLookup
.
The getDefaultFontColors
, getDefaultFontColorDefaults
and setDefaultFontColors
methods in the EditorSettings
classe were deprecated in favor of using EditorSettings.getFontColorSettings(String[])
with an empty mime path, which is the standard way of getting defaults
for all document types.
The PROP_DEFAULT_FONT_COLORS
and PROP_EDITOR_FONT_COLORS
should have never been made public. They are only used internally.
The module is now 'eager' and it provides the org.netbeans.api.editor.settings.implementation
token required by the editor/settings
module. Also
the API was properly marked as for-friends-only.
The friend API provided by this module is used only by the new options dialog. It is not expected to have any other clients or users. The API gives the options dialog a read/write access to the editor settings storage allowing it to implement UI for maintaining the settings.
Various modules need to provide predefined font a colors for text tokens from
languages they support. An example of such a module is java/editor
which defines colorings for tokens in java files. Defining colorings is as simple
as writing an XML file with the appropriate information. The example below shows
how to do that.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE fontscolors PUBLIC "-//NetBeans//DTD Editor Fonts and Colors settings 1.1//EN" "http://www.netbeans.org/dtds/EditorFontsColors-1_1.dtd"> <fontscolors> <fontcolor name="mylang-keyword" foreColor="0000CC" default="keyword"> <font style="bold" /> </fontcolor> </fontscolors>
Please see the http://www.netbeans.org/dtds/EditorFontsColors-1_1.dtd for more details.
As well as providing predefined colorings modules need to provide predefined key bindings. This can be accomplished by writing another simple XML file.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE bindings PUBLIC "-//NetBeans//DTD Editor KeyBindings settings 1.1//EN" "http://www.netbeans.org/dtds/EditorKeyBindings-1_1.dtd"> <bindings> <bind actionName="goto-source" key="O-O"/> </bindings>
Please see the http://www.netbeans.org/dtds/EditorKeyBindings-1_1.dtd for more details.
|
|
The sources for the module are in NetBeans CVS in editor/settings/storage directory.
Read more about the implementation in the answers to architecture questions.
|
org.netbeans.modules.editor.settings.storage/1 1.10 | |||||||||
PREV NEXT | FRAMES NO FRAMES |