X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetbranch.C;h=d39d69c718adfa5716e679c9fdecbfba235e1e53;hb=e28331ed63062dea10d0a21b9ec12034b4b17b9a;hp=40003e9687fb868ae5b045da23045238f2c81c1e;hpb=ccc5d5576437a7615f54bf1ed6e83e05bfbaaf78;p=lyx.git diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index 40003e9687..d39d69c718 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -18,12 +18,16 @@ #include "cursor.h" #include "dispatchresult.h" #include "funcrequest.h" +#include "FuncStatus.h" #include "gettext.h" #include "LColor.h" #include "lyxlex.h" #include "paragraph.h" -#include "support/std_sstream.h" +#include + + +namespace lyx { using std::string; using std::auto_ptr; @@ -34,7 +38,7 @@ using std::ostringstream; void InsetBranch::init() { - setInsetName("Branch"); + setInsetName(from_utf8("Branch")); setButtonLabel(); } @@ -60,13 +64,13 @@ InsetBranch::~InsetBranch() } -auto_ptr InsetBranch::clone() const +auto_ptr InsetBranch::doClone() const { return auto_ptr(new InsetBranch(*this)); } -string const InsetBranch::editMessage() const +docstring const InsetBranch::editMessage() const { return _("Opened Branch Inset"); } @@ -93,12 +97,19 @@ void InsetBranch::setButtonLabel() font.decSize(); font.decSize(); - setLabel("Branch: " + params_.branch); + 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); } @@ -110,42 +121,96 @@ bool InsetBranch::showInsetDialog(BufferView * bv) const } -DispatchResult -InsetBranch::priv_dispatch(LCursor & cur, FuncRequest const & cmd) +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(); - return DispatchResult(true, true); + break; } case LFUN_MOUSE_PRESS: if (cmd.button() != mouse_button::button3) - return InsetCollapsable::priv_dispatch(cur, cmd); - return DispatchResult(false); + InsetCollapsable::doDispatch(cur, cmd); + else + cur.undispatched(); + break; case LFUN_INSET_DIALOG_UPDATE: InsetBranchMailer(*this).updateDialog(&cur.bv()); - return DispatchResult(true); + break; case LFUN_MOUSE_RELEASE: - if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { + if (cmd.button() == mouse_button::button3 && hitButton(cmd)) InsetBranchMailer(*this).showDialog(&cur.bv()); - return DispatchResult(true); + else + InsetCollapsable::doDispatch(cur, cmd); + break; + + + case LFUN_INSET_TOGGLE: + if (cmd.argument() == "assign" || cmd.argument().empty()) { + // The branch inset uses "assign". + if (isBranchSelected(cur.buffer())) { + if (status() != Open) + setStatus(cur, Open); + else + cur.undispatched(); + } else { + if (status() != Collapsed) + setStatus(cur, Collapsed); + else + cur.undispatched(); + } } - return InsetCollapsable::priv_dispatch(cur, cmd); + else + InsetCollapsable::doDispatch(cur, cmd); + break; + + default: + InsetCollapsable::doDispatch(cur, cmd); + break; + } +} + + +bool InsetBranch::getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & flag) const +{ + switch (cmd.action) { + case LFUN_INSET_MODIFY: + case LFUN_INSET_DIALOG_UPDATE: + flag.enabled(true); + break; + + case LFUN_INSET_TOGGLE: + if (cmd.argument() == "open" || cmd.argument() == "close" || + cmd.argument() == "toggle") + flag.enabled(true); + 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; default: - return InsetCollapsable::priv_dispatch(cur, cmd); + return InsetCollapsable::getStatus(cur, cmd, flag); } + return true; } -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, @@ -156,46 +221,45 @@ 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()) ? - inset.latex(buf, os, runparams) : 0; + return isBranchSelected(buf) ? + InsetText::latex(buf, os, runparams) : 0; } -int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os, - OutputParams const & runparams) const +int InsetBranch::docbook(Buffer const & buf, odocstream & os, + OutputParams const & runparams) const { - return isBranchSelected(buf.params().branchlist()) ? - inset.linuxdoc(buf, os, runparams) : 0; + return isBranchSelected(buf) ? + InsetText::docbook(buf, os, runparams) : 0; } -int InsetBranch::docbook(Buffer const & buf, std::ostream & os, - OutputParams const & runparams) const +int InsetBranch::plaintext(Buffer const & buf, odocstream & os, + OutputParams const & runparams) const { - return isBranchSelected(buf.params().branchlist()) ? - inset.docbook(buf, os, runparams) : 0; + return isBranchSelected(buf) ? + InsetText::plaintext(buf, os, runparams): 0; } -int InsetBranch::plaintext(Buffer const & buf, std::ostream & os, - OutputParams const & runparams) const +void InsetBranch::textString(Buffer const & buf, odocstream & os) const { - return isBranchSelected(buf.params().branchlist()) ? - inset.plaintext(buf, os, runparams): 0; + if (isBranchSelected(buf)) + os << paragraphs().begin()->asString(buf, true); } void InsetBranch::validate(LaTeXFeatures & features) const { - inset.validate(features); + InsetText::validate(features); } -string const InsetBranchMailer:: name_("branch"); +string const InsetBranchMailer::name_("branch"); InsetBranchMailer::InsetBranchMailer(InsetBranch & inset) : inset_(inset) @@ -246,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'; } @@ -254,3 +318,5 @@ void InsetBranchParams::read(LyXLex & lex) { lex >> branch; } + +} // namespace lyx