From beec2f8a5bcf86081f2815b0788a0e7f0924ccb2 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Thu, 20 Dec 2018 22:42:20 -0600 Subject: [PATCH] Discard history on project-file save/load (#2468) * Discard history on project-file save/load (#2400) * updates.py: add newline at end of file * conversion: total_size() for data structs * project_data: Log load and save operations Believe it or not, in all the logging OpenShot does, never was the fact that a project file was being loaded or saved actually logged as such. Now it is, complete with the `file_path`. * project_data: Discard history On both load and save of project file data, any `"history"` in the JSON will be discarded, replaced with an empty struct: `{ "undo": [], "redo": [] }` Temporarily, while testing the feature, the total size of the data structure being discarded will first be computed and logged. ``` project_data:INFO Discarding history of size 105246892 bytes ``` * Removing logging of history size, since it does not serve much of a purpose. Soon we need to revisit this and try and improve the persistance of history (within reason to a few dozen changes perhaps), and ensure we don't allow nested histories (since history is an attribute of a project object). --- src/classes/project_data.py | 12 ++++++++++++ src/classes/updates.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/classes/project_data.py b/src/classes/project_data.py index 79e7d9412d..60b32e5839 100644 --- a/src/classes/project_data.py +++ b/src/classes/project_data.py @@ -309,6 +309,8 @@ def load(self, file_path): self.new() if file_path: + log.info("Loading project file: {}".format(file_path)) + # Default project data default_project = self._data @@ -337,6 +339,10 @@ def load(self, file_path): # Check if paths are all valid self.check_if_paths_are_valid() + # Discard history + log.info("Discarding history") + self._data["history"] = { "undo": [], "redo": [] } + # Copy any project thumbnails to main THUMBNAILS folder loaded_project_folder = os.path.dirname(self.current_filepath) project_thumbnails_folder = os.path.join(loaded_project_folder, "thumbnail") @@ -687,6 +693,8 @@ def save(self, file_path, move_temp_files=True, make_paths_relative=True): """ Save project file to disk """ import openshot + log.info("Saving project file: {}".format(file_path)) + # Move all temp files (i.e. Blender animations) to the project folder if move_temp_files: self.move_temp_paths_to_project_folder(file_path) @@ -695,6 +703,10 @@ def save(self, file_path, move_temp_files=True, make_paths_relative=True): if make_paths_relative: self.convert_paths_to_relative(file_path) + # Discard history + log.info("Discarding history") + self._data["history"] = { "undo": [], "redo": [] } + # Append version info v = openshot.GetVersion() self._data["version"] = { "openshot-qt" : info.VERSION, diff --git a/src/classes/updates.py b/src/classes/updates.py index fea05f3d4a..21087c9141 100644 --- a/src/classes/updates.py +++ b/src/classes/updates.py @@ -308,4 +308,4 @@ def apply_last_action_to_history(self, previous_value): """ Apply the last action to the history """ if self.last_action: self.last_action.set_old_values(previous_value) - self.actionHistory.append(self.last_action) \ No newline at end of file + self.actionHistory.append(self.last_action)