Commits

Hidetaka Iwata committed 07ab34f

fileview: add `Go to line` action

Comments (0)

Files changed (1)

tortoisehg/hgqt/fileview.py

         self.actionPrevDiff.triggered.connect(self.prevDiff)
         self._setModeByAction(self.actionDiffMode)
 
+        self.actionGotoLine = QAction(qtlib.geticon('go-jump'),
+                                      _('Go to line') + ' (ctrl+J)', self)
+        self.actionGotoLine.setShortcut('CTRL+J')
+        self.actionGotoLine.triggered.connect(self.gotoLine)
+
         self.actionFirstParent = QAction('1', self)
         self.actionFirstParent.setCheckable(True)
         self.actionFirstParent.setChecked(True)
         tb.addSeparator()
         tb.addAction(self.actionNextDiff)
         tb.addAction(self.actionPrevDiff)
+        tb.addAction(self.actionGotoLine)
         tb.addSeparator()
         tb.addAction(self.actionFind)
         tb.addAction(self.actionShelf)
     def nDiffs(self):
         return len(self._diffs)
 
+    def gotoLine(self):
+        max = self.sci.lines()
+        if max == 0:
+            return
+        line, ok = QInputDialog.getInt(self, _("Goto line"),
+                                       _("Enter line no") + " (1 - %d)" % max,
+                                       1, 1, max)
+        if ok:
+            self.sci.setCursorPosition(line - 1, 0)
+            self.sci.ensureLineVisible(line - 1)
+            self.sci.setFocus()
+
     def editSelected(self, path, rev, line):
         """Open editor to show the specified file"""
         path = hglib.fromunicode(path)