X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetBranch.cpp;h=6ab2fb79e73e5712a08c3face65b7bafc933eb6c;hb=55a3dd7b346d29a52ba305a4558e9e380ef50f47;hp=5e943a7ff1298e18d6d8b71c2b90ef7095a6b5df;hpb=bad0d577e8bb35c68b1f2395968a5be4090e2023;p=lyx.git diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 5e943a7ff1..6ab2fb79e7 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -62,17 +62,15 @@ void InsetBranch::read(Lexer & lex) } -docstring InsetBranch::toolTip(BufferView const & bv, int x, int y) const +docstring InsetBranch::toolTip(BufferView const & bv, int, int) const { docstring const status = isBranchSelected() ? _("active") : _("non-active"); docstring const heading = support::bformat(_("Branch (%1$s): %2$s"), status, params_.branch); - docstring const contents = InsetCollapsable::toolTip(bv, x, y); - if (isOpen(bv) || contents.empty()) + if (isOpen(bv)) return heading; - else - return heading + from_ascii("\n") + contents; + return toolTipText(heading + from_ascii("\n")); } @@ -114,26 +112,43 @@ ColorCode InsetBranch::backgroundColor(PainterInfo const & pi) const void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) { - switch (cmd.action) { + switch (cmd.action()) { case LFUN_INSET_MODIFY: { InsetBranchParams params; InsetBranch::string2params(to_utf8(cmd.argument()), params); + + cur.recordUndoInset(ATOMIC_UNDO, this); params_.branch = params.branch; + // what we really want here is a TOC update, but that means + // a full buffer update + cur.forceBufferUpdate(); break; } 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(branchlist.find(params_.branch)); - if (!our_branch) { + Buffer * buf = const_cast(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(); } - our_branch->setSelected(cmd.action == LFUN_BRANCH_ACTIVATE); break; } case LFUN_INSET_TOGGLE: @@ -153,7 +168,7 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { - switch (cmd.action) { + switch (cmd.action()) { case LFUN_INSET_MODIFY: flag.setEnabled(true); break; @@ -171,6 +186,7 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd, flag.setEnabled(true); else return InsetCollapsable::getStatus(cur, cmd, flag); + break; default: return InsetCollapsable::getStatus(cur, cmd, flag); @@ -195,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); } @@ -207,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; } @@ -224,16 +238,27 @@ 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(); } -void InsetBranch::tocString(odocstream & os) const +void InsetBranch::toString(odocstream & os) const +{ + if (isBranchSelected()) + InsetCollapsable::toString(os); +} + + +void InsetBranch::forToc(docstring & os, size_t maxlen) const { if (isBranchSelected()) - InsetCollapsable::tocString(os); + InsetCollapsable::forToc(os, maxlen); } @@ -244,9 +269,9 @@ void InsetBranch::validate(LaTeXFeatures & features) const } -docstring InsetBranch::contextMenu(BufferView const &, int, int) const +string InsetBranch::contextMenuName() const { - return from_ascii("context-branch"); + return "context-branch"; } @@ -279,14 +304,15 @@ 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(*this))); Toc & toc = buffer().tocBackend().toc("branch"); - docstring const str = params_.branch + ": " + text().getPar(0).asString(); - toc.push_back(TocItem(pit, 0, str)); + docstring str = params_.branch + ": "; + text().forToc(str, TOC_ENTRY_LENGTH); + toc.push_back(TocItem(pit, 0, str, toolTipText(docstring(), 3, 60))); // Proceed with the rest of the inset. InsetCollapsable::addToToc(cpit); } @@ -300,7 +326,8 @@ void InsetBranchParams::write(ostream & os) const void InsetBranchParams::read(Lexer & lex) { - lex >> branch; + lex.eatLine(); + branch = lex.getDocString(); } } // namespace lyx