mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Describe left and right panels at the bottom of the diff view
This commit is contained in:
parent
f3e36ef2c5
commit
b69889da8f
@ -486,7 +486,7 @@ class LayoutMixin(object): # {{{
|
|||||||
path1, path2 = db.format_abspath(book_id, ofmt), db.format_abspath(book_id, fmt)
|
path1, path2 = db.format_abspath(book_id, ofmt), db.format_abspath(book_id, fmt)
|
||||||
from calibre.gui2.tweak_book.diff.main import compare_books
|
from calibre.gui2.tweak_book.diff.main import compare_books
|
||||||
compare_books(path1, path2, parent=self, revert_msg=_('Restore %s') % ofmt, revert_callback=partial(
|
compare_books(path1, path2, parent=self, revert_msg=_('Restore %s') % ofmt, revert_callback=partial(
|
||||||
self.iactions['Remove Books'].restore_format, book_id, ofmt))
|
self.iactions['Remove Books'].restore_format, book_id, ofmt), names=(ofmt, fmt))
|
||||||
|
|
||||||
def save_layout_state(self):
|
def save_layout_state(self):
|
||||||
for x in ('library', 'memory', 'card_a', 'card_b'):
|
for x in ('library', 'memory', 'card_a', 'card_b'):
|
||||||
|
@ -518,7 +518,9 @@ class Boss(QObject):
|
|||||||
self.commit_all_editors_to_container()
|
self.commit_all_editors_to_container()
|
||||||
d = self.create_diff_dialog()
|
d = self.create_diff_dialog()
|
||||||
d.revert_requested.connect(partial(self.revert_requested, self.global_undo.previous_container))
|
d.revert_requested.connect(partial(self.revert_requested, self.global_undo.previous_container))
|
||||||
d.container_diff(to_container or self.global_undo.previous_container, self.global_undo.current_container)
|
other = to_container or self.global_undo.previous_container
|
||||||
|
d.container_diff(other, self.global_undo.current_container,
|
||||||
|
names=(self.global_undo.label_for_container(other), self.global_undo.label_for_container(self.global_undo.current_container)))
|
||||||
|
|
||||||
def compare_book(self):
|
def compare_book(self):
|
||||||
self.commit_all_editors_to_container()
|
self.commit_all_editors_to_container()
|
||||||
@ -529,7 +531,8 @@ class Boss(QObject):
|
|||||||
with TemporaryDirectory('_compare') as tdir:
|
with TemporaryDirectory('_compare') as tdir:
|
||||||
other = _gc(path[0], tdir=tdir, tweak_mode=True)
|
other = _gc(path[0], tdir=tdir, tweak_mode=True)
|
||||||
d = self.create_diff_dialog(revert_msg=None)
|
d = self.create_diff_dialog(revert_msg=None)
|
||||||
d.container_diff(other, c)
|
d.container_diff(other, c,
|
||||||
|
names=(_('Other book'), _('Current book')))
|
||||||
|
|
||||||
def revert_requested(self, container):
|
def revert_requested(self, container):
|
||||||
self.commit_all_editors_to_container()
|
self.commit_all_editors_to_container()
|
||||||
|
@ -12,7 +12,7 @@ from functools import partial
|
|||||||
from PyQt4.Qt import (
|
from PyQt4.Qt import (
|
||||||
QGridLayout, QToolButton, QIcon, QRadioButton, QMenu, QApplication, Qt,
|
QGridLayout, QToolButton, QIcon, QRadioButton, QMenu, QApplication, Qt,
|
||||||
QSize, QWidget, QLabel, QStackedLayout, QPainter, QRect, QVBoxLayout,
|
QSize, QWidget, QLabel, QStackedLayout, QPainter, QRect, QVBoxLayout,
|
||||||
QCursor, QEventLoop, QKeySequence, pyqtSignal, QTimer)
|
QCursor, QEventLoop, QKeySequence, pyqtSignal, QTimer, QHBoxLayout)
|
||||||
|
|
||||||
from calibre.ebooks.oeb.polish.container import Container
|
from calibre.ebooks.oeb.polish.container import Container
|
||||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||||
@ -213,18 +213,18 @@ class Diff(Dialog):
|
|||||||
b.clicked.connect(partial(self.view.next_change, -1))
|
b.clicked.connect(partial(self.view.next_change, -1))
|
||||||
b.setToolTip(_('Go to previous change') + ' [p]')
|
b.setToolTip(_('Go to previous change') + ' [p]')
|
||||||
b.setText(_('&Previous change')), b.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
b.setText(_('&Previous change')), b.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
||||||
l.addWidget(b, r, l.columnCount(), 1, 1)
|
l.addWidget(b, r, 0)
|
||||||
|
|
||||||
self.bn = b = QToolButton(self)
|
self.bn = b = QToolButton(self)
|
||||||
b.setIcon(QIcon(I('forward.png')))
|
b.setIcon(QIcon(I('forward.png')))
|
||||||
b.clicked.connect(partial(self.view.next_change, 1))
|
b.clicked.connect(partial(self.view.next_change, 1))
|
||||||
b.setToolTip(_('Go to next change') + ' [n]')
|
b.setToolTip(_('Go to next change') + ' [n]')
|
||||||
b.setText(_('&Next change')), b.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
b.setText(_('&Next change')), b.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
||||||
l.addWidget(b, r, l.columnCount(), 1, 1)
|
l.addWidget(b, r, 1)
|
||||||
|
|
||||||
self.search = s = HistoryLineEdit2(self)
|
self.search = s = HistoryLineEdit2(self)
|
||||||
s.initialize('diff_search_history')
|
s.initialize('diff_search_history')
|
||||||
l.addWidget(s, r, l.columnCount(), 1, 1)
|
l.addWidget(s, r, 2)
|
||||||
s.setPlaceholderText(_('Search for text'))
|
s.setPlaceholderText(_('Search for text'))
|
||||||
s.returnPressed.connect(partial(self.do_search, False))
|
s.returnPressed.connect(partial(self.do_search, False))
|
||||||
self.sbn = b = QToolButton(self)
|
self.sbn = b = QToolButton(self)
|
||||||
@ -232,19 +232,19 @@ class Diff(Dialog):
|
|||||||
b.clicked.connect(partial(self.do_search, False))
|
b.clicked.connect(partial(self.do_search, False))
|
||||||
b.setToolTip(_('Find next match'))
|
b.setToolTip(_('Find next match'))
|
||||||
b.setText(_('Next &match')), b.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
b.setText(_('Next &match')), b.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
||||||
l.addWidget(b, l.rowCount() - 1, l.columnCount(), 1, 1)
|
l.addWidget(b, r, 3)
|
||||||
self.sbp = b = QToolButton(self)
|
self.sbp = b = QToolButton(self)
|
||||||
b.setIcon(QIcon(I('arrow-up.png')))
|
b.setIcon(QIcon(I('arrow-up.png')))
|
||||||
b.clicked.connect(partial(self.do_search, True))
|
b.clicked.connect(partial(self.do_search, True))
|
||||||
b.setToolTip(_('Find previous match'))
|
b.setToolTip(_('Find previous match'))
|
||||||
b.setText(_('P&revious match')), b.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
b.setText(_('P&revious match')), b.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
||||||
l.addWidget(b, l.rowCount() - 1, l.columnCount(), 1, 1)
|
l.addWidget(b, r, 4)
|
||||||
self.lb = b = QRadioButton(_('Left panel'), self)
|
self.lb = b = QRadioButton(_('Left panel'), self)
|
||||||
b.setToolTip(_('Perform search in the left panel'))
|
b.setToolTip(_('Perform search in the left panel'))
|
||||||
l.addWidget(b, l.rowCount() - 1, l.columnCount(), 1, 1)
|
l.addWidget(b, r, 5)
|
||||||
self.rb = b = QRadioButton(_('Right panel'), self)
|
self.rb = b = QRadioButton(_('Right panel'), self)
|
||||||
b.setToolTip(_('Perform search in the right panel'))
|
b.setToolTip(_('Perform search in the right panel'))
|
||||||
l.addWidget(b, l.rowCount() - 1, l.columnCount(), 1, 1)
|
l.addWidget(b, r, 6)
|
||||||
b.setChecked(True)
|
b.setChecked(True)
|
||||||
self.pb = b = QToolButton(self)
|
self.pb = b = QToolButton(self)
|
||||||
b.setIcon(QIcon(I('config.png')))
|
b.setIcon(QIcon(I('config.png')))
|
||||||
@ -259,7 +259,12 @@ class Diff(Dialog):
|
|||||||
cm.addAction(_('Show all text'), partial(self.change_context, None))
|
cm.addAction(_('Show all text'), partial(self.change_context, None))
|
||||||
m.addAction(_('Beautify files before comparing them'), partial(self.change_beautify, True))
|
m.addAction(_('Beautify files before comparing them'), partial(self.change_beautify, True))
|
||||||
m.addMenu(cm)
|
m.addMenu(cm)
|
||||||
l.addWidget(b, l.rowCount() - 1, l.columnCount(), 1, 1)
|
l.addWidget(b, r, 7)
|
||||||
|
|
||||||
|
self.hl = QHBoxLayout()
|
||||||
|
l.addLayout(self.hl, l.rowCount(), 0, 1, -1)
|
||||||
|
self.names = QLabel('')
|
||||||
|
self.hl.addWidget(self.names, r)
|
||||||
|
|
||||||
self.bb.setStandardButtons(self.bb.Close)
|
self.bb.setStandardButtons(self.bb.Close)
|
||||||
if self.revert_button_msg is not None:
|
if self.revert_button_msg is not None:
|
||||||
@ -267,7 +272,7 @@ class Diff(Dialog):
|
|||||||
b.setIcon(QIcon(I('edit-undo.png')))
|
b.setIcon(QIcon(I('edit-undo.png')))
|
||||||
b.clicked.connect(self.revert_requested)
|
b.clicked.connect(self.revert_requested)
|
||||||
self.bb.button(self.bb.Close).setDefault(True)
|
self.bb.button(self.bb.Close).setDefault(True)
|
||||||
l.addWidget(self.bb, l.rowCount(), 0, 1, -1)
|
self.hl.addWidget(self.bb, r)
|
||||||
|
|
||||||
self.view.setFocus(Qt.OtherFocusReason)
|
self.view.setFocus(Qt.OtherFocusReason)
|
||||||
|
|
||||||
@ -318,14 +323,22 @@ class Diff(Dialog):
|
|||||||
self.stacks.setCurrentIndex(1)
|
self.stacks.setCurrentIndex(1)
|
||||||
QApplication.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
|
|
||||||
def ebook_diff(self, path1, path2):
|
def set_names(self, names):
|
||||||
|
if isinstance(names, tuple):
|
||||||
|
self.names.setText('%s <--> %s' % names)
|
||||||
|
else:
|
||||||
|
self.names.setText('')
|
||||||
|
|
||||||
|
def ebook_diff(self, path1, path2, names=None):
|
||||||
|
self.set_names(names)
|
||||||
with self:
|
with self:
|
||||||
identical = self.apply_diff(_('The books are identical'), *ebook_diff(path1, path2))
|
identical = self.apply_diff(_('The books are identical'), *ebook_diff(path1, path2))
|
||||||
self.view.finalize()
|
self.view.finalize()
|
||||||
if identical:
|
if identical:
|
||||||
self.reject()
|
self.reject()
|
||||||
|
|
||||||
def container_diff(self, left, right, identical_msg=None):
|
def container_diff(self, left, right, identical_msg=None, names=None):
|
||||||
|
self.set_names(names)
|
||||||
with self:
|
with self:
|
||||||
identical = self.apply_diff(identical_msg or _('No changes found'), *container_diff(left, right))
|
identical = self.apply_diff(identical_msg or _('No changes found'), *container_diff(left, right))
|
||||||
self.view.finalize()
|
self.view.finalize()
|
||||||
@ -399,11 +412,11 @@ class Diff(Dialog):
|
|||||||
return
|
return
|
||||||
return Dialog.keyPressEvent(self, ev)
|
return Dialog.keyPressEvent(self, ev)
|
||||||
|
|
||||||
def compare_books(path1, path2, revert_msg=None, revert_callback=None, parent=None):
|
def compare_books(path1, path2, revert_msg=None, revert_callback=None, parent=None, names=None):
|
||||||
d = Diff(parent=parent, revert_button_msg=revert_msg)
|
d = Diff(parent=parent, revert_button_msg=revert_msg)
|
||||||
if revert_msg is not None:
|
if revert_msg is not None:
|
||||||
d.revert_requested.connect(revert_callback)
|
d.revert_requested.connect(revert_callback)
|
||||||
QTimer.singleShot(0, partial(d.ebook_diff, path1, path2))
|
QTimer.singleShot(0, partial(d.ebook_diff, path1, path2, names=names))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
try:
|
try:
|
||||||
d.revert_requested.disconnect()
|
d.revert_requested.disconnect()
|
||||||
|
@ -43,15 +43,7 @@ class GlobalUndoHistory(QAbstractListModel):
|
|||||||
|
|
||||||
def data(self, index, role=Qt.DisplayRole):
|
def data(self, index, role=Qt.DisplayRole):
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
row = index.row()
|
return QVariant(self.label_for_row(index.row()))
|
||||||
msg = self.states[row].message
|
|
||||||
if self.pos == row:
|
|
||||||
msg = _('Current state')
|
|
||||||
elif not msg:
|
|
||||||
msg = _('[Unnamed state]')
|
|
||||||
else:
|
|
||||||
msg = _('Before %s') % msg
|
|
||||||
return QVariant(msg)
|
|
||||||
if role == Qt.FontRole and index.row() == self.pos:
|
if role == Qt.FontRole and index.row() == self.pos:
|
||||||
f = QApplication.instance().font()
|
f = QApplication.instance().font()
|
||||||
f.setBold(True)
|
f.setBold(True)
|
||||||
@ -60,6 +52,21 @@ class GlobalUndoHistory(QAbstractListModel):
|
|||||||
return QVariant(self.states[index.row()])
|
return QVariant(self.states[index.row()])
|
||||||
return NONE
|
return NONE
|
||||||
|
|
||||||
|
def label_for_row(self, row):
|
||||||
|
msg = self.states[row].message
|
||||||
|
if self.pos == row:
|
||||||
|
msg = _('Current state')
|
||||||
|
elif not msg:
|
||||||
|
msg = _('[Unnamed state]')
|
||||||
|
else:
|
||||||
|
msg = _('Before %s') % msg
|
||||||
|
return msg
|
||||||
|
|
||||||
|
def label_for_container(self, container):
|
||||||
|
for i, state in enumerate(self.states):
|
||||||
|
if state.container is container:
|
||||||
|
return self.label_for_row(i)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_container(self):
|
def current_container(self):
|
||||||
return self.states[self.pos].container
|
return self.states[self.pos].container
|
||||||
|
Loading…
x
Reference in New Issue
Block a user