X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetBranch.cpp;h=a3eb164d90cebef3d34c27be690e5ab67bdce3ac;hb=2c357c1d23b7b83839a9beb8225d4f1ae4f793b4;hp=3251090ff56c749c0bcab42b8f06c91597408bf9;hpb=39e79d8602920eefe36e898c9f415afb979521b2;p=lyx.git diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 3251090ff5..a3eb164d90 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -15,48 +15,33 @@ #include "Buffer.h" #include "BufferParams.h" #include "BranchList.h" -#include "LCursor.h" +#include "Color.h" +#include "Counters.h" +#include "Cursor.h" #include "DispatchResult.h" #include "FuncRequest.h" #include "FuncStatus.h" -#include "gettext.h" -#include "LColor.h" +#include "support/gettext.h" #include "Lexer.h" -#include "Paragraph.h" #include "OutputParams.h" +#include "TextClass.h" #include +using namespace std; namespace lyx { -using std::string; -using std::auto_ptr; -using std::istringstream; -using std::ostream; -using std::ostringstream; - - -void InsetBranch::init() -{ - setInsetName(from_utf8("Branch")); - setButtonLabel(); -} - InsetBranch::InsetBranch(BufferParams const & bp, InsetBranchParams const & params) : InsetCollapsable(bp), params_(params) -{ - init(); -} +{} InsetBranch::InsetBranch(InsetBranch const & in) : InsetCollapsable(in), params_(in.params_) -{ - init(); -} +{} InsetBranch::~InsetBranch() @@ -65,9 +50,9 @@ InsetBranch::~InsetBranch() } -auto_ptr InsetBranch::doClone() const +Inset * InsetBranch::clone() const { - return auto_ptr(new InsetBranch(*this)); + return new InsetBranch(*this); } @@ -88,30 +73,43 @@ void InsetBranch::read(Buffer const & buf, Lexer & lex) { params_.read(lex); InsetCollapsable::read(buf, lex); - setButtonLabel(); } -void InsetBranch::setButtonLabel() +docstring InsetBranch::toolTip(BufferView const & bv, int x, int y) const { - LyXFont font(LyXFont::ALL_SANE); - font.decSize(); - font.decSize(); + return _("Branch: ") + params_.branch; +} + +void InsetBranch::setButtonLabel() +{ docstring s = _("Branch: ") + params_.branch; - font.setColor(LColor::foreground); if (!params_.branch.empty()) { // FIXME UNICODE - LColor_color c = lcolor.getFromLyXName(to_utf8(params_.branch)); - if (c == LColor::none) { - c = LColor::error; + ColorCode c = lcolor.getFromLyXName(to_utf8(params_.branch)); + if (c == Color_none) { s = _("Undef: ") + s; } - setBackgroundColor(c); + } + if (decoration() == Deco_Classic) + setLabel(isOpen() ? s : getNewLabel(s) ); + else + setLabel(params_.branch + ": " + getNewLabel(s)); +} + + +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 - setBackgroundColor(LColor::background); - setLabel(isOpen() ? s : getNewLabel(s) ); - setLabelFont(font); + return Inset::backgroundColor(); } @@ -122,14 +120,14 @@ bool InsetBranch::showInsetDialog(BufferView * bv) const } -void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd) +void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action) { case LFUN_INSET_MODIFY: { InsetBranchParams params; InsetBranchMailer::string2params(to_utf8(cmd.argument()), params); params_.branch = params.branch; - setButtonLabel(); + setLayout(cur.buffer().params()); break; } @@ -153,7 +151,7 @@ void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_INSET_TOGGLE: - if (cmd.argument() == "assign" || cmd.argument().empty()) { + if (cmd.argument() == "assign") { // The branch inset uses "assign". if (isBranchSelected(cur.buffer())) { if (status() != Open) @@ -178,7 +176,7 @@ void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd) } -bool InsetBranch::getStatus(LCursor & cur, FuncRequest const & cmd, +bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action) { @@ -210,11 +208,11 @@ bool InsetBranch::getStatus(LCursor & 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; @@ -222,8 +220,21 @@ bool InsetBranch::isBranchSelected(Buffer const & buffer) const } +void InsetBranch::updateLabels(Buffer const & buf, ParIterator const & it) +{ + if (isBranchSelected(buf)) + InsetCollapsable::updateLabels(buf, it); + else { + TextClass const & tclass = buf.params().getTextClass(); + Counters savecnt = tclass.counters(); + InsetCollapsable::updateLabels(buf, it); + tclass.counters() = savecnt; + } +} + + int InsetBranch::latex(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const + OutputParams const & runparams) const { return isBranchSelected(buf) ? InsetText::latex(buf, os, runparams) : 0; @@ -231,12 +242,12 @@ int InsetBranch::latex(Buffer const & buf, odocstream & os, int InsetBranch::plaintext(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const + OutputParams const & runparams) const { if (!isBranchSelected(buf)) return 0; - os << '[' << _("branch") << ' ' << params_.branch << ":\n"; + os << '[' << buf.B_("branch") << ' ' << params_.branch << ":\n"; InsetText::plaintext(buf, os, runparams); os << "\n]"; @@ -245,7 +256,7 @@ int InsetBranch::plaintext(Buffer const & buf, odocstream & os, int InsetBranch::docbook(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const + OutputParams const & runparams) const { return isBranchSelected(buf) ? InsetText::docbook(buf, os, runparams) : 0; @@ -265,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"); @@ -305,7 +322,7 @@ void InsetBranchMailer::string2params(string const & in, return print_mailer_error("InsetBranchMailer", in, 1, name_); // This is part of the inset proper that is usually swallowed - // by LyXText::readInset + // by Text::readInset string id; lex >> id; if (!lex || id != "Branch")