X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetbranch.C;h=d39d69c718adfa5716e679c9fdecbfba235e1e53;hb=e28331ed63062dea10d0a21b9ec12034b4b17b9a;hp=c2fc42df2ca42e1301f3ab9e3e60d1d134b5dee7;hpb=323cafa18c2315759087d976e800aebd894fb40f;p=lyx.git diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index c2fc42df2c..d39d69c718 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -26,6 +26,9 @@ #include + +namespace lyx { + using std::string; using std::auto_ptr; using std::istringstream; @@ -35,7 +38,7 @@ using std::ostringstream; void InsetBranch::init() { - setInsetName("Branch"); + setInsetName(from_utf8("Branch")); setButtonLabel(); } @@ -67,7 +70,7 @@ auto_ptr InsetBranch::doClone() const } -string const InsetBranch::editMessage() const +docstring const InsetBranch::editMessage() const { return _("Opened Branch Inset"); } @@ -94,13 +97,19 @@ void InsetBranch::setButtonLabel() font.decSize(); font.decSize(); - string s = "Branch: " + params_.branch; - setLabel(isOpen() ? s : getNewLabel(s) ); + docstring s = _("Branch: ") + params_.branch; font.setColor(LColor::foreground); - if (!params_.branch.empty()) - setBackgroundColor(lcolor.getFromLyXName(params_.branch)); - else + if (!params_.branch.empty()) { + // FIXME UNICODE + LColor_color c = lcolor.getFromLyXName(to_utf8(params_.branch)); + if (c == LColor::none) { + c = LColor::error; + s = _("Undef: ") + s; + } + setBackgroundColor(c); + } else setBackgroundColor(LColor::background); + setLabel(isOpen() ? s : getNewLabel(s) ); setLabelFont(font); } @@ -117,7 +126,7 @@ void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd) switch (cmd.action) { case LFUN_INSET_MODIFY: { InsetBranchParams params; - InsetBranchMailer::string2params(cmd.argument, params); + InsetBranchMailer::string2params(to_utf8(cmd.argument()), params); params_.branch = params.branch; setButtonLabel(); break; @@ -143,39 +152,22 @@ void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_INSET_TOGGLE: - // We assume that this lfun is indeed going to be dispatched. - cur.dispatched(); - - if (cmd.argument == "open") - setStatus(Open); - else if (cmd.argument == "close") { - setStatus(Collapsed); - leaveInset(cur, *this); - } else if (cmd.argument == "toggle") { - if (isOpen()) { - setStatus(Collapsed); - leaveInset(cur, *this); - } else - setStatus(Open); - - // The branch inset uses "assign". - } else if (cmd.argument == "assign" - || cmd.argument.empty()) { - BranchList const & branchlist = - cur.buffer().params().branchlist(); - if (isBranchSelected(branchlist)) { + if (cmd.argument() == "assign" || cmd.argument().empty()) { + // The branch inset uses "assign". + if (isBranchSelected(cur.buffer())) { if (status() != Open) - setStatus(Open); + setStatus(cur, Open); else cur.undispatched(); } else { - if (status() != Collapsed) { - setStatus(Collapsed); - leaveInset(cur, *this); - } else + if (status() != Collapsed) + setStatus(cur, Collapsed); + else cur.undispatched(); } } + else + InsetCollapsable::doDispatch(cur, cmd); break; default: @@ -195,24 +187,15 @@ bool InsetBranch::getStatus(LCursor & cur, FuncRequest const & cmd, break; case LFUN_INSET_TOGGLE: - if (cmd.argument == "open" || cmd.argument == "close" || - cmd.argument == "toggle") + if (cmd.argument() == "open" || cmd.argument() == "close" || + cmd.argument() == "toggle") flag.enabled(true); - else if (cmd.argument == "assign" - || cmd.argument.empty()) { - BranchList const & branchlist = - cur.buffer().params().branchlist(); - if (isBranchSelected(branchlist)) { - if (status() != Open) - flag.enabled(true); - else - flag.enabled(false); - } else { - if (status() != Collapsed) - flag.enabled(true); - else - flag.enabled(false); - } + else if (cmd.argument() == "assign" + || cmd.argument().empty()) { + if (isBranchSelected(cur.buffer())) + flag.enabled(status() != Open); + else + flag.enabled(status() != Collapsed); } else flag.enabled(true); break; @@ -224,8 +207,10 @@ bool InsetBranch::getStatus(LCursor & cur, FuncRequest const & cmd, } -bool InsetBranch::isBranchSelected(BranchList const & branchlist) const +bool InsetBranch::isBranchSelected(Buffer const & buffer) const { + Buffer const & realbuffer = *buffer.getMasterBuffer(); + BranchList const & branchlist = realbuffer.params().branchlist(); BranchList::const_iterator const end = branchlist.end(); BranchList::const_iterator it = std::find_if(branchlist.begin(), end, @@ -236,38 +221,37 @@ bool InsetBranch::isBranchSelected(BranchList const & branchlist) const } -int InsetBranch::latex(Buffer const & buf, ostream & os, +int InsetBranch::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { - return isBranchSelected(buf.params().branchlist()) ? + return isBranchSelected(buf) ? InsetText::latex(buf, os, runparams) : 0; } -int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os, - OutputParams const & runparams) const -{ - return isBranchSelected(buf.params().branchlist()) ? - InsetText::linuxdoc(buf, os, runparams) : 0; -} - - -int InsetBranch::docbook(Buffer const & buf, std::ostream & os, +int InsetBranch::docbook(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { - return isBranchSelected(buf.params().branchlist()) ? + return isBranchSelected(buf) ? InsetText::docbook(buf, os, runparams) : 0; } -int InsetBranch::plaintext(Buffer const & buf, std::ostream & os, +int InsetBranch::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { - return isBranchSelected(buf.params().branchlist()) ? + return isBranchSelected(buf) ? InsetText::plaintext(buf, os, runparams): 0; } +void InsetBranch::textString(Buffer const & buf, odocstream & os) const +{ + if (isBranchSelected(buf)) + os << paragraphs().begin()->asString(buf, true); +} + + void InsetBranch::validate(LaTeXFeatures & features) const { InsetText::validate(features); @@ -326,7 +310,7 @@ void InsetBranchMailer::string2params(string const & in, void InsetBranchParams::write(ostream & os) const { - os << "Branch " << branch << '\n'; + os << "Branch " << to_utf8(branch) << '\n'; } @@ -334,3 +318,5 @@ void InsetBranchParams::read(LyXLex & lex) { lex >> branch; } + +} // namespace lyx