mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 12:54:40 +01:00
converted copy file action
This commit is contained in:
parent
700006692a
commit
e05ffe0263
3 changed files with 115 additions and 63 deletions
|
|
@ -1,34 +0,0 @@
|
|||
from ayon_core.style import get_default_entity_icon_color
|
||||
from ayon_core.pipeline import load
|
||||
|
||||
|
||||
class CopyFile(load.LoaderPlugin):
|
||||
"""Copy the published file to be pasted at the desired location"""
|
||||
|
||||
representations = {"*"}
|
||||
product_types = {"*"}
|
||||
|
||||
label = "Copy File"
|
||||
order = 10
|
||||
icon = "copy"
|
||||
color = get_default_entity_icon_color()
|
||||
|
||||
def load(self, context, name=None, namespace=None, data=None):
|
||||
path = self.filepath_from_context(context)
|
||||
self.log.info("Added copy to clipboard: {0}".format(path))
|
||||
self.copy_file_to_clipboard(path)
|
||||
|
||||
@staticmethod
|
||||
def copy_file_to_clipboard(path):
|
||||
from qtpy import QtCore, QtWidgets
|
||||
|
||||
clipboard = QtWidgets.QApplication.clipboard()
|
||||
assert clipboard, "Must have running QApplication instance"
|
||||
|
||||
# Build mime data for clipboard
|
||||
data = QtCore.QMimeData()
|
||||
url = QtCore.QUrl.fromLocalFile(path)
|
||||
data.setUrls([url])
|
||||
|
||||
# Set to Clipboard
|
||||
clipboard.setMimeData(data)
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
import os
|
||||
|
||||
from ayon_core.pipeline import load
|
||||
|
||||
|
||||
class CopyFilePath(load.LoaderPlugin):
|
||||
"""Copy published file path to clipboard"""
|
||||
representations = {"*"}
|
||||
product_types = {"*"}
|
||||
|
||||
label = "Copy File Path"
|
||||
order = 20
|
||||
icon = "clipboard"
|
||||
color = "#999999"
|
||||
|
||||
def load(self, context, name=None, namespace=None, data=None):
|
||||
path = self.filepath_from_context(context)
|
||||
self.log.info("Added file path to clipboard: {0}".format(path))
|
||||
self.copy_path_to_clipboard(path)
|
||||
|
||||
@staticmethod
|
||||
def copy_path_to_clipboard(path):
|
||||
from qtpy import QtWidgets
|
||||
|
||||
clipboard = QtWidgets.QApplication.clipboard()
|
||||
assert clipboard, "Must have running QApplication instance"
|
||||
|
||||
# Set to Clipboard
|
||||
clipboard.setText(os.path.normpath(path))
|
||||
115
client/ayon_core/plugins/loader/copy_file.py
Normal file
115
client/ayon_core/plugins/loader/copy_file.py
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
import os
|
||||
import collections
|
||||
|
||||
from typing import Optional, Any
|
||||
|
||||
from ayon_core.pipeline.load import get_representation_path_with_anatomy
|
||||
from ayon_core.pipeline.actions import (
|
||||
LoaderActionPlugin,
|
||||
LoaderActionItem,
|
||||
LoaderActionSelection,
|
||||
LoaderActionResult,
|
||||
)
|
||||
|
||||
|
||||
class CopyFileActionPlugin(LoaderActionPlugin):
|
||||
"""Copy published file path to clipboard"""
|
||||
identifier = "core.copy-action"
|
||||
|
||||
def get_action_items(
|
||||
self, selection: LoaderActionSelection
|
||||
) -> list[LoaderActionItem]:
|
||||
repres = []
|
||||
if selection.selected_type in "representations":
|
||||
repres = selection.entities.get_representations(
|
||||
selection.selected_ids
|
||||
)
|
||||
|
||||
if selection.selected_type in "version":
|
||||
repres = selection.entities.get_versions_representations(
|
||||
selection.selected_ids
|
||||
)
|
||||
|
||||
output = []
|
||||
if not repres:
|
||||
return output
|
||||
|
||||
repre_ids_by_name = collections.defaultdict(set)
|
||||
for repre in repres:
|
||||
repre_ids_by_name[repre["name"]].add(repre["id"])
|
||||
|
||||
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",
|
||||
entity_ids=repre_ids,
|
||||
entity_type="representation",
|
||||
icon={
|
||||
"type": "material-symbols",
|
||||
"name": "content_copy",
|
||||
"color": "#999999",
|
||||
}
|
||||
)
|
||||
)
|
||||
output.append(
|
||||
LoaderActionItem(
|
||||
identifier="copy-file",
|
||||
label=repre_name,
|
||||
group_label="Copy file",
|
||||
entity_ids=repre_ids,
|
||||
entity_type="representation",
|
||||
icon={
|
||||
"type": "material-symbols",
|
||||
"name": "file_copy",
|
||||
"color": "#999999",
|
||||
}
|
||||
)
|
||||
)
|
||||
return output
|
||||
|
||||
def execute_action(
|
||||
self,
|
||||
identifier: str,
|
||||
entity_ids: set[str],
|
||||
entity_type: str,
|
||||
selection: LoaderActionSelection,
|
||||
form_values: dict[str, Any],
|
||||
) -> Optional[LoaderActionResult]:
|
||||
from qtpy import QtWidgets, QtCore
|
||||
|
||||
repre = next(iter(selection.entities.get_representations(entity_ids)))
|
||||
path = get_representation_path_with_anatomy(
|
||||
repre, selection.get_project_anatomy()
|
||||
)
|
||||
self.log.info(f"Added file path to clipboard: {path}")
|
||||
|
||||
clipboard = QtWidgets.QApplication.clipboard()
|
||||
if not clipboard:
|
||||
return LoaderActionResult(
|
||||
"Failed to copy file path to clipboard",
|
||||
success=False,
|
||||
)
|
||||
|
||||
if identifier == "copy-path":
|
||||
# Set to Clipboard
|
||||
clipboard.setText(os.path.normpath(path))
|
||||
|
||||
return LoaderActionResult(
|
||||
"Path stored to clipboard",
|
||||
success=True,
|
||||
)
|
||||
|
||||
# Build mime data for clipboard
|
||||
data = QtCore.QMimeData()
|
||||
url = QtCore.QUrl.fromLocalFile(path)
|
||||
data.setUrls([url])
|
||||
|
||||
# Set to Clipboard
|
||||
clipboard.setMimeData(data)
|
||||
|
||||
return LoaderActionResult(
|
||||
"File added to clipboard",
|
||||
success=True,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue