Commit 7cf49fa6 authored by Dan Pascu's avatar Dan Pascu

Improved Undo Delete text in context menu for the search view as well

parent a5fd5fdb
...@@ -1316,13 +1316,26 @@ class ContactSearchListView(QListView): ...@@ -1316,13 +1316,26 @@ class ContactSearchListView(QListView):
model = self.model() model = self.model()
source_model = model.sourceModel() source_model = model.sourceModel()
selected_items = [model.data(index) for index in self.selectionModel().selectedIndexes()] selected_items = [model.data(index) for index in self.selectionModel().selectedIndexes()]
if not source_model.deleted_items:
undo_delete_text = "Undo Delete"
elif len(source_model.deleted_items[-1]) == 1:
item = source_model.deleted_items[-1][0]
if type(item) is Contact:
name = item.name or item.uri
else:
name = item.name
undo_delete_text = 'Undo Delete "%s"' % name
else:
undo_delete_text = "Undo Delete (%d items)" % len(source_model.deleted_items[-1])
menu = QMenu(self) menu = QMenu(self)
if not selected_items: if not selected_items:
menu.addAction(self.actions.undo_last_delete) menu.addAction(self.actions.undo_last_delete)
self.actions.undo_last_delete.setText(undo_delete_text)
self.actions.undo_last_delete.setEnabled(len(source_model.deleted_items) > 0) self.actions.undo_last_delete.setEnabled(len(source_model.deleted_items) > 0)
elif len(selected_items) > 1: elif len(selected_items) > 1:
menu.addAction(self.actions.delete_selection) menu.addAction(self.actions.delete_selection)
menu.addAction(self.actions.undo_last_delete) menu.addAction(self.actions.undo_last_delete)
self.actions.undo_last_delete.setText(undo_delete_text)
self.actions.delete_selection.setEnabled(any(item.deletable for item in selected_items)) self.actions.delete_selection.setEnabled(any(item.deletable for item in selected_items))
self.actions.undo_last_delete.setEnabled(len(source_model.deleted_items) > 0) self.actions.undo_last_delete.setEnabled(len(source_model.deleted_items) > 0)
else: else:
...@@ -1341,6 +1354,7 @@ class ContactSearchListView(QListView): ...@@ -1341,6 +1354,7 @@ class ContactSearchListView(QListView):
menu.addAction(self.actions.edit_item) menu.addAction(self.actions.edit_item)
menu.addAction(self.actions.delete_item) menu.addAction(self.actions.delete_item)
menu.addAction(self.actions.undo_last_delete) menu.addAction(self.actions.undo_last_delete)
self.actions.undo_last_delete.setText(undo_delete_text)
self.actions.edit_item.setEnabled(contact.editable) self.actions.edit_item.setEnabled(contact.editable)
self.actions.delete_item.setEnabled(contact.deletable) self.actions.delete_item.setEnabled(contact.deletable)
self.actions.undo_last_delete.setEnabled(len(source_model.deleted_items) > 0) self.actions.undo_last_delete.setEnabled(len(source_model.deleted_items) > 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment