From 5ace899bfba768016886083247b8bea770a64863 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 27 Aug 2014 18:29:05 +0530 Subject: [PATCH] Book list: Fix Ctrl+Home/End not selecting the first/last book --- src/calibre/gui2/library/alternate_views.py | 8 +++++++- src/calibre/gui2/library/views.py | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index 25c90f9a0d..1d9c72b5db 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -18,7 +18,8 @@ from PyQt5.Qt import ( QTimer, QPalette, QColor, QItemSelection, QPixmap, QMenu, QApplication, QMimeData, QUrl, QDrag, QPoint, QPainter, QRect, pyqtProperty, QEvent, QPropertyAnimation, QEasingCurve, pyqtSlot, QHelpEvent, QAbstractItemView, - QStyleOptionViewItem, QToolTip, QByteArray, QBuffer, QBrush, qRed, qGreen, qBlue) + QStyleOptionViewItem, QToolTip, QByteArray, QBuffer, QBrush, qRed, qGreen, + qBlue, QItemSelectionModel) from calibre import fit_image, prints, prepare_string_for_xml, human_readable from calibre.constants import DEBUG, config_dir @@ -955,4 +956,9 @@ class GridView(QListView): index = self.model().index(nr, 0) return index + def selectionCommand(self, index, event): + if event and event.type() == event.KeyPress and event.key() in (Qt.Key_Home, Qt.Key_End) and event.modifiers() & Qt.CTRL: + return QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows + return super(GridView, self).selectionCommand(index, event) + # }}} diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 5baee4f5d0..26ee5ae0d5 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -13,7 +13,7 @@ from collections import OrderedDict from PyQt5.Qt import ( QTableView, Qt, QAbstractItemView, QMenu, pyqtSignal, QFont, QModelIndex, QIcon, QItemSelection, QMimeData, QDrag, QStyle, QPoint, QUrl, QHeaderView, - QStyleOptionHeader) + QStyleOptionHeader, QItemSelectionModel) from calibre.gui2.library.delegates import (RatingDelegate, PubDateDelegate, TextDelegate, DateDelegate, CompleteDelegate, CcTextDelegate, @@ -904,6 +904,11 @@ class BooksView(QTableView): # {{{ return self.model().index(self.model().rowCount(QModelIndex()) - 1, orig.column()) return index + def selectionCommand(self, index, event): + if event and event.type() == event.KeyPress and event.key() in (Qt.Key_Home, Qt.Key_End) and event.modifiers() & Qt.CTRL: + return QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows + return super(BooksView, self).selectionCommand(index, event) + def ids_to_rows(self, ids): row_map = OrderedDict() ids = frozenset(ids)