mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Allow copying the Table of Contents to the clipboard by right clicking on it. Fixes #1548791 [[Enhancement] Copy book index to clipboard](https://bugs.launchpad.net/calibre/+bug/1548791)
This commit is contained in:
parent
8626437fe1
commit
014631a8e3
@ -13,7 +13,7 @@ from functools import partial
|
||||
from PyQt5.Qt import (
|
||||
QStandardItem, QStandardItemModel, Qt, QFont, QTreeView, QWidget,
|
||||
QHBoxLayout, QToolButton, QIcon, QModelIndex, pyqtSignal, QMenu,
|
||||
QStyledItemDelegate, QToolTip)
|
||||
QStyledItemDelegate, QToolTip, QApplication)
|
||||
|
||||
from calibre.ebooks.metadata.toc import TOC as MTOC
|
||||
from calibre.gui2 import error_dialog
|
||||
@ -93,6 +93,8 @@ class TOCView(QTreeView):
|
||||
m.addSeparator()
|
||||
m.addAction(_('Expand all items'), self.expandAll)
|
||||
m.addAction(_('Collapse all items'), self.collapseAll)
|
||||
m.addSeparator()
|
||||
m.addAction(_('Copy table of contents to clipboard'), self.copy_to_clipboard)
|
||||
m.exec_(self.mapToGlobal(pos))
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
@ -103,6 +105,10 @@ class TOCView(QTreeView):
|
||||
pass
|
||||
return QTreeView.keyPressEvent(self, event)
|
||||
|
||||
def copy_to_clipboard(self):
|
||||
m = self.model()
|
||||
QApplication.clipboard().setText(getattr(m, 'as_plain_text', ''))
|
||||
|
||||
class TOCSearch(QWidget):
|
||||
|
||||
def __init__(self, toc_view, parent=None):
|
||||
@ -383,3 +389,10 @@ class TOC(QStandardItemModel):
|
||||
index = self.indexFromItem(item)
|
||||
return index
|
||||
return QModelIndex()
|
||||
|
||||
@property
|
||||
def as_plain_text(self):
|
||||
lines = []
|
||||
for item in self.all_items:
|
||||
lines.append(' ' * (4 * item.depth) + (item.title or ''))
|
||||
return '\n'.join(lines)
|
||||
|
Loading…
x
Reference in New Issue
Block a user