Skip to content

Commit

Permalink
Scene.py add _hideReloadMessage, connect to startReloadAll
Browse files Browse the repository at this point in the history
When all files are being reloaded, the file modification reload
dialog is redundant.  This allows pressing F5 to reload and dismiss
the dialog.
  • Loading branch information
dfries committed Sep 3, 2024
1 parent 7b76536 commit 625eaea
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions UM/Scene/Scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def __init__(self) -> None:

self._metadata: Dict[str, Any] = {}

# If available connect reloadAll to hide the file change reload message.
import UM.Application
app = UM.Application.Application.getInstance()
if getattr(app, "startReloadAll", None):
app.startReloadAll.connect(self._hideReloadMessage)

def setMetaDataEntry(self, key: str, entry: Any) -> None:
self._metadata[key] = entry

Expand Down Expand Up @@ -189,8 +195,7 @@ def _onFileChanged(self, file_path: str) -> None:
if modified_nodes:
# Hide the message if it was already visible
# Todo: keep one message for each modified file, when multiple had been updated at same time
if self._reload_message is not None:
self._reload_message.hide()
self._hideReloadMessage()

self._reload_message = Message(i18n_catalog.i18nc("@info", "Would you like to reload {filename}?").format(
filename = os.path.basename(file_path)),
Expand All @@ -212,8 +217,7 @@ def _reloadNodes(self, nodes: List["SceneNode"], file_path: str, message: str, a

if action != "reload":
return
if self._reload_message is not None:
self._reload_message.hide()
self._hideReloadMessage()

if not file_path or not os.path.isfile(file_path): # File doesn't exist anymore.
return
Expand Down Expand Up @@ -265,3 +269,10 @@ def _reloadJobFinished(self, replaced_nodes: [SceneNode], job: ReadMeshJob) -> N
# Current node is a new one in the file, or it's name has changed
# TODO: Load this mesh into the scene. Also alter the "ReloadAll" action in CuraApplication.
Logger.log("w", "Could not find matching node for object '{0}' in the scene.", node_name)

def _hideReloadMessage(self) -> None:
"""Hide file modification reload dialog if showing"""
if self._reload_message is not None:
self._reload_message.hide()
if self._reload_callback is not None:
self._reload_callback = None

0 comments on commit 625eaea

Please sign in to comment.