]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBranch.cpp
This should be the last of the commits refactoring the InsetLayout code.
[lyx.git] / src / insets / InsetBranch.cpp
index 3510d4bdaa4dbfef2b0326532e176ba370bb554e..a3eb164d90cebef3d34c27be690e5ab67bdce3ac 100644 (file)
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BranchList.h"
+#include "Color.h"
 #include "Counters.h"
 #include "Cursor.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "gettext.h"
-#include "Color.h"
+#include "support/gettext.h"
 #include "Lexer.h"
 #include "OutputParams.h"
+#include "TextClass.h"
 
 #include <sstream>
 
+using namespace std;
 
 namespace lyx {
 
-using std::string;
-using std::istringstream;
-using std::ostream;
-using std::ostringstream;
-
-
-void InsetBranch::init()
-{
-       setButtonLabel();
-}
-
 
 InsetBranch::InsetBranch(BufferParams const & bp,
                         InsetBranchParams const & params)
        : InsetCollapsable(bp), params_(params)
-{
-       setLayout(bp);
-       init();
-}
+{}
 
 
 InsetBranch::InsetBranch(InsetBranch const & in)
        : InsetCollapsable(in), params_(in.params_)
-{
-       init();
-}
+{}
 
 
 InsetBranch::~InsetBranch()
@@ -87,8 +73,12 @@ void InsetBranch::read(Buffer const & buf, Lexer & lex)
 {
        params_.read(lex);
        InsetCollapsable::read(buf, lex);
-       setLayout(buf.params());
-       setButtonLabel();
+}
+
+
+docstring InsetBranch::toolTip(BufferView const & bv, int x, int y) const
+{
+       return _("Branch: ") + params_.branch;
 }
 
 
@@ -97,22 +87,25 @@ void InsetBranch::setButtonLabel()
        docstring s = _("Branch: ") + params_.branch;
        if (!params_.branch.empty()) {
                // FIXME UNICODE
-               Color_color c = lcolor.getFromLyXName(to_utf8(params_.branch));
-               if (c == Color::none) {
+               ColorCode c = lcolor.getFromLyXName(to_utf8(params_.branch));
+               if (c == Color_none) {
                        s = _("Undef: ") + s;
                }
        }
-       setLabel(isOpen() ? s : getNewLabel(s) );
+       if (decoration() == Deco_Classic)
+               setLabel(isOpen() ? s : getNewLabel(s) );
+       else
+               setLabel(params_.branch + ": " + getNewLabel(s));
 }
 
 
-Color_color InsetBranch::backgroundColor() const
+ColorCode InsetBranch::backgroundColor() const
 {
        if (!params_.branch.empty()) {
                // FIXME UNICODE
-               Color_color c = lcolor.getFromLyXName(to_utf8(params_.branch));
-               if (c == Color::none) {
-                       c = Color::error;
+               ColorCode c = lcolor.getFromLyXName(to_utf8(params_.branch));
+               if (c == Color_none) {
+                       c = Color_error;
                }
                return c;
        } else
@@ -135,7 +128,6 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
                InsetBranchMailer::string2params(to_utf8(cmd.argument()), params);
                params_.branch = params.branch;
                setLayout(cur.buffer().params());
-               setButtonLabel();
                break;
        }
 
@@ -216,11 +208,11 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 bool InsetBranch::isBranchSelected(Buffer const & buffer) const
 {
-       Buffer const & realbuffer = *buffer.getMasterBuffer();
+       Buffer const & realbuffer = *buffer.masterBuffer();
        BranchList const & branchlist = realbuffer.params().branchlist();
        BranchList::const_iterator const end = branchlist.end();
        BranchList::const_iterator it =
-               std::find_if(branchlist.begin(), end,
+               find_if(branchlist.begin(), end,
                             BranchNamesEqual(params_.branch));
        if (it == end)
                return false;
@@ -284,6 +276,12 @@ void InsetBranch::validate(LaTeXFeatures & features) const
 }
 
 
+bool InsetBranch::isMacroScope(Buffer const & buf) const 
+{
+       // Its own scope if not selected by buffer
+       return !isBranchSelected(buf);
+}
+
 
 string const InsetBranchMailer::name_("branch");