/usr/share/gps/library/treemove.py is in gnat-gps-common 6.1.2016-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | """
This plug-in improves the behavior of Left and Right arrow keys
when navigating in a tree, for instance the project explorer.
It brings a behavior similar to the Windows default, that is:
- Right expands the current node, and then selects its first child
The Down key does not expand before it moves the cursor down.
- Left collapse the current node if it is expanded otherwise it moves
the cursor to the parent node.
"""
import GPS
from gps_utils import interactive
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
logger = GPS.Logger("treemove")
def current_tree():
"""Return the current tree widget and path that has the focus or None"""
for widget in Gtk.Window.list_toplevels():
if widget.is_active():
result = widget.get_focus()
if isinstance(result, Gtk.TreeView):
return result, result.get_cursor()[0]
return None
return None
@interactive(category="General",
filter=lambda x: current_tree() is not None,
key="Left")
def move_cursor_up_or_collapse():
current = current_tree()
if current is None:
return
tree, path = current
if tree and path:
if tree.row_expanded(path):
# The current cursor is on an expanded row, so collapse
# the row
logger.log("collapse row %s" % path)
tree.collapse_row(path)
else:
# The current cursor is not on an expanded row so try to
# to move up to the parent node.
path.up()
if path:
# Check that path is valid as path.up on the root
# node might return an invalid path ?
tree.set_cursor(path, tree.get_column(0))
@interactive(category="General",
filter=lambda x: current_tree() is not None,
key="Right")
def expand_and_move_cursor_down():
current = current_tree()
if current is None:
return
tree, path = current
if tree and path:
logger.log("expand row %s" % path)
if tree.row_expanded(path):
path.down()
tree.set_cursor(path, tree.get_column(0))
else:
tree.expand_row(path, False)
|