From dd15d1b6ed13b269c918759d11c7997549ad74e6 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Thu, 19 Nov 2015 17:37:34 +0100 Subject: [PATCH] Delete key and shift modifier Addresses #114 - delete from sent works when pressing delete key - delete from trash deletes rather than moves - delete with shift deletes rather than moves --- src/bitmessageqt/__init__.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 2d591d9b..650b83f1 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -1065,7 +1065,7 @@ class MyForm(settingsmixin.SMainWindow): tableWidget.setSortingEnabled(False) tableWidget.horizontalHeader().setSortIndicator(3, Qt.DescendingOrder) - tableWidget.keyPressEvent = self.tableWidgetInboxKeyPressEvent + tableWidget.keyPressEvent = self.tableWidgetSentKeyPressEvent # Load messages from database file def loadMessagelist(self, tableWidget, account, folder="inbox", where="", what=""): @@ -1497,6 +1497,12 @@ class MyForm(settingsmixin.SMainWindow): self.on_action_InboxTrash() return QtGui.QTableWidget.keyPressEvent(self.getCurrentMessagelist(), event) + # set delete key in inbox + def tableWidgetSentKeyPressEvent(self, event): + if event.key() == QtCore.Qt.Key_Delete: + self.on_action_SentTrash() + return QtGui.QTableWidget.keyPressEvent(self.getCurrentMessagelist(), event) + # menu button 'manage keys' def click_actionManageKeys(self): if 'darwin' in sys.platform or 'linux' in sys.platform: @@ -3161,11 +3167,18 @@ class MyForm(settingsmixin.SMainWindow): return unread = False currentRow = 0 + folder = self.getCurrentFolder() + shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier while tableWidget.selectedIndexes(): currentRow = tableWidget.selectedIndexes()[0].row() inventoryHashToTrash = str(tableWidget.item( currentRow, 3).data(Qt.UserRole).toPyObject()) - sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash) + if folder == "trash" or shifted: + logger.debug ("deleting") + sqlExecute('''DELETE FROM inbox WHERE msgid=?''', inventoryHashToTrash) + else: + logger.debug ("moving to trash, because folder = \"%s\" and shifted = %r %x", folder, shifted) + sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash) if tableWidget.item(currentRow, 0).font().bold(): unread = True self.getCurrentMessageTextedit().setText("") @@ -3241,11 +3254,16 @@ class MyForm(settingsmixin.SMainWindow): tableWidget = self.getCurrentMessagelist() if not tableWidget: return + folder = self.getCurrentFolder() + shifted = (QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier) > 0 while tableWidget.selectedIndexes() != []: currentRow = tableWidget.selectedIndexes()[0].row() ackdataToTrash = str(tableWidget.item( currentRow, 3).data(Qt.UserRole).toPyObject()) - sqlExecute('''UPDATE sent SET folder='trash' WHERE ackdata=?''', ackdataToTrash) + if folder == "trash" or shifted: + sqlExecute('''DELETE FROM sent WHERE ackdata=?''', ackdataToTrash) + else: + sqlExecute('''UPDATE sent SET folder='trash' WHERE ackdata=?''', ackdataToTrash) if tableWidget.item(currentRow, 0).font().bold(): unread = True self.getCurrentMessageTextedit().setPlainText("")