Skip to content

Commit

Permalink
menu for open files
Browse files Browse the repository at this point in the history
Right click in the drawing area will open a context menu, with all open
files to select from.
  • Loading branch information
stettberger committed Aug 11, 2015
1 parent 9e1a435 commit 55c1d87
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions xdot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,10 @@ def __init__(self, command_line_files, widget=None):
self.open_files.append(os.path.abspath(filename))
self.open_file_idx = 0

# Connect the Button click event of the drawing menu, in order
# to display a file menu
self.dotwidget.connect("button-press-event", self.on_file_menu)

self.last_open_dir = "."

self.set_focus(self.dotwidget)
Expand Down Expand Up @@ -2151,6 +2155,28 @@ def on_go_back(self, action):
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 == Gdk.EventType.BUTTON_PRESS and event.button == 3:
menu = Gtk.Menu()
for filename in self.open_files:
label = os.path.basename(filename)
item = Gtk.MenuItem()
item.set_label(label)
item.connect("activate", lambda _, f: self.open_file(f), filename)
menu.append(item)
menu.show_all()
self.menu = menu
menu.popup(None, None, None, None,
event.button, event.time)
return True

def on_key_press_event(self, widget, event):
if event.keyval == Gdk.KEY_bracketleft:
self.on_go_back()
return True
if event.keyval == Gdk.KEY_bracketright:
self.on_go_forward()
return True

class OptionParser(optparse.OptionParser):

Expand Down

0 comments on commit 55c1d87

Please sign in to comment.