diff --git a/docs/events/index.rst b/docs/events/index.rst index 6b75699f2..c468a1fad 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -265,6 +265,26 @@ FileRemoved .. versionadded:: 1.3.3 +FileMoved + A file has been moved from one location to an other location. + + Payload: + * ``storage``: the storage's identifier + * ``source_path``: the source file's path within its storage location + * ``source_name``: the source file's name + * ``source_type``: the source file's type, a list of the path within the type hierarchy, e.g. ``["machinecode", "gcode"]`` or + ``["model", "stl"]`` + * ``destination_path``: the source file's path within its storage location + * ``destination_name``: the source file's name + * ``destination_type``: the source file's type, a list of the path within the type hierarchy, e.g. ``["machinecode", "gcode"]`` or + ``["model", "stl"]`` + + .. note:: + + A moved file still triggers first a ``FileRemoved`` for its original path and then ``FileAdded`` event for the new one. After that a ```UpdatedFiles``` event is also fired. + + .. versionadded:: 1.8.0 + FolderAdded A folder has been added to a storage. @@ -294,6 +314,22 @@ FolderRemoved .. versionadded:: 1.3.3 +FolderMoved + A folder has been moved from one location to an other location. + + Payload: + * ``storage``: the storage's identifier + * ``source_path``: the source folder's path within its storage location + * ``source_name``: the source folder's name + * ``destination_path``: the source folder's path within its storage location + * ``destination_name``: the source folder's name + + .. note:: + + A moved folder still triggers first a ``FolderRemoved`` for its original path and then ``FolderAdded`` event for the new one. After that a ```UpdatedFiles``` event is also fired. + + .. versionadded:: 1.8.0 + UpdatedFiles A file list was modified. diff --git a/src/octoprint/events.py b/src/octoprint/events.py index 17ed69b1e..1928fe7d7 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -62,8 +62,10 @@ class Events: FILE_ADDED = "FileAdded" FILE_REMOVED = "FileRemoved" + FILE_MOVED = "FileMoved" FOLDER_ADDED = "FolderAdded" FOLDER_REMOVED = "FolderRemoved" + FOLDER_MOVED = "FolderMoved" # SD Upload TRANSFER_STARTED = "TransferStarted" diff --git a/src/octoprint/filemanager/__init__.py b/src/octoprint/filemanager/__init__.py index a209c2d89..4315221db 100644 --- a/src/octoprint/filemanager/__init__.py +++ b/src/octoprint/filemanager/__init__.py @@ -823,6 +823,19 @@ class FileManager: "type": get_file_type(dst_name), }, ) + eventManager().fire( + Events.FILE_MOVED, + { + "storage": destination, + "source_path": source_path_in_storage, + "source_name": source_name, + "source_type": get_file_type(source_name), + "destination_path": dst_path_in_storage, + "destination_name": dst_name, + "destination_type": get_file_type(dst_name), + }, + ) + eventManager().fire(Events.UPDATED_FILES, {"type": "printables"}) def add_folder(self, destination, path, ignore_existing=True, display=None): @@ -884,6 +897,17 @@ class FileManager: Events.FOLDER_ADDED, {"storage": destination, "path": dst_path_in_storage, "name": dst_name}, ) + eventManager().fire( + Events.FOLDER_MOVED, + { + "storage": destination, + "source_path": source_path_in_storage, + "source_name": source_name, + "destination_path": dst_path_in_storage, + "destination_name": dst_name, + }, + ) + eventManager().fire(Events.UPDATED_FILES, {"type": "printables"}) def has_analysis(self, destination, path):