+bool Buffer::branchActivationDispatch(FuncCode act, docstring const & branch)
+{
+ bool const master = (act == LFUN_BRANCH_MASTER_ACTIVATE
+ || act == LFUN_BRANCH_MASTER_DEACTIVATE);
+ bool const activate = (act == LFUN_BRANCH_ACTIVATE
+ || act == LFUN_BRANCH_MASTER_ACTIVATE);
+ Buffer * buf = master ? const_cast<Buffer *>(masterBuffer()) : this;
+ Branch * our_branch = buf->params().branchlist().find(branch);
+
+ // See comment in branchActivationStatus
+ if ((master && parent() == nullptr)
+ || !our_branch
+ || our_branch->isSelected() == activate)
+ return false;
+
+ if (master && !buf->hasGuiDelegate()
+ && (!theApp() || !theApp()->unhide(buf)))
+ // at least issue a warning for now (ugly, but better than dataloss).
+ frontend::Alert::warning(_("Branch state changes in master document"),
+ lyx::support::bformat(_("The state of the branch '%1$s' "
+ "was changed in the master file. "
+ "Please make sure to save the master."), branch), true);
+
+ UndoGroupHelper ugh(buf);
+ buf->undo().recordUndoBufferParams(CursorData());
+ our_branch->setSelected(activate);
+ // cur.forceBufferUpdate() is not enough)
+ buf->updateBuffer();
+
+ // if branch exists in a descendant, update previews.
+ // TODO: only needed if "Show preview" is enabled in the included inset.
+ bool exists_in_desc = false;
+ for (auto const & it : buf->getDescendants()) {
+ if (it->params().branchlist().find(branch))
+ exists_in_desc = true;
+ }
+ if (exists_in_desc) {
+ // TODO: ideally we would only update the previews of the
+ // specific children that have this branch directly or
+ // in one of their descendants
+ buf->removePreviews();
+ buf->updatePreviews();
+ }
+ return true;
+}
+
+