]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathHull.cpp
Fix build with GNU libstdc++ C++11 ABI
[lyx.git] / src / mathed / InsetMathHull.cpp
index 386c373a85537c216c183860a036d84edb825c18..19206331152f3532a7dd742788dfdf766bece62a 100644 (file)
@@ -66,6 +66,7 @@ using namespace lyx::support;
 namespace lyx {
 
 using cap::grabAndEraseSelection;
+using cap::reduceSelectionToOneCell;
 
 namespace {
 
@@ -636,12 +637,22 @@ void InsetMathHull::preparePreview(DocIterator const & pos,
        buffer->listMacroNames(macros);
        MacroNameSet::iterator it = macros.begin();
        MacroNameSet::iterator end = macros.end();
-       odocstringstream macro_preamble;
+       docstring macro_preamble;
        for (; it != end; ++it) {
                MacroData const * data = buffer->getMacro(*it, pos, true);
                if (data) {
-                       data->write(macro_preamble, true);
-                       macro_preamble << endl;
+                       odocstringstream mac_preamble;
+                       data->write(mac_preamble, false);
+                       docstring const mps = mac_preamble.str();
+                       bool const is_new_def = prefixIs(mps, from_ascii("\\newcomm"));
+                       // assure that \newcommand definitions of macros are only added once
+                       if (!is_new_def || !preview_->hasMacroDef(mps, *buffer)) {
+                               if (is_new_def)
+                                       preview_->addMacroDef(mps, *buffer);
+                               if (!macro_preamble.empty())
+                                       macro_preamble += '\n';
+                               macro_preamble += mps;
+                       }
                }
        }
 
@@ -666,8 +677,7 @@ void InsetMathHull::preparePreview(DocIterator const & pos,
                                          '{' + convert<docstring>(num) + '}';
                }
        }
-       docstring const snippet = macro_preamble.str() +
-           setcnt + latexString(*this);
+       docstring const snippet = macro_preamble + setcnt + latexString(*this);
        LYXERR(Debug::MACROS, "Preview snippet: " << snippet);
        preview_->addPreview(snippet, *buffer, forexport);
 }
@@ -1302,7 +1312,7 @@ void InsetMathHull::normalize(NormalStream & os) const
 
 void InsetMathHull::infoize(odocstream & os) const
 {
-       os << "Type: " << hullName(type_);
+       os << bformat(_("Type: %1$s"), hullName(type_));
 }
 
 
@@ -1324,14 +1334,14 @@ void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func)
                extra = from_ascii("noextra");
        string const lang = to_ascii(dlang);
 
-       // FIXME: temporarily disabled
-       //if (cur.selection()) {
-       //      MathData ar;
-       //      selGet(cur.ar);
-       //      lyxerr << "use selection: " << ar << endl;
-       //      insert(pipeThroughExtern(lang, extra, ar));
-       //      return;
-       //}
+       // replace selection with result of computation
+       if (reduceSelectionToOneCell(cur)) {
+               MathData ar;
+               asArray(grabAndEraseSelection(cur), ar);
+               lyxerr << "use selection: " << ar << endl;
+               cur.insert(pipeThroughExtern(lang, extra, ar));
+               return;
+       }
 
        // only inline, display or eqnarray math is allowed
        if (getType() > hullEqnArray) {
@@ -1352,9 +1362,7 @@ void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func)
        if (getType() == hullSimple) {
                size_type pos = cur.cell().find_last(eq);
                MathData ar;
-               if (cur.inMathed() && cur.selection()) {
-                       asArray(grabAndEraseSelection(cur), ar);
-               } else if (!pos == cur.cell().empty()) {
+               if (pos == cur.cell().size()) {
                        ar = cur.cell();
                        lyxerr << "use whole cell: " << ar << endl;
                } else {
@@ -1646,6 +1654,7 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
                                enable = display() != Inline;
                }
                status.setEnabled(enable);
+               status.setOnOff(display() != Inline);
                return true;
        }
 
@@ -1970,7 +1979,8 @@ int InsetMathHull::plaintext(odocstringstream & os,
                        // and do not include the newline.
                        if (op.for_toc || op.for_tooltip || oss.str().size() >= max_length)
                                break;
-                       wi << "\n";
+                        if (r < nrows() - 1)
+                               wi << "\n";
                }
        }
        docstring const str = oss.str();