mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Make the edit saved search/add saved search popup window non-modal. Fixes #1354785 [The "Edit Search" window blocks interaction with the ebook-editor main window](https://bugs.launchpad.net/calibre/+bug/1354785)
This commit is contained in:
parent
e3aa9e0c0d
commit
d00eeecd98
@ -10,6 +10,7 @@ import json, copy
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
import sip
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QWidget, QToolBar, Qt, QHBoxLayout, QSize, QIcon, QGridLayout, QLabel, QTimer,
|
QWidget, QToolBar, Qt, QHBoxLayout, QSize, QIcon, QGridLayout, QLabel, QTimer,
|
||||||
QPushButton, pyqtSignal, QComboBox, QCheckBox, QSizePolicy, QVBoxLayout, QFont,
|
QPushButton, pyqtSignal, QComboBox, QCheckBox, QSizePolicy, QVBoxLayout, QFont,
|
||||||
@ -466,6 +467,9 @@ class EditSearch(Dialog): # {{{
|
|||||||
self.dot_all.setChecked(state['dot_all'])
|
self.dot_all.setChecked(state['dot_all'])
|
||||||
self.mode_box.mode = state.get('mode')
|
self.mode_box.mode = state.get('mode')
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
Dialog.show(self), self.raise_(), self.activateWindow()
|
||||||
|
|
||||||
def sizeHint(self):
|
def sizeHint(self):
|
||||||
ans = Dialog.sizeHint(self)
|
ans = Dialog.sizeHint(self)
|
||||||
ans.setWidth(600)
|
ans.setWidth(600)
|
||||||
@ -712,7 +716,14 @@ class SavedSearches(Dialog):
|
|||||||
return
|
return
|
||||||
self.run_saved_searches.emit(searches, action)
|
self.run_saved_searches.emit(searches, action)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def editing_search(self):
|
||||||
|
d = getattr(self, 'current_edit_search', None)
|
||||||
|
return d is not None and not sip.isdeleted(d) and d.isVisible()
|
||||||
|
|
||||||
def move_entry(self, delta):
|
def move_entry(self, delta):
|
||||||
|
if self.editing_search:
|
||||||
|
return
|
||||||
rows = {index.row() for index in self.searches.selectionModel().selectedIndexes()} - {-1}
|
rows = {index.row() for index in self.searches.selectionModel().selectedIndexes()} - {-1}
|
||||||
if rows:
|
if rows:
|
||||||
with tprefs:
|
with tprefs:
|
||||||
@ -726,33 +737,40 @@ class SavedSearches(Dialog):
|
|||||||
|
|
||||||
def edit_search(self):
|
def edit_search(self):
|
||||||
index = self.searches.currentIndex()
|
index = self.searches.currentIndex()
|
||||||
if index.isValid():
|
if index.isValid() and not self.editing_search:
|
||||||
search_index, search = index.data(Qt.UserRole)
|
search_index, search = index.data(Qt.UserRole)
|
||||||
d = EditSearch(search=search, search_index=search_index, parent=self)
|
d = self.current_edit_search = EditSearch(search=search, search_index=search_index, parent=self)
|
||||||
if d.exec_() == d.Accepted:
|
d.accepted.connect(partial(self.model.dataChanged.emit, index, index))
|
||||||
self.model.dataChanged.emit(index, index)
|
d.show()
|
||||||
|
|
||||||
def remove_search(self):
|
def remove_search(self):
|
||||||
|
if self.editing_search:
|
||||||
|
return
|
||||||
rows = {index.row() for index in self.searches.selectionModel().selectedIndexes()} - {-1}
|
rows = {index.row() for index in self.searches.selectionModel().selectedIndexes()} - {-1}
|
||||||
self.model.remove_searches(rows)
|
self.model.remove_searches(rows)
|
||||||
self.show_details()
|
self.show_details()
|
||||||
|
|
||||||
def add_search(self):
|
def add_search(self):
|
||||||
d = EditSearch(parent=self)
|
if self.editing_search:
|
||||||
self._add_search(d)
|
return
|
||||||
|
self.current_edit_search = d = EditSearch(parent=self)
|
||||||
|
d.accepted.connect(self._add_search)
|
||||||
|
d.show()
|
||||||
|
|
||||||
def _add_search(self, d):
|
def _add_search(self):
|
||||||
if d.exec_() == d.Accepted:
|
self.model.add_searches()
|
||||||
self.model.add_searches()
|
index = self.model.index(self.model.rowCount() - 1)
|
||||||
index = self.model.index(self.model.rowCount() - 1)
|
self.searches.scrollTo(index)
|
||||||
self.searches.scrollTo(index)
|
sm = self.searches.selectionModel()
|
||||||
sm = self.searches.selectionModel()
|
sm.setCurrentIndex(index, sm.ClearAndSelect)
|
||||||
sm.setCurrentIndex(index, sm.ClearAndSelect)
|
self.show_details()
|
||||||
self.show_details()
|
|
||||||
|
|
||||||
def add_predefined_search(self, state):
|
def add_predefined_search(self, state):
|
||||||
d = EditSearch(parent=self, state=state)
|
if self.editing_search:
|
||||||
self._add_search(d)
|
return
|
||||||
|
self.current_edit_search = d = EditSearch(parent=self, state=state)
|
||||||
|
d.accepted.connect(self._add_search)
|
||||||
|
d.show()
|
||||||
|
|
||||||
def show_details(self):
|
def show_details(self):
|
||||||
self.description.setText(' \n \n ')
|
self.description.setText(' \n \n ')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user