I am attaching what I have right now. Many parts are missing but the main points are there:
Sorry, last patch does not have InsetListingsParams.h/cpp. Bo
Index: src/LyXAction.cpp =================================================================== --- src/LyXAction.cpp (revision 18187) +++ src/LyXAction.cpp (working copy) @@ -371,6 +371,7 @@ { LFUN_NOMENCL_PRINT, "nomencl-print", Noop }, { LFUN_CLEARPAGE_INSERT, "clearpage-insert", Noop }, { LFUN_CLEARDOUBLEPAGE_INSERT, "cleardoublepage-insert", Noop }, + { LFUN_LISTING_INSERT, "listing-insert", Noop }, { LFUN_NOACTION, "", Noop } }; Index: src/insets/Inset.cpp =================================================================== --- src/insets/Inset.cpp (revision 18187) +++ src/insets/Inset.cpp (working copy) @@ -76,6 +76,7 @@ InsetName("bibtex", Inset::BIBTEX_CODE), InsetName("text", Inset::TEXT_CODE), InsetName("ert", Inset::ERT_CODE), + InsetName("listings", Inset::ERT_CODE), InsetName("foot", Inset::FOOT_CODE), InsetName("margin", Inset::MARGIN_CODE), InsetName("float", Inset::FLOAT_CODE), Index: src/insets/InsetListings.h =================================================================== --- src/insets/InsetListings.h (revision 0) +++ src/insets/InsetListings.h (revision 0) @@ -0,0 +1,116 @@ +// -*- C++ -*- +/** + * \file InsetListings.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Vigna + * \author Lars Gullik Bjønnes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef INSETLISTINGS_H +#define INSETLISTINGS_H + +#include "LaTeXFeatures.h" +#include "InsetCollapsable.h" +#include "InsetListingsParams.h" +#include "Length.h" +#include "MailInset.h" + + +namespace lyx { + +/** A collapsable text inset for program listings. +*/ + + +class InsetListings : public InsetCollapsable { +public: + /// + InsetListings(BufferParams const &, CollapseStatus status = Open); + /// + ~InsetListings(); + /// + Inset::Code lyxCode() const { return Inset::ERT_CODE; } + /// + docstring name() const { return from_ascii("Listings"); } + /// + void write(Buffer const & buf, std::ostream & os) const; + /// + void read(Buffer const & buf, Lexer & lex); + /// + virtual docstring const editMessage() const; + /// + bool insetAllowed(Inset::Code code) const; + /// + int latex(Buffer const &, odocstream &, + OutputParams const &) const; + /// + int plaintext(Buffer const &, odocstream &, + OutputParams const &) const; + /// + int docbook(Buffer const &, odocstream &, + OutputParams const &) const; + /// + void validate(LaTeXFeatures &) const; + /// + bool metrics(MetricsInfo &, Dimension &) const; + /// + void draw(PainterInfo & pi, int x, int y) const; + /// + bool showInsetDialog(BufferView *) const; + /// + void getDrawFont(Font &) const; + /// + bool forceDefaultParagraphs(idx_type) const { return true; } + /// should paragraph indendation be ommitted in any case? + bool neverIndent(Buffer const &) const { return true; } + /// + InsetListingsParams const & params() const { return params_; } +protected: + InsetListings(InsetListings const &); + /// + virtual void doDispatch(Cursor & cur, FuncRequest & cmd); + /// + bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; +private: + virtual std::auto_ptr<Inset> doClone() const; + /// + void init(); + /// + void setButtonLabel(); + /// + bool allowSpellCheck() const { return false; } + /// + InsetListingsParams params_; +}; + + +class InsetListingsMailer : public MailInset { +public: + /// + InsetListingsMailer(InsetListings & inset); + /// + virtual Inset & inset() const { return inset_; } + /// + virtual std::string const & name() const { return name_; } + /// + virtual std::string const inset2string(Buffer const &) const; + /// + static void string2params(std::string const &, + InsetListingsParams &); + /// + static std::string const params2string(InsetListingsParams const &); +private: + /// + static std::string const name_; + /// + InsetListings & inset_; +}; + + +} // namespace lyx + +#endif Index: src/insets/InsetListingsParams.h =================================================================== --- src/insets/InsetListingsParams.h (revision 0) +++ src/insets/InsetListingsParams.h (revision 0) @@ -0,0 +1,203 @@ +// -*- C++ -*- +/** + * \file InsetListings.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Vigna + * \author Lars Gullik Bjønnes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef INSETLISTINGSPARAMS_H +#define INSETLISTINGSPARAMS_H + +#include <vector> +#include "Lexer.h" + +namespace lyx { + +struct listings_param { + std::string name; + std::string value; + // for option with value "true", "false", + // if onoff is true, + // "true": option + // "false": + // false: + // "true": option=true + // "false": option=false + bool onoff; +}; + +/// options copied from page 26 of listings manual +// FIXME: add default parameters ... +listings_param const listings_params[] = { + { "float", "false", true }, + { "floatplacement", "tbp", false }, + { "aboveskip", "", false }, + { "belowskip", "", false }, + { "lineskip", "", false }, + { "boxpos", "", false }, + { "print", "", false }, + { "firstline", "", false }, + { "lastline", "", false }, + { "showlines", "", false }, + { "emptylines", "", false }, + { "gobble", "", false }, + { "style", "", false }, + { "language", "", false }, + { "alsolanguage", "", false }, + { "defaultdialect", "", false }, + { "printpod", "", false }, + { "usekeywordsintag", "", false }, + { "tagstyle", "", false }, + { "markfirstintag", "", false }, + { "makemacrouse", "", false }, + { "basicstyle", "", false }, + { "identifierstyle", "", false }, + { "commentstyle", "", false }, + { "stringstyle", "", false }, + { "keywordstyle", "", false }, + { "ndkeywordstyle", "", false }, + { "classoffset", "", false }, + { "texcsstyle", "", false }, + { "directivestyle", "", false }, + { "emph", "", false }, + { "moreemph", "", false }, + { "deleteemph", "", false }, + { "emphstyle", "", false }, + { "delim", "", false }, + { "moredelim", "", false }, + { "deletedelim", "", false }, + { "extendedchars", "", false }, + { "inputencoding", "", false }, + { "upquote", "", false }, + { "tabsize", "", false }, + { "showtabs", "", false }, + { "tab", "", false }, + { "showspaces", "", false }, + { "showstringspaces", "", false }, + { "formfeed", "", false }, + { "numbers", "", false }, + { "stepnumber", "", false }, + { "numberfirstline", "", false }, + { "numberstyle", "", false }, + { "numbersep", "", false }, + { "numberblanklines", "", false }, + { "firstnumber", "", false }, + { "name", "", false }, + { "thelstnumber", "", false }, + { "title", "", false }, + { "caption", "", false }, + { "label", "", false }, + { "nolol", "", false }, + { "captionpos", "", false }, + { "abovecaptionskip", "", false }, + { "belowcaptionskip", "", false }, + { "linewidth", "", false }, + { "xleftmargin", "", false }, + { "xrightmargin", "", false }, + { "resetmargin", "", false }, + { "breaklines", "", false }, + { "prebreak", "", false }, + { "postbreak", "", false }, + { "breakindent", "", false }, + { "breakautoindent", "", false }, + { "frame", "", false }, + { "frameround", "", false }, + { "framesep", "", false }, + { "rulesep", "", false }, + { "framerule", "", false }, + { "framexleftmargin", "", false }, + { "framexrightmargin", "", false }, + { "framextopmargin", "", false }, + { "framexbottommargin", "", false }, + { "backgroundcolor", "", false }, + { "rulecolor", "", false }, + { "fillcolor", "", false }, + { "rulesepcolor", "", false }, + { "frameshape", "", false }, + { "index", "", false }, + { "moreindex", "", false }, + { "deleteindex", "", false }, + { "indexstyle", "", false }, + { "columns", "", false }, + { "flexiblecolumns", "", false }, + { "keepspaces", "", false }, + { "basewidth", "", false }, + { "fontadjust", "", false }, + { "texcl", "", false }, + { "mathescape", "", false }, + { "escapechar", "", false }, + { "escapeinside", "", false }, + { "escepeinside", "", false }, + { "escepebegin", "", false }, + { "escepeend", "", false }, + { "fancyvrb", "", false }, + { "fvcmdparams", "", false }, + { "morefvcmdparams", "", false }, + { "keywordsprefix", "", false }, + { "keywords", "", false }, + { "morekeywords", "", false }, + { "deletekeywords", "", false }, + { "ndkeywords", "", false }, + { "morendkeywords", "", false }, + { "deletendkeywords", "", false }, + { "texcs", "", false }, + { "moretexcs", "", false }, + { "deletetexcs", "", false }, + { "directives", "", false }, + { "moredirectives", "", false }, + { "deletedirectives", "", false }, + { "sensitive", "", false }, + { "alsoletter", "", false }, + { "alsodigit", "", false }, + { "alsoother", "", false }, + { "otherkeywords", "", false }, + { "tag", "", false }, + { "string", "", false }, + { "morestring", "", false }, + { "deletestring", "", false }, + { "comment", "", false }, + { "morecomment", "", false }, + { "deletecomment", "", false }, + { "keywordcomment", "", false }, + { "morekeywordcomment", "", false }, + { "deletekeywordcomment", "", false }, + { "keywordcommentsemicolon", "", false }, + { "podcomment", "", false }, + + { "", "", false} +}; + +class InsetListingsParams { +public: + /// + InsetListingsParams(); + + /// write parameters to an ostream + void write(std::ostream &) const; + + /// read parameters from an ostream + void read(Lexer &); + + /// generate an option string, options with default values + /// will not be outputed. + std::string paramString() const; + + /// + std::vector<listings_param> params; + + /// + size_t size() { return params.size(); } + + /// + listings_param& operator[](size_t i) { return params[i]; } +}; + + +} // namespace lyx + +#endif Index: src/insets/InsetListings.cpp =================================================================== --- src/insets/InsetListings.cpp (revision 0) +++ src/insets/InsetListings.cpp (revision 0) @@ -0,0 +1,475 @@ +/** + * \file InsetListings.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Vigna + * \author Lars Gullik Bjønnes + * \author Bo Peng + * + * Full author contact details are available in file CREDITS. + */ + +#include <config.h> + +#include "InsetListings.h" + +#include "Buffer.h" +#include "BufferParams.h" +#include "BufferView.h" +#include "Cursor.h" +#include "debug.h" +#include "DispatchResult.h" +#include "FuncRequest.h" +#include "FuncStatus.h" +#include "gettext.h" +#include "Language.h" +#include "Color.h" +#include "LyXAction.h" +#include "Lexer.h" +#include "TextClass.h" +#include "MetricsInfo.h" +#include "ParagraphParameters.h" +#include "Paragraph.h" + +#include "frontends/alert.h" + +#include <sstream> + + +namespace lyx { + +using support::token; + +using std::endl; +using std::min; + +using std::auto_ptr; +using std::istringstream; +using std::ostream; +using std::ostringstream; +using std::string; + + +void InsetListings::init() +{ + setButtonLabel(); + Font font(Font::ALL_SANE); + font.decSize(); + font.decSize(); + font.setColor(Color::foreground); + setLabelFont(font); + text_.current_font.setLanguage(english_language); + text_.real_current_font.setLanguage(english_language); +} + + +InsetListings::InsetListings(BufferParams const & bp, CollapseStatus status) + : InsetCollapsable(bp, status) +{ + init(); +} + + +InsetListings::InsetListings(InsetListings const & in) + : InsetCollapsable(in) +{ + init(); +} + + +auto_ptr<Inset> InsetListings::doClone() const +{ + return auto_ptr<Inset>(new InsetListings(*this)); +} + + +InsetListings::~InsetListings() +{ + InsetListingsMailer(*this).hideDialog(); +} + + +void InsetListings::write(Buffer const & buf, ostream & os) const +{ + os << "Listings" << "\n"; + InsetCollapsable::write(buf, os); +} + + +void InsetListings::read(Buffer const & buf, Lexer & lex) +{ + InsetCollapsable::read(buf, lex); + + // Force default font + // This avoids paragraphs in buffer language that would have a + // foreign language after a document langauge change, and it ensures + // that all new text in Listings gets the "english" language, since new text + // inherits the language from the last position of the existing text. + // As a side effect this makes us also robust against bugs in LyX + // that might lead to font changes in Listings in .lyx files. + Font font(Font::ALL_INHERIT, english_language); + ParagraphList::iterator par = paragraphs().begin(); + ParagraphList::iterator const end = paragraphs().end(); + while (par != end) { + pos_type siz = par->size(); + for (pos_type i = 0; i <= siz; ++i) { + par->setFont(i, font); + } + ++par; + } +} + + + +docstring const InsetListings::editMessage() const +{ + return _("Opened Listings Inset"); +} + + +int InsetListings::latex(Buffer const &, odocstream & os, + OutputParams const &) const +{ + // FIXME: add params to the environment + string param_string = params().paramString(); + if (param_string.empty()) + os << "\n\\begin{lstlisting}\n"; + else + os << "\n\\begin{lstlisting}[" << param_string << "]\n"; + ParagraphList::const_iterator par = paragraphs().begin(); + ParagraphList::const_iterator end = paragraphs().end(); + + int lines = 2; + while (par != end) { + pos_type siz = par->size(); + for (pos_type i = 0; i < siz; ++i) { + // ignore all struck out text + if (par->isDeleted(i)) + continue; + + os.put(par->getChar(i)); + } + ++par; + if (par != end) { + os << "\n"; + ++lines; + } + } + os << "\n\\end{lstlisting}\n"; + lines += 2; + + return lines; +} + + +int InsetListings::plaintext(Buffer const &, odocstream &, + OutputParams const &) const +{ + // FIXME + return 0; +} + +/// FIXME +int InsetListings::docbook(Buffer const &, odocstream & os, + OutputParams const &) const +{ + ParagraphList::const_iterator par = paragraphs().begin(); + ParagraphList::const_iterator end = paragraphs().end(); + + int lines = 0; + while (par != end) { + pos_type siz = par->size(); + for (pos_type i = 0; i < siz; ++i) + os.put(par->getChar(i)); + ++par; + if (par != end) { + os << "\n"; + ++lines; + } + } + + return lines; +} + + +void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd) +{ + //lyxerr << "\nInsetListings::doDispatch (begin): cmd: " << cmd << endl; + switch (cmd.action) { + + case LFUN_QUOTE_INSERT: { + // We need to bypass the fancy quotes in Text + FuncRequest f(LFUN_SELF_INSERT, "\""); + dispatch(cur, f); + break; + } + case LFUN_INSET_MODIFY: { + InsetListingsParams params; + InsetListingsMailer::string2params(to_utf8(cmd.argument()), params); + break; + } + case LFUN_INSET_DIALOG_UPDATE: + InsetListingsMailer(*this).updateDialog(&cur.bv()); + break; + case LFUN_PASTE: + case LFUN_CLIPBOARD_PASTE: + case LFUN_PRIMARY_SELECTION_PASTE: { + InsetCollapsable::doDispatch(cur, cmd); + + // Since we can only store plain text, we must reset all + // attributes. + // FIXME: Change only the pasted paragraphs + + BufferParams const & bp = cur.buffer().params(); + Layout_ptr const layout = + bp.getTextClass().defaultLayout(); + Font font = layout->font; + // ERT contents has always english_language + font.setLanguage(english_language); + ParagraphList::iterator const end = paragraphs().end(); + for (ParagraphList::iterator par = paragraphs().begin(); + par != end; ++par) { + // in case par had a manual label + par->setBeginOfBody(); + pos_type const siz = par->size(); + for (pos_type i = 0; i < siz; ++i) { + par->setFont(i, font); + } + par->params().clear(); + } + break; + } + case LFUN_MOUSE_RELEASE: { + if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { + InsetListingsMailer(*this).showDialog(&cur.bv()); + break; + } + InsetCollapsable::doDispatch(cur, cmd); + break; + } + default: + InsetCollapsable::doDispatch(cur, cmd); + break; + } +} + + +bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd, + FuncStatus & status) const +{ + switch (cmd.action) { + // suppress these + case LFUN_ACCENT_ACUTE: + case LFUN_ACCENT_BREVE: + case LFUN_ACCENT_CARON: + case LFUN_ACCENT_CEDILLA: + case LFUN_ACCENT_CIRCLE: + case LFUN_ACCENT_CIRCUMFLEX: + case LFUN_ACCENT_DOT: + case LFUN_ACCENT_GRAVE: + case LFUN_ACCENT_HUNGARIAN_UMLAUT: + case LFUN_ACCENT_MACRON: + case LFUN_ACCENT_OGONEK: + case LFUN_ACCENT_SPECIAL_CARON: + case LFUN_ACCENT_TIE: + case LFUN_ACCENT_TILDE: + case LFUN_ACCENT_UMLAUT: + case LFUN_ACCENT_UNDERBAR: + case LFUN_ACCENT_UNDERDOT: + case LFUN_APPENDIX: + case LFUN_BREAK_LINE: + case LFUN_CAPTION_INSERT: + case LFUN_DEPTH_DECREMENT: + case LFUN_DEPTH_INCREMENT: + case LFUN_DOTS_INSERT: + case LFUN_END_OF_SENTENCE_PERIOD_INSERT: + case LFUN_ENVIRONMENT_INSERT: + case LFUN_ERT_INSERT: + case LFUN_LISTING_INSERT: + case LFUN_FILE_INSERT: + case LFUN_FLOAT_INSERT: + case LFUN_FLOAT_WIDE_INSERT: + case LFUN_WRAP_INSERT: + case LFUN_FONT_BOLD: + case LFUN_FONT_CODE: + case LFUN_FONT_DEFAULT: + case LFUN_FONT_EMPH: + case LFUN_FONT_FREE_APPLY: + case LFUN_FONT_FREE_UPDATE: + case LFUN_FONT_NOUN: + case LFUN_FONT_ROMAN: + case LFUN_FONT_SANS: + case LFUN_FONT_FRAK: + case LFUN_FONT_ITAL: + case LFUN_FONT_SIZE: + case LFUN_FONT_STATE: + case LFUN_FONT_UNDERLINE: + case LFUN_FOOTNOTE_INSERT: + case LFUN_HFILL_INSERT: + case LFUN_HTML_INSERT: + case LFUN_HYPHENATION_POINT_INSERT: + case LFUN_LIGATURE_BREAK_INSERT: + case LFUN_INDEX_INSERT: + case LFUN_INDEX_PRINT: + case LFUN_LABEL_INSERT: + case LFUN_OPTIONAL_INSERT: + case LFUN_BIBITEM_INSERT: + case LFUN_LINE_INSERT: + case LFUN_PAGEBREAK_INSERT: + case LFUN_CLEARPAGE_INSERT: + case LFUN_CLEARDOUBLEPAGE_INSERT: + case LFUN_LANGUAGE: + case LFUN_LAYOUT: + case LFUN_LAYOUT_PARAGRAPH: + case LFUN_LAYOUT_TABULAR: + case LFUN_MARGINALNOTE_INSERT: + case LFUN_MATH_DISPLAY: + case LFUN_MATH_INSERT: + case LFUN_MATH_MATRIX: + case LFUN_MATH_MODE: + case LFUN_MENU_OPEN: + case LFUN_MENU_SEPARATOR_INSERT: + case LFUN_BRANCH_INSERT: + case LFUN_CHARSTYLE_INSERT: + case LFUN_NOTE_INSERT: + case LFUN_BOX_INSERT: + case LFUN_NOTE_NEXT: + case LFUN_PARAGRAPH_SPACING: + case LFUN_LABEL_GOTO: + case LFUN_REFERENCE_NEXT: + case LFUN_SPACE_INSERT: + case LFUN_SERVER_GOTO_FILE_ROW: + case LFUN_SERVER_NOTIFY: + case LFUN_SERVER_SET_XY: + case LFUN_TABULAR_INSERT: + case LFUN_TOC_INSERT: + case LFUN_URL_INSERT: + case LFUN_FLOAT_LIST: + case LFUN_INSET_INSERT: + case LFUN_PARAGRAPH_PARAMS_APPLY: + case LFUN_PARAGRAPH_UPDATE: + case LFUN_NOMENCL_INSERT: + case LFUN_NOMENCL_PRINT: + case LFUN_NOACTION: + status.enabled(false); + return true; + + case LFUN_QUOTE_INSERT: + case LFUN_INSET_MODIFY: + case LFUN_PASTE: + case LFUN_CLIPBOARD_PASTE: + case LFUN_PRIMARY_SELECTION_PASTE: + status.enabled(true); + return true; + + // this one is difficult to get right. As a half-baked + // solution, we consider only the first action of the sequence + case LFUN_COMMAND_SEQUENCE: { + // argument contains ';'-terminated commands + string const firstcmd = token(to_utf8(cmd.argument()), ';', 0); + FuncRequest func(lyxaction.lookupFunc(firstcmd)); + func.origin = cmd.origin; + return getStatus(cur, func, status); + } + + default: + return InsetCollapsable::getStatus(cur, cmd, status); + } +} + + +void InsetListings::setButtonLabel() +{ + // FIXME UNICODE + setLabel(isOpen() ? _("Listings") : getNewLabel(_("Listings"))); +} + + +bool InsetListings::insetAllowed(Inset::Code /* code */) const +{ + return false; +} + + +void InsetListings::validate(LaTeXFeatures & features) const +{ + features.require("listings"); + InsetCollapsable::validate(features); +} + + +bool InsetListings::metrics(MetricsInfo & mi, Dimension & dim) const +{ + Font tmpfont = mi.base.font; + getDrawFont(mi.base.font); + mi.base.font.realize(tmpfont); + InsetCollapsable::metrics(mi, dim); + mi.base.font = tmpfont; + bool const changed = dim_ != dim; + dim_ = dim; + return changed; +} + + +void InsetListings::draw(PainterInfo & pi, int x, int y) const +{ + Font tmpfont = pi.base.font; + getDrawFont(pi.base.font); + pi.base.font.realize(tmpfont); + InsetCollapsable::draw(pi, x, y); + pi.base.font = tmpfont; +} + + +bool InsetListings::showInsetDialog(BufferView * bv) const +{ + InsetListingsMailer(const_cast<InsetListings &>(*this)).showDialog(bv); + return true; +} + + +void InsetListings::getDrawFont(Font & font) const +{ + font = Font(Font::ALL_INHERIT, english_language); + font.setFamily(Font::TYPEWRITER_FAMILY); + font.setColor(Color::foreground); +} + + +string const InsetListingsMailer::name_("listings"); + +InsetListingsMailer::InsetListingsMailer(InsetListings & inset) + : inset_(inset) +{} + + +string const InsetListingsMailer::inset2string(Buffer const &) const +{ + return params2string(inset_.params()); +} + + +void InsetListingsMailer::string2params(string const & in, + InsetListingsParams & params) +{ + params = InsetListingsParams(); + if (in.empty()) + return; + istringstream data(in); + Lexer lex(0, 0); + lex.setStream(data); + params.read(lex); +} + + +string const +InsetListingsMailer::params2string(InsetListingsParams const & params) +{ + ostringstream data; + params.write(data); + return data.str(); +} + + +} // namespace lyx Index: src/insets/InsetListingsParams.cpp =================================================================== --- src/insets/InsetListingsParams.cpp (revision 0) +++ src/insets/InsetListingsParams.cpp (revision 0) @@ -0,0 +1,82 @@ +/** + * \file InsetListings.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Vigna + * \author Lars Gullik Bjønnes + * \author Bo Peng + * + * Full author contact details are available in file CREDITS. + */ + +#include <config.h> + +#include "Lexer.h" +#include "debug.h" +#include "InsetListingsParams.h" + +#include <sstream> + + +using std::ostream; +using std::string; +using std::vector; +using std::endl; + +namespace lyx +{ + +InsetListingsParams::InsetListingsParams() +{ + for (int i = 0; listings_params[i].name != ""; ++i) + // initialize params with default values + // these values can be changed. + params.push_back(listings_params[i]); +} + +void InsetListingsParams::write(ostream & os) const +{ + for (size_t i = 0; i < params.size(); ++i) + os << params[i].name << " " << params[i].value << '\n'; +} + + +void InsetListingsParams::read(Lexer & lex) +{ + string token; + string value; + size_t i; + while (true) { + lex >> token; + lex >> value; + for (i = 0; i < params.size(); ++i) + if (params[i].name == token) { + params[i].value = value; + break; + } + // not found! + if (i == params.size()) + lyxerr << "InsetListings::Read:: Unknown " << token << " option." << endl; + if (!lex) + return; + } +} + +string InsetListingsParams::paramString() const +{ + string param; + for (size_t i = 0; i < params.size(); ++i) + // if the value is different from the default + if (params[i].value != listings_params[i].value) { + if (listings_params[i].onoff) { + if (params[i].value == "true") + param += params[i].name + ", "; + // else, not output at all + } else + param += params[i].name + "=" + params[i].value + ", "; + } + return param; +} + +} // namespace lyx Index: src/frontends/qt4/QListings.h =================================================================== --- src/frontends/qt4/QListings.h (revision 0) +++ src/frontends/qt4/QListings.h (revision 0) @@ -0,0 +1,58 @@ +// -*- C++ -*- +/** + * \file QListings.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef QLISTINGS_H +#define QLISTINGS_H + +#include "QDialogView.h" +#include "ui/ListingsUi.h" + +#include <QDialog> +#include <QCloseEvent> + +namespace lyx { +namespace frontend { + +class QListings; + +class QListingsDialog : public QDialog, public Ui::QListingsUi { + Q_OBJECT +public: + QListingsDialog(QListings * form); +protected Q_SLOTS: + virtual void change_adaptor(); +protected: + virtual void closeEvent(QCloseEvent * e); +private: + QListings * form_; +}; + + +class ControlListings; + +class QListings : public QController<ControlListings, QView<QListingsDialog> > { +public: + friend class QListingsDialog; + + QListings(Dialog &); +private: + /// Apply changes + virtual void apply(); + /// update + virtual void update_contents(); + /// build the dialog + virtual void build_dialog(); +}; + +} // namespace frontend +} // namespace lyx + +#endif // QLISTINGS_H Index: src/frontends/qt4/ui/ListingsUi.ui =================================================================== --- src/frontends/qt4/ui/ListingsUi.ui (revision 0) +++ src/frontends/qt4/ui/ListingsUi.ui (revision 0) @@ -0,0 +1,163 @@ +<ui version="4.0" > + <class>QListingsUi</class> + <widget class="QDialog" name="QListingsUi" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>379</width> + <height>259</height> + </rect> + </property> + <property name="windowTitle" > + <string>Listing</string> + </property> + <property name="sizeGripEnabled" > + <bool>true</bool> + </property> + <widget class="QGroupBox" name="paramsGB" > + <property name="geometry" > + <rect> + <x>9</x> + <y>9</y> + <width>361</width> + <height>206</height> + </rect> + </property> + <property name="title" > + <string>StringList</string> + </property> + <layout class="QGridLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="1" column="0" colspan="2" > + <layout class="QVBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QLabel" name="valueLabel" > + <property name="text" > + <string>&Value:</string> + </property> + <property name="buddy" > + <cstring>valueLE</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="valueLE" /> + </item> + </layout> + </item> + </layout> + </item> + <item row="0" column="0" colspan="2" > + <widget class="QListWidget" name="paramsLW" > + <property name="uniformItemSizes" > + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="" > + <property name="geometry" > + <rect> + <x>10</x> + <y>220</y> + <width>361</width> + <height>29</height> + </rect> + </property> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" > + <size> + <width>101</width> + <height>27</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="restorePB" > + <property name="contextMenuPolicy" > + <enum>Qt::CustomContextMenu</enum> + </property> + <property name="text" > + <string>Restore</string> + </property> + <property name="default" > + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="okPB" > + <property name="text" > + <string>OK</string> + </property> + <property name="default" > + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="closePB" > + <property name="text" > + <string>Cancel</string> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + <tabstops> + <tabstop>okPB</tabstop> + <tabstop>closePB</tabstop> + </tabstops> + <includes> + <include location="local" >qt_helpers.h</include> + </includes> + <resources/> + <connections/> +</ui> Index: src/frontends/qt4/QListings.cpp =================================================================== --- src/frontends/qt4/QListings.cpp (revision 0) +++ src/frontends/qt4/QListings.cpp (revision 0) @@ -0,0 +1,115 @@ +/** + * \file QListings.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#include <config.h> + +#include "QListings.h" +#include "Qt2BC.h" +#include "qt_helpers.h" +#include "controllers/ControlListings.h" +#include "insets/InsetListingsParams.h" + +#include "support/convert.h" +#include "support/lstrings.h" + +#include <QLineEdit> +#include <QCloseEvent> +#include <QPushButton> + + +using std::string; + +namespace lyx { +namespace frontend { + +///////////////////////////////////////////////////////////////////// +// +// QListingsDialog +// +///////////////////////////////////////////////////////////////////// + + +QListingsDialog::QListingsDialog(QListings * form) + : form_(form) +{ + setupUi(this); + + connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore())); + connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + + // FIXME: connect listview selection to valueedit + // FIXME: connect valieedit modification to listview update +} + + +void QListingsDialog::closeEvent(QCloseEvent * e) +{ + form_->slotWMHide(); + e->accept(); +} + + +void QListingsDialog::change_adaptor() +{ + form_->changed(); +} + + +///////////////////////////////////////////////////////////////////// +// +// QListings +// +///////////////////////////////////////////////////////////////////// + +typedef QController<ControlListings, QView<QListingsDialog> > wrap_base_class; + +QListings::QListings(Dialog & parent) + : wrap_base_class(parent, _("Program Listings Settings")) +{ +} + + +void QListings::build_dialog() +{ + dialog_.reset(new QListingsDialog(this)); + + bcview().setOK(dialog_->okPB); + bcview().setCancel(dialog_->closePB); + // add params to listview + InsetListingsParams params = controller().params(); + + for (size_t i = 0; i < params.size(); ++i) { + dialog_->paramsLW->addItem(toqstr(params[i].name)); + } +} + + +void QListings::apply() +{ + // FIXME + // update params with listview items +} + + +void QListings::update_contents() +{ + // add params to listview + InsetListingsParams params = controller().params(); + // update listview + dialog_->paramsLW->clear(); +} + + +} // namespace frontend +} // namespace lyx + + +#include "QListings_moc.cpp" Index: src/frontends/qt4/Dialogs.cpp =================================================================== --- src/frontends/qt4/Dialogs.cpp (revision 18187) +++ src/frontends/qt4/Dialogs.cpp (working copy) @@ -25,6 +25,7 @@ #include "ControlFloat.h" #include "ControlGraphics.h" #include "ControlInclude.h" +#include "ControlListings.h" #include "ControlLog.h" #include "ControlViewSource.h" #include "ControlMath.h" @@ -66,6 +67,7 @@ #include "QIndex.h" #include "QMathMatrixDialog.h" #include "QNomencl.h" +#include "QListings.h" #include "QLog.h" #include "QViewSource.h" #include "QNote.h" @@ -112,7 +114,7 @@ "thesaurus", #endif -"texinfo", "toc", "url", "view-source", "vspace", "wrap" }; +"texinfo", "toc", "url", "view-source", "vspace", "wrap", "listings" }; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -318,6 +320,10 @@ dialog->setController(new ControlWrap(*dialog)); dialog->setView(new QWrap(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); + } else if (name == "listings") { + dialog->setController(new ControlListings(*dialog)); + dialog->setView(new QListings(*dialog)); + dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); } return dialog; Index: src/frontends/controllers/ControlListings.h =================================================================== --- src/frontends/controllers/ControlListings.h (revision 0) +++ src/frontends/controllers/ControlListings.h (revision 0) @@ -0,0 +1,48 @@ +// -*- C++ -*- +/** + * \file ControlListings.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Dekel Tsur + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef CONTROLLISTINGS_H +#define CONTROLLISTINGS_H + +#include "Dialog.h" + + +namespace lyx { + +class InsetListingsParams; + +namespace frontend { + +class ControlListings : public Dialog::Controller { +public: + /// + ControlListings(Dialog &); + /// + virtual bool initialiseParams(std::string const & data); + /// clean-up on hide. + virtual void clearParams(); + /// clean-up on hide. + virtual void dispatchParams(); + /// + virtual bool isBufferDependent() const { return true; } + /// + InsetListingsParams & params() { return *params_.get(); } + /// + InsetListingsParams const & params() const { return *params_.get(); } +private: + /// + boost::scoped_ptr<InsetListingsParams> params_; +}; + +} // namespace frontend +} // namespace lyx + +#endif Index: src/frontends/controllers/ControlListings.cpp =================================================================== --- src/frontends/controllers/ControlListings.cpp (revision 0) +++ src/frontends/controllers/ControlListings.cpp (revision 0) @@ -0,0 +1,63 @@ +/** + * \file ControlListings.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Dekel Tsur + * + * Full author contact details are available in file CREDITS. + */ + +#include <config.h> + +#include "ControlListings.h" +#include "FuncRequest.h" +#include "insets/InsetListings.h" + +/* +string const languages = + "no language\nBAP\nACSL\nAda\nALGOL\nC\nC++\nCaml\nClean\nCobol\n" + "Comal 80\ncsh\nDelphi\nEiffel\nElan\nEuphoria\nFortran\nHaskell\n" + "HTML\nIDL\nJava\nLisp\nLogo\nmake\nMathematica\nMatlab\nMercury\n" + "Miranda\nML\nModula-2\nOberon-2\nOCL\nPascal\nPerl\nPHP\nPL/I\nPOV\n" + "Python\nProlog\nR\nS\nSAS\nSHELXL\nSimula\ntcl\nSQL\nTeX\nVBScript\n" + "VHDL\nXML"; +string const frames = "none\nleftline\ntopline\nlines\nsingle\nshadowbox"; +string const fontsizes = "default\ntiny\nscriptsize\nfootnotesize\nsmall\n" + "normalsize\nlarge\nLarge"; +string const fontstyles = "default\nrmfamily\nttfamily\nsffamily"; +*/ + +using std::string; + +namespace lyx { +namespace frontend { + +ControlListings::ControlListings(Dialog & parent) + : Dialog::Controller(parent) +{} + + +bool ControlListings::initialiseParams(string const & data) +{ + InsetListingsParams params; + InsetListingsMailer::string2params(data, params); + params_.reset(new InsetListingsParams(params)); + return true; +} + + +void ControlListings::clearParams() +{ + params_.reset(); +} + + +void ControlListings::dispatchParams() +{ + string const lfun = InsetListingsMailer::params2string(params()); + kernel().dispatch(FuncRequest(getLfun(), lfun)); +} + +} // namespace frontend +} // namespace lyx Index: src/LyXFunc.cpp =================================================================== --- src/LyXFunc.cpp (revision 18187) +++ src/LyXFunc.cpp (working copy) @@ -67,6 +67,7 @@ #include "insets/InsetERT.h" #include "insets/InsetExternal.h" #include "insets/InsetFloat.h" +#include "insets/InsetListings.h" #include "insets/InsetGraphics.h" #include "insets/InsetInclude.h" #include "insets/InsetNote.h" @@ -1317,6 +1318,9 @@ } else if (name == "float") { InsetFloatParams p; data = InsetFloatMailer::params2string(p); + } else if (name == "listings") { + InsetListingsParams p; + data = InsetListingsMailer::params2string(p); } else if (name == "graphics") { InsetGraphicsParams p; Buffer const & buffer = *lyx_view_->buffer(); Index: src/factory.cpp =================================================================== --- src/factory.cpp (revision 18187) +++ src/factory.cpp (working copy) @@ -30,6 +30,7 @@ #include "insets/InsetCharStyle.h" #include "insets/InsetEnvironment.h" #include "insets/InsetERT.h" +#include "insets/InsetListings.h" #include "insets/InsetExternal.h" #include "insets/InsetFloat.h" #include "insets/InsetFloatList.h" @@ -136,6 +137,9 @@ case LFUN_ERT_INSERT: return new InsetERT(params); + case LFUN_LISTING_INSERT: + return new InsetListings(params); + case LFUN_FOOTNOTE_INSERT: return new InsetFoot(params); @@ -486,6 +490,8 @@ inset.reset(new InsetEnvironment(buf.params(), lex.getString())); } else if (tmptok == "ERT") { inset.reset(new InsetERT(buf.params())); + } else if (tmptok == "Listings") { + inset.reset(new InsetListings(buf.params())); } else if (tmptok == "InsetSpace") { inset.reset(new InsetSpace); } else if (tmptok == "Tabular") { Index: src/LaTeXFeatures.cpp =================================================================== --- src/LaTeXFeatures.cpp (revision 18187) +++ src/LaTeXFeatures.cpp (working copy) @@ -544,6 +544,9 @@ "\\providecommand{\\makenomenclature}{\\makeglossary}\n" "\\makenomenclature\n"; } + + if (mustProvide("listings")) + packages << "\\usepackage{listings}\n"; return packages.str(); } Index: src/Text3.cpp =================================================================== --- src/Text3.cpp (revision 18187) +++ src/Text3.cpp (working copy) @@ -1198,6 +1198,7 @@ case LFUN_BRANCH_INSERT: case LFUN_BIBITEM_INSERT: case LFUN_ERT_INSERT: + case LFUN_LISTING_INSERT: case LFUN_FOOTNOTE_INSERT: case LFUN_MARGINALNOTE_INSERT: case LFUN_OPTIONAL_INSERT: @@ -1700,6 +1701,9 @@ case LFUN_ERT_INSERT: code = Inset::ERT_CODE; break; + case LFUN_LISTING_INSERT: + code = Inset::ERT_CODE; + break; case LFUN_FOOTNOTE_INSERT: code = Inset::FOOT_CODE; break; Index: src/lfuns.h =================================================================== --- src/lfuns.h (revision 18187) +++ src/lfuns.h (working copy) @@ -380,6 +380,7 @@ LFUN_CLEARPAGE_INSERT, // Ugras 20061125 LFUN_CLEARDOUBLEPAGE_INSERT, // Ugras 20061125 //290 + LFUN_LISTING_INSERT, // Herbert 20011110, bpeng 20070502 LFUN_LASTACTION // end of the table }; Index: lib/ui/stdmenus.inc =================================================================== --- lib/ui/stdmenus.inc (revision 18187) +++ lib/ui/stdmenus.inc (working copy) @@ -311,6 +311,7 @@ Item "Marginal Note|M" "marginalnote-insert" Item "Short Title|S" "optional-insert" Item "TeX Code|X" "ert-insert" + Item "Program Code" "listing-insert" Item "Date" "date-insert" End Index: development/scons/scons_manifest.py =================================================================== --- development/scons/scons_manifest.py (revision 18187) +++ development/scons/scons_manifest.py (working copy) @@ -726,6 +726,7 @@ ControlFloat.h ControlGraphics.h ControlInclude.h + ControlListings.h ControlLog.h ControlMath.h ControlNote.h @@ -771,6 +772,7 @@ ControlFloat.cpp ControlGraphics.cpp ControlInclude.cpp + ControlListings.cpp ControlLog.cpp ControlMath.cpp ControlNote.cpp @@ -866,6 +868,7 @@ QInclude.h QIndex.h QKeySymbol.h + QListings.h QLImage.h QLMenubar.h QLPainter.h @@ -955,6 +958,7 @@ QInclude.cpp QIndex.cpp QKeySymbol.cpp + QListings.cpp QLImage.cpp QLMenubar.cpp QLPainter.cpp @@ -1030,6 +1034,7 @@ QGraphicsDialog.cpp QInclude.cpp QIndex.cpp + QListings.cpp QLMenubar.cpp QLPopupMenu.cpp QLPrintDialog.cpp @@ -1101,6 +1106,7 @@ IndexUi.ui LaTeXUi.ui LanguageUi.ui + ListingsUi.ui LogUi.ui MarginsUi.ui MathMatrixUi.ui @@ -1183,6 +1189,8 @@ InsetIndex.h InsetLabel.h InsetLine.h + InsetListings.h + InsetListingsParams.h InsetMarginal.h InsetNewline.h InsetNomencl.h @@ -1236,6 +1244,8 @@ InsetIndex.cpp InsetLabel.cpp InsetLine.cpp + InsetListings.cpp + InsetListingsParams.cpp InsetMarginal.cpp InsetNewline.cpp InsetNomencl.cpp