]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBranch.cpp
Stupid bug fix.
[lyx.git] / src / insets / InsetBranch.cpp
index 85e5a2a472a23be7e8dc12d84892c94518bca246..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,13 +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();
+       return ourBranch->getSelected();
 }
 
 
@@ -276,6 +271,19 @@ void InsetBranch::string2params(string const & in, InsetBranchParams & params)
 }
 
 
+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);
+}
+
+
 void InsetBranchParams::write(ostream & os) const
 {
        os << "Branch " << to_utf8(branch) << '\n';