diff --git a/__main__.py b/__main__.py index 8eeb497..52295ff 100755 --- a/__main__.py +++ b/__main__.py @@ -219,6 +219,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): self.listView.verticalScrollBar().setSingleStep(9) self.listView.doubleClicked.connect(self.library_doubleclick) self.listView.setItemDelegate(LibraryDelegate(self.temp_dir.path(), self)) + self.listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + self.listView.customContextMenuRequested.connect(self.generate_library_context_menu) self.listView.verticalScrollBar().valueChanged.connect(self.start_culling_timer) self.listView.setStyleSheet( @@ -240,6 +242,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): self.tableView.horizontalHeader().setStretchLastSection(True) self.tableView.horizontalHeader().sectionClicked.connect( self.lib_ref.table_proxy_model.sort_table_columns) + self.tableView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + self.tableView.customContextMenuRequested.connect(self.generate_library_context_menu) # Keyboard shortcuts self.ks_close_tab = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+W'), self) @@ -257,6 +261,30 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): if self.settings['scan_library']: self.settings_dialog.start_library_scan() + def generate_library_context_menu(self, position): + # TODO + # The library might have multiple items selected + # Make sure the context menu actions are carried out on each + + index = self.sender().indexAt(position) + if not index.isValid(): + return + + context_menu = QtWidgets.QMenu() + + openAction = context_menu.addAction( + QtGui.QIcon.fromTheme('view-readermode'), 'Start reading') + editAction = context_menu.addAction( + QtGui.QIcon.fromTheme('edit-rename'), 'Edit') + deleteAction = context_menu.addAction( + QtGui.QIcon.fromTheme('trash-empty'), 'Delete') + readAction = context_menu.addAction( + QtGui.QIcon.fromTheme('vcs-normal'), 'Mark read') + unreadAction = context_menu.addAction( + QtGui.QIcon.fromTheme('emblem-unavailable'), 'Mark unread') + + action = context_menu.exec_(self.sender().mapToGlobal(position)) + def open_books_at_startup(self): # Last open books and command line books aren't being opened together # so that command line books are processed last and therefore retain focus diff --git a/library.py b/library.py index 162c6f4..20ade74 100644 --- a/library.py +++ b/library.py @@ -19,7 +19,7 @@ import os import pickle import pathlib -from PyQt5 import QtGui, QtCore +from PyQt5 import QtGui, QtCore, QtWidgets import database from models import TableProxyModel, ItemProxyModel diff --git a/widgets.py b/widgets.py index fdc913f..561e115 100644 --- a/widgets.py +++ b/widgets.py @@ -106,6 +106,9 @@ class Tab(QtWidgets.QWidget): self.dockListView.setMaximumWidth(350) self.dockListView.setItemDelegate(BookmarkDelegate(self.dockListView)) self.dockListView.setUniformItemSizes(True) + self.dockListView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + self.dockListView.customContextMenuRequested.connect( + self.generate_bookmark_context_menu) self.dockListView.clicked.connect(self.navigate_to_bookmark) self.dockWidget.setWidget(self.dockListView) @@ -299,6 +302,9 @@ class Tab(QtWidgets.QWidget): self.dockWidget.show() def add_bookmark(self): + # TODO + # Start dockListView.edit(index) when something new is added + identifier = uuid.uuid4().hex[:10] description = 'New bookmark' @@ -366,6 +372,29 @@ class Tab(QtWidgets.QWidget): self.proxy_model.setFilterFixedString( self.window().bookToolBar.searchBar.text()) + def generate_bookmark_context_menu(self, position): + index = self.dockListView.indexAt(position) + if not index.isValid(): + return + + bookmark_menu = QtWidgets.QMenu() + editAction = bookmark_menu.addAction( + QtGui.QIcon.fromTheme('edit-rename'), 'Edit') + deleteAction = bookmark_menu.addAction( + QtGui.QIcon.fromTheme('trash-empty'), 'Delete') + + action = bookmark_menu.exec_(self.dockListView.mapToGlobal(position)) + + if action == editAction: + self.dockListView.edit(index) + + if action == deleteAction: + row = index.row() + delete_uuid = self.bookmark_model.item(row).data(QtCore.Qt.UserRole + 2) + + self.metadata['bookmarks'].pop(delete_uuid) + self.bookmark_model.removeRow(index.row()) + def hide_mouse(self): self.contentView.setCursor(QtCore.Qt.BlankCursor)