This commit is contained in:
Kovid Goyal 2014-01-31 08:30:58 +05:30
parent 6a64723156
commit f3e36ef2c5

View File

@ -394,51 +394,6 @@ class Boss(QObject):
d.resize(600, 400) d.resize(600, 400)
d.exec_() d.exec_()
def create_diff_dialog(self, revert_msg=_('&Revert changes'), show_open_in_editor=True):
global _diff_dialogs
from calibre.gui2.tweak_book.diff.main import Diff
def line_activated(name, lnum, right):
if right:
self.edit_file_requested(name, None, guess_type(name))
if name in editors:
editor = editors[name]
editor.go_to_line(lnum)
editor.setFocus(Qt.OtherFocusReason)
self.gui.raise_()
d = Diff(revert_button_msg=revert_msg, show_open_in_editor=show_open_in_editor)
[x.break_cycles() for x in _diff_dialogs if not x.isVisible()]
_diff_dialogs = [x for x in _diff_dialogs if x.isVisible()] + [d]
d.show(), d.raise_(), d.setFocus(Qt.OtherFocusReason), d.setWindowModality(Qt.NonModal)
if show_open_in_editor:
d.line_activated.connect(line_activated)
return d
def show_current_diff(self, allow_revert=True, to_container=None):
self.commit_all_editors_to_container()
d = self.create_diff_dialog()
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)
def compare_book(self):
self.commit_all_editors_to_container()
c = current_container()
path = choose_files(self.gui, 'select-book-for-comparison', _('Choose book'), filters=[
(_('%s books') % c.book_type.upper(), (c.book_type,))], select_only_single_file=True, all_files=False)
if path and path[0]:
with TemporaryDirectory('_compare') as tdir:
other = _gc(path[0], tdir=tdir, tweak_mode=True)
d = self.create_diff_dialog(revert_msg=None)
d.container_diff(other, c)
def revert_requested(self, container):
self.commit_all_editors_to_container()
nc = self.global_undo.revert_to(container)
set_current_container(nc)
self.apply_container_update_to_gui()
def compare_requested(self, container):
self.show_current_diff(to_container=container)
# Renaming {{{ # Renaming {{{
def rationalize_folders(self): def rationalize_folders(self):
@ -539,6 +494,52 @@ class Boss(QObject):
if container is not None: if container is not None:
set_current_container(container) set_current_container(container)
self.update_global_history_actions() self.update_global_history_actions()
def create_diff_dialog(self, revert_msg=_('&Revert changes'), show_open_in_editor=True):
global _diff_dialogs
from calibre.gui2.tweak_book.diff.main import Diff
def line_activated(name, lnum, right):
if right:
self.edit_file_requested(name, None, guess_type(name))
if name in editors:
editor = editors[name]
editor.go_to_line(lnum)
editor.setFocus(Qt.OtherFocusReason)
self.gui.raise_()
d = Diff(revert_button_msg=revert_msg, show_open_in_editor=show_open_in_editor)
[x.break_cycles() for x in _diff_dialogs if not x.isVisible()]
_diff_dialogs = [x for x in _diff_dialogs if x.isVisible()] + [d]
d.show(), d.raise_(), d.setFocus(Qt.OtherFocusReason), d.setWindowModality(Qt.NonModal)
if show_open_in_editor:
d.line_activated.connect(line_activated)
return d
def show_current_diff(self, allow_revert=True, to_container=None):
self.commit_all_editors_to_container()
d = self.create_diff_dialog()
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)
def compare_book(self):
self.commit_all_editors_to_container()
c = current_container()
path = choose_files(self.gui, 'select-book-for-comparison', _('Choose book'), filters=[
(_('%s books') % c.book_type.upper(), (c.book_type,))], select_only_single_file=True, all_files=False)
if path and path[0]:
with TemporaryDirectory('_compare') as tdir:
other = _gc(path[0], tdir=tdir, tweak_mode=True)
d = self.create_diff_dialog(revert_msg=None)
d.container_diff(other, c)
def revert_requested(self, container):
self.commit_all_editors_to_container()
nc = self.global_undo.revert_to(container)
set_current_container(nc)
self.apply_container_update_to_gui()
def compare_requested(self, container):
self.show_current_diff(to_container=container)
# }}} # }}}
def set_modified(self): def set_modified(self):