Skip to content

Commit

Permalink
Add shortcut (ctrl + click) for jumping to edge's destination node.
Browse files Browse the repository at this point in the history
  • Loading branch information
rrbutani committed Apr 4, 2024
1 parent 8694118 commit 92423a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ You can also pass the following options:
Escape halt animation
Ctrl-drag zoom in/out
Shift-drag zooms an area
Click (on edge) focus edge's source node
Ctrl-click (on edge) focus edge's *destination* node

If `-` is given as input file then _xdot.py_ will read the dot graph from the standard input.

Expand Down
2 changes: 2 additions & 0 deletions xdot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def main():
Escape halt animation
Ctrl-drag zoom in/out
Shift-drag zooms an area
Click (on edge) focus edge's source node
Ctrl-click (on edge) focus edge's *destination* node
'''
)
parser.add_argument(
Expand Down
9 changes: 5 additions & 4 deletions xdot/ui/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def is_inside(self, x, y):
return True
return False

def get_jump(self, x, y):
def get_jump(self, x, y, to_dst = False):
for shape in self.shapes:
x1, y1, x2, y2 = shape.bounding
if (x1 - self.RADIUS) <= x and x <= (x2 + self.RADIUS) and (y1 - self.RADIUS) <= y and y <= (y2 + self.RADIUS):
Expand All @@ -639,7 +639,8 @@ def get_jump(self, x, y):
for shape in self.shapes:
distance = shape.get_smallest_distance(x, y)
if distance is not None and distance <= self.RADIUS:
return Jump(self, self.src.x, self.src.y)
jmp_dest = self.dst if to_dst else self.src
return Jump(self, jmp_dest.x, jmp_dest.y)

return None

Expand Down Expand Up @@ -730,9 +731,9 @@ def get_url(self, x, y):
return url
return None

def get_jump(self, x, y):
def get_jump(self, x, y, to_dst = False):
for edge in self.edges:
jump = edge.get_jump(x, y)
jump = edge.get_jump(x, y, to_dst)
if jump is not None:
return jump
for node in self.nodes:
Expand Down
7 changes: 4 additions & 3 deletions xdot/ui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ def on_area_button_release(self, area, event):
if url is not None:
self.emit('clicked', url.url, event)
else:
jump = self.get_jump(x, y)
ctrl_held = event.get_state() & Gdk.ModifierType.CONTROL_MASK
jump = self.get_jump(x, y, to_dst=ctrl_held)
if jump is not None:
self.animate_to(jump.x, jump.y)

Expand Down Expand Up @@ -528,9 +529,9 @@ def get_url(self, x, y):
x, y = self.window2graph(x, y)
return self.graph.get_url(x, y)

def get_jump(self, x, y):
def get_jump(self, x, y, to_dst = False):
x, y = self.window2graph(x, y)
return self.graph.get_jump(x, y)
return self.graph.get_jump(x, y, to_dst)


class FindMenuToolAction(Gtk.Action):
Expand Down

0 comments on commit 92423a7

Please sign in to comment.