Skip to content

Extract PromptSaveChanges helper for save-changes dialogs#11987

Merged
niksedk merged 1 commit into
mainfrom
refactor/save-changes-prompt-helper
Jun 29, 2026
Merged

Extract PromptSaveChanges helper for save-changes dialogs#11987
niksedk merged 1 commit into
mainfrom
refactor/save-changes-prompt-helper

Conversation

@niksedk

@niksedk niksedk commented Jun 29, 2026

Copy link
Copy Markdown
Member

Follow-up to #11985.

The five "Save changes?" Yes/No/Cancel prompts in MainViewModel each repeated the same show dialog → decide → maybe save block. This extracts a single PromptSaveChanges helper (plus SaveCurrentSubtitle / SaveCurrentSubtitleOriginal) so the dialog and — importantly — the cancel/dismiss handling live in one place:

private async Task<bool> PromptSaveChanges(string promptText, Func<Task<bool>> save)
{
    var dr = await MessageBox.Show(Window!, Se.Language.General.SaveChangesTitle, promptText,
        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

    if (dr == MessageBoxResult.Yes)
    {
        return await save();        // proceed only if the save succeeded
    }

    return dr == MessageBoxResult.No; // No → proceed; Cancel / None (dismissed) → abort
}

Behavior is unchanged:

  • Yes → save, proceed only if the save succeeded (so a cancelled "Save as" still aborts).
  • No → discard and proceed.
  • Cancel, or dismissing via the title bar (MessageBoxResult.None) → abort.

The two close handlers (OnClosing, OnWindowClosing) keep calling SaveSubtitle() directly as before (via the inline save lambda); the three text-flow sites keep the save-as-if-untitled logic via the small SaveCurrent* helpers.

Net −36 lines, and the None (dismissal) handling is no longer duplicated across five call sites.

🤖 Generated with Claude Code

The five 'Save changes?' Yes/No/Cancel prompts in MainViewModel each repeated
the same show-dialog-and-decide block. Extract a PromptSaveChanges helper (plus
SaveCurrentSubtitle / SaveCurrentSubtitleOriginal) so the dialog and the
cancel/dismiss handling live in one place. Behavior is unchanged: Yes saves and
proceeds only if the save succeeds, No discards and proceeds, Cancel or a
title-bar dismissal (MessageBoxResult.None) aborts.

Net -36 lines. Follow-up to #11985.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@niksedk niksedk merged commit 01f949e into main Jun 29, 2026
1 of 3 checks passed
@niksedk niksedk deleted the refactor/save-changes-prompt-helper branch June 29, 2026 11:29
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