]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetListings.cpp
Use the same code for editable and non-editable buttons
[lyx.git] / src / insets / InsetListings.cpp
index b5a5701817aebe74db5e876179c281a065e02400..b847131f57acb95002b3e707dc73fea573e045f3 100644 (file)
@@ -72,6 +72,15 @@ Inset::DisplayType InsetListings::display() const
 }
 
 
+docstring InsetListings::layoutName() const
+{
+       if (buffer().params().use_minted)
+               return from_ascii("MintedListings");
+       else
+               return from_ascii("Listings");
+}
+
+
 void InsetListings::write(ostream & os) const
 {
        os << "listings" << "\n";
@@ -178,6 +187,9 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
                encoding_switched = true;
        }
 
+       bool const captionfirst = !isfloat && par->isInset(0)
+                               && par->getInset(0)->lyxCode() == CAPTION_CODE;
+
        while (par != end) {
                pos_type siz = par->size();
                bool captionline = false;
@@ -268,10 +280,16 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
                }
                os << delim << code << delim;
        } else if (use_minted) {
+               OutputParams rp = runparams;
+               rp.moving_arg = true;
+               TexString caption = getCaption(rp);
                if (isfloat) {
                        os << breakln << "\\begin{listing}";
                        if (!float_placement.empty())
                                os << '[' << float_placement << "]";
+               } else if (captionfirst && !caption.str.empty()) {
+                       os << breakln << "\\lyxmintcaption[t]{"
+                          << move(caption) << "}\n";
                }
                os << breakln << "\\begin{minted}";
                if (!param_string.empty())
@@ -279,12 +297,12 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
                os << "{" << minted_language << "}\n"
                   << code << breakln << "\\end{minted}\n";
                if (isfloat) {
-                       OutputParams rp = runparams;
-                       rp.moving_arg = true;
-                       TexString caption = getCaption(rp);
                        if (!caption.str.empty())
                                os << "\\caption{" << move(caption) << "}\n";
                        os << "\\end{listing}\n";
+               } else if (!captionfirst && !caption.str.empty()) {
+                       os << breakln << "\\lyxmintcaption[b]{"
+                          << move(caption) << "}";
                }
        } else {
                OutputParams rp = runparams;
@@ -441,14 +459,18 @@ docstring const InsetListings::buttonLabel(BufferView const & bv) const
 
 void InsetListings::validate(LaTeXFeatures & features) const
 {
-       if (buffer().params().use_minted)
-               features.require("minted");
-       else
-               features.require("listings");
        features.useInsetLayout(getLayout());
        string param_string = params().params();
-       if (param_string.find("\\color") != string::npos)
-               features.require("color");
+       if (buffer().params().use_minted) {
+               features.require("minted");
+               OutputParams rp = features.runparams();
+               if (!params().isFloat() && !getCaption(rp).str.empty())
+                       features.require("lyxmintcaption");
+       } else {
+               features.require("listings");
+               if (contains(param_string, "\\color"))
+                       features.require("color");
+       }
        InsetCaptionable::validate(features);
 }