New release.
[rox-edit.git] / goto.py
blobb124e62e18ffcb296170f841de2a73e6f9646352
1 from rox import g
2 import rox
3 from EditWindow import Minibuffer
5 class Goto(Minibuffer):
6 "A minibuffer used to find a line by number."
8 def setup(self, window):
9 self.window = window
10 self.window.set_mini_label(_('Goto line:'))
12 info = _('Enter the line number to go to. Line numbers start from 1. '
13 'Press Escape to cancel, or Return to jump to the line.')
15 def activate(self):
16 line = self.window.mini_entry.get_text()
17 if line:
18 try:
19 line = int(line)
20 assert line >= 1
21 except:
22 rox.alert(_('Invalid line number: %s') % line)
23 else:
24 buffer = self.window.buffer
25 iter = buffer.get_iter_at_line(line - 1)
26 buffer.place_cursor(iter)
27 self.window.text.scroll_to_iter(iter,
28 0.05, g.FALSE)
29 self.window.set_minibuffer(None)