]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBranch.cpp
Stupid bug fix.
[lyx.git] / src / insets / InsetBranch.cpp
index 33397b71aaf43354a00cd5cc2d9be7727d0ea4d4..02537c05f60353e75903f4de61e51b2bca2ea906 100644 (file)
@@ -25,6 +25,7 @@
 #include "Lexer.h"
 #include "OutputParams.h"
 #include "TextClass.h"
+#include "TocBackend.h"
 
 #include "support/debug.h"
 #include "support/gettext.h"
@@ -81,9 +82,8 @@ void InsetBranch::setButtonLabel()
        if (!params_.branch.empty()) {
                // FIXME UNICODE
                ColorCode c = lcolor.getFromLyXName(to_utf8(params_.branch));
-               if (c == Color_none) {
+               if (c == Color_none)
                        s = _("Undef: ") + s;
-               }
        }
        if (decoration() == InsetLayout::Classic)
                setLabel(isOpen() ? s : getNewLabel(s) );
@@ -94,15 +94,13 @@ void InsetBranch::setButtonLabel()
 
 ColorCode InsetBranch::backgroundColor() const
 {
-       if (!params_.branch.empty()) {
-               // FIXME UNICODE
-               ColorCode c = lcolor.getFromLyXName(to_utf8(params_.branch));
-               if (c == Color_none) {
-                       c = Color_error;
-               }
-               return c;
-       } else
+       if (params_.branch.empty())
                return Inset::backgroundColor();
+       // FIXME UNICODE
+       ColorCode c = lcolor.getFromLyXName(to_utf8(params_.branch));
+       if (c == Color_none)
+               c = Color_error;
+       return c;
 }
 
 
@@ -168,20 +166,20 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
        switch (cmd.action) {
        case LFUN_INSET_MODIFY:
        case LFUN_INSET_DIALOG_UPDATE:
-               flag.enabled(true);
+               flag.setEnabled(true);
                break;
 
        case LFUN_INSET_TOGGLE:
                if (cmd.argument() == "open" || cmd.argument() == "close" ||
                    cmd.argument() == "toggle")
-                       flag.enabled(true);
+                       flag.setEnabled(true);
                else if (cmd.argument() == "assign" || cmd.argument().empty()) {
                        if (isBranchSelected())
-                               flag.enabled(status() != Open);
+                               flag.setEnabled(status() != Open);
                        else
-                               flag.enabled(status() != Collapsed);
+                               flag.setEnabled(status() != Collapsed);
                } else
-                       flag.enabled(true);
+                       flag.setEnabled(true);
                break;
 
        default:
@@ -195,26 +193,10 @@ bool InsetBranch::isBranchSelected() const
 {
        Buffer const & realbuffer = *buffer().masterBuffer();
        BranchList const & branchlist = realbuffer.params().branchlist();
-       BranchList::const_iterator const end = branchlist.end();
-       BranchList::const_iterator it =
-               find_if(branchlist.begin(), end,
-                            BranchNamesEqual(params_.branch));
-       if (it == end)
+       Branch const * ourBranch = branchlist.find(params_.branch);
+       if (!ourBranch)
                return false;
-       return it->getSelected();
-}
-
-
-void InsetBranch::updateLabels(ParIterator const & it)
-{
-       if (isBranchSelected())
-               InsetCollapsable::updateLabels(it);
-       else {
-               DocumentClass const & tclass = buffer().params().documentClass();
-               Counters savecnt = tclass.counters();
-               InsetCollapsable::updateLabels(it);
-               tclass.counters() = savecnt;
-       }
+       return ourBranch->getSelected();
 }
 
 
@@ -248,7 +230,7 @@ int InsetBranch::docbook(odocstream & os,
 void InsetBranch::textString(odocstream & os) const
 {
        if (isBranchSelected())
-               os << paragraphs().begin()->asString(true);
+               os << paragraphs().begin()->asString(AS_STR_LABEL | AS_STR_INSETS);
 }
 
 
@@ -283,26 +265,22 @@ void InsetBranch::string2params(string const & in, InsetBranchParams & params)
        istringstream data(in);
        Lexer lex;
        lex.setStream(data);
+       lex.setContext("InsetBranch::string2params");
+       lex >> "branch" >> "Branch";
+       params.read(lex);
+}
 
-       string name;
-       lex >> name;
-       if (name != "branch") {
-               LYXERR0("InsetBranch::string2params(" << in << ")\n"
-                                         "Expected arg 1 to be \"branch\"\n");
-               return;
-       }
-
-       // This is part of the inset proper that is usually swallowed
-       // by Text::readInset
-       string id;
-       lex >> id;
-       if (!lex || id != "Branch") {
-               LYXERR0("InsetBranch::string2params(" << in << ")\n"
-                                         "Expected arg 2 to be \"Branch\"\n");
-               return;
-       }
 
-       params.read(lex);
+void InsetBranch::addToToc(DocIterator const & cpit)
+{
+       DocIterator pit = cpit;
+       pit.push_back(CursorSlice(*this));
+
+       Toc & toc = buffer().tocBackend().toc("branch");
+       docstring const str = params_.branch + ": " + text_.getPar(0).asString();
+       toc.push_back(TocItem(pit, 0, str));
+       // Proceed with the rest of the inset.
+       InsetCollapsable::addToToc(cpit);
 }