From f06fbe159f4dcdf8b87586706a1a0d0f4810d17b Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 25 Aug 2025 15:00:10 +0200 Subject: [PATCH] added group label to 'ActionItem' --- client/ayon_core/tools/loader/abstract.py | 4 +++ .../ayon_core/tools/loader/models/actions.py | 18 ++-------- .../ayon_core/tools/loader/models/sitesync.py | 1 + .../tools/loader/ui/actions_utils.py | 34 ++++++++++++++++--- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/client/ayon_core/tools/loader/abstract.py b/client/ayon_core/tools/loader/abstract.py index a58ddf11d7..d3de8fb7c2 100644 --- a/client/ayon_core/tools/loader/abstract.py +++ b/client/ayon_core/tools/loader/abstract.py @@ -322,6 +322,7 @@ class ActionItem: entity_ids (set[str]): Entity ids. entity_type (str): Entity type. label (str): Action label. + group_label (str): Group label. icon (dict[str, Any]): Action icon definition. tooltip (str): Action tooltip. order (int): Action order. @@ -336,6 +337,7 @@ class ActionItem: entity_ids, entity_type, label, + group_label, icon, tooltip, order, @@ -346,6 +348,7 @@ class ActionItem: self.entity_ids = entity_ids self.entity_type = entity_type self.label = label + self.group_label = group_label self.icon = icon self.tooltip = tooltip self.order = order @@ -375,6 +378,7 @@ class ActionItem: "entity_ids": list(self.entity_ids), "entity_type": self.entity_type, "label": self.label, + "group_label": self.group_label, "icon": self.icon, "tooltip": self.tooltip, "order": self.order, diff --git a/client/ayon_core/tools/loader/models/actions.py b/client/ayon_core/tools/loader/models/actions.py index d3d053ae85..684adf36a9 100644 --- a/client/ayon_core/tools/loader/models/actions.py +++ b/client/ayon_core/tools/loader/models/actions.py @@ -116,8 +116,6 @@ class LoaderActionsModel: entity_ids, entity_type, )) - - action_items.sort(key=self._actions_sorter) return action_items def trigger_action_item( @@ -350,6 +348,7 @@ class LoaderActionsModel: entity_ids=entity_ids, entity_type=entity_type, label=label, + group_label=None, icon=self._get_action_icon(loader), tooltip=self._get_action_tooltip(loader), order=loader.order, @@ -407,15 +406,6 @@ class LoaderActionsModel: loaders_by_identifier = loaders_by_identifier_c.get_data() return loaders_by_identifier.get(identifier) - def _actions_sorter(self, action_item): - """Sort the Loaders by their order and then their name. - - Returns: - tuple[int, str]: Sort keys. - """ - - return action_item.order, action_item.label - def _contexts_for_versions(self, project_name, version_ids): """Get contexts for given version ids. @@ -793,15 +783,13 @@ class LoaderActionsModel: ) items = [] for action in self._loader_actions.get_action_items(selection): - label = action.label - if action.group_label: - label = f"{action.group_label} ({label})" items.append(ActionItem( action.plugin_identifier, action.identifier, action.entity_ids, action.entity_type, - label=label, + label=action.label, + group_label=action.group_label, icon=action.icon, tooltip=None, # action.tooltip, order=action.order, diff --git a/client/ayon_core/tools/loader/models/sitesync.py b/client/ayon_core/tools/loader/models/sitesync.py index ced4ac5d05..4d6ffcf9d4 100644 --- a/client/ayon_core/tools/loader/models/sitesync.py +++ b/client/ayon_core/tools/loader/models/sitesync.py @@ -487,6 +487,7 @@ class SiteSyncModel: "sitesync.loader.action", identifier=identifier, label=label, + group_label=None, icon={ "type": "awesome-font", "name": icon_name, diff --git a/client/ayon_core/tools/loader/ui/actions_utils.py b/client/ayon_core/tools/loader/ui/actions_utils.py index b601cd95bd..3281a170bd 100644 --- a/client/ayon_core/tools/loader/ui/actions_utils.py +++ b/client/ayon_core/tools/loader/ui/actions_utils.py @@ -1,6 +1,7 @@ import uuid +from typing import Optional, Any -from qtpy import QtWidgets, QtGui +from qtpy import QtWidgets, QtGui, QtCore import qtawesome from ayon_core.lib.attribute_definitions import AbstractAttrDef @@ -11,9 +12,26 @@ from ayon_core.tools.utils.widgets import ( OptionDialog, ) from ayon_core.tools.utils import get_qt_icon +from ayon_core.tools.loader.abstract import ActionItem -def show_actions_menu(action_items, global_point, one_item_selected, parent): +def _actions_sorter(item: tuple[str, ActionItem]): + """Sort the Loaders by their order and then their name. + + Returns: + tuple[int, str]: Sort keys. + + """ + label, action_item = item + return action_item.order, label + + +def show_actions_menu( + action_items: list[ActionItem], + global_point: QtCore.QPoint, + one_item_selected: bool, + parent: QtWidgets.QWidget, +) -> tuple[Optional[ActionItem], Optional[dict[str, Any]]]: selected_action_item = None selected_options = None @@ -26,15 +44,23 @@ def show_actions_menu(action_items, global_point, one_item_selected, parent): menu = OptionalMenu(parent) - action_items_by_id = {} + action_items_with_labels = [] for action_item in action_items: + label = action_item.label + if action_item.group_label: + label = f"{action_item.group_label} ({label})" + action_items_with_labels.append((label, action_item)) + + action_items_by_id = {} + for item in sorted(action_items_with_labels, key=_actions_sorter): + label, action_item = item item_id = uuid.uuid4().hex action_items_by_id[item_id] = action_item item_options = action_item.options icon = get_qt_icon(action_item.icon) use_option = bool(item_options) action = OptionalAction( - action_item.label, + label, icon, use_option, menu