Skip to content

Commit

Permalink
keybindings for next and previous file
Browse files Browse the repository at this point in the history
[ and ] are now keybindings for the next and the previous open file.
  • Loading branch information
stettberger committed Aug 11, 2015
1 parent cc9d59f commit 598af3e
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions xdot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,8 @@ def __init__(self, command_line_files, widget=None):
# to display a file menu
self.widget.connect("button-press-event", self.on_file_menu)

self.connect('key-press-event', self.on_key_press_event)

self.last_open_dir = "."

self.set_focus(self.dotwidget)
Expand Down Expand Up @@ -2145,16 +2147,35 @@ def on_close_file(self, action):
self.open_file_idx = min(len(self.open_files)-1, self.open_file_idx)
self.open_file(self.open_files[self.open_file_idx])

def on_go_forward(self, action):
def on_go_forward(self, action = None):
"""Display the next file"""
self.open_file_idx = min(self.open_file_idx + 1, len(self.open_files) - 1)
self.open_file(self.open_files[self.open_file_idx])

def on_go_back(self, action):
def on_go_back(self, action = None):
"""Display the previous file"""
self.open_file_idx = max(0, self.open_file_idx - 1)
self.open_file(self.open_files[self.open_file_idx])

def on_file_menu(self, widget, event):
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
menu = gtk.Menu()
for filename in self.open_files:
label = os.path.basename(filename)
item = gtk.MenuItem(label)
menu.append(item)
item.connect("activate", lambda _, f: self.open_file(f), filename)
item.show()
menu.popup(None, None, None, 3, event.time)

def on_key_press_event(self, widget, event):
if event.keyval == gtk.keysyms.bracketleft:
self.on_go_back()
return True
if event.keyval == gtk.keysyms.bracketright:
self.on_go_forward()
return True


class OptionParser(optparse.OptionParser):

Expand All @@ -2173,6 +2194,8 @@ def main():
Up, Down, Left, Right scroll
PageUp, +, = zoom in
PageDown, - zoom out
[ previous open file
] next open file
R reload dot file
F find
Q quit
Expand Down

0 comments on commit 598af3e

Please sign in to comment.