]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetListings.cpp
Restore XHTML output for InsetListings.
[lyx.git] / src / insets / InsetListings.cpp
index aa8a831a600a7e85a3d3a999788a5e6676aa93f4..e20d3c76df477b23ce7415066d4d7dfde29d152c 100644 (file)
@@ -26,6 +26,7 @@
 #include "Language.h"
 #include "MetricsInfo.h"
 #include "output_latex.h"
+#include "output_xhtml.h"
 #include "TextClass.h"
 
 #include "support/debug.h"
@@ -51,7 +52,7 @@ using boost::regex;
 char const lstinline_delimiters[] =
        "!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
 
-InsetListings::InsetListings(Buffer const & buf, InsetListingsParams const & par)
+InsetListings::InsetListings(Buffer * buf, InsetListingsParams const & par)
        : InsetCollapsable(buf)
 {
        status_ = par.status();
@@ -70,7 +71,7 @@ Inset::DisplayType InsetListings::display() const
 }
 
 
-void InsetListings::updateLabels(ParIterator const & it)
+void InsetListings::updateLabels(ParIterator const & it, bool out)
 {
        Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
        string const saveflt = cnts.current_float();
@@ -78,7 +79,7 @@ void InsetListings::updateLabels(ParIterator const & it)
        // Tell to captions what the current float is
        cnts.current_float("listing");
 
-       InsetCollapsable::updateLabels(it);
+       InsetCollapsable::updateLabels(it, out);
 
        //reset afterwards
        cnts.current_float(saveflt);
@@ -123,19 +124,13 @@ void InsetListings::read(Lexer & lex)
 }
 
 
-docstring InsetListings::editMessage() const
-{
-       return _("Opened Listing Inset");
-}
-
-
 int InsetListings::latex(odocstream & os, OutputParams const & runparams) const
 {
        string param_string = params().params();
        // 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;
@@ -273,6 +268,42 @@ int InsetListings::latex(odocstream & os, OutputParams const & runparams) const
 }
 
 
+docstring InsetListings::xhtml(XHTMLStream & os, OutputParams const & rp) const
+{
+       odocstringstream ods;
+       XHTMLStream out(ods);
+
+       bool const isInline = params().isInline();
+       if (isInline) 
+               out << CompTag("br");
+       else {
+               out << StartTag("div", "class='float float-listings'");
+               docstring caption = getCaptionHTML(rp);
+               if (!caption.empty())
+                       out << StartTag("div", "class='float-caption'") 
+                           << caption << EndTag("div");
+       }
+
+       out << StartTag("pre");
+       OutputParams newrp = rp;
+       newrp.html_disable_captions = true;
+       docstring def = InsetText::xhtml(out, newrp);
+       out << EndTag("pre");
+
+       if (isInline) {
+               out << CompTag("br");
+               // escaping will already have been done
+               os << XHTMLStream::NextRaw() << ods.str();
+       } else {
+               out << EndTag("div");
+               // In this case, this needs to be deferred, but we'll put it
+               // before anything the text itself deferred.
+               def = ods.str() + '\n' + def;
+       }
+       return def;
+}
+
+
 docstring InsetListings::contextMenu(BufferView const &, int, int) const
 {
        return from_ascii("context-listings");
@@ -292,86 +323,6 @@ void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd)
                cur.bv().updateDialog("listings", params2string(params()));
                break;
 
-       case LFUN_TAB_INSERT: {
-               bool const multi_par_selection = cur.selection() &&
-                       cur.selBegin().pit() != cur.selEnd().pit();
-               if (multi_par_selection) {
-                       // If there is a multi-paragraph 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.
-                       FuncRequest cmd(LFUN_SELF_INSERT, from_ascii("\t"));
-                       dispatch(cur, cmd);     
-               }
-               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;
@@ -390,10 +341,6 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
                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);
        }