#include "FuncRequest.h"
#include "FuncStatus.h"
#include "InsetCaption.h"
-#include "InsetList.h"
#include "Language.h"
#include "MetricsInfo.h"
#include "output_latex.h"
// 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;
}
+docstring InsetListings::xhtml(odocstream & os, OutputParams const & rp) const
+{
+ odocstringstream out;
+
+ bool const isInline = params().isInline();
+ if (isInline)
+ out << "<br />\n";
+ else {
+ out << "<div class='float float-listings'>\n";
+ docstring caption = getCaptionHTML(rp);
+ if (!caption.empty())
+ out << "<div class='float-caption'>" << caption << "</div>\n";
+ }
+
+ out << "<pre>\n";
+ OutputParams newrp = rp;
+ newrp.disable_captions = true;
+ docstring def = InsetText::xhtml(out, newrp);
+ out << "\n</pre>\n";
+
+ if (isInline) {
+ out << "<br />\n";
+ os << out.str();
+ } else {
+ out << "</div>";
+ // 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");
InsetListings::string2params(to_utf8(cmd.argument()), params());
break;
}
+
case LFUN_INSET_DIALOG_UPDATE:
cur.bv().updateDialog("listings", params2string(params()));
break;
- case LFUN_TAB_INSERT:
- if (cur.selection()) {
- // If there is a selection, a tab is inserted at the
- // beginning of each paragraph.
- cur.recordUndoSelection();
- pit_type const pit_end = cur.selEnd().pit();
- for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
- paragraphs()[pit].insertChar(0, '\t',
- buffer().params().trackChanges);
- // Update the selection pos to make sure the selection does not
- // change as the inserted tab will increase the logical pos.
- if (cur.anchor_.pit() == pit)
- cur.anchor_.forwardPos();
- if (cur.pit() == pit)
- cur.forwardPos();
- }
- cur.finishUndo();
- } else {
- // Maybe we shouldn't allow tabs within a line, because they
- // are not (yet) aligned as one might do expect.
- cur.recordUndo();
- cur.insert(from_ascii("\t"));
- cur.finishUndo();
- }
- break;
- case LFUN_TAB_DELETE:
- if (cur.selection()) {
- // If there is a selection, a tab (if present) is removed from
- // the beginning of each paragraph.
- cur.recordUndoSelection();
- pit_type const pit_end = cur.selEnd().pit();
- for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
- Paragraph & par = paragraphs()[pit];
- if (par.getChar(0) == '\t') {
- if (cur.pit() == pit)
- cur.posBackward();
- if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
- cur.anchor_.backwardPos();
-
- par.eraseChar(0, buffer().params().trackChanges);
- } else
- // If no tab was present, try to remove up to four spaces.
- for (int n_spaces = 0;
- par.getChar(0) == ' ' && n_spaces < 4; ++n_spaces) {
- if (cur.pit() == pit)
- cur.posBackward();
- if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 )
- cur.anchor_.backwardPos();
-
- par.eraseChar(0, buffer().params().trackChanges);
- }
- }
- cur.finishUndo();
- } else {
- // If there is no selection, try to remove a tab or some spaces
- // before the position of the cursor.
- Paragraph & par = paragraphs()[cur.pit()];
- pos_type const pos = cur.pos();
- if (pos == 0)
- break;
-
- char_type const c = par.getChar(pos - 1);
- cur.recordUndo();
- if (c == '\t') {
- cur.posBackward();
- par.eraseChar(cur.pos(), buffer().params().trackChanges);
- } else
- for (int n_spaces = 0; cur.pos() > 0
- && par.getChar(cur.pos() - 1) == ' ' && n_spaces < 4;
- ++n_spaces) {
- cur.posBackward();
- par.eraseChar(cur.pos(), buffer().params().trackChanges);
- }
- cur.finishUndo();
- }
- break;
default:
InsetCollapsable::doDispatch(cur, cmd);
break;
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:
status.setEnabled(!params().isInline());
return true;
- case LFUN_TAB_INSERT:
- case LFUN_TAB_DELETE:
- status.setEnabled(true);
- return true;
default:
return InsetCollapsable::getStatus(cur, cmd, status);
}
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<InsetCaption *>(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));
}