X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetListings.cpp;h=b54b4106fd537bc4517e1c8538dd880d6ba4be49;hb=51d4d42906dd553ec72fa03e6c707c02bd73d494;hp=f0820a60e227cf6cc180d2971a1be8c0c4280963;hpb=e4a6b62f03cf1b0901aa3e56aaea347267f287de;p=lyx.git
diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp
index f0820a60e2..b54b4106fd 100644
--- a/src/insets/InsetListings.cpp
+++ b/src/insets/InsetListings.cpp
@@ -18,13 +18,11 @@
#include "BufferParams.h"
#include "Counters.h"
#include "Cursor.h"
-#include "CutAndPaste.h"
#include "DispatchResult.h"
#include "Encoding.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "InsetCaption.h"
-#include "InsetList.h"
#include "Language.h"
#include "MetricsInfo.h"
#include "output_latex.h"
@@ -137,7 +135,7 @@ int InsetListings::latex(odocstream & os, OutputParams const & runparams) const
// NOTE: I use {} to quote text, which is an experimental feature
// of the listings package (see page 25 of the manual)
int lines = 0;
- bool isInline = params().isInline();
+ bool const isInline = params().isInline();
// get the paragraphs. We can not output them directly to given odocstream
// because we can not yet determine the delimiter character of \lstinline
docstring code;
@@ -275,6 +273,37 @@ int InsetListings::latex(odocstream & os, OutputParams const & runparams) const
}
+docstring InsetListings::xhtml(odocstream & os, OutputParams const & rp) const
+{
+ odocstringstream out;
+
+ bool const isInline = params().isInline();
+ if (isInline)
+ out << "
\n";
+ else {
+ out << "
\n";
+ docstring caption = getCaptionHTML(rp);
+ if (!caption.empty())
+ out << "
" << caption << "
\n";
+ }
+
+ out << "
\n";
+ docstring def = InsetText::xhtml(out, rp);
+ out << "\n
\n";
+
+ if (isInline) {
+ out << "
\n";
+ os << out.str();
+ } else {
+ out << "
";
+ // In this case, this needs to be deferred, but we'll put it
+ // before anything the text itself deferred.
+ def = out.str() + '\n' + def;
+ }
+ return def;
+}
+
+
docstring InsetListings::contextMenu(BufferView const &, int, int) const
{
return from_ascii("context-listings");
@@ -387,7 +416,6 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
switch (cmd.action) {
case LFUN_INSET_MODIFY:
case LFUN_INSET_DIALOG_UPDATE:
- case LFUN_INSET_SETTINGS:
status.setEnabled(true);
return true;
case LFUN_CAPTION_INSERT:
@@ -436,37 +464,29 @@ docstring InsetListings::getCaption(OutputParams const & runparams) const
if (paragraphs().empty())
return docstring();
- ParagraphList::const_iterator pit = paragraphs().begin();
- for (; pit != paragraphs().end(); ++pit) {
- InsetList::const_iterator it = pit->insetList().begin();
- for (; it != pit->insetList().end(); ++it) {
- Inset & inset = *it->inset;
- if (inset.lyxCode() == CAPTION_CODE) {
- odocstringstream ods;
- InsetCaption * ins =
- static_cast(it->inset);
- ins->getOptArg(ods, runparams);
- ins->getArgument(ods, runparams);
- // the caption may contain \label{} but the listings
- // package prefer caption={}, label={}
- docstring cap = ods.str();
- if (!contains(to_utf8(cap), "\\label{"))
- return cap;
- // convert from
- // blah1\label{blah2} blah3
- // to
- // blah1 blah3},label={blah2
- // to form options
- // caption={blah1 blah3},label={blah2}
- //
- // NOTE that } is not allowed in blah2.
- regex const reg("(.*)\\\\label\\{(.*?)\\}(.*)");
- string const new_cap("\\1\\3},label={\\2");
- return from_utf8(regex_replace(to_utf8(cap), reg, new_cap));
- }
- }
- }
- return docstring();
+ InsetCaption const * ins = getCaptionInset();
+ if (ins == 0)
+ return docstring();
+
+ odocstringstream ods;
+ ins->getOptArg(ods, runparams);
+ ins->getArgument(ods, runparams);
+ // the caption may contain \label{} but the listings
+ // package prefer caption={}, label={}
+ docstring cap = ods.str();
+ if (!contains(to_utf8(cap), "\\label{"))
+ return cap;
+ // convert from
+ // blah1\label{blah2} blah3
+ // to
+ // blah1 blah3},label={blah2
+ // to form options
+ // caption={blah1 blah3},label={blah2}
+ //
+ // NOTE that } is not allowed in blah2.
+ regex const reg("(.*)\\\\label\\{(.*?)\\}(.*)");
+ string const new_cap("\\1\\3},label={\\2");
+ return from_utf8(regex_replace(to_utf8(cap), reg, new_cap));
}