]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetBranch.cpp
Completion: handle undo in insets' insertCompletion methods
[features.git] / src / insets / InsetBranch.cpp
index ad7cbc5cdc21fb6f83efc517a2be06a1842790b8..c25f16a0c4c66d3f49d16a09021ced9bf12f8f3b 100644 (file)
 #include "FuncStatus.h"
 #include "Lexer.h"
 #include "LyX.h"
-#include "OutputParams.h"
+#include "output_docbook.h"
 #include "output_xhtml.h"
 #include "TextClass.h"
 #include "TocBackend.h"
 
+#include "support/convert.h"
 #include "support/debug.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -111,8 +112,10 @@ docstring const InsetBranch::buttonLabel(BufferView const &) const
        if (inchild && master_selected != child_selected)
                symb += (child_selected ? tick : cross);
 
-       if (decoration() == InsetLayout::MINIMALISTIC)
-               return symb + params_.branch;
+       docstring inv_symb = from_ascii(params_.inverted ? "~" : "");
+
+       if (decoration() == InsetDecoration::MINIMALISTIC)
+               return symb + inv_symb + params_.branch;
 
        docstring s;
        if (inmaster && inchild)
@@ -123,7 +126,7 @@ docstring const InsetBranch::buttonLabel(BufferView const &) const
                s = _("Branch (master): ");
        else // !inmaster && !inchild
                s = _("Branch (undefined): ");
-       s += params_.branch;
+       s += inv_symb + params_.branch;
 
        return symb + s;
 }
@@ -133,8 +136,12 @@ ColorCode InsetBranch::backgroundColor(PainterInfo const & pi) const
 {
        if (params_.branch.empty())
                return Inset::backgroundColor(pi);
+       string const branch_id = (buffer().masterParams().branchlist().find(params_.branch))
+                       ? convert<string>(buffer().masterParams().branchlist().id())
+                       : convert<string>(buffer().params().branchlist().id());
        // FIXME UNICODE
-       ColorCode c = lcolor.getFromLyXName(to_utf8(params_.branch));
+       string const branchcol = "branch" + branch_id + to_utf8(params_.branch);
+       ColorCode c = lcolor.getFromLyXName(branchcol);
        if (c == Color_none)
                c = Color_error;
        return c;
@@ -217,9 +224,12 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_BRANCH_ADD:
                lyx::dispatch(FuncRequest(LFUN_BRANCH_ADD, params_.branch));
                break;
+       case LFUN_BRANCH_SYNC_ALL:
+               lyx::dispatch(FuncRequest(LFUN_INSET_FORALL, "Branch:" + params_.branch + " inset-toggle assign"));
+               break;
        case LFUN_INSET_TOGGLE:
                if (cmd.argument() == "assign")
-                       setStatus(cur, isBranchSelected() ? Open : Collapsed);
+                       setStatus(cur, (isBranchSelected(true) != params_.inverted) ? Open : Collapsed);
                else
                        InsetCollapsible::doDispatch(cur, cmd);
                break;
@@ -269,6 +279,10 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
                flag.setEnabled(buffer().parent() && isBranchSelected());
                break;
 
+       case LFUN_BRANCH_SYNC_ALL:
+               flag.setEnabled(known_branch);
+               break;
+
        case LFUN_INSET_TOGGLE:
                if (cmd.argument() == "assign")
                        flag.setEnabled(true);
@@ -307,10 +321,13 @@ bool InsetBranch::producesOutput() const
 
 void InsetBranch::latex(otexstream & os, OutputParams const & runparams) const
 {
-       if (producesOutput()) {
+       if (producesOutput() || runparams.find_with_non_output()) {
                OutputParams rp = runparams;
                rp.inbranch = true;
                InsetText::latex(os, rp);
+               // These need to be passed upstream
+               runparams.need_maketitle = rp.need_maketitle;
+               runparams.have_maketitle = rp.have_maketitle;
        }
 }
 
@@ -318,7 +335,7 @@ void InsetBranch::latex(otexstream & os, OutputParams const & runparams) const
 int InsetBranch::plaintext(odocstringstream & os,
                           OutputParams const & runparams, size_t max_length) const
 {
-       if (!producesOutput())
+       if (!producesOutput() && !runparams.find_with_non_output())
                return 0;
 
        int len = InsetText::plaintext(os, runparams, max_length);
@@ -326,14 +343,18 @@ int InsetBranch::plaintext(odocstringstream & os,
 }
 
 
-int InsetBranch::docbook(odocstream & os,
-                        OutputParams const & runparams) const
+void InsetBranch::docbook(XMLStream & xs, OutputParams const & runparams) const
 {
-       return producesOutput() ?  InsetText::docbook(os, runparams) : 0;
+       if (producesOutput()) {
+               OutputParams rp = runparams;
+               rp.par_begin = 0;
+               rp.par_end = text().paragraphs().size();
+               docbookParagraphs(text(), buffer(), xs, rp);
+       }
 }
 
 
-docstring InsetBranch::xhtml(XHTMLStream & xs, OutputParams const & rp) const
+docstring InsetBranch::xhtml(XMLStream & xs, OutputParams const & rp) const
 {
        if (producesOutput()) {
                OutputParams newrp = rp;