Pass the "add to recent" as an input var to dialogs that open projects

This way it is clear before to the dialog whether it should add the file to the recent files list,
before the dialog opens.

CURA-7996
This commit is contained in:
Kostas Karmas 2021-02-08 11:55:28 +01:00
parent b54f792561
commit f8a9e7f2d2
4 changed files with 13 additions and 9 deletions

View File

@ -1733,7 +1733,7 @@ class CuraApplication(QtApplication):
def log(self, msg): def log(self, msg):
Logger.log("d", msg) Logger.log("d", msg)
openProjectFile = pyqtSignal(QUrl, arguments = ["project_file"]) # Emitted when a project file is about to open. openProjectFile = pyqtSignal(QUrl, bool, arguments = ["project_file", "add_to_recent_files"]) # Emitted when a project file is about to open.
@pyqtSlot(QUrl, str, bool) @pyqtSlot(QUrl, str, bool)
@pyqtSlot(QUrl, str) @pyqtSlot(QUrl, str)
@ -1773,7 +1773,7 @@ class CuraApplication(QtApplication):
if is_project_file and project_mode == "always_ask": if is_project_file and project_mode == "always_ask":
# present a dialog asking to open as project or import models # present a dialog asking to open as project or import models
self.callLater(self.openProjectFile.emit, file) self.callLater(self.openProjectFile.emit, file, add_to_recent_files)
return return
# Either the file is a model file or we want to load only models from project. Continue to load models. # Either the file is a model file or we want to load only models from project. Continue to load models.

View File

@ -691,6 +691,9 @@ UM.MainWindow
function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList) function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList)
{ {
// Make sure the files opened through the openFilesIncludingProjectDialog are added to the recent files list
openFilesIncludingProjectsDialog.addtoRecent = true;
// we only allow opening one project file // we only allow opening one project file
if (selectedMultipleFiles && hasProjectFile) if (selectedMultipleFiles && hasProjectFile)
{ {
@ -717,6 +720,7 @@ UM.MainWindow
{ {
// ask whether to open as project or as models // ask whether to open as project or as models
askOpenAsProjectOrModelsDialog.fileUrl = projectFile; askOpenAsProjectOrModelsDialog.fileUrl = projectFile;
askOpenAsProjectOrModelsDialog.addToRecent = true;
askOpenAsProjectOrModelsDialog.show(); askOpenAsProjectOrModelsDialog.show();
} }
} }
@ -776,6 +780,7 @@ UM.MainWindow
onOpenProjectFile: onOpenProjectFile:
{ {
askOpenAsProjectOrModelsDialog.fileUrl = project_file; askOpenAsProjectOrModelsDialog.fileUrl = project_file;
askOpenAsProjectOrModelsDialog.addToRecent = add_to_recent_files;
askOpenAsProjectOrModelsDialog.show(); askOpenAsProjectOrModelsDialog.show();
} }
} }

View File

@ -29,6 +29,7 @@ UM.Dialog
modality: Qt.WindowModal modality: Qt.WindowModal
property var fileUrl property var fileUrl
property var addToRecent: true
// load the entire project // load the entire project
function loadProjectFile() { function loadProjectFile() {
@ -37,8 +38,7 @@ UM.Dialog
UM.Preferences.setValue("cura/choice_on_open_project", "open_as_project") UM.Preferences.setValue("cura/choice_on_open_project", "open_as_project")
} }
var addToRecent = UM.WorkspaceFileHandler.getAddToRecentFilesHint(base.fileUrl); UM.WorkspaceFileHandler.readLocalFile(base.fileUrl, base.addToRecent);
UM.WorkspaceFileHandler.readLocalFile(base.fileUrl, addToRecent);
base.hide() base.hide()
} }
@ -50,8 +50,7 @@ UM.Dialog
UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model") UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model")
} }
var addToRecent = UM.WorkspaceFileHandler.getAddToRecentFilesHint(base.fileUrl); CuraApplication.readLocalFile(base.fileUrl, "open_as_model", base.addToRecent)
CuraApplication.readLocalFile(base.fileUrl, "open_as_model", addToRecent)
base.hide() base.hide()
} }

View File

@ -28,19 +28,19 @@ UM.Dialog
modality: Qt.WindowModal modality: Qt.WindowModal
property var fileUrls: [] property var fileUrls: []
property var addToRecent: true
property int spacerHeight: 10 * screenScaleFactor property int spacerHeight: 10 * screenScaleFactor
function loadProjectFile(projectFile) function loadProjectFile(projectFile)
{ {
var addToRecent = UM.WorkspaceFileHandler.getAddToRecentFilesHint(projectFile); UM.WorkspaceFileHandler.readLocalFile(projectFile, base.addToRecent);
UM.WorkspaceFileHandler.readLocalFile(projectFile, addToRecent);
} }
function loadModelFiles(fileUrls) function loadModelFiles(fileUrls)
{ {
for (var i in fileUrls) for (var i in fileUrls)
{ {
CuraApplication.readLocalFile(fileUrls[i], "open_as_model"); CuraApplication.readLocalFile(fileUrls[i], "open_as_model", base.addToRecent);
} }
} }