X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCommand.cpp;h=9ca958b5f880857c6195614fa93dcdf9d14cc50c;hb=3a949b32f08ce4884906a9c5d47c4d7031c794b2;hp=1c9a170b11214caf6d2387b369ee0205ea1dfeb5;hpb=7287a259c5436b8f3f384c0d0bd7641a2f2601e9;p=lyx.git diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp index 1c9a170b11..9ca958b5f8 100644 --- a/src/insets/InsetCommand.cpp +++ b/src/insets/InsetCommand.cpp @@ -14,57 +14,73 @@ #include "InsetCommand.h" #include "Buffer.h" +#include "BufferEncodings.h" +#include "BufferParams.h" #include "BufferView.h" #include "Cursor.h" -#include "DispatchResult.h" #include "FuncRequest.h" #include "FuncStatus.h" #include "Lexer.h" +#include "LyX.h" #include "MetricsInfo.h" +#include "texstream.h" #include "insets/InsetBox.h" #include "insets/InsetBranch.h" -#include "insets/InsetCommand.h" #include "insets/InsetERT.h" #include "insets/InsetExternal.h" #include "insets/InsetFloat.h" #include "insets/InsetGraphics.h" #include "insets/InsetIndex.h" -#include "insets/InsetLine.h" #include "insets/InsetListings.h" #include "insets/InsetNote.h" #include "insets/InsetPhantom.h" #include "insets/InsetSpace.h" -#include "insets/InsetTabular.h" #include "insets/InsetVSpace.h" #include "insets/InsetWrap.h" #include "support/debug.h" -#include "support/gettext.h" +#include "support/lstrings.h" #include "frontends/Application.h" #include using namespace std; +using namespace lyx::support; namespace lyx { -// FIXME Would it now be possible to use the InsetCode in +// FIXME Would it now be possible to use the InsetCode in // place of the mailer name and recover that information? InsetCommand::InsetCommand(Buffer * buf, InsetCommandParams const & p) - : Inset(buf), p_(p) + : Inset(buf), p_(p), broken_(false) {} // The sole purpose of this copy constructor is to make sure // that the mouse_hover_ map is not copied and remains empty. InsetCommand::InsetCommand(InsetCommand const & rhs) - : Inset(rhs), p_(rhs.p_) + : Inset(rhs), p_(rhs.p_), broken_(false) {} +InsetCommand & InsetCommand::operator=(InsetCommand const & rhs) +{ + if (&rhs == this) + return *this; + + Inset::operator=(rhs); + p_ = rhs.p_; + mouse_hover_.clear(); + button_ = RenderButton(); + broken_ = false; + + return *this; +} + + InsetCommand::~InsetCommand() { if (p_.code() != NO_CODE) @@ -80,7 +96,8 @@ InsetCommand::~InsetCommand() void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const { - button_.update(screenLabel(), editable() || hasSettings()); + button_.update(screenLabel(), editable() || clickable(*mi.base.bv, 0, 0), + inheritFont(), broken_); button_.metrics(mi, dim); } @@ -122,11 +139,16 @@ void InsetCommand::setParams(InsetCommandParams const & p) void InsetCommand::latex(otexstream & os, OutputParams const & runparams_in) const { OutputParams runparams = runparams_in; - os << getCommand(runparams); + docstring command = getCommand(runparams); + if (buffer().params().use_minted + && prefixIs(command, from_ascii("\\lstlistoflistings"))) + command.erase(1, 3); + os << command; } -int InsetCommand::plaintext(odocstream & os, OutputParams const &) const +int InsetCommand::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { docstring const str = "[" + buffer().B_("LaTeX Command: ") + from_utf8(getCmdName()) + "]"; @@ -135,9 +157,49 @@ int InsetCommand::plaintext(odocstream & os, OutputParams const &) const } -int InsetCommand::docbook(odocstream &, OutputParams const &) const +void InsetCommand::docbook(XMLStream &, OutputParams const &) const { - return 0; + return; +} + + +void InsetCommand::validate(LaTeXFeatures & features) const +{ + if (params().info().hasParam("literal") + && params()["literal"] == "true") + return; + + ParamInfo::const_iterator it = params().info().begin(); + ParamInfo::const_iterator end = params().info().end(); + for (; it != end; ++it) { + if (it->handling() == ParamInfo::HANDLING_LATEXIFY) { + docstring const text = params()[it->name()]; + // Validate the contents (if we LaTeXify, specific + // macros might require packages) + for (pos_type i = 0; i < int(text.size()) ; ++i) + BufferEncodings::validate(text[i], features); + } + } +} + + +void InsetCommand::changeCmdName(string const & new_name) +{ + string const & old_name = getCmdName(); + if (old_name == new_name) + return; + + if (buffer().masterParams().track_changes) { + // With change tracking, we insert a new inset and + // delete the old one + InsetCommandParams p(p_.code()); + p = p_; + p.setCmdName(new_name); + string const data = InsetCommand::params2string(p); + lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data)); + lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_FORWARD)); + } else + p_.setCmdName(new_name); } @@ -147,18 +209,30 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_INSET_MODIFY: { if (cmd.getArg(0) == "changetype") { cur.recordUndo(); - p_.setCmdName(cmd.getArg(1)); + changeCmdName(cmd.getArg(1)); cur.forceBufferUpdate(); initView(); break; } InsetCommandParams p(p_.code()); InsetCommand::string2params(to_utf8(cmd.argument()), p); + if (p == p_) + // no change + break; if (p.getCmdName().empty()) cur.noScreenUpdate(); else { cur.recordUndo(); - setParams(p); + if (buffer().masterParams().track_changes) { + // With change tracking, we insert a new inset and + // delete the old one + string const data = InsetCommand::params2string(p); + lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data)); + lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_FORWARD)); + cur.forceBufferUpdate(); + break; + } else + setParams(p); } // FIXME We might also want to check here if this one is in the TOC. // But I think most of those are labeled. @@ -189,21 +263,21 @@ bool InsetCommand::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_ERT_INSERT: status.setEnabled(false); return true; - + // we handle these case LFUN_INSET_MODIFY: if (cmd.getArg(0) == "changetype") { string const newtype = cmd.getArg(1); status.setEnabled(p_.isCompatibleCommand(p_.code(), newtype)); status.setOnOff(newtype == p_.getCmdName()); - } + } status.setEnabled(true); return true; - + case LFUN_INSET_DIALOG_UPDATE: status.setEnabled(true); return true; - + default: return Inset::getStatus(cur, cmd, status); } @@ -272,7 +346,8 @@ bool decodeInsetParam(string const & name, string & data, case NOMENCL_PRINT_CODE: case REF_CODE: case TOC_CODE: - case HYPERLINK_CODE: { + case HYPERLINK_CODE: + case COUNTER_CODE: { InsetCommandParams p(code); data = InsetCommand::params2string(p); break; @@ -304,7 +379,7 @@ bool decodeInsetParam(string const & name, string & data, break; } case ERT_CODE: { - data = InsetERT::params2string(InsetCollapsable::Open); + data = InsetERT::params2string(InsetCollapsible::Open); break; } case EXTERNAL_CODE: { @@ -333,7 +408,7 @@ bool decodeInsetParam(string const & name, string & data, break; } case MATH_SPACE_CODE: { - InsetSpaceParams p(true); + InsetSpaceParams p(true); data = InsetSpace::params2string(p); break; }