Changes

Jump to navigation Jump to search

D2Editor:registerFilter

2,028 bytes added, 02:36, 26 May 2013
Created page with "'''registerFilter''' is a function that is part of D2Editor (2D Editor). This routine registers a table of handler functions that can filter events befor..."
'''registerFilter''' is a function that is part of [[:Category:D2Editor|D2Editor]] (2D Editor).

This routine registers a table of handler functions that can filter events before they are sent to the 2D editor widget, or unregisters if nil is passed.

The handlerTable is a table of event handler functions. Any [[Events|event function]] described within the handlerTable can be filtered by a function in the handler table.

In the example code below, if the user presses ''Tab'' in the text editor ''ed'', the ''tabKey'' filter function moves the focus to text editor ''ed2''. Events charIn and arrowKey simply report which key was pressed and then allow the event to pass on through to the text editor.


{{Since|3.2}}

== Syntax ==
D2Editor.'''registerFilter'''([handlerTable])<br />
( or editor:'''registerFilter'''([handlerTable]) )

{| class="wikitable"
|-
! Parameter !! Type !! Description
|-
| <u><center>handlerTable</center></u> || table || table of event functions (like ''enterKey'', ''tabKey''...)
|-
|}

The ''handlerTable'' argument is optional, since not passing an argument (nil) is the way to reset (turn off) the 2DEditor's event filtering.

== Example ==
<syntaxhighlight>-- Create an editor
ed = D2Editor.newRichText()

-- Register filters for events
ed:registerFilter {
tabKey = function() ed2:setFocus() return true end,
charIn = function(ch) print(ch) return false end
arrowKey = function(key) print(arrowKey) return false end
}</syntaxhighlight>

== Good to know ==
* The event handler functions have to be defined "on their own", like "enterKey", "tabKey" etc, and not like the usual definitions "on.enterKey", "on.tabKey" (this is because in that case, you're defining methods of the "on" table, the global events)
* The event handler functions in the registerFilter table have to return either true or false : true meaning that no further action will be taken for that event, while false means that the default action for the event will still be executed.

<br /><br />[[Category:D2Editor]]

Navigation menu