Skip to content

P2: Editor tool dialogs stay open across New/Open, ask before losing edits, and FRED Revert no longer crashes - #8039

Open
dustinspace217 wants to merge 7 commits into
scp-fs2open:masterfrom
dustinspace217:qtfred/dialogs-across-missions
Open

dustinspace217 wants to merge 7 commits into
scp-fs2open:masterfrom
dustinspace217:qtfred/dialogs-across-missions

Conversation

@dustinspace217

Copy link
Copy Markdown
Contributor

What?

Tool dialogs in qtFRED stay open when you start a new mission or open another one, and they show the new mission instead of the old one. Both editors now ask "keep your changes?" before throwing away unapplied edits, and they mark the mission as changed when a dialog's OK changes it. In FRED, Revert no longer crashes, and Revert after an FS1 import reloads the imported mission.

Why?

If you left a tool open and opened another mission, the tool kept showing the old mission. In FRED, pressing OK in the Event Editor then wrote the old mission's events into the new one. Several dialogs (Fiction Viewer, Shield System, Global Ship Flags, Mission Specs, Background) changed the mission without marking it as changed, so New or Open threw the work away without asking. FRED's File > Revert crashed every time. After importing a single FS1 mission, Revert or closing the Campaign Editor reloaded the mission you had open before the import.

How?

qtFRED closes its open tools before New/Open/Revert/quit, which lets each one ask about unsaved edits, then reopens them on the new mission. FRED does the same for the Event and Message editors through SaveModified. Models mark the mission changed only when something actually changed. Revert passes the current file path instead of NULL. The FS1 import records the converted file's path.

Testing?

  • qtFRED (Linux): headless harness cells, each run on master and on this branch.
  • FRED (Windows 11 VM, MSVC v143 FastDebug):
    • Revert crash and the import path reproduced on master, fixed on the branch.
    • Keep-changes prompt: Yes, No and Cancel, plus a no-edit control.
    • Save keeps unapplied edits.
    • Global flags: change and no-change.
  • Pre-push checks: Debug and Release builds with no warnings, unit tests pass, CI's clang-tidy is clean.
  • Not run: Undo, Message Editor across New, a failed load.

Anything Else?

FRED's Event Editor still stops its sound twice on Cancel; the second call does nothing, so I left it alone. I used Claude Code to help find, fix and test these.

A tool dialog's model copies the mission when it is built, so a dialog left
open across New, Open or the FS1 import kept showing the old mission, and OK
wrote the old mission's data into the new one (fiction viewer: the new
mission saved with the old mission's three stages).

Before a load, each open mission tool is closed through its own close path
(its keep-your-changes prompt still applies; Cancel cancels the load), and
after the load the same tools are opened again where they were. About, the
music player and the campaign editor hold no mission data and stay as they
are.
Most tool dialogs committed their edits on OK without telling the editor the
mission changed, so New, Open or quitting right after did not offer to save
and the edits were lost (fiction viewer: edit, OK, File > New, no prompt).
These models now signal the change when they have one, the same way the
events, goals and cutscenes editors already do; the shield system and
global ship flags dialogs, which apply on their buttons, signal it there.
Both editors are modeless and copy the mission's events and messages when
they are created. Left open across File > New or Open, they kept the old
mission's events, and OK wrote them into the new mission.

Before the save question on New, Open, FS1 import, Revert, the Campaign
Editor and exit, each open editor now runs its own "Do you want to keep your
changes?" prompt, as qtFRED's tools do: Yes applies, No discards, Cancel
stops the action. The editors reopen afterwards, and are rebuilt from the new
mission whenever it replaces the old one (New, Open, FS1 import, Undo, a
failed load). The reload after a save keeps them and their edits, as before.
Run FreeSpace does not replace the mission, so it skips the prompt.
… or global ship flags change it

None of these called set_modified, so New, Open or exit right after did
not offer to save and the change was lost. Each now marks the mission only
when something actually changed.
The import cleared the modified flag right after the save question, before its two
file pickers. Choosing Discard and then cancelling either picker left the unsaved
mission marked as saved, so a later New or Open replaced it without asking. The flag
is now cleared only once both pickers have returned a choice.
Revert called OnOpenDocument(NULL), which used to mean the current file. Since
ee42e76 OnOpenDocument starts with strrchr on the path, so a null path is
dereferenced. Revert now passes the document's path, the same way closing the
Campaign Editor reloads the mission. The menu item now also needs that path:
File > New clears the path but not the mission name, which left Revert enabled
on a new mission.
The import saved the converted mission, set the title and added it to the
recent files, but left the document's path on the mission open before the
import. Revert and closing the Campaign Editor then reloaded that older
mission instead of the imported one.
@dustinspace217

Copy link
Copy Markdown
Contributor Author

Heads-up on an overlap: #8030 also changes FredView::closeEvent and loadMissionFile. At quit it closes every editor window and deletes them before shutdown; this PR closes the registered tool dialogs and reopens them if the quit is cancelled. The two fit together, and I will merge master into this branch and combine them once #8030 lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant