added group label to 'ActionItem'

This commit is contained in:
Jakub Trllo 2025-08-25 15:00:10 +02:00
parent 270d7cbff9
commit f06fbe159f
4 changed files with 38 additions and 19 deletions

View file

@ -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,

View file

@ -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,

View file

@ -487,6 +487,7 @@ class SiteSyncModel:
"sitesync.loader.action",
identifier=identifier,
label=label,
group_label=None,
icon={
"type": "awesome-font",
"name": icon_name,

View file

@ -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