mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Context menu actions to go to next/previous change
This commit is contained in:
parent
183048d01a
commit
ce99832337
@ -48,6 +48,7 @@ class TextBrowser(PlainTextEdit): # {{{
|
||||
|
||||
resized = pyqtSignal()
|
||||
wheel_event = pyqtSignal(object)
|
||||
goto_change = pyqtSignal(object)
|
||||
|
||||
def __init__(self, right=False, parent=None):
|
||||
PlainTextEdit.__init__(self, parent)
|
||||
@ -114,6 +115,30 @@ class TextBrowser(PlainTextEdit): # {{{
|
||||
i = unicode(self.textCursor().selectedText())
|
||||
if i:
|
||||
a(QIcon(I('edit-copy.png')), _('Copy to clipboard'), self.copy)
|
||||
|
||||
if len(self.changes) > 0:
|
||||
try:
|
||||
b = self.cursorForPosition(pos).block().blockNumber()
|
||||
except Exception:
|
||||
b = -1
|
||||
if b > -1:
|
||||
pc = nc = None
|
||||
for i, (top, bot, kind) in enumerate(self.changes):
|
||||
if top <= b and bot >= b:
|
||||
if len(self.changes) == 1:
|
||||
break
|
||||
pc = (i - 1) % len(self.changes)
|
||||
nc = (i + 1) % len(self.changes)
|
||||
if bot < b:
|
||||
pc = i
|
||||
if top > b:
|
||||
nc = i
|
||||
break
|
||||
if pc is not None:
|
||||
a(QIcon(I('arrow-up.png')), _('Previous change'), partial(self.goto_change.emit, pc))
|
||||
if nc is not None:
|
||||
a(QIcon(I('arrow-down.png')), _('Next change'), partial(self.goto_change.emit, nc))
|
||||
|
||||
if len(m.actions()) > 0:
|
||||
m.exec_(self.mapToGlobal(pos))
|
||||
|
||||
@ -755,6 +780,17 @@ class DiffView(QWidget): # {{{
|
||||
self.view.left.resized.connect(self.resized)
|
||||
for v in self.view.left, self.view.right, self.view.handle(1):
|
||||
v.wheel_event.connect(self.scrollbar.wheelEvent)
|
||||
if hasattr(v, 'goto_change'):
|
||||
v.goto_change.connect(self.goto_change)
|
||||
|
||||
def goto_change(self, change):
|
||||
for v in (self.view.left, self.view.right):
|
||||
c = QTextCursor(v.document().findBlockByNumber(v.changes[change][0]))
|
||||
v.setTextCursor(c)
|
||||
v.centerCursor()
|
||||
with self:
|
||||
self.scroll_to(0, self.get_position_from_scrollbar(1))
|
||||
self.view.handle(1).update()
|
||||
|
||||
def resized(self):
|
||||
self.resize_timer.start(100)
|
||||
@ -805,7 +841,7 @@ class DiffView(QWidget): # {{{
|
||||
val = start + offset
|
||||
bar.setValue(val - syncpos)
|
||||
|
||||
def scrolled(self, which):
|
||||
def scrolled(self, which, *args):
|
||||
if self.syncing:
|
||||
return
|
||||
position = self.get_position_from_scrollbar(which)
|
||||
|
Loading…
x
Reference in New Issue
Block a user