#@+leo-ver=4
#@+node:@file arrows.py
"""Rebind up/down arrow keys"""

from leoPlugins import *
from leoGlobals import *

try:
	import Tkinter
except ImportError:
	Tkinter = None

if Tkinter: # Register the handlers...

	#@	@+others
	#@+node:onOpen
	# Warning: the bindings created this way conflict with shift-arrow keys.
	
	def onOpen (tag,keywords):
	
		c = keywords.get("new_c")
		body = c.frame.body
		tree = c.frame.tree
	
		# Add "hard" bindings to have up/down arrows move by visual lines.
		old_binding = body.bodyCtrl.bind("<Up>")
		if len(old_binding) == 0:
			body.bodyCtrl.bind("<Up>",tree.OnUpKey)
	
		old_binding = body.bodyCtrl.bind("<Down>")
		if len(old_binding) == 0:
			body.bodyCtrl.bind("<Down>",tree.OnDownKey)
	#@-node:onOpen
	#@-others

	if app.gui is None:
		app.createTkGui(__file__)

	if app.gui.guiName() == "tkinter":

		registerHandler("open2", onOpen)
	
		__version__ = "1.3"
		plugin_signon(__name__)
#@nonl
#@-node:@file arrows.py
#@-leo
