mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Manage user dictionaries: Allow copying all selected words by right clicking them and choosing "Copy to clipboard". Fixes #1315340 [Export words from a user dictionary](https://bugs.launchpad.net/calibre/+bug/1315340)
This commit is contained in:
parent
8e049b3600
commit
482afd9952
@ -122,7 +122,40 @@ class AddDictionary(QDialog): # {{{
|
|||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class ManageUserDictionaries(Dialog): # {{{
|
# User Dictionaries {{{
|
||||||
|
|
||||||
|
class UserWordList(QListWidget):
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
QListWidget.__init__(self, parent)
|
||||||
|
|
||||||
|
def contextMenuEvent(self, ev):
|
||||||
|
m = QMenu(self)
|
||||||
|
m.addAction(_('Copy selected words to clipboard'), self.copy_to_clipboard)
|
||||||
|
m.addAction(_('Select all words'), self.select_all)
|
||||||
|
m.exec_(ev.globalPos())
|
||||||
|
|
||||||
|
def select_all(self):
|
||||||
|
for item in (self.item(i) for i in xrange(self.count())):
|
||||||
|
item.setSelected(True)
|
||||||
|
|
||||||
|
def copy_to_clipboard(self):
|
||||||
|
words = []
|
||||||
|
for item in (self.item(i) for i in xrange(self.count())):
|
||||||
|
if item.isSelected():
|
||||||
|
words.append(item.data(Qt.UserRole).toPyObject()[0])
|
||||||
|
if words:
|
||||||
|
QApplication.clipboard().setText('\n'.join(words))
|
||||||
|
|
||||||
|
def keyPressEvent(self, ev):
|
||||||
|
if ev == QKeySequence.Copy:
|
||||||
|
self.copy_to_clipboard()
|
||||||
|
ev.accept()
|
||||||
|
return
|
||||||
|
return QListWidget.keyPressEvent(self, ev)
|
||||||
|
|
||||||
|
|
||||||
|
class ManageUserDictionaries(Dialog):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
self.dictionaries_changed = False
|
self.dictionaries_changed = False
|
||||||
@ -162,7 +195,7 @@ class ManageUserDictionaries(Dialog): # {{{
|
|||||||
l.addWidget(a)
|
l.addWidget(a)
|
||||||
self.la = la = QLabel(_('Words in this dictionary:'))
|
self.la = la = QLabel(_('Words in this dictionary:'))
|
||||||
l.addWidget(la)
|
l.addWidget(la)
|
||||||
self.words = w = QListWidget(self)
|
self.words = w = UserWordList(self)
|
||||||
w.setSelectionMode(w.ExtendedSelection)
|
w.setSelectionMode(w.ExtendedSelection)
|
||||||
l.addWidget(w)
|
l.addWidget(w)
|
||||||
self.add_word_button = b = QPushButton(_('&Add word'), self)
|
self.add_word_button = b = QPushButton(_('&Add word'), self)
|
||||||
@ -1221,5 +1254,5 @@ def find_next(word, locations, current_editor, current_editor_name,
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
dictionaries.initialize()
|
dictionaries.initialize()
|
||||||
SpellCheck.test()
|
ManageUserDictionaries.test()
|
||||||
del app
|
del app
|
||||||
|
Loading…
x
Reference in New Issue
Block a user