mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
remove action identifier
This commit is contained in:
parent
365d0a95e0
commit
81a0b67640
13 changed files with 48 additions and 73 deletions
|
|
@ -493,27 +493,24 @@ class LoaderActionItem:
|
|||
and ids to be executed on.
|
||||
|
||||
Attributes:
|
||||
identifier (str): Unique action identifier. What is sent to the action
|
||||
plugin when the action is executed.
|
||||
label (str): Text shown in UI.
|
||||
order (int): Order of the action in UI.
|
||||
group_label (Optional[str]): Label of the group to which the action
|
||||
belongs.
|
||||
icon (Optional[dict[str, Any]): Icon definition.
|
||||
data (Optional[DataType]): Action item data.
|
||||
plugin_identifier (Optional[str]): Identifier of the plugin which
|
||||
identifier (Optional[str]): Identifier of the plugin which
|
||||
created the action item. Is filled automatically. Is not changed
|
||||
if is filled -> can lead to different plugin.
|
||||
|
||||
"""
|
||||
identifier: str
|
||||
label: str
|
||||
order: int = 0
|
||||
group_label: Optional[str] = None
|
||||
icon: Optional[dict[str, Any]] = None
|
||||
data: Optional[DataType] = None
|
||||
# Is filled automatically
|
||||
plugin_identifier: str = None
|
||||
identifier: str = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -667,7 +664,6 @@ class LoaderActionPlugin(ABC):
|
|||
@abstractmethod
|
||||
def execute_action(
|
||||
self,
|
||||
identifier: str,
|
||||
selection: LoaderActionSelection,
|
||||
data: Optional[DataType],
|
||||
form_values: dict[str, Any],
|
||||
|
|
@ -675,7 +671,6 @@ class LoaderActionPlugin(ABC):
|
|||
"""Execute an action.
|
||||
|
||||
Args:
|
||||
identifier (str): Action identifier.
|
||||
selection (LoaderActionSelection): Selection wrapper. Can be used
|
||||
to get entities or get context of original selection.
|
||||
data (Optional[DataType]): Additional action item data.
|
||||
|
|
@ -771,8 +766,8 @@ class LoaderActionsContext:
|
|||
for plugin_id, plugin in self._get_plugins().items():
|
||||
try:
|
||||
for action_item in plugin.get_action_items(selection):
|
||||
if action_item.plugin_identifier is None:
|
||||
action_item.plugin_identifier = plugin_id
|
||||
if action_item.identifier is None:
|
||||
action_item.identifier = plugin_id
|
||||
output.append(action_item)
|
||||
|
||||
except Exception:
|
||||
|
|
@ -785,8 +780,7 @@ class LoaderActionsContext:
|
|||
|
||||
def execute_action(
|
||||
self,
|
||||
plugin_identifier: str,
|
||||
action_identifier: str,
|
||||
identifier: str,
|
||||
selection: LoaderActionSelection,
|
||||
data: Optional[DataType],
|
||||
form_values: dict[str, Any],
|
||||
|
|
@ -794,8 +788,7 @@ class LoaderActionsContext:
|
|||
"""Trigger action execution.
|
||||
|
||||
Args:
|
||||
plugin_identifier (str): Identifier of the plugin.
|
||||
action_identifier (str): Identifier of the action.
|
||||
identifier (str): Identifier of the plugin.
|
||||
selection (LoaderActionSelection): Selection wrapper. Can be used
|
||||
to get what is selected in UI and to get access to entity
|
||||
cache.
|
||||
|
|
@ -805,9 +798,8 @@ class LoaderActionsContext:
|
|||
|
||||
"""
|
||||
plugins_by_id = self._get_plugins()
|
||||
plugin = plugins_by_id[plugin_identifier]
|
||||
plugin = plugins_by_id[identifier]
|
||||
return plugin.execute_action(
|
||||
action_identifier,
|
||||
selection,
|
||||
data,
|
||||
form_values,
|
||||
|
|
@ -910,7 +902,6 @@ class LoaderSimpleActionPlugin(LoaderActionPlugin):
|
|||
label = self.label or self.__class__.__name__
|
||||
return [
|
||||
LoaderActionItem(
|
||||
identifier=self.identifier,
|
||||
label=label,
|
||||
order=self.order,
|
||||
group_label=self.group_label,
|
||||
|
|
|
|||
|
|
@ -41,10 +41,12 @@ class CopyFileActionPlugin(LoaderActionPlugin):
|
|||
for repre_name, repre_ids in repre_ids_by_name.items():
|
||||
output.append(
|
||||
LoaderActionItem(
|
||||
identifier="copy-path",
|
||||
label=repre_name,
|
||||
group_label="Copy file path",
|
||||
data={"representation_ids": list(repre_ids)},
|
||||
data={
|
||||
"representation_ids": list(repre_ids),
|
||||
"action": "copy-path",
|
||||
},
|
||||
icon={
|
||||
"type": "material-symbols",
|
||||
"name": "content_copy",
|
||||
|
|
@ -54,10 +56,12 @@ class CopyFileActionPlugin(LoaderActionPlugin):
|
|||
)
|
||||
output.append(
|
||||
LoaderActionItem(
|
||||
identifier="copy-file",
|
||||
label=repre_name,
|
||||
group_label="Copy file",
|
||||
data={"representation_ids": list(repre_ids)},
|
||||
data={
|
||||
"representation_ids": list(repre_ids),
|
||||
"action": "copy-file",
|
||||
},
|
||||
icon={
|
||||
"type": "material-symbols",
|
||||
"name": "file_copy",
|
||||
|
|
@ -69,13 +73,13 @@ class CopyFileActionPlugin(LoaderActionPlugin):
|
|||
|
||||
def execute_action(
|
||||
self,
|
||||
identifier: str,
|
||||
selection: LoaderActionSelection,
|
||||
data: dict,
|
||||
form_values: dict[str, Any],
|
||||
) -> Optional[LoaderActionResult]:
|
||||
from qtpy import QtWidgets, QtCore
|
||||
|
||||
action = data["action"]
|
||||
repre_id = next(iter(data["representation_ids"]))
|
||||
repre = next(iter(selection.entities.get_representations({repre_id})))
|
||||
path = get_representation_path_with_anatomy(
|
||||
|
|
@ -90,7 +94,7 @@ class CopyFileActionPlugin(LoaderActionPlugin):
|
|||
success=False,
|
||||
)
|
||||
|
||||
if identifier == "copy-path":
|
||||
if action == "copy-path":
|
||||
# Set to Clipboard
|
||||
clipboard.setText(os.path.normpath(path))
|
||||
|
||||
|
|
|
|||
|
|
@ -58,10 +58,12 @@ class DeleteOldVersions(LoaderActionPlugin):
|
|||
|
||||
return [
|
||||
LoaderActionItem(
|
||||
identifier="delete-versions",
|
||||
label="Delete Versions",
|
||||
order=35,
|
||||
data={"product_ids": list(product_ids)},
|
||||
data={
|
||||
"product_ids": list(product_ids),
|
||||
"action": "delete-versions",
|
||||
},
|
||||
icon={
|
||||
"type": "material-symbols",
|
||||
"name": "delete",
|
||||
|
|
@ -69,10 +71,12 @@ class DeleteOldVersions(LoaderActionPlugin):
|
|||
}
|
||||
),
|
||||
LoaderActionItem(
|
||||
identifier="calculate-versions-size",
|
||||
label="Calculate Versions size",
|
||||
order=30,
|
||||
data={"product_ids": list(product_ids)},
|
||||
data={
|
||||
"product_ids": list(product_ids),
|
||||
"action": "calculate-versions-size",
|
||||
},
|
||||
icon={
|
||||
"type": "material-symbols",
|
||||
"name": "auto_delete",
|
||||
|
|
@ -83,17 +87,17 @@ class DeleteOldVersions(LoaderActionPlugin):
|
|||
|
||||
def execute_action(
|
||||
self,
|
||||
identifier: str,
|
||||
selection: LoaderActionSelection,
|
||||
data: dict[str, Any],
|
||||
form_values: dict[str, Any],
|
||||
) -> Optional[LoaderActionResult]:
|
||||
step = form_values.get("step")
|
||||
action = data["action"]
|
||||
versions_to_keep = form_values.get("versions_to_keep")
|
||||
remove_publish_folder = form_values.get("remove_publish_folder")
|
||||
if step is None:
|
||||
return self._first_step(
|
||||
identifier,
|
||||
action,
|
||||
versions_to_keep,
|
||||
remove_publish_folder,
|
||||
)
|
||||
|
|
@ -106,7 +110,7 @@ class DeleteOldVersions(LoaderActionPlugin):
|
|||
product_ids = data["product_ids"]
|
||||
if step == "prepare-data":
|
||||
return self._prepare_data_step(
|
||||
identifier,
|
||||
action,
|
||||
versions_to_keep,
|
||||
remove_publish_folder,
|
||||
product_ids,
|
||||
|
|
@ -121,7 +125,7 @@ class DeleteOldVersions(LoaderActionPlugin):
|
|||
|
||||
def _first_step(
|
||||
self,
|
||||
identifier: str,
|
||||
action: str,
|
||||
versions_to_keep: Optional[int],
|
||||
remove_publish_folder: Optional[bool],
|
||||
) -> LoaderActionResult:
|
||||
|
|
@ -137,7 +141,7 @@ class DeleteOldVersions(LoaderActionPlugin):
|
|||
default=2,
|
||||
),
|
||||
]
|
||||
if identifier == "delete-versions":
|
||||
if action == "delete-versions":
|
||||
fields.append(
|
||||
BoolDef(
|
||||
"remove_publish_folder",
|
||||
|
|
@ -165,7 +169,7 @@ class DeleteOldVersions(LoaderActionPlugin):
|
|||
|
||||
def _prepare_data_step(
|
||||
self,
|
||||
identifier: str,
|
||||
action: str,
|
||||
versions_to_keep: int,
|
||||
remove_publish_folder: bool,
|
||||
entity_ids: set[str],
|
||||
|
|
@ -235,7 +239,7 @@ class DeleteOldVersions(LoaderActionPlugin):
|
|||
if os.path.exists(filepath):
|
||||
size += os.path.getsize(filepath)
|
||||
|
||||
if identifier == "calculate-versions-size":
|
||||
if action == "calculate-versions-size":
|
||||
return LoaderActionResult(
|
||||
message="Calculated size",
|
||||
success=True,
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ class DeliveryAction(LoaderActionPlugin):
|
|||
|
||||
return [
|
||||
LoaderActionItem(
|
||||
identifier="deliver-versions",
|
||||
label="Deliver Versions",
|
||||
order=35,
|
||||
data={"version_ids": list(version_ids)},
|
||||
|
|
@ -65,7 +64,6 @@ class DeliveryAction(LoaderActionPlugin):
|
|||
|
||||
def execute_action(
|
||||
self,
|
||||
identifier: str,
|
||||
selection: LoaderActionSelection,
|
||||
data: dict[str, Any],
|
||||
form_values: dict[str, Any],
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ class OpenFileAction(LoaderActionPlugin):
|
|||
|
||||
return [
|
||||
LoaderActionItem(
|
||||
identifier="open-file",
|
||||
label=repre_name,
|
||||
group_label="Open file",
|
||||
order=-10,
|
||||
|
|
@ -96,7 +95,6 @@ class OpenFileAction(LoaderActionPlugin):
|
|||
|
||||
def execute_action(
|
||||
self,
|
||||
identifier: str,
|
||||
selection: LoaderActionSelection,
|
||||
data: dict[str, Any],
|
||||
form_values: dict[str, Any],
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ class PushToProject(LoaderActionPlugin):
|
|||
if version_ids and len(folder_ids) == 1:
|
||||
output.append(
|
||||
LoaderActionItem(
|
||||
identifier="core.push-to-project",
|
||||
label="Push to project",
|
||||
order=35,
|
||||
data={"version_ids": list(version_ids)},
|
||||
|
|
@ -54,7 +53,6 @@ class PushToProject(LoaderActionPlugin):
|
|||
|
||||
def execute_action(
|
||||
self,
|
||||
identifier: str,
|
||||
selection: LoaderActionSelection,
|
||||
data: dict[str, Any],
|
||||
form_values: dict[str, Any],
|
||||
|
|
|
|||
|
|
@ -314,7 +314,6 @@ class ActionItem:
|
|||
use 'identifier' and context, it necessary also use 'options'.
|
||||
|
||||
Args:
|
||||
plugin_identifier (str): Action identifier.
|
||||
identifier (str): Action identifier.
|
||||
label (str): Action label.
|
||||
group_label (Optional[str]): Group label.
|
||||
|
|
@ -328,7 +327,6 @@ class ActionItem:
|
|||
"""
|
||||
def __init__(
|
||||
self,
|
||||
plugin_identifier: str,
|
||||
identifier: str,
|
||||
label: str,
|
||||
group_label: Optional[str],
|
||||
|
|
@ -338,7 +336,6 @@ class ActionItem:
|
|||
data: Optional[dict[str, Any]],
|
||||
options: Optional[list],
|
||||
):
|
||||
self.plugin_identifier = plugin_identifier
|
||||
self.identifier = identifier
|
||||
self.label = label
|
||||
self.group_label = group_label
|
||||
|
|
@ -366,7 +363,6 @@ class ActionItem:
|
|||
def to_data(self) -> dict[str, Any]:
|
||||
options = self._options_to_data()
|
||||
return {
|
||||
"plugin_identifier": self.plugin_identifier,
|
||||
"identifier": self.identifier,
|
||||
"label": self.label,
|
||||
"group_label": self.group_label,
|
||||
|
|
@ -1003,7 +999,6 @@ class FrontendLoaderController(_BaseLoaderController):
|
|||
@abstractmethod
|
||||
def trigger_action_item(
|
||||
self,
|
||||
plugin_identifier: str,
|
||||
identifier: str,
|
||||
project_name: str,
|
||||
selected_ids: set[str],
|
||||
|
|
@ -1028,8 +1023,7 @@ class FrontendLoaderController(_BaseLoaderController):
|
|||
}
|
||||
|
||||
Args:
|
||||
plugin_identifier (sttr): Plugin identifier.
|
||||
identifier (sttr): Action identifier.
|
||||
identifier (sttr): Plugin identifier.
|
||||
project_name (str): Project name.
|
||||
selected_ids (set[str]): Selected entity ids.
|
||||
selected_entity_type (str): Selected entity type.
|
||||
|
|
|
|||
|
|
@ -315,7 +315,6 @@ class LoaderController(BackendLoaderController, FrontendLoaderController):
|
|||
|
||||
def trigger_action_item(
|
||||
self,
|
||||
plugin_identifier: str,
|
||||
identifier: str,
|
||||
project_name: str,
|
||||
selected_ids: set[str],
|
||||
|
|
@ -324,16 +323,14 @@ class LoaderController(BackendLoaderController, FrontendLoaderController):
|
|||
options: dict[str, Any],
|
||||
form_values: dict[str, Any],
|
||||
):
|
||||
if self._sitesync_model.is_sitesync_action(plugin_identifier):
|
||||
if self._sitesync_model.is_sitesync_action(identifier):
|
||||
self._sitesync_model.trigger_action_item(
|
||||
identifier,
|
||||
project_name,
|
||||
data,
|
||||
)
|
||||
return
|
||||
|
||||
self._loader_actions_model.trigger_action_item(
|
||||
plugin_identifier=plugin_identifier,
|
||||
identifier=identifier,
|
||||
project_name=project_name,
|
||||
selected_ids=selected_ids,
|
||||
|
|
|
|||
|
|
@ -122,7 +122,6 @@ class LoaderActionsModel:
|
|||
|
||||
def trigger_action_item(
|
||||
self,
|
||||
plugin_identifier: str,
|
||||
identifier: str,
|
||||
project_name: str,
|
||||
selected_ids: set[str],
|
||||
|
|
@ -140,8 +139,7 @@ class LoaderActionsModel:
|
|||
happened.
|
||||
|
||||
Args:
|
||||
plugin_identifier (str): Plugin identifier.
|
||||
identifier (str): Action identifier.
|
||||
identifier (str): Plugin identifier.
|
||||
project_name (str): Project name.
|
||||
selected_ids (set[str]): Selected entity ids.
|
||||
selected_entity_type (str): Selected entity type.
|
||||
|
|
@ -151,7 +149,6 @@ class LoaderActionsModel:
|
|||
|
||||
"""
|
||||
event_data = {
|
||||
"plugin_identifier": plugin_identifier,
|
||||
"identifier": identifier,
|
||||
"project_name": project_name,
|
||||
"selected_ids": list(selected_ids),
|
||||
|
|
@ -164,13 +161,12 @@ class LoaderActionsModel:
|
|||
event_data,
|
||||
ACTIONS_MODEL_SENDER,
|
||||
)
|
||||
if plugin_identifier != LOADER_PLUGIN_ID:
|
||||
if identifier != LOADER_PLUGIN_ID:
|
||||
result = None
|
||||
crashed = False
|
||||
try:
|
||||
result = self._loader_actions.execute_action(
|
||||
plugin_identifier=plugin_identifier,
|
||||
action_identifier=identifier,
|
||||
identifier=identifier,
|
||||
selection=LoaderActionSelection(
|
||||
project_name,
|
||||
selected_ids,
|
||||
|
|
@ -197,7 +193,7 @@ class LoaderActionsModel:
|
|||
return
|
||||
|
||||
loader = self._get_loader_by_identifier(
|
||||
project_name, identifier
|
||||
project_name, data["loader"]
|
||||
)
|
||||
entity_type = data["entity_type"]
|
||||
entity_ids = data["entity_ids"]
|
||||
|
|
@ -342,10 +338,10 @@ class LoaderActionsModel:
|
|||
label = f"{label} ({repre_name})"
|
||||
return ActionItem(
|
||||
LOADER_PLUGIN_ID,
|
||||
get_loader_identifier(loader),
|
||||
data={
|
||||
"entity_ids": entity_ids,
|
||||
"entity_type": entity_type,
|
||||
"loader": get_loader_identifier(loader),
|
||||
},
|
||||
label=label,
|
||||
group_label=None,
|
||||
|
|
@ -804,7 +800,6 @@ class LoaderActionsModel:
|
|||
items = []
|
||||
for action in self._loader_actions.get_action_items(selection):
|
||||
items.append(ActionItem(
|
||||
action.plugin_identifier,
|
||||
action.identifier,
|
||||
label=action.label,
|
||||
group_label=action.group_label,
|
||||
|
|
|
|||
|
|
@ -300,33 +300,32 @@ class SiteSyncModel:
|
|||
|
||||
return action_items
|
||||
|
||||
def is_sitesync_action(self, plugin_identifier: str) -> bool:
|
||||
def is_sitesync_action(self, identifier: str) -> bool:
|
||||
"""Should be `identifier` handled by SiteSync.
|
||||
|
||||
Args:
|
||||
plugin_identifier (str): Plugin identifier.
|
||||
identifier (str): Plugin identifier.
|
||||
|
||||
Returns:
|
||||
bool: Should action be handled by SiteSync.
|
||||
|
||||
"""
|
||||
return plugin_identifier == "sitesync.loader.action"
|
||||
return identifier == "sitesync.loader.action"
|
||||
|
||||
def trigger_action_item(
|
||||
self,
|
||||
identifier: str,
|
||||
project_name: str,
|
||||
data: dict[str, Any],
|
||||
):
|
||||
"""Resets status for site_name or remove local files.
|
||||
|
||||
Args:
|
||||
identifier (str): Action identifier.
|
||||
project_name (str): Project name.
|
||||
data (dict[str, Any]): Action item data.
|
||||
|
||||
"""
|
||||
representation_ids = data["representation_ids"]
|
||||
action_identifier = data["action_identifier"]
|
||||
active_site = self.get_active_site(project_name)
|
||||
remote_site = self.get_remote_site(project_name)
|
||||
|
||||
|
|
@ -350,17 +349,17 @@ class SiteSyncModel:
|
|||
for repre_id in representation_ids:
|
||||
repre_entity = repre_entities_by_id.get(repre_id)
|
||||
product_type = product_type_by_repre_id[repre_id]
|
||||
if identifier == DOWNLOAD_IDENTIFIER:
|
||||
if action_identifier == DOWNLOAD_IDENTIFIER:
|
||||
self._add_site(
|
||||
project_name, repre_entity, active_site, product_type
|
||||
)
|
||||
|
||||
elif identifier == UPLOAD_IDENTIFIER:
|
||||
elif action_identifier == UPLOAD_IDENTIFIER:
|
||||
self._add_site(
|
||||
project_name, repre_entity, remote_site, product_type
|
||||
)
|
||||
|
||||
elif identifier == REMOVE_IDENTIFIER:
|
||||
elif action_identifier == REMOVE_IDENTIFIER:
|
||||
self._sitesync_addon.remove_site(
|
||||
project_name,
|
||||
repre_id,
|
||||
|
|
@ -480,14 +479,13 @@ class SiteSyncModel:
|
|||
self,
|
||||
project_name,
|
||||
representation_ids,
|
||||
identifier,
|
||||
action_identifier,
|
||||
label,
|
||||
tooltip,
|
||||
icon_name
|
||||
):
|
||||
return ActionItem(
|
||||
"sitesync.loader.action",
|
||||
identifier=identifier,
|
||||
label=label,
|
||||
group_label=None,
|
||||
icon={
|
||||
|
|
@ -499,6 +497,7 @@ class SiteSyncModel:
|
|||
order=1,
|
||||
data={
|
||||
"representation_ids": representation_ids,
|
||||
"action_identifier": action_identifier,
|
||||
},
|
||||
options=None,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -438,7 +438,6 @@ class ProductsWidget(QtWidgets.QWidget):
|
|||
return
|
||||
|
||||
self._controller.trigger_action_item(
|
||||
plugin_identifier=action_item.plugin_identifier,
|
||||
identifier=action_item.identifier,
|
||||
project_name=project_name,
|
||||
selected_ids=version_ids,
|
||||
|
|
|
|||
|
|
@ -399,7 +399,6 @@ class RepresentationsWidget(QtWidgets.QWidget):
|
|||
return
|
||||
|
||||
self._controller.trigger_action_item(
|
||||
plugin_identifier=action_item.plugin_identifier,
|
||||
identifier=action_item.identifier,
|
||||
project_name=self._selected_project_name,
|
||||
selected_ids=repre_ids,
|
||||
|
|
|
|||
|
|
@ -584,7 +584,6 @@ class LoaderWindow(QtWidgets.QWidget):
|
|||
|
||||
form_values = dialog.get_values()
|
||||
self._controller.trigger_action_item(
|
||||
plugin_identifier=event["plugin_identifier"],
|
||||
identifier=event["identifier"],
|
||||
project_name=event["project_name"],
|
||||
selected_ids=event["selected_ids"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue