X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetnote.C;h=b840955032cdb0b16831769f57f38ed2e1158825;hb=e28331ed63062dea10d0a21b9ec12034b4b17b9a;hp=a9b0cb966219da60a2e07f59e3b712c59f6ec150;hpb=5198e1d9a383d60f915092f17661f98f59998ed0;p=lyx.git diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index a9b0cb9662..b840955032 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -18,18 +18,24 @@ #include "cursor.h" #include "debug.h" #include "dispatchresult.h" +#include "exporter.h" #include "funcrequest.h" +#include "FuncStatus.h" #include "gettext.h" #include "LaTeXFeatures.h" #include "LColor.h" #include "lyxlex.h" #include "metricsinfo.h" +#include "outputparams.h" #include "paragraph.h" #include "support/lyxalgo.h" -#include "support/std_sstream.h" #include "support/translator.h" +#include + + +namespace lyx { using std::string; using std::auto_ptr; @@ -41,31 +47,40 @@ using std::ostringstream; namespace { typedef Translator NoteTranslator; +typedef Translator NoteTranslatorLoc; -NoteTranslator const init_notetranslator() { +NoteTranslator const init_notetranslator() +{ NoteTranslator translator("Note", InsetNoteParams::Note); translator.addPair("Comment", InsetNoteParams::Comment); translator.addPair("Greyedout", InsetNoteParams::Greyedout); + translator.addPair("Framed", InsetNoteParams::Framed); + translator.addPair("Shaded", InsetNoteParams::Shaded); return translator; } -NoteTranslator const init_notetranslator_loc() { - NoteTranslator translator(_("Note"), InsetNoteParams::Note); +NoteTranslatorLoc const init_notetranslator_loc() +{ + NoteTranslatorLoc translator(_("Note"), InsetNoteParams::Note); translator.addPair(_("Comment"), InsetNoteParams::Comment); translator.addPair(_("Greyed out"), InsetNoteParams::Greyedout); + translator.addPair(_("Framed"), InsetNoteParams::Framed); + translator.addPair(_("Shaded"), InsetNoteParams::Shaded); return translator; } -NoteTranslator const & notetranslator() { +NoteTranslator const & notetranslator() +{ static NoteTranslator translator = init_notetranslator(); return translator; } -NoteTranslator const & notetranslator_loc() { - static NoteTranslator translator = init_notetranslator_loc(); +NoteTranslatorLoc const & notetranslator_loc() +{ + static NoteTranslatorLoc translator = init_notetranslator_loc(); return translator; } @@ -97,7 +112,7 @@ void InsetNoteParams::read(LyXLex & lex) void InsetNote::init() { - setInsetName("Note"); + setInsetName(from_ascii("Note")); setButtonLabel(); } @@ -123,13 +138,13 @@ InsetNote::~InsetNote() } -auto_ptr InsetNote::clone() const +auto_ptr InsetNote::doClone() const { return auto_ptr(new InsetNote(*this)); } -string const InsetNote::editMessage() const +docstring const InsetNote::editMessage() const { return _("Opened Note Inset"); } @@ -152,7 +167,7 @@ void InsetNote::read(Buffer const & buf, LyXLex & lex) void InsetNote::setButtonLabel() { - string const label = notetranslator_loc().find(params_.type); + docstring const label = notetranslator_loc().find(params_.type); setLabel(label); LyXFont font(LyXFont::ALL_SANE); @@ -172,6 +187,14 @@ void InsetNote::setButtonLabel() font.setColor(LColor::greyedout); setBackgroundColor(LColor::greyedoutbg); break; + case InsetNoteParams::Framed: + font.setColor(LColor::greyedout); + setBackgroundColor(LColor::greyedoutbg); + break; + case InsetNoteParams::Shaded: + font.setColor(LColor::greyedout); + setBackgroundColor(LColor::shadedbg); + break; } setLabelFont(font); } @@ -184,14 +207,13 @@ bool InsetNote::showInsetDialog(BufferView * bv) const } -void InsetNote::priv_dispatch(LCursor & cur, FuncRequest & cmd) +void InsetNote::doDispatch(LCursor & cur, FuncRequest & cmd) { switch (cmd.action) { case LFUN_INSET_MODIFY: - InsetNoteMailer::string2params(cmd.argument, params_); + InsetNoteMailer::string2params(to_utf8(cmd.argument()), params_); setButtonLabel(); - cur.bv().update(); break; case LFUN_INSET_DIALOG_UPDATE: @@ -202,99 +224,120 @@ void InsetNote::priv_dispatch(LCursor & cur, FuncRequest & cmd) if (cmd.button() == mouse_button::button3 && hitButton(cmd)) InsetNoteMailer(*this).showDialog(&cur.bv()); else - InsetCollapsable::priv_dispatch(cur, cmd); + InsetCollapsable::doDispatch(cur, cmd); break; default: - InsetCollapsable::priv_dispatch(cur, cmd); + InsetCollapsable::doDispatch(cur, cmd); break; } } -int InsetNote::latex(Buffer const & buf, ostream & os, - OutputParams const & runparams) const +bool InsetNote::getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & flag) const { - if (params_.type == InsetNoteParams::Note) - return 0; - - string type; - if (params_.type == InsetNoteParams::Comment) - type = "comment"; - else if (params_.type == InsetNoteParams::Greyedout) - type = "lyxgreyedout"; + switch (cmd.action) { - ostringstream ss; - ss << "%\n\\begin{" << type << "}\n"; - inset.latex(buf, ss, runparams); - ss << "%\n\\end{" << type << "}\n"; + case LFUN_INSET_MODIFY: + case LFUN_INSET_DIALOG_UPDATE: + flag.enabled(true); + return true; - string const str = ss.str(); - os << str; - // Return how many newlines we issued. - return int(lyx::count(str.begin(), str.end(),'\n') + 1); + default: + return InsetCollapsable::getStatus(cur, cmd, flag); + } } -int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os, - OutputParams const & runparams) const +int InsetNote::latex(Buffer const & buf, odocstream & os, + OutputParams const & runparams_in) const { if (params_.type == InsetNoteParams::Note) return 0; - ostringstream ss; - if (params_.type == InsetNoteParams::Comment) - ss << "\n"; - - inset.linuxdoc(buf, ss, runparams); - + OutputParams runparams(runparams_in); + string type; + if (params_.type == InsetNoteParams::Comment) { + type = "comment"; + runparams.inComment = true; + // Ignore files that are exported inside a comment + runparams.exportdata.reset(new ExportData); + } else if (params_.type == InsetNoteParams::Greyedout) + type = "lyxgreyedout"; + else if (params_.type == InsetNoteParams::Framed) + type = "framed"; + else if (params_.type == InsetNoteParams::Shaded) + type = "shaded"; + + odocstringstream ss; + ss << "%\n\\begin{" << from_ascii(type) << "}\n"; + InsetText::latex(buf, ss, runparams); + ss << "\n\\end{" << from_ascii(type) << "}\n"; + // the space after the comment in 'a[comment] b' will be eaten by the + // comment environment since the space before b is ignored with the + // following latex output: + // + // a% + // \begin{comment} + // comment + // \end{comment} + // b + // + // Adding {} before ' b' fixes this. if (params_.type == InsetNoteParams::Comment) - ss << "\n\n"; + ss << "{}"; - string const str = ss.str(); + docstring const str = ss.str(); os << str; // Return how many newlines we issued. - return int(lyx::count(str.begin(), str.end(),'\n') + 1); + return int(lyx::count(str.begin(), str.end(), '\n')); } -int InsetNote::docbook(Buffer const & buf, std::ostream & os, - OutputParams const & runparams) const +int InsetNote::docbook(Buffer const & buf, odocstream & os, + OutputParams const & runparams_in) const { if (params_.type == InsetNoteParams::Note) return 0; - ostringstream ss; - if (params_.type == InsetNoteParams::Comment) - ss << "\n"; + OutputParams runparams(runparams_in); + if (params_.type == InsetNoteParams::Comment) { + os << "\n"; + runparams.inComment = true; + // Ignore files that are exported inside a comment + runparams.exportdata.reset(new ExportData); + } - inset.docbook(buf, ss, runparams); + int const n = InsetText::docbook(buf, os, runparams); if (params_.type == InsetNoteParams::Comment) - ss << "\n\n"; + os << "\n\n"; - string const str = ss.str(); - os << str; // Return how many newlines we issued. - return int(lyx::count(str.begin(), str.end(),'\n') + 1); + //return int(count(str.begin(), str.end(), '\n')); + return n + 1 + 2; } -int InsetNote::plaintext(Buffer const & buf, std::ostream & os, - OutputParams const & runparams) const +int InsetNote::plaintext(Buffer const & buf, odocstream & os, + OutputParams const & runparams_in) const { if (params_.type == InsetNoteParams::Note) return 0; - ostringstream ss; - ss << "["; - inset.plaintext(buf, ss, runparams); - ss << "]"; + OutputParams runparams(runparams_in); + if (params_.type == InsetNoteParams::Comment) { + runparams.inComment = true; + // Ignore files that are exported inside a comment + runparams.exportdata.reset(new ExportData); + } + os << "["; + int const nlines = InsetText::plaintext(buf, os, runparams); + os << "]"; - string const str = ss.str(); - os << str; // Return how many newlines we issued. - return int(lyx::count(str.begin(), str.end(),'\n') + 1); + return nlines; } @@ -306,12 +349,18 @@ void InsetNote::validate(LaTeXFeatures & features) const features.require("color"); features.require("lyxgreyedout"); } - inset.validate(features); + if (params_.type == InsetNoteParams::Shaded) { + features.require("color"); + features.require("framed"); + } + if (params_.type == InsetNoteParams::Framed) + features.require("framed"); + InsetText::validate(features); } -string const InsetNoteMailer:: name_("note"); +string const InsetNoteMailer::name_("note"); InsetNoteMailer::InsetNoteMailer(InsetNote & inset) : inset_(inset) @@ -359,3 +408,6 @@ void InsetNoteMailer::string2params(string const & in, params.read(lex); } + + +} // namespace lyx