ToC Editor: Ignore in succession clicks on the OK and Cancel buttons to avoid accidentally closing the window when finishing creating a new entry

This commit is contained in:
Kovid Goyal 2021-10-19 22:27:14 +05:30
parent 016a62b95e
commit fad59ba7c7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 0 deletions

View File

@ -16,6 +16,7 @@ from qt.core import (
QWidget, pyqtSignal
)
from threading import Thread
from time import monotonic
from calibre.constants import TOC_DIALOG_APP_UID, islinux, iswindows
from calibre.ebooks.oeb.polish.container import AZW3Container, get_container
@ -988,6 +989,7 @@ class TOCEditor(QDialog): # {{{
def __init__(self, pathtobook, title=None, parent=None, prefs=None, write_result_to=None):
QDialog.__init__(self, parent)
self.last_reject_at = self.last_accept_at = -1000
self.write_result_to = write_result_to
self.prefs = prefs or te_prefs
self.pathtobook = pathtobook
@ -1052,6 +1054,9 @@ class TOCEditor(QDialog): # {{{
self.stacks.setCurrentIndex(2)
def accept(self):
if monotonic() - self.last_accept_at < 1:
return
self.last_accept_at = monotonic()
if self.stacks.currentIndex() == 2:
self.toc_view.update_item(*self.item_edit.result)
self.prefs['toc_edit_splitter_state'] = bytearray(self.item_edit.splitter.saveState())
@ -1079,6 +1084,9 @@ class TOCEditor(QDialog): # {{{
def reject(self):
if not self.bb.isEnabled():
return
if monotonic() - self.last_reject_at < 1:
return
self.last_reject_at = monotonic()
if self.stacks.currentIndex() == 2:
self.prefs['toc_edit_splitter_state'] = bytearray(self.item_edit.splitter.saveState())
self.stacks.setCurrentIndex(1)

View File

@ -10,6 +10,7 @@ from qt.core import (
QSize, QStackedWidget, QStyledItemDelegate, Qt, QTimer, QTreeWidget,
QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal
)
from time import monotonic
from calibre.ebooks.oeb.polish.toc import commit_toc, get_toc
from calibre.gui2 import error_dialog, make_view_use_window_background
@ -26,6 +27,7 @@ class TOCEditor(QDialog):
def __init__(self, title=None, parent=None):
QDialog.__init__(self, parent)
self.last_reject_at = self.last_accept_at = -1000
t = title or current_container().mi.title
self.book_title = t
@ -64,6 +66,9 @@ class TOCEditor(QDialog):
self.stacks.setCurrentIndex(1)
def accept(self):
if monotonic() - self.last_accept_at < 1:
return
self.last_accept_at = monotonic()
if self.stacks.currentIndex() == 1:
self.toc_view.update_item(*self.item_edit.result)
tprefs['toc_edit_splitter_state'] = bytearray(self.item_edit.splitter.saveState())
@ -87,6 +92,9 @@ class TOCEditor(QDialog):
def reject(self):
if not self.bb.isEnabled():
return
if monotonic() - self.last_reject_at < 1:
return
self.last_reject_at = monotonic()
if self.stacks.currentIndex() == 1:
tprefs['toc_edit_splitter_state'] = bytearray(self.item_edit.splitter.saveState())
self.stacks.setCurrentIndex(0)