Skip to content

Commit

Permalink
Discard history on project-file save/load (OpenShot#2468)
Browse files Browse the repository at this point in the history
* Discard history on project-file save/load (OpenShot#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).
  • Loading branch information
jonoomph authored Dec 21, 2018
1 parent 8dd399e commit beec2f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/classes/project_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/classes/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
self.actionHistory.append(self.last_action)

0 comments on commit beec2f8

Please sign in to comment.