From 6f8a57daaf26e170075cf12a27bc7ed4428eb386 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 12 May 2021 15:48:21 +0200 Subject: [PATCH] context menu has add task and add asset actions --- .../project_manager/project_manager/view.py | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/openpype/tools/project_manager/project_manager/view.py b/openpype/tools/project_manager/project_manager/view.py index a91f02a590..c8ce7219ca 100644 --- a/openpype/tools/project_manager/project_manager/view.py +++ b/openpype/tools/project_manager/project_manager/view.py @@ -10,7 +10,8 @@ from .delegates import ( from openpype.lib import ApplicationManager from .constants import ( REMOVED_ROLE, - IDENTIFIER_ROLE + IDENTIFIER_ROLE, + ITEM_TYPE_ROLE ) @@ -347,7 +348,8 @@ class HierarchyView(QtWidgets.QTreeView): def _on_context_menu(self, point): index = self.indexAt(point) - if index.column() != 0: + column = index.column() + if column != 0: return actions = [] @@ -358,11 +360,31 @@ class HierarchyView(QtWidgets.QTreeView): items_by_id = {} for index in indexes: - item_id = index.data(IDENTIFIER_ROLE) - if item_id in items_by_id: + if index.column() != column: continue + + item_id = index.data(IDENTIFIER_ROLE) items_by_id[item_id] = self._source_model.items_by_id[item_id] + item_ids = tuple(items_by_id.keys()) + if len(item_ids) == 1: + item = items_by_id[item_ids[0]] + item_type = item.data(None, ITEM_TYPE_ROLE) + if item_type in ("asset", "project"): + add_asset_action = QtWidgets.QAction("Add Asset", context_menu) + add_asset_action.triggered.connect( + lambda: self._add_asset() + ) + actions.append(add_asset_action) + + if item_type in ("asset", "task"): + add_task_action = QtWidgets.QAction("Add Task", context_menu) + add_task_action.triggered.connect( + lambda: self._add_task() + ) + actions.append(add_task_action) + + # Remove delete tag on items removed_item_ids = [] for item_id, item in items_by_id.items(): if item.data(None, REMOVED_ROLE):