]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBranch.cpp
listerrors.lyx : Update a link.
[lyx.git] / src / insets / InsetBranch.cpp
index 62fb7c4442b3d5cc2351734534788de524762d78..6ab2fb79e73e5712a08c3face65b7bafc933eb6c 100644 (file)
@@ -126,18 +126,26 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
        }
        case LFUN_BRANCH_ACTIVATE:
        case LFUN_BRANCH_DEACTIVATE: {
-               // FIXME: I do not like this cast, but have no other idea...
-               Buffer const * buf = buffer().masterBuffer();
-               BranchList const & branchlist = buf->params().branchlist();
-               Branch * our_branch = const_cast<Branch *>(branchlist.find(params_.branch));
-               if (!our_branch) {
+               Buffer * buf = const_cast<Buffer *>(buffer().masterBuffer());
+               // is the branch in our master buffer?
+               bool branch_in_master = (buf != &buffer());
+
+               Branch * our_branch = buf->params().branchlist().find(params_.branch);
+               if (branch_in_master && !our_branch) {
                        // child only?
                        our_branch = buffer().params().branchlist().find(params_.branch);
                        if (!our_branch)
                                break;
+                       branch_in_master = false;
                }
                bool const activate = (cmd.action() == LFUN_BRANCH_ACTIVATE);
                if (our_branch->isSelected() != activate) {
+                       // FIXME If the branch is in the master document, we cannot
+                       // call recordUndo..., becuase the master may be hidden, and
+                       // the code presently assumes that hidden documents can never
+                       // be dirty. See GuiView::closeBufferAll(), for example.
+                       if (!branch_in_master)
+                               buffer().undo().recordUndoFullDocument(cur);
                        our_branch->setSelected(activate);
                        cur.forceBufferUpdate();
                }
@@ -203,9 +211,10 @@ bool InsetBranch::isBranchSelected() const
 }
 
 
-int InsetBranch::latex(odocstream & os, OutputParams const & runparams) const
+void InsetBranch::latex(otexstream & os, OutputParams const & runparams) const
 {
-       return isBranchSelected() ?  InsetText::latex(os, runparams) : 0;
+       if (isBranchSelected())
+               InsetText::latex(os, runparams);
 }
 
 
@@ -215,11 +224,8 @@ int InsetBranch::plaintext(odocstream & os,
        if (!isBranchSelected())
                return 0;
 
-       os << '[' << buffer().B_("branch") << ' ' << params_.branch << ":\n";
-       InsetText::plaintext(os, runparams);
-       os << "\n]";
-
-       return PLAINTEXT_NEWLINE + 1; // one char on a separate line
+       int len = InsetText::plaintext(os, runparams);
+       return len;
 }
 
 
@@ -232,8 +238,12 @@ int InsetBranch::docbook(odocstream & os,
 
 docstring InsetBranch::xhtml(XHTMLStream & xs, OutputParams const & rp) const
 {
-       if (isBranchSelected())
-                return InsetText::xhtml(xs, rp);
+       if (isBranchSelected()) {
+               OutputParams newrp = rp;
+               newrp.par_begin = 0;
+               newrp.par_end = text().paragraphs().size();
+               xhtmlParagraphs(text(), buffer(), xs, newrp);
+       }
        return docstring();
 }
 
@@ -259,9 +269,9 @@ void InsetBranch::validate(LaTeXFeatures & features) const
 }
 
 
-docstring InsetBranch::contextMenuName() const
+string InsetBranch::contextMenuName() const
 {
-       return from_ascii("context-branch");
+       return "context-branch";
 }
 
 
@@ -294,10 +304,10 @@ void InsetBranch::string2params(string const & in, InsetBranchParams & params)
 }
 
 
-void InsetBranch::addToToc(DocIterator const & cpit)
+void InsetBranch::addToToc(DocIterator const & cpit) const
 {
        DocIterator pit = cpit;
-       pit.push_back(CursorSlice(*this));
+       pit.push_back(CursorSlice(const_cast<InsetBranch &>(*this)));
 
        Toc & toc = buffer().tocBackend().toc("branch");
        docstring str = params_.branch + ": ";
@@ -316,7 +326,8 @@ void InsetBranchParams::write(ostream & os) const
 
 void InsetBranchParams::read(Lexer & lex)
 {
-       lex >> branch;
+       lex.eatLine();
+       branch = lex.getDocString();
 }
 
 } // namespace lyx