]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetListings.cpp
try to pass a Buffer & to inset construction if some buffer(param)
[lyx.git] / src / insets / InsetListings.cpp
index b52e9fb9afa9b09b51ea23e7976bc20a88d4c060..0b63ec28e6783c45f3bd06a9da710068096c7d42 100644 (file)
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "gettext.h"
+#include "support/gettext.h"
 #include "InsetList.h"
 #include "Language.h"
 #include "MetricsInfo.h"
+#include "TextClass.h"
 
+#include "support/docstream.h"
 #include "support/lstrings.h"
 
 #include <sstream>
 
-namespace lyx {
+using namespace std;
+using namespace lyx::support;
 
-using support::token;
-using support::contains;
-using support::subst;
+namespace lyx {
 
-using std::istringstream;
-using std::ostream;
-using std::ostringstream;
-using std::string;
 
 char const lstinline_delimiters[] =
        "!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
 
-void InsetListings::init()
-{
-       setButtonLabel();
-       FontInfo font = sane_font;
-       font.decSize();
-       font.decSize();
-       font.setColor(Color_none);
-       setLabelFont(font);
-       // FIXME: what to do with those?
-       //text_.current_font.setLanguage(latex_language);
-       //text_.real_current_font.setLanguage(latex_language);
-}
-
-
-InsetListings::InsetListings(BufferParams const & bp, InsetListingsParams const & par)
-       : InsetCollapsable(bp, par.status())
-{
-       setLayout(bp);
-       init();
-}
+InsetListings::InsetListings(Buffer const & buf, InsetListingsParams const & par)
+       : InsetCollapsable(buf, par.status())
+{}
 
 
 InsetListings::InsetListings(InsetListings const & in)
        : InsetCollapsable(in), params_(in.params_)
-{
-       init();
-}
+{}
 
 
 Inset * InsetListings::clone() const
@@ -91,22 +69,22 @@ Inset::DisplayType InsetListings::display() const
 }
 
 
-void InsetListings::updateLabels(Buffer const & buf, ParIterator const & it)
+void InsetListings::updateLabels(ParIterator const & it)
 {
-       Counters & cnts = buf.params().getTextClass().counters();
+       Counters & cnts = buffer().params().documentClass().counters();
        string const saveflt = cnts.current_float();
 
        // Tell to captions what the current float is
        cnts.current_float("listing");
 
-       InsetCollapsable::updateLabels(buf, it);
+       InsetCollapsable::updateLabels(it);
 
        //reset afterwards
        cnts.current_float(saveflt);
 }
 
 
-void InsetListings::write(Buffer const & buf, ostream & os) const
+void InsetListings::write(ostream & os) const
 {
        os << "listings" << "\n";
        InsetListingsParams const & par = params();
@@ -118,11 +96,11 @@ void InsetListings::write(Buffer const & buf, ostream & os) const
                os << "inline true\n";
        else
                os << "inline false\n";
-       InsetCollapsable::write(buf, os);
+       InsetCollapsable::write(os);
 }
 
 
-void InsetListings::read(Buffer const & buf, Lexer & lex)
+void InsetListings::read(Lexer & lex)
 {
        while (lex.isOK()) {
                lex.next();
@@ -140,18 +118,17 @@ void InsetListings::read(Buffer const & buf, Lexer & lex)
                        break;
                }
        }
-       InsetCollapsable::read(buf, lex);
+       InsetCollapsable::read(lex);
 }
 
 
-docstring const InsetListings::editMessage() const
+docstring InsetListings::editMessage() const
 {
        return _("Opened Listing Inset");
 }
 
 
-int InsetListings::latex(Buffer const & buf, odocstream & os,
-                   OutputParams const & runparams) const
+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
@@ -206,7 +183,7 @@ int InsetListings::latex(Buffer const & buf, odocstream & os,
                // but real_current_font moved to cursor.
                //rp.local_font = &text_.real_current_font;
                rp.moving_arg = true;
-               docstring const caption = getCaption(buf, rp);
+               docstring const caption = getCaption(rp);
                runparams.encoding = rp.encoding;
                if (param_string.empty() && caption.empty())
                        os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}\n";
@@ -220,8 +197,7 @@ int InsetListings::latex(Buffer const & buf, odocstream & os,
                        os << from_utf8(param_string) << "]\n";
                }
                lines += 4;
-                os << code
-                   << "\n\\end{lstlisting}\n\\endgroup\n";
+               os << code << "\n\\end{lstlisting}\n\\endgroup\n";
                lines += 3;
        }
 
@@ -274,7 +250,7 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
 void InsetListings::setButtonLabel()
 {
        // FIXME UNICODE
-       if (decoration() == Classic)
+       if (decoration() == InsetLayout::Classic)
                setLabel(isOpen() ?  _("Listing") : getNewLabel(_("Listing")));
        else
                setLabel(getNewLabel(_("Listing")));
@@ -295,8 +271,7 @@ bool InsetListings::showInsetDialog(BufferView * bv) const
 }
 
 
-docstring InsetListings::getCaption(Buffer const & buf,
-                   OutputParams const & runparams) const
+docstring InsetListings::getCaption(OutputParams const & runparams) const
 {
        if (paragraphs().empty())
                return docstring();
@@ -310,8 +285,8 @@ docstring InsetListings::getCaption(Buffer const & buf,
                                odocstringstream ods;
                                InsetCaption * ins =
                                        static_cast<InsetCaption *>(it->inset);
-                               ins->getOptArg(buf, ods, runparams);
-                               ins->getArgument(buf, ods, runparams);
+                               ins->getOptArg(ods, runparams);
+                               ins->getArgument(ods, runparams);
                                return ods.str();
                        }
                }