net.jakubholy.jedit.autocomplete
Class PreferencesManager

java.lang.Object
  extended by net.jakubholy.jedit.autocomplete.PreferencesManager

public class PreferencesManager
extends java.lang.Object

Makes user settings available for other classes so that they don't need to deal with properties directly, calling PreferencesManager's methods instead.

An instance of this class keeps values of the various settings and makes them availabe through getter methods. The settings are also stored as jEdit properties (see jEdit.setProperty(java.lang.String, java.lang.String)). To change a setting, modify the appropriate jEdit property and call aPreferencesManager.optionsChanged().

Most settings can be changed via the menu Plugins > Plugins Options... > TextAutocomplete. See TextAutocompletePane.

Author:
Jakub Holy

Field Summary
protected  WordTypedListener.Filter isWordFilter
          Used to check whether an insertion appended to a word is still a word.
 
Method Summary
 java.net.URL getDefaultWordListForBuffer(java.lang.String bufferName, boolean onlyIfExists)
          Return a list of default words for a newly opened buffer of the given name if there is any.
 java.lang.String getFilenameFilter()
          Returns the filename filter registered for inclusion or exclusion from auto completion.
 java.util.regex.Pattern getFilenameFilterPattern()
          Returns the filename filter pattern.
 WordTypedListener.Filter getIsWordFilter()
          Checker that determines what is a word separator and what is not.
 int getLogLevel()
          True if the autocompletion should be started automatically for new buffers.
 int getMaxCountOfWords()
          The maximal number of words that we do remeber for a given buffer.
 java.lang.String getNoWordSeparators()
          Characters that do not end word such as '@' or '_' in PHP.
static PreferencesManager getPreferencesManager()
          Create a new Pref.Manager or return the existing one if exists.
 int getSelectionByNumberModifier()
          Returns the mask for the special key that must be pressed together with a number N to select the Nth completion in the popup.
 boolean isAcceptKey(java.awt.event.KeyEvent evt)
          Return true for keys used to accept a selected completition.
 boolean isDisposeKey(java.awt.event.KeyEvent evt)
          Return true for keys used to dispose (hide) the popup window.
 boolean isExclusionFilter()
          Returns whether filenames matching the filename filter should be excluded.
 boolean isInclusionFilter()
          Returns whether filenames matching the filename filter should be included.
 boolean isLoadMainModeOnly()
          When loading keywords associated with the buffer's edit mode, shall we load only those from the default mode? E.g.
 boolean isLoadModeKeywords()
          True if keywords from the buffer's edit mode shall be loaded upon start.
 boolean isSelectionByNumberEnabled()
          Do we allow to select an entry in the completion popup by typing its number?
 boolean isSelectionDownKey(java.awt.event.KeyEvent evt)
          Return true for keys used to move down in the popup list of completitions.
 boolean isSelectionUpKey(java.awt.event.KeyEvent evt)
          Return true for keys used to move up in the popup list of completitions.
 boolean isStartForBuffers()
          True if the autocompletion should be started automatically for new buffers.
 boolean isWordToRemember(java.lang.String word)
          Return true if the word shall be rememberd i.e.
 int minPrefixLength()
          Return the minimal length the word being typed must have for the list of completions to be displayed.
 void optionsChanged()
          Called to notify the PreferencesManager that preferences have changed.
static java.lang.String sanitizeCode(java.lang.String code)
          Make sure that the code ends with ';' i.e.
 void setBooleanProperty(java.lang.String name, boolean value)
          Set the boolean jEdit property named TextAutocompletePlugin.PROPS_PREFIX + 'name' to the value 'value'.
 void setIntegerProperty(java.lang.String name, int value)
          Set the int jEdit property named TextAutocompletePlugin.PROPS_PREFIX + 'name' to the value 'value'.
 void setNoWordSeparators(java.lang.String noWordSeparators)
          Characters that do not end word such as '@' or '_' in PHP.
 void setProperty(java.lang.String name, java.lang.String value)
          Set the String jEdit property named TextAutocompletePlugin.PROPS_PREFIX + 'name' to the value 'value'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isWordFilter

protected final WordTypedListener.Filter isWordFilter
Used to check whether an insertion appended to a word is still a word.

Method Detail

getPreferencesManager

public static PreferencesManager getPreferencesManager()
Create a new Pref.Manager or return the existing one if exists.


optionsChanged

public void optionsChanged()
Called to notify the PreferencesManager that preferences have changed.


getIsWordFilter

public WordTypedListener.Filter getIsWordFilter()
Checker that determines what is a word separator and what is not. The filter's method boolean accept(StringBuffer word, char insertion) is used for that.


minPrefixLength

public int minPrefixLength()
Return the minimal length the word being typed must have for the list of completions to be displayed. At least minPrefixLength characters must be typed before the pop-up window appears. It can be set to any value >= 1.


isAcceptKey

public boolean isAcceptKey(java.awt.event.KeyEvent evt)
Return true for keys used to accept a selected completition.


isDisposeKey

public boolean isDisposeKey(java.awt.event.KeyEvent evt)
Return true for keys used to dispose (hide) the popup window.


isSelectionUpKey

public boolean isSelectionUpKey(java.awt.event.KeyEvent evt)
Return true for keys used to move up in the popup list of completitions.


isSelectionDownKey

public boolean isSelectionDownKey(java.awt.event.KeyEvent evt)
Return true for keys used to move down in the popup list of completitions.


isWordToRemember

public boolean isWordToRemember(java.lang.String word)
Return true if the word shall be rememberd i.e. added to the completion word list.


getMaxCountOfWords

public int getMaxCountOfWords()
The maximal number of words that we do remeber for a given buffer. Additional words that would otherwise be remembered are ignored.


isStartForBuffers

public boolean isStartForBuffers()
True if the autocompletion should be started automatically for new buffers.


isLoadMainModeOnly

public boolean isLoadMainModeOnly()
When loading keywords associated with the buffer's edit mode, shall we load only those from the default mode? E.g. for PHP there is over 10 edit modes (or perhaps more exactly sub-modes). This may save memory while still providing the most important keywords for completion.

See Also:
isLoadModeKeywords()

isLoadModeKeywords

public boolean isLoadModeKeywords()
True if keywords from the buffer's edit mode shall be loaded upon start.


getFilenameFilterPattern

public java.util.regex.Pattern getFilenameFilterPattern()
Returns the filename filter pattern. completion. Use 'isIncludeFilter' or 'isExcludeFilter' to find whether filenames matching the filter should be included or excluded.


getFilenameFilter

public java.lang.String getFilenameFilter()
Returns the filename filter registered for inclusion or exclusion from auto completion. Use 'isIncludeFilter' or 'isExcludeFilter' to find whether filenames matching the filter should be included or excluded.


isInclusionFilter

public boolean isInclusionFilter()
Returns whether filenames matching the filename filter should be included.


isExclusionFilter

public boolean isExclusionFilter()
Returns whether filenames matching the filename filter should be excluded.


getLogLevel

public int getLogLevel()
True if the autocompletion should be started automatically for new buffers. TODO: Make it possible to start only for buffers matching some condition (edit mode, file name extension, ...)


isSelectionByNumberEnabled

public boolean isSelectionByNumberEnabled()
Do we allow to select an entry in the completion popup by typing its number?

Returnes true by default. The corrseponding property is TextAutocompletePlugin.PROPS_PREFIX + "isSelectionByNumberEnabled".

Returns:
True if a number key selects an entry in the completion popup win., false if the number should be just inserted into the buffer.

getSelectionByNumberModifier

public int getSelectionByNumberModifier()
Returns the mask for the special key that must be pressed together with a number N to select the Nth completion in the popup. Returns 0 if no modifier key is required and the number on itself selects the entry.

The corresponding property is TextAutocompletePlugin.PROPS_PREFIX + 'selectionByNumberModifierMask'.

Valid values: InputEvent.CTRL_MASK, InputEvent.ALT_MASK, InputEvent.ALT_GRAPH_MASK.

Returns:
0 = no modifier [default] or a mask defined in InputEvent such as InputEvent.CTRL_DOWN_MASK.

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
Set the String jEdit property named TextAutocompletePlugin.PROPS_PREFIX + 'name' to the value 'value'.


setBooleanProperty

public void setBooleanProperty(java.lang.String name,
                               boolean value)
Set the boolean jEdit property named TextAutocompletePlugin.PROPS_PREFIX + 'name' to the value 'value'.


setIntegerProperty

public void setIntegerProperty(java.lang.String name,
                               int value)
Set the int jEdit property named TextAutocompletePlugin.PROPS_PREFIX + 'name' to the value 'value'.


sanitizeCode

public static java.lang.String sanitizeCode(java.lang.String code)
Make sure that the code ends with ';' i.e. that it is a valid java statement


getDefaultWordListForBuffer

public java.net.URL getDefaultWordListForBuffer(java.lang.String bufferName,
                                                boolean onlyIfExists)
Return a list of default words for a newly opened buffer of the given name if there is any. The format of the file pointed to by the URL is the same as used by AutoComplete.importWordList().

This method shall be called when AutoCompletion is started for a new buffer and perhaps also when the buffer name changes (e.g. after the change from 'Untitled-1' to 'SourceCode.java' we will want to load default words for Java files).

Parameters:
bufferName - (required) a name of the buffer that AutoComplete has just been started for; examples: 'SourceCode.java', 'Untitled-1'. It's used to find a suitable word list, usually based on the file name extension. To get the default, not buffer-specific word list you can pass an empty string ("") as the buffer name.
onlyIfExists - (required) If false then the word list file path is returned even if the file doesn't currently exist othewrise null is returned if the file doesn't exist
Returns:
either URL of a list of default words as in AutoComplete.importWordList() or null if there're no defaults. Beware that the URL may point to a non-existing file.

getNoWordSeparators

public java.lang.String getNoWordSeparators()
Characters that do not end word such as '@' or '_' in PHP.


setNoWordSeparators

public void setNoWordSeparators(java.lang.String noWordSeparators)
Characters that do not end word such as '@' or '_' in PHP.

Parameters:
noWordSeparators - (required) ex.: "_@-"