\begin{tikzpicture} \node[initial] (start) {}; \node[activity,below=0.35cm of start] (cancelPreview) {\textbf{Controller / Scene}\\Cancel an active drag preview}; \node[choice,below=0.35cm of cancelPreview] (loaded) {Document loaded?}; \node[activitySide] (unloaded) at ([xshift=-5.4cm]loaded.center) {Failure: no document is open}; \node[final,below=0.4cm of unloaded] (unloadedEnd) {}; \node[choice,below=0.55cm of loaded] (dirty) {Unsaved changes?}; \node[activitySide] (unchanged) at ([xshift=5.4cm]dirty.center) {Success: no changes to save}; \node[final,below=0.4cm of unchanged] (unchangedEnd) {}; \node[activity,below=0.45cm of dirty] (baseline) {\textbf{Controller}\\Re-read original file; compare with baseline}; \node[choice,below=0.45cm of baseline] (matches) {Read succeeds and baseline matches?}; \node[activity,below=0.45cm of matches] (write) {\textbf{Controller / QSaveFile}\\Disable direct-write fallback; open, write all bytes, commit; stop at first failure}; \node[activitySide] (failed) at ([xshift=-5.4cm]write.center) {Return failure; report read, conflict, or write error; keep source, history and dirty state}; \node[final,below=0.4cm of failed] (failedEnd) {}; \node[choice,below=0.45cm of write] (written) {Write and commit succeeded?}; \node[activity,below=0.45cm of written] (saved) {\textbf{Controller / Document}\\Update baseline; markSaved(); retain history; emit documentChanged}; \node[activity,below=0.4cm of saved] (report) {\textbf{tkrMainWindow}\\Show saved status; refresh dirty flag and Save action}; \node[final,below=0.35cm of report] (finish) {}; \draw[flow] (start) -- (cancelPreview); \draw[flow] (cancelPreview) -- (loaded); \draw[flow] (loaded) -- node[guard,above]{[no]} (unloaded); \draw[flow] (unloaded) -- (unloadedEnd); \draw[flow] (loaded) -- node[guard,right]{[yes]} (dirty); \draw[flow] (dirty) -- node[guard,above]{[no]} (unchanged); \draw[flow] (unchanged) -- (unchangedEnd); \draw[flow] (dirty) -- node[guard,right]{[yes]} (baseline); \draw[flow] (baseline) -- (matches); \draw[flow] (matches.west) -- node[guard,above]{[no]} ([xshift=-5.4cm]matches.center) |- (failed.north); \draw[flow] (matches) -- node[guard,right]{[yes]} (write); \draw[flow] (write) -- (written); \draw[flow] (written.west) -- node[guard,above]{[no]} ([xshift=-3.5cm]written.center) |- (failed.east); \draw[flow] (failed) -- (failedEnd); \draw[flow] (written) -- node[guard,right]{[yes]} (saved); \draw[flow] (saved) -- (report); \draw[flow] (report) -- (finish); \end{tikzpicture}