Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Project Manager: Allow to paste Tasks into multiple assets at the same time #3226

Merged
merged 3 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions openpype/tools/project_manager/project_manager/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,12 +1476,7 @@ def copy_mime_data(self, indexes):
mimedata.setData("application/copy_task", encoded_data)
return mimedata

def paste_mime_data(self, index, mime_data):
if not index.isValid():
return

item_id = index.data(IDENTIFIER_ROLE)
item = self._items_by_id[item_id]
def paste_mime_data(self, item, mime_data):
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
if not isinstance(item, (AssetItem, TaskItem)):
return

Expand Down Expand Up @@ -1515,6 +1510,25 @@ def paste_mime_data(self, index, mime_data):
task_item = TaskItem(task_data, True)
self.add_item(task_item, parent)

def paste(self, indices, mime_data):
BigRoy marked this conversation as resolved.
Show resolved Hide resolved

# Get the selected Assets uniquely
items = set()
for index in indices:
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
if not index.isValid():
return
item_id = index.data(IDENTIFIER_ROLE)
item = self._items_by_id[item_id]

# Do not copy into the Task Item so get parent Asset instead
if isinstance(item, TaskItem):
item = item.parent()

items.add(item)

for item in items:
self.paste_mime_data(item, mime_data)
BigRoy marked this conversation as resolved.
Show resolved Hide resolved


class BaseItem:
"""Base item for HierarchyModel.
Expand Down
10 changes: 7 additions & 3 deletions openpype/tools/project_manager/project_manager/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,20 +365,24 @@ def keyPressEvent(self, event):
event.accept()

def _copy_items(self, indexes=None):
clipboard = QtWidgets.QApplication.clipboard()
try:
if indexes is None:
indexes = self.selectedIndexes()
mime_data = self._source_model.copy_mime_data(indexes)

QtWidgets.QApplication.clipboard().setMimeData(mime_data)
clipboard.setMimeData(mime_data)
self._show_message("Tasks copied")
except ValueError as exc:
# Change clipboard to contain empty data
empty_mime_data = QtCore.QMimeData()
clipboard.setMimeData(empty_mime_data)
self._show_message(str(exc))

def _paste_items(self):
index = self.currentIndex()
mime_data = QtWidgets.QApplication.clipboard().mimeData()
self._source_model.paste_mime_data(index, mime_data)
rows = self.selectionModel().selectedRows()
self._source_model.paste(rows, mime_data)

def _delete_items(self, indexes=None):
if indexes is None:
Expand Down