SetDocumentVariantsCommand.h header

#include <ew/core/SetDocumentVariantsCommand.h>

Namespace ew::core

SetDocumentVariantsCommand class

class ew::core::SetDocumentVariantsCommand

Command that sets a document's alternate-variant state as one undoable step: the parallel alternate drafts, the name of the active variant, and the live body. Switching between variants swaps the live body with a stored alternative, so the three must change together; creating, renaming, or deleting a variant leaves the body unchanged (pass the current body). Undo restores the previous state and redo re-applies the new one. This owns the wholesale body swap of a variant switch (a structural change), separate from the editor's own incremental text undo.

Members

ew::core::document::SetDocumentVariantsCommand::SetDocumentVariantsCommand(Document &document, std::vector< DocumentVariant > variants, QString activeVariantName, QString body, BodyFormat format)

Creates a command that, when applied, sets document's variants to variants, its active variant name to activeVariantName, its body to body, and its body format to format.

The format is part of the swap because a parked draft can be a different kind of text from the one replacing it – a draft the Markdown migration could not convert is still legacy HTML while the main body is Markdown. Applying the body without its tag left the document claiming one format and holding the other (F-0071), and undoing without it would do the same in reverse.

ew::core::document::SetDocumentVariantsCommand::~SetDocumentVariantsCommand() override

Destroys the command.

void ew::core::document::SetDocumentVariantsCommand::apply() override

Records the document's current variant state and body, then applies the new ones.

void ew::core::document::SetDocumentVariantsCommand::undo() override

Restores the previous variant state and body.

QString ew::core::document::SetDocumentVariantsCommand::description() const override

Returns a short description for the undo/redo UI.