Display the correct message when opening deleted files from Recent

If a file that existed in the Recent Files list was deleted, Cura was still trying to open the file
on user's request without properly displaying an error if the file was not found.

This is now fixed by popping up a message to indicate that the file doesn't exist.

CURA-7996
This commit is contained in:
Kostas Karmas 2021-02-05 12:10:23 +01:00
parent ba5b033499
commit e2699a5ab8

View file

@ -1743,6 +1743,7 @@ class CuraApplication(QtApplication):
:param project_mode: How to handle project files. Either None(default): Follow user preference, "open_as_model"
or "open_as_project". This parameter is only considered if the file is a project file.
:param add_to_recent_files: Whether or not to add the file as an option to the Recent Files list.
"""
Logger.log("i", "Attempting to read file %s", file.toString())
if not file.isValid():
@ -1757,6 +1758,10 @@ class CuraApplication(QtApplication):
is_project_file = self.checkIsValidProjectFile(file)
if is_project_file is False:
# The file isn't a valid project file so abort reading it.
return
if project_mode is None:
project_mode = self.getPreferences().getValue("cura/choice_on_open_project")
@ -1940,6 +1945,13 @@ class CuraApplication(QtApplication):
try:
result = workspace_reader.preRead(file_path, show_dialog=False)
return result == WorkspaceReader.PreReadResult.accepted
except FileNotFoundError:
result_message = Message(text = self._i18n_catalog.i18nc("@info:status Don't translate the XML tag <filename>!",
"Failed to load <filename>{0}</filename>. No such file or directory.",
file_path), lifetime = 0,
title = self._i18n_catalog.i18nc("@info:title", "Unable to Open File"))
result_message.show()
return False
except Exception:
Logger.logException("e", "Could not check file %s", file_url)
return False