Skip to content

Commit

Permalink
Avoid changing project name and recent files when writing file
Browse files Browse the repository at this point in the history
CURA-12138
  • Loading branch information
wawanbreton committed Sep 27, 2024
1 parent 7a944c8 commit ada7c53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion UM/Qt/Bindings/OutputDeviceManagerProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ def requestWriteToDevice(self, device_id: str, file_name: str, kwargs: Mapping[s
limit_mimetypes = kwargs.get("limit_mimetypes", None)
file_type = kwargs.get("file_type", "mesh")
preferred_mimetypes = kwargs.get("preferred_mimetypes", None)
silent_save = kwargs.get("silent_save", False)
# On Windows, calling requestWrite() on LocalFileOutputDevice crashes when called from a signal
# handler attached to a QML MenuItem. So instead, defer the call to the next run of the event
# loop, since that does work.
Application.getInstance().callLater(self._writeToDevice, [Application.getInstance().getController().getScene().getRoot()], device_id, file_name, limit_mimetypes, file_type, preferred_mimetypes = preferred_mimetypes)
Application.getInstance().callLater(self._writeToDevice, [Application.getInstance().getController().getScene().getRoot()], device_id, file_name, limit_mimetypes, file_type, preferred_mimetypes = preferred_mimetypes, silent_save = silent_save)

@pyqtSlot(str, str, "QVariantMap")
def requestWriteSelectionToDevice(self, device_id: str, file_name: str, kwargs: Mapping[str, str]) -> None:
Expand Down
12 changes: 8 additions & 4 deletions plugins/LocalFileOutputDevice/LocalFileOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,19 @@ def requestWrite(self, nodes, file_name = None, limit_mimetypes = None, file_han
result = QMessageBox.question(None, catalog.i18nc("@title:window", "File Already Exists"), catalog.i18nc("@label Don't translate the XML tag <filename>!", "The file <filename>{0}</filename> already exists. Are you sure you want to overwrite it?").format(file_name))
if result == QMessageBox.StandardButton.No:
raise OutputDeviceError.UserCanceledError()
self._performWrite(file_name, selected_type, file_handler, nodes)

def _performWrite(self, file_name, selected_type, file_handler, nodes):
silent_save = kwargs.get("silent_save", False)
self._performWrite(file_name, selected_type, file_handler, nodes, silent_save)

def _performWrite(self, file_name, selected_type, file_handler, nodes, silent_save):
"""Writes the specified nodes to a file. This is split from requestWrite to allow interception
in other plugins. See Ultimaker/Cura#10917.
:param file_name: File path to write to.
:param selected_type: Selected file type to write.
:param file_handler: File handler for writing to the file.
:param nodes: A collection of scene nodes that should be written to the
:param silent_save: When true, ignore all side effects (set project name, add recent file, ...)
file.
"""

Expand All @@ -155,7 +158,7 @@ def _performWrite(self, file_name, selected_type, file_handler, nodes):
else:
file_writer = Application.getInstance().getMeshFileHandler().getWriter(selected_type["id"])

if isinstance(file_writer, WorkspaceWriter):
if isinstance(file_writer, WorkspaceWriter) and not silent_save:
self.setLastOutputName(file_name)
self.writeStarted.emit(self)

Expand All @@ -173,7 +176,8 @@ def _performWrite(self, file_name, selected_type, file_handler, nodes):

job = WriteFileJob(file_writer, stream, nodes, mode)
job.setFileName(file_name)
job.setAddToRecentFiles(True) # The file will be added into the "recent files" list upon success
if not silent_save:
job.setAddToRecentFiles(True) # The file will be added into the "recent files" list upon success
job.progress.connect(self._onJobProgress)
job.finished.connect(self._onWriteJobFinished)

Expand Down

0 comments on commit ada7c53

Please sign in to comment.