mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
Allow right clicking on row numbers to mark/unmark books
This commit is contained in:
commit
c116696086
@ -76,6 +76,9 @@ class MarkWithTextDialog(QDialog):
|
||||
super().accept()
|
||||
|
||||
|
||||
mark_books_with_text = None
|
||||
|
||||
|
||||
class MarkBooksAction(InterfaceAction):
|
||||
|
||||
name = 'Mark Books'
|
||||
@ -119,12 +122,16 @@ class MarkBooksAction(InterfaceAction):
|
||||
m.aboutToShow.connect(self.about_to_show_menu)
|
||||
ma = partial(self.create_menu_action, m)
|
||||
self.show_marked_action = a = ma('mark_with_text', _('Mark books with text label'), icon='marked.png')
|
||||
a.triggered.connect(self.mark_with_text)
|
||||
a.triggered.connect(partial(self.mark_with_text, book_ids = None))
|
||||
global mark_books_with_text
|
||||
mark_books_with_text = self.mark_with_text
|
||||
self.show_marked_action = a = ma('show-marked', _('Show marked books'), icon='search.png', shortcut='Shift+Ctrl+M')
|
||||
a.triggered.connect(self.show_marked)
|
||||
self.show_marked_with_text = QMenu(_('Show marked books with text label'))
|
||||
self.show_marked_with_text.setIcon(self.search_icon)
|
||||
m.addMenu(self.show_marked_with_text)
|
||||
self.clear_selected_marked_action = a = ma('clear-marks-on-selected', _('Clear marks for selected books'), icon='clear_left.png')
|
||||
a.triggered.connect(self.clear_marks_on_selected_books)
|
||||
self.clear_marked_action = a = ma('clear-all-marked', _('Clear all marked books'), icon='clear_left.png')
|
||||
a.triggered.connect(self.clear_all_marked)
|
||||
m.addSeparator()
|
||||
@ -226,8 +233,9 @@ class MarkBooksAction(InterfaceAction):
|
||||
mids.pop(book_id, None)
|
||||
db.data.set_marked_ids(mids)
|
||||
|
||||
def mark_with_text(self):
|
||||
book_ids = self._get_selected_ids()
|
||||
def mark_with_text(self, book_ids=None):
|
||||
if book_ids is None:
|
||||
book_ids = self._get_selected_ids()
|
||||
if not book_ids:
|
||||
return
|
||||
dialog = MarkWithTextDialog(self.gui)
|
||||
@ -240,3 +248,13 @@ class MarkBooksAction(InterfaceAction):
|
||||
for book_id in book_ids:
|
||||
mids[book_id] = txt
|
||||
db.data.set_marked_ids(mids)
|
||||
|
||||
def clear_marks_on_selected_books(self):
|
||||
book_ids = self._get_selected_ids()
|
||||
if not book_ids:
|
||||
return
|
||||
db = self.gui.current_db
|
||||
items = db.data.marked_ids.copy()
|
||||
for book_id in book_ids:
|
||||
items.pop(book_id, None)
|
||||
self.gui.current_db.data.set_marked_ids(items)
|
||||
|
@ -516,11 +516,29 @@ class BooksView(QTableView): # {{{
|
||||
|
||||
def show_row_header_context_menu(self, pos):
|
||||
menu = QMenu(self)
|
||||
menu.addAction(_('Hide row numbers'), self.hide_row_numbers)
|
||||
# Even when hidden, row numbers show if any marks show, which is why it makes
|
||||
# sense to offer "show row numbers" here. Saves having to go to Preferences
|
||||
# Look & feel, assuming you know the trick.
|
||||
if gprefs['row_numbers_in_book_list']:
|
||||
menu.addAction(_('Hide row numbers'), partial(self.hide_row_numbers, show=False))
|
||||
else:
|
||||
menu.addAction(_('Show row numbers'), partial(self.hide_row_numbers, show=True))
|
||||
db = self._model.db
|
||||
row = self.row_header.logicalIndexAt(pos)
|
||||
if row >= 0 and row < len(db.data):
|
||||
book_id_col = db.field_metadata['id']['rec_index']
|
||||
book_id = db.data[row][book_id_col]
|
||||
m = menu.addAction(_('Toggle mark for book'), lambda: db.data.toggle_marked_ids({book_id,}))
|
||||
ic = QIcon.ic('marked.png')
|
||||
m.setIcon(ic)
|
||||
from calibre.gui2.actions.mark_books import mark_books_with_text
|
||||
m = menu.addAction(_('Mark book with text label'), partial(mark_books_with_text, {book_id,}))
|
||||
m.setIcon(ic)
|
||||
menu.popup(self.mapToGlobal(pos))
|
||||
|
||||
def hide_row_numbers(self):
|
||||
gprefs['row_numbers_in_book_list'] = False
|
||||
# Probably should change the method name, but leave it for compatibility
|
||||
def hide_row_numbers(self, show=False):
|
||||
gprefs['row_numbers_in_book_list'] = show
|
||||
self.set_row_header_visibility()
|
||||
|
||||
def show_column_header_context_menu(self, pos, view=None):
|
||||
|
Loading…
x
Reference in New Issue
Block a user