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

Commit

Permalink
Merge pull request #3226 from BigRoy/project_manager_paste_multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
mkolar authored May 23, 2022
2 parents 876f9cb + 8079654 commit ea339f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
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 @@ -1472,12 +1472,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):
if not isinstance(item, (AssetItem, TaskItem)):
return

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

def paste(self, indexes, mime_data):

# Get the selected Assets uniquely
items = set()
for index in indexes:
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)


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

0 comments on commit ea339f8

Please sign in to comment.