When you view a file's diff or Blame in TortoiseHg, you'll also see an indicator showing your changes, right?
When I scroll the window, the gray box moves accordingly. Do you want to click here? I would be very happy if you click it and jump to that position. I.
That's why I tried a little. https://bitbucket.org/iwata0303/thg/commits/bbb613be1df57a43c4e3f6c20aa10ad45fe26c93
I have a file called tortoisehg / hgqt / blockmatcher.py and I'm adding this method to a class called BlockList there.
blockmatcher.py
def scrollToPos(self, y):
# Scroll to the position which specified by Y coodinate.
if not isinstance(self._sbar, QScrollBar):
return
ratio = float(y) / self.height()
minimum, maximum, step = self._minimum, self._maximum, self._pagestep
value = minimum + (maximum + step - minimum) * ratio - (step * 0.5)
value = min(maximum, max(minimum, value)) # round to valid range.
self.setValue(value)
def mousePressEvent(self, event):
super(BlockList, self).mousePressEvent(event)
self.scrollToPos(event.y())
def mouseMoveEvent(self, event):
super(BlockList, self).mouseMoveEvent(event)
self.scrollToPos(event.y())
Now, if you click on the indicator, it will jump to that position, and if you drag it up or down as it is, scrolling will also work.
By the way, it's a hassle to get the TortoiseHg source and build it just for this.
** It's not recommended for a good boy **, but I'll try using an extension to apply a monkey patch.
thg_blocklist_patch.py
# -*- coding:utf-8 -*-
def extsetup():
import sys
import os
# thg.exe and thgw.Only process when executed from exe
if not os.path.basename(sys.argv[0]).startswith('thg'):
return
from PyQt4.QtGui import QScrollBar
from tortoisehg.hgqt.blockmatcher import BlockList
from types import MethodType
mousePressEvent_org = BlockList.mousePressEvent
mouseMoveEvent_org = BlockList.mouseMoveEvent
def scrollToPos(bl, y):
# Scroll to the position which specified by Y coodinate.
if not isinstance(bl._sbar, QScrollBar):
return
ratio = float(y) / bl.height()
minimum, maximum, step = bl._minimum, bl._maximum, bl._pagestep
value = minimum + (maximum + step - minimum) * ratio - (step * 0.5)
value = min(maximum, max(minimum, value)) # round to valid range.
bl.setValue(value)
def mousePressEvent(self, event):
mousePressEvent_org(self, event)
scrollToPos(self, event.y())
def mouseMoveEvent(self, event):
mouseMoveEvent_org(self, event)
scrollToPos(self, event.y())
BlockList.mousePressEvent = MethodType(mousePressEvent, None, BlockList)
BlockList.mouseMoveEvent = MethodType(mouseMoveEvent, None, BlockList)
Normally, I don't want to be hurt when I hit the hg command, so I try to process it only when it is executed from thg * .exe.
I haven't confirmed it, but on Linux, I think that sys.arg [0]
will contain the python path, so in that case, check with sys.arg [1]
.
If you register this file as an extension properly, you will not have to touch the source of the main body. ** This is a monkey patch, so be careful when upgrading. ** **
Recommended Posts