LyX file-format changes
-----------------------
+2007-05-08 Bo Peng <ben.bob@gmail.com>
+ * format incremented to 269: add listings support
+ - add preamble flag \listings_params, e.g. \listings_params "language=Python,float"
+ - add inset listings, with options lstparams and inline, e.g.
+ \begin_inset listings
+ lstparams "xleftmargin=50pt,language=Python"
+ inline false
+ - add \lstinputlisting Include type. e.g.
+ \begin_inset Include \lstinputlisting{newfile1.lyx}[firstline=10,lastline=15]
+
2007-05-06 Uwe Stöhr <uwestoehr@web.de>
* format incremented to 268: add support for the CJK encodings
ControlFloat.h
ControlGraphics.h
ControlInclude.h
+ ControlListings.h
ControlLog.h
ControlMath.h
ControlNote.h
ControlFloat.cpp
ControlGraphics.cpp
ControlInclude.cpp
+ ControlListings.cpp
ControlLog.cpp
ControlMath.cpp
ControlNote.cpp
QInclude.h
QIndex.h
QKeySymbol.h
+ QListings.h
QLImage.h
QLMenubar.h
QLPainter.h
QInclude.cpp
QIndex.cpp
QKeySymbol.cpp
+ QListings.cpp
QLImage.cpp
QLMenubar.cpp
QLPainter.cpp
QGraphicsDialog.cpp
QInclude.cpp
QIndex.cpp
+ QListings.cpp
QLMenubar.cpp
QLPopupMenu.cpp
QLPrintDialog.cpp
IndexUi.ui
LaTeXUi.ui
LanguageUi.ui
+ ListingsUi.ui
LogUi.ui
MarginsUi.ui
MathMatrixUi.ui
InsetIndex.h
InsetLabel.h
InsetLine.h
+ InsetListings.h
+ InsetListingsParams.h
InsetMarginal.h
InsetNewline.h
InsetNomencl.h
InsetIndex.cpp
InsetLabel.cpp
InsetLine.cpp
+ InsetListings.cpp
+ InsetListingsParams.cpp
InsetMarginal.cpp
InsetNewline.cpp
InsetNomencl.cpp
("1_2", [220], generate_minor_versions("1.2" , 4)),
("1_3", [221], generate_minor_versions("1.3" , 7)),
("1_4", range(222,246), generate_minor_versions("1.4" , 4)),
- ("1_5", range(246,269), generate_minor_versions("1.5" , 0))]
+ ("1_5", range(246,270), generate_minor_versions("1.5" , 0))]
def formats_list():
document.header[i] = "\\language english"
+def revert_preamble_listings_params(document):
+ " Revert preamble option \listings_params "
+ i = find_token(document.header, "\\listings_params", 0)
+ if i != -1:
+ document.preamble.append('\\usepackage{listings}')
+ document.preamble.append('\\lstset{%s}' % document.header[i].split()[1].strip('"'))
+ document.header.pop(i);
+
+
+def revert_listings_inset(document):
+ r''' Revert listings inset to \lstinline or \begin, \end lstlisting, translate
+FROM
+
+\begin_inset
+lstparams "language=Delphi"
+inline true
+status open
+
+\begin_layout Standard
+var i = 10;
+\end_layout
+
+\end_inset
+
+TO
+
+\begin_inset ERT
+status open
+\begin_layout Standard
+
+
+\backslash
+lstinline[language=Delphi]{var i = 10;}
+\end_layout
+
+\end_inset
+'''
+ i = 0
+ while True:
+ i = find_token(document.body, '\\begin_inset listings', i)
+ if i == -1:
+ break
+ j = find_end_of_inset(document.body, i + 1)
+ if j == -1:
+ # this should not happen
+ break
+ inline = 'false'
+ params = ''
+ status = 'open'
+ inlinecode = ''
+ # first three lines
+ for line in range(i + 1, i + 4):
+ if document.body[line].startswith('inline'):
+ inline = document.body[line].split()[1]
+ if document.body[line].startswith('lstparams'):
+ params = document.body[line].split()[1].strip('"')
+ if document.body[line].startswith('status'):
+ status = document.body[line].split()[1].strip()
+ k = line + 1
+ # looking for the oneline code for lstinline
+ for line in range(i + 2, j + 1):
+ if document.body[line].startswith(r'\begin_layout'):
+ inlinecode = document.body[line+1]
+ break
+ if inline == 'true':
+ document.body[i:(j+1)] = [r'\begin_inset ERT'
+ 'status %s' % status,
+ r'\begin_layout Standard',
+ '',
+ '',
+ r'\backslash',
+ 'lstinline[%s]{%s}' % (params, inlinecode),
+ r'\end_layout',
+ '',
+ r'\end_inset']
+ else:
+ document.body[i: k] = [r'\begin_inset ERT',
+ 'status %s' % status,
+ '',
+ r'\begin_layout Standard',
+ '',
+ '',
+ r'\backslash',
+ r'lstlisting[%s]{' % params,
+ r'\end_layout'
+ ]
+
+
+def revert_include_listings(document):
+ r''' Revert lstinputlisting Include option , translate
+\begin_inset Include \lstinputlisting{file}[opt]
+preview false
+
+\end_inset
+
+TO
+
+\begin_inset ERT
+status open
+
+\begin_layout Standard
+
+
+\backslash
+lstinputlisting{file}[opt]
+\end_layout
+
+\end_inset
+ '''
+
+ i = 0
+ while True:
+ i = find_token(document.body, r'\begin_inset Include \lstinputlisting', i)
+ if i == -1:
+ break
+ j = find_end_of_inset(document.body, i + 1)
+ if j == -1:
+ # this should not happen
+ break
+ # find command line
+ cmd = document.body[i].split()[2]
+ document.body[i : j + 1] = [r'\begin_inset ERT',
+ 'status open',
+ '',
+ r'\begin_layout Standard',
+ '',
+ '',
+ r'\backslash',
+ '%s' % cmd[1:],
+ r'\end_layout',
+ '',
+ r'\end_inset']
+
+
##
# Conversion hub
#
[265, [convert_tableborder]],
[266, []],
[267, []],
- [268, []]]
+ [268, []],
+ [269, []]]
-revert = [[267, [revert_CJK]],
+revert = [
+ [268, [revert_preamble_listings_params, revert_listings_inset, revert_include_listings]],
+ [267, [revert_CJK]],
[266, [revert_utf8plain]],
[265, [revert_armenian]],
[264, [revert_tableborder]],
Item "Marginal Note|M" "marginalnote-insert"
Item "Short Title|S" "optional-insert"
Item "TeX Code|X" "ert-insert"
+ Item "Program Listing" "listing-insert"
Item "Date" "date-insert"
End
src/frontends/qt4/QFloat.cpp
src/frontends/qt4/QGraphics.cpp
src/frontends/qt4/QInclude.cpp
+src/frontends/qt4/QListings.cpp
src/frontends/qt4/QMathMatrixDialog.cpp
src/frontends/qt4/QNote.cpp
src/frontends/qt4/QParagraph.cpp
src/insets/InsetHFill.cpp
src/insets/InsetInclude.cpp
src/insets/InsetIndex.cpp
+src/insets/InsetListings.cpp
src/insets/InsetMarginal.cpp
src/insets/InsetNomencl.cpp
src/insets/InsetNote.cpp
src/insets/InsetTOC.cpp
src/insets/InsetTabular.cpp
src/insets/InsetText.cpp
+src/insets/InsetTheorem.cpp
src/insets/InsetUrl.cpp
src/insets/InsetVSpace.cpp
src/insets/InsetWrap.cpp
src/insets/RenderPreview.cpp
src/lengthcommon.cpp
src/lyxfind.cpp
+src/mathed/InsetFormulaMacro.cpp
src/mathed/InsetMathAMSArray.cpp
src/mathed/InsetMathCases.cpp
src/mathed/InsetMathGrid.cpp
return;
}
- if (par.ownerCode() == Inset::ERT_CODE) {
+ if (par.ownerCode() == Inset::ERT_CODE || par.ownerCode() == Inset::LISTINGS_CODE) {
start_ = -1;
return;
}
namespace {
-int const LYX_FORMAT = 268;
+int const LYX_FORMAT = 269;
} // namespace anon
#include "VSpace.h"
#include "frontends/alert.h"
+#include "insets/InsetListingsParams.h"
#include "support/lyxalgo.h" // for lyx::count
#include "support/convert.h"
graphicsDriver = "default";
sides = TextClass::OneSide;
columns = 1;
+ listings_params = string();
pagestyle = "default";
compressed = false;
for (int iter = 0; iter < 4; ++iter) {
lex >> fontsize;
} else if (token == "\\papercolumns") {
lex >> columns;
+ } else if (token == "\\listings_params") {
+ string par;
+ lex >> par;
+ // validate par and produce a valid listings parameter string
+ try {
+ listings_params = InsetListingsParams(par).params();
+ } catch (invalidParam & e) {
+ lyxerr << "Invalid parameter string " << par << endl;
+ lyxerr << e.what() << endl;
+ listings_params = string();
+ }
} else if (token == "\\papersides") {
int psides;
lex >> psides;
<< "\n\\papercolumns " << columns
<< "\n\\papersides " << sides
<< "\n\\paperpagestyle " << pagestyle << '\n';
+ if (!listings_params.empty())
+ os << "\\listings_params \"" <<
+ InsetListingsParams(listings_params).encodedString() << "\"\n";
for (int i = 0; i < 4; ++i) {
if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
if (user_defined_bullet(i).getFont() != -1) {
texrow.newline();
}
+ if (!listings_params.empty()) {
+ os << "\\usepackage{listings}\n";
+ texrow.newline();
+ os << "\\lstset{";
+ // do not test validity because listings_params is supposed to be valid
+ string par = InsetListingsParams(listings_params).separatedParams(true);
+ os << from_ascii(par);
+ // count the number of newlines
+ for (size_t i = 0; i < par.size(); ++i)
+ if (par[i] == '\n')
+ texrow.newline();
+ os << "}\n";
+ texrow.newline();
+ }
if (use_geometry || nonstandard_papersize) {
os << "\\usepackage{geometry}\n";
texrow.newline();
std::string float_placement;
///
unsigned int columns;
+ /// parameters for the listings package
+ std::string listings_params;
///
TextClass::PageSides sides;
///
// Convert newline to paragraph break in ERT inset.
// This should not be here!
if (pars[pit].inInset() &&
- pars[pit].inInset()->lyxCode() == Inset::ERT_CODE) {
+ (pars[pit].inInset()->lyxCode() == Inset::ERT_CODE ||
+ pars[pit].inInset()->lyxCode() == Inset::LISTINGS_CODE)) {
for (ParagraphList::size_type i = 0; i < insertion.size(); ++i) {
for (pos_type j = 0; j < insertion[i].size(); ++j) {
if (insertion[i].isNewline(j)) {
// ERT paragraphs have the Language latex_language.
// This is invalid outside of ERT, so we need to change it
// to the buffer language.
- if (it->ownerCode() == Inset::ERT_CODE) {
+ if (it->ownerCode() == Inset::ERT_CODE || it->ownerCode() == Inset::LISTINGS_CODE) {
it->changeLanguage(buf.params(), latex_language,
buf.getLanguage());
}
"\\providecommand{\\makenomenclature}{\\makeglossary}\n"
"\\makenomenclature\n";
}
+
+ if (mustProvide("listings"))
+ packages << "\\usepackage{listings}\n";
return packages.str();
}
{ 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 }
};
#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"
case Inset::BOX_CODE:
enable = cmd.argument() == "box";
break;
+ case Inset::LISTINGS_CODE:
+ enable = cmd.argument() == "listings";
+ break;
default:
break;
}
enable = Exporter::isExportable(*buf, "dvi")
&& lyxrc.print_command != "none";
else if (name == "character")
- enable = cur.inset().lyxCode() != Inset::ERT_CODE;
+ enable = cur.inset().lyxCode() != Inset::ERT_CODE &&
+ cur.inset().lyxCode() != Inset::LISTINGS_CODE;
else if (name == "latexlog")
enable = isFileReadable(FileName(buf->getLogName().second));
else if (name == "spellchecker")
}
case LFUN_DIALOG_SHOW_NEW_INSET:
- enable = cur.inset().lyxCode() != Inset::ERT_CODE;
+ enable = cur.inset().lyxCode() != Inset::ERT_CODE &&
+ cur.inset().lyxCode() != Inset::LISTINGS_CODE;
if (cur.inset().lyxCode() == Inset::CAPTION_CODE) {
FuncStatus flag;
if (cur.inset().getStatus(cur, cmd, flag))
} 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();
lyx_code != Inset::INCLUDE_CODE &&
lyx_code != Inset::GRAPHICS_CODE &&
lyx_code != Inset::ERT_CODE &&
+ lyx_code != Inset::LISTINGS_CODE &&
lyx_code != Inset::FLOAT_CODE &&
lyx_code != Inset::TABULAR_CODE) {
return false;
{
return lyxrc.rtl_support
&& getParLanguage(bparams)->rightToLeft()
- && ownerCode() != Inset::ERT_CODE;
+ && ownerCode() != Inset::ERT_CODE
+ && ownerCode() != Inset::LISTINGS_CODE;
}
// for now we just need this, later should we need this in some
// other way we can always add a function to Inset too.
- return ownerCode() == Inset::ERT_CODE;
+ return ownerCode() == Inset::ERT_CODE || ownerCode() == Inset::LISTINGS_CODE;
}
{
if (layout()->keepempty)
return true;
- return ownerCode() == Inset::ERT_CODE;
+ return ownerCode() == Inset::ERT_CODE || ownerCode() == Inset::LISTINGS_CODE;
}
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:
code = Inset::VSPACE_CODE;
else if (cmd.argument() == "wrap")
code = Inset::WRAP_CODE;
+ else if (cmd.argument() == "listings")
+ code = Inset::LISTINGS_CODE;
break;
case LFUN_ERT_INSERT:
code = Inset::ERT_CODE;
break;
+ case LFUN_LISTING_INSERT:
+ code = Inset::LISTINGS_CODE;
+ break;
case LFUN_FOOTNOTE_INSERT:
code = Inset::FOOT_CODE;
break;
#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"
case LFUN_ERT_INSERT:
return new InsetERT(params);
+ case LFUN_LISTING_INSERT:
+ return new InsetListings(params);
+
case LFUN_FOOTNOTE_INSERT:
return new InsetFoot(params);
InsetCollapsable::CollapseStatus st;
InsetERTMailer::string2params(to_utf8(cmd.argument()), st);
return new InsetERT(params, st);
+
+ } else if (name == "listings") {
+ InsetListingsParams par;
+ InsetListingsMailer::string2params(to_utf8(cmd.argument()), par);
+ return new InsetListings(params, par);
} else if (name == "external") {
Buffer const & buffer = *bv->buffer();
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") {
break;
case VERBATIM:
break;
+ case LISTINGS:
+ break;
}
pair<docstring, docstring> dir1(_("Documents|#o#O"),
///
VERBATIM,
///
- INCLUDE
+ INCLUDE,
+ ///
+ LISTINGS,
};
///
ControlInclude(Dialog &);
--- /dev/null
+/**
+ * \file ControlListings.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "ControlListings.h"
+#include "FuncRequest.h"
+#include "insets/InsetListings.h"
+
+#include "debug.h"
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+ControlListings::ControlListings(Dialog & parent)
+ : Dialog::Controller(parent), params_()
+{}
+
+
+bool ControlListings::initialiseParams(string const & data)
+{
+ InsetListingsMailer::string2params(data, params_);
+ return true;
+}
+
+
+void ControlListings::clearParams()
+{
+ params_.clear();
+}
+
+
+void ControlListings::dispatchParams()
+{
+ string const lfun = InsetListingsMailer::params2string(params());
+ kernel().dispatch(FuncRequest(getLfun(), lfun));
+}
+
+
+void ControlListings::setParams(InsetListingsParams const & params)
+{
+ params_ = params;
+}
+
+
+} // namespace frontend
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file ControlListings.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef CONTROLLISTINGS_H
+#define CONTROLLISTINGS_H
+
+#include "Dialog.h"
+#include "insets/InsetListingsParams.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_; }
+ ///
+ InsetListingsParams const & params() const { return params_; }
+ ///
+ void setParams(InsetListingsParams const &);
+private:
+ ///
+ InsetListingsParams params_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif
ControlGraphics.cpp \
ControlGraphics.h \
ControlInclude.cpp \
+ ControlListings.h \
+ ControlListings.cpp \
ControlInclude.h \
ControlLog.cpp \
ControlLog.h \
#include "ControlFloat.h"
#include "ControlGraphics.h"
#include "ControlInclude.h"
+#include "ControlListings.h"
#include "ControlLog.h"
#include "ControlViewSource.h"
#include "ControlMath.h"
#include "QIndex.h"
#include "QMathMatrixDialog.h"
#include "QNomencl.h"
+#include "QListings.h"
#include "QLog.h"
#include "QViewSource.h"
#include "QNote.h"
"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 *));
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;
QDialogView.cpp QDialogView.h \
QFloat.cpp QFloat.h \
QGraphics.cpp QGraphics.h \
+ QListings.cpp QListings.h \
QLImage.cpp QLImage.h \
QViewSource.cpp QViewSource.h \
QLPainter.cpp QLPainter.h \
IndexUi.ui \
LanguageUi.ui \
LaTeXUi.ui \
+ ListingsUi.ui \
LogUi.ui \
MarginsUi.ui \
MathMatrixUi.ui \
QIndex.cpp QIndex.h \
QLog.cpp QLog.h \
QViewSource.cpp QViewSource.h \
+ QListings.cpp QListings.h \
QLMenubar.cpp QLMenubar.h \
QLPopupMenu.cpp QLPopupMenu.h \
QLPrintDialog.cpp QLPrintDialog.h \
#include "TextClassList.h"
#include "Spacing.h"
+#include "insets/InsetListingsParams.h"
#include "controllers/ControlDocument.h"
#include "support/lstrings.h"
this, SLOT(enableSkip(bool)));
connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
+ connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
+ this, SLOT(change_adaptor()));
+ connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
+ this, SLOT(validate_listings_params()));
+ textLayoutModule->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
textLayoutModule->lspacingLE));
textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
}
+void QDocumentDialog::validate_listings_params()
+{
+ static bool isOK = true;
+ try {
+ InsetListingsParams par(fromqstr(textLayoutModule->listingsED->toPlainText()));
+ if (!isOK) {
+ isOK = true;
+ // listingsTB->setTextColor("black");
+ textLayoutModule->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+ okPB->setEnabled(true);
+ }
+ } catch (invalidParam & e) {
+ isOK = false;
+ // listingsTB->setTextColor("red");
+ textLayoutModule->listingsTB->setPlainText(e.what());
+ okPB->setEnabled(false);
+ }
+}
+
+
void QDocumentDialog::closeEvent(QCloseEvent * e)
{
form_->slotWMHide();
else
params.columns = 1;
+ // text should have passed validation
+ params.listings_params = InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
+
if (textLayoutModule->indentRB->isChecked())
params.paragraph_separation = BufferParams::PARSEP_INDENT;
else
textLayoutModule->twoColumnCB->setChecked(
params.columns == 2);
+
+ // break listings_params to multiple lines
+ string lstparams = InsetListingsParams(params.listings_params).separatedParams();
+ textLayoutModule->listingsED->setText(toqstr(lstparams));
if (!params.options.empty()) {
latexModule->optionsLE->setText(
public Q_SLOTS:
void updateNumbering();
void change_adaptor();
+ void validate_listings_params();
void saveDefaultClicked();
void useDefaultsClicked();
#include "LyXRC.h"
+#include "insets/InsetListingsParams.h"
#include "controllers/ControlInclude.h"
#include <QPushButton>
connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
connect(previewCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+ connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
+ connect(listingsED, SIGNAL(textChanged()), this, SLOT(validate_listings_params()));
filenameED->setValidator(new PathValidator(true, filenameED));
setFocusProxy(filenameED);
}
+void QIncludeDialog::validate_listings_params()
+{
+ static bool isOK = true;
+ try {
+ InsetListingsParams par(fromqstr(listingsED->toPlainText()));
+ if (!isOK) {
+ isOK = true;
+ // listingsTB->setTextColor("black");
+ listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+ okPB->setEnabled(true);
+ }
+ } catch (invalidParam & e) {
+ isOK = false;
+ // listingsTB->setTextColor("red");
+ listingsTB->setPlainText(e.what());
+ okPB->setEnabled(false);
+ }
+}
+
+
void QIncludeDialog::closeEvent(QCloseEvent * e)
{
form_->slotWMHide();
visiblespaceCB->setChecked(false);
previewCB->setEnabled(false);
previewCB->setChecked(false);
+ listingsGB->setEnabled(false);
+ listingsED->setEnabled(false);
break;
//case Input
case 1:
visiblespaceCB->setEnabled(false);
visiblespaceCB->setChecked(false);
previewCB->setEnabled(true);
+ listingsGB->setEnabled(false);
+ listingsED->setEnabled(false);
+ break;
+ //case listings
+ case 3:
+ visiblespaceCB->setEnabled(false);
+ visiblespaceCB->setChecked(false);
+ previewCB->setEnabled(false);
+ listingsGB->setEnabled(true);
+ listingsED->setEnabled(true);
break;
//case Verbatim
default:
visiblespaceCB->setEnabled(true);
previewCB->setEnabled(false);
previewCB->setChecked(false);
+ listingsGB->setEnabled(false);
+ listingsED->setEnabled(false);
break;
}
}
bcview().addReadOnly(dialog_->browsePB);
bcview().addReadOnly(dialog_->visiblespaceCB);
bcview().addReadOnly(dialog_->typeCO);
+ bcview().addReadOnly(dialog_->listingsED);
+ dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
addCheckedLineEdit(bcview(), dialog_->filenameED, dialog_->filenameLA);
}
dialog_->visiblespaceCB->setEnabled(false);
dialog_->previewCB->setChecked(false);
dialog_->previewCB->setEnabled(false);
+ dialog_->listingsGB->setEnabled(false);
+ dialog_->listingsED->setEnabled(false);
string cmdname = controller().params().getCmdName();
if (cmdname != "include" &&
cmdname != "verbatiminput" &&
- cmdname != "verbatiminput*")
+ cmdname != "verbatiminput*" &&
+ cmdname != "lstinputlisting")
cmdname = "input";
if (cmdname == "include") {
} else if (cmdname == "verbatiminput") {
dialog_->typeCO->setCurrentIndex(2);
dialog_->visiblespaceCB->setEnabled(true);
- }
+
+ } else if (cmdname == "lstinputlisting") {
+ dialog_->typeCO->setCurrentIndex(3);
+ dialog_->listingsGB->setEnabled(true);
+ dialog_->listingsED->setEnabled(true);
+ InsetListingsParams par(params.getOptions());
+ dialog_->listingsED->setText(toqstr(par.separatedParams()));
+ }
}
params.preview(dialog_->previewCB->isChecked());
int const item = dialog_->typeCO->currentIndex();
- if (item == 0)
+ if (item == 0) {
params.setCmdName("include");
- else if (item == 1)
+ params.setOptions(string());
+ } else if (item == 1) {
params.setCmdName("input");
- else {
+ params.setOptions(string());
+ } else if (item == 3) {
+ params.setCmdName("lstinputlisting");
+ // the parameter string should have passed validation
+ params.setOptions(InsetListingsParams(fromqstr(dialog_->listingsED->toPlainText())).params());
+ } else {
if (dialog_->visiblespaceCB->isChecked())
params.setCmdName("verbatiminput*");
else
params.setCmdName("verbatiminput");
+ params.setOptions(string());
}
controller().setParams(params);
}
type = ControlInclude::INCLUDE;
else if (item == 1)
type = ControlInclude::INPUT;
- else
+ else if (item == 2)
type = ControlInclude::VERBATIM;
+ else
+ type = ControlInclude::LISTINGS;
docstring const & name =
controller().browse(qstring_to_ucs4(dialog_->filenameED->text()), type);
virtual void show();
protected Q_SLOTS:
virtual void change_adaptor();
+ void validate_listings_params();
virtual void loadClicked();
virtual void browseClicked();
virtual void typeChanged(int v);
--- /dev/null
+/**
+ * \file QListings.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ *
+ * 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 "debug.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(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+ connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+ connect(inlineCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+ connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
+ connect(listingsED, SIGNAL(textChanged()), this, SLOT(validate_listings_params()));
+}
+
+
+void QListingsDialog::closeEvent(QCloseEvent * e)
+{
+ form_->slotWMHide();
+ e->accept();
+}
+
+
+void QListingsDialog::change_adaptor()
+{
+ form_->changed();
+}
+
+
+void QListingsDialog::validate_listings_params()
+{
+ static bool isOK = true;
+ try {
+ InsetListingsParams par(fromqstr(listingsED->toPlainText()));
+ if (!isOK) {
+ isOK = true;
+ // listingsTB->setTextColor("black");
+ listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+ okPB->setEnabled(true);
+ }
+ } catch (invalidParam & e) {
+ isOK = false;
+ // listingsTB->setTextColor("red");
+ listingsTB->setPlainText(e.what());
+ okPB->setEnabled(false);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////
+//
+// 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);
+ dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+
+ update_contents();
+}
+
+
+/// not used right now.
+void QListings::apply()
+{
+ InsetListingsParams & params = controller().params();
+ params.setInline(dialog_->inlineCB->isChecked());
+ params.setParams(fromqstr(dialog_->listingsED->toPlainText()));
+ controller().setParams(params);
+}
+
+
+void QListings::update_contents()
+{
+ InsetListingsParams & params = controller().params();
+ dialog_->listingsED->setText(toqstr(params.separatedParams()));
+
+ if (params.isInline())
+ dialog_->inlineCB->setChecked(true);
+ else
+ dialog_->inlineCB->setChecked(false);
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+
+#include "QListings_moc.cpp"
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file QListings.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ *
+ * 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();
+ /// AFAIK, QValidator only works for QLineEdit so
+ /// I have to validate listingsED (QTextEdit) manually.
+ void validate_listings_params();
+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
<rect>
<x>0</x>
<y>0</y>
- <width>386</width>
- <height>171</height>
+ <width>416</width>
+ <height>373</height>
</rect>
</property>
<property name="windowTitle" >
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
+ <widget class="QWidget" name="" >
+ <property name="geometry" >
+ <rect>
+ <x>9</x>
+ <y>9</y>
+ <width>401</width>
+ <height>361</height>
+ </rect>
</property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="3" column="0" colspan="2" >
- <widget class="QCheckBox" name="previewCB" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>3</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="toolTip" >
- <string>Show LaTeX preview</string>
- </property>
- <property name="text" >
- <string>&Show preview</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0" colspan="2" >
- <widget class="QCheckBox" name="visiblespaceCB" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>3</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="toolTip" >
- <string>Underline spaces in generated output</string>
- </property>
- <property name="text" >
- <string>&Mark spaces in output</string>
- </property>
- </widget>
- </item>
- <item rowspan="2" row="2" column="2" colspan="3" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>130</width>
- <height>50</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="0" column="1" colspan="3" >
- <widget class="QLineEdit" name="filenameED" >
- <property name="toolTip" >
- <string>File name to include</string>
- </property>
- </widget>
- </item>
- <item row="1" column="4" >
- <widget class="QPushButton" name="loadPB" >
- <property name="toolTip" >
- <string>Load the file</string>
- </property>
- <property name="text" >
- <string>&Load</string>
- </property>
- </widget>
- </item>
- <item row="1" column="3" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>28</width>
- <height>28</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="1" column="1" colspan="2" >
- <widget class="QComboBox" name="typeCO" >
- <item>
- <property name="text" >
- <string>Include</string>
+ <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>
+ <item>
+ <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>
+ <item>
+ <widget class="QLabel" name="filenameLA" >
+ <property name="toolTip" >
+ <string/>
+ </property>
+ <property name="text" >
+ <string>&File:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>filenameED</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="filenameED" >
+ <property name="toolTip" >
+ <string>File name to include</string>
+ </property>
+ </widget>
+ </item>
+ </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="TextLabel1" >
+ <property name="text" >
+ <string>&Include Type:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>typeCO</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="typeCO" >
+ <item>
+ <property name="text" >
+ <string>Include</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Input</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Verbatim</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Listings</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>28</width>
+ <height>28</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QPushButton" name="browsePB" >
+ <property name="toolTip" >
+ <string>Select a file</string>
+ </property>
+ <property name="text" >
+ <string>&Browse...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="loadPB" >
+ <property name="toolTip" >
+ <string>Load the file</string>
+ </property>
+ <property name="text" >
+ <string>&Load</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
</property>
- </item>
- <item>
- <property name="text" >
- <string>Input</string>
+ <item>
+ <widget class="QGroupBox" name="includeGB" >
+ <property name="title" >
+ <string/>
+ </property>
+ <widget class="QCheckBox" name="previewCB" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>20</y>
+ <width>100</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>3</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip" >
+ <string>Show LaTeX preview</string>
+ </property>
+ <property name="text" >
+ <string>&Show preview</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="visiblespaceCB" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>50</y>
+ <width>142</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>3</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip" >
+ <string>Underline spaces in generated output</string>
+ </property>
+ <property name="text" >
+ <string>&Mark spaces in output</string>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="listingsGB" >
+ <property name="title" >
+ <string>Listing Params</string>
+ </property>
+ <widget class="QTextEdit" name="listingsED" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>100</y>
+ <width>171</width>
+ <height>121</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QTextBrowser" name="listingsTB" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>20</y>
+ <width>171</width>
+ <height>71</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>4</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="cursor" >
+ <cursor>14</cursor>
+ </property>
+ <property name="acceptDrops" >
+ <bool>false</bool>
+ </property>
+ <property name="frameShape" >
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Plain</enum>
+ </property>
+ <property name="lineWidth" >
+ <number>0</number>
+ </property>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
</property>
- </item>
- <item>
- <property name="text" >
- <string>Verbatim</string>
+ <property name="spacing" >
+ <number>6</number>
</property>
- </item>
- </widget>
- </item>
- <item row="1" column="0" >
- <widget class="QLabel" name="TextLabel1" >
- <property name="text" >
- <string>&Include Type:</string>
- </property>
- <property name="buddy" >
- <cstring>typeCO</cstring>
- </property>
- </widget>
- </item>
- <item row="0" column="4" >
- <widget class="QPushButton" name="browsePB" >
- <property name="toolTip" >
- <string>Select a file</string>
- </property>
- <property name="text" >
- <string>&Browse...</string>
- </property>
- </widget>
- </item>
- <item row="0" column="0" >
- <widget class="QLabel" name="filenameLA" >
- <property name="toolTip" >
- <string/>
- </property>
- <property name="text" >
- <string>&File:</string>
- </property>
- <property name="buddy" >
- <cstring>filenameED</cstring>
- </property>
- </widget>
- </item>
- <item row="4" column="0" colspan="5" >
- <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>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </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>&Close</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </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>&Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
</widget>
<tabstops>
<tabstop>filenameED</tabstop>
--- /dev/null
+<ui version="4.0" >
+ <class>QListingsUi</class>
+ <widget class="QDialog" name="QListingsUi" >
+ <property name="windowModality" >
+ <enum>Qt::ApplicationModal</enum>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>451</width>
+ <height>392</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Listing</string>
+ </property>
+ <property name="sizeGripEnabled" >
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="layoutWidget" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>431</width>
+ <height>371</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QCheckBox" name="inlineCB" >
+ <property name="text" >
+ <string>Inlined listing (\lstinline)</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="listingsGB" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>7</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title" >
+ <string>Parameters</string>
+ </property>
+ <widget class="QTextEdit" name="listingsED" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>100</y>
+ <width>411</width>
+ <height>171</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QTextBrowser" name="listingsTB" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>20</y>
+ <width>411</width>
+ <height>71</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>4</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="cursor" >
+ <cursor>14</cursor>
+ </property>
+ <property name="acceptDrops" >
+ <bool>false</bool>
+ </property>
+ <property name="frameShape" >
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Plain</enum>
+ </property>
+ <property name="lineWidth" >
+ <number>0</number>
+ </property>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <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="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>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <tabstops>
+ <tabstop>okPB</tabstop>
+ <tabstop>closePB</tabstop>
+ </tabstops>
+ <includes>
+ <include location="local" >qt_helpers.h</include>
+ </includes>
+ <resources/>
+ <connections/>
+</ui>
<ui version="4.0" >
- <author></author>
- <comment></comment>
- <exportmacro></exportmacro>
<class>TextLayoutUi</class>
<widget class="QWidget" name="TextLayoutUi" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
- <width>287</width>
- <height>208</height>
+ <width>449</width>
+ <height>517</height>
</rect>
</property>
<property name="windowTitle" >
<string/>
</property>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
+ <widget class="QWidget" name="" >
+ <property name="geometry" >
+ <rect>
+ <x>9</x>
+ <y>10</y>
+ <width>399</width>
+ <height>511</height>
+ </rect>
</property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="1" column="2" >
- <widget class="QLineEdit" name="lspacingLE" >
- <property name="enabled" >
- <bool>false</bool>
- </property>
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>1</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- </widget>
- </item>
- <item row="1" column="1" >
- <widget class="QComboBox" name="lspacingCO" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>5</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="duplicatesEnabled" >
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="0" >
- <widget class="QLabel" name="lspacingL" >
- <property name="text" >
- <string>&Line spacing:</string>
- </property>
- <property name="buddy" >
- <cstring>lspacingCO</cstring>
- </property>
- </widget>
- </item>
- <item row="0" column="0" colspan="3" >
- <widget class="QGroupBox" name="ButtonGroup6" >
- <property name="title" >
- <string>Separate Paragraphs With</string>
- </property>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QGroupBox" name="ButtonGroup6" >
+ <property name="title" >
+ <string>Separate Paragraphs With</string>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="2" column="1" >
+ <widget class="QComboBox" name="skipCO" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2" colspan="2" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>178</width>
+ <height>22</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="3" column="3" >
+ <widget class="LengthCombo" native="1" name="skipLengthCO" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" colspan="2" >
+ <widget class="QLineEdit" name="skipLE" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item rowspan="2" row="2" column="0" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>31</width>
+ <height>58</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="0" colspan="4" >
+ <widget class="QRadioButton" name="skipRB" >
+ <property name="toolTip" >
+ <string/>
+ </property>
+ <property name="text" >
+ <string>&Vertical space</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" colspan="4" >
+ <widget class="QRadioButton" name="indentRB" >
+ <property name="toolTip" >
+ <string>Indent consecutive paragraphs</string>
+ </property>
+ <property name="text" >
+ <string>&Indentation</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox" >
+ <property name="title" >
+ <string>Spacing</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <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>
+ <item>
+ <widget class="QLabel" name="lspacingL" >
+ <property name="text" >
+ <string>&Line spacing:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>lspacingCO</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="lspacingCO" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>5</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="duplicatesEnabled" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lspacingLE" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="twoColumnCB" >
+ <property name="toolTip" >
+ <string>Format text into two columns</string>
+ </property>
+ <property name="text" >
+ <string>Two-&column document</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="listingsGB" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize" >
+ <size>
+ <width>0</width>
+ <height>150</height>
+ </size>
+ </property>
+ <property name="layoutDirection" >
+ <enum>Qt::LeftToRight</enum>
+ </property>
+ <property name="title" >
+ <string>Listings settings</string>
+ </property>
+ <widget class="QTextBrowser" name="listingsTB" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>70</y>
+ <width>371</width>
+ <height>71</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>4</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="cursor" >
+ <cursor>14</cursor>
+ </property>
+ <property name="acceptDrops" >
+ <bool>false</bool>
+ </property>
+ <property name="frameShape" >
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Plain</enum>
+ </property>
+ <property name="lineWidth" >
+ <number>0</number>
+ </property>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QTextEdit" name="listingsED" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>20</y>
+ <width>371</width>
+ <height>75</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
</property>
- <property name="spacing" >
- <number>6</number>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Expanding</enum>
</property>
- <item row="2" column="1" >
- <widget class="QComboBox" name="skipCO" >
- <property name="enabled" >
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item row="2" column="2" colspan="2" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>178</width>
- <height>22</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="3" column="3" >
- <widget class="LengthCombo" name="skipLengthCO" >
- <property name="enabled" >
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item row="3" column="1" colspan="2" >
- <widget class="QLineEdit" name="skipLE" >
- <property name="enabled" >
- <bool>false</bool>
- </property>
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>1</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- </widget>
- </item>
- <item rowspan="2" row="2" column="0" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::Fixed</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>31</width>
- <height>58</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="1" column="0" colspan="4" >
- <widget class="QRadioButton" name="skipRB" >
- <property name="toolTip" >
- <string/>
- </property>
- <property name="text" >
- <string>&Vertical space</string>
- </property>
- </widget>
- </item>
- <item row="0" column="0" colspan="4" >
- <widget class="QRadioButton" name="indentRB" >
- <property name="toolTip" >
- <string>Indent consecutive paragraphs</string>
- </property>
- <property name="text" >
- <string>&Indentation</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item row="3" column="0" colspan="3" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="2" column="0" colspan="3" >
- <widget class="QCheckBox" name="twoColumnCB" >
- <property name="toolTip" >
- <string>Format text into two columns</string>
- </property>
- <property name="text" >
- <string>Two-&column document</string>
- </property>
- </widget>
- </item>
- </layout>
+ <property name="sizeHint" >
+ <size>
+ <width>397</width>
+ <height>27</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
</widget>
- <pixmapfunction></pixmapfunction>
- <includes>
- <include location="local" >qt_helpers.h</include>
- </includes>
<customwidgets>
<customwidget>
<class>LengthCombo</class>
<extends>QWidget</extends>
<header>LengthCombo.h</header>
- <container>0</container>
- <pixmap></pixmap>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>lspacingLE</tabstop>
<tabstop>twoColumnCB</tabstop>
</tabstops>
+ <includes>
+ <include location="local" >qt_helpers.h</include>
+ </includes>
<resources/>
<connections/>
</ui>
InsetName("charstyle", Inset::CHARSTYLE_CODE),
InsetName("vspace", Inset::VSPACE_CODE),
InsetName("mathmacroarg", Inset::MATHMACROARG_CODE),
+ InsetName("listings", Inset::LISTINGS_CODE),
};
std::size_t const insetnames_size =
///
NOMENCL_PRINT_CODE,
///
- PAGEBREAK_CODE
+ PAGEBREAK_CODE,
+ ///
+ LISTINGS_CODE
};
/** returns the Code corresponding to the \c name.
return &info;
}
+ if (name == "lstinputlisting") {
+ static const char * const paramnames[] = {"filename", "lstparams", ""};
+ static const bool isoptional[] = {false, true};
+ static const CommandInfo info = {2, paramnames, isoptional};
+ return &info;
+ }
+
// InsetIndex, InsetPrintIndex, InsetLabel
if (name == "index" || name == "printindex" || name == "label") {
static const char * const paramnames[] = {"name", ""};
docstring const getCommand() const;
/// Return the command name
std::string const & getCmdName() const { return name_; }
-private:
- /// FIXME remove
+ /// this is used by listings package.
std::string const getOptions() const;
+private:
/// FIXME remove
std::string const getSecOptions() const;
public:
/// are cleared except those that exist also in the new command.
/// What matters here is the parameter name, not position.
void setCmdName(std::string const & n);
-private:
- /// FIXME remove
+ /// this is used by the listings package
void setOptions(std::string const &);
+private:
/// FIXME remove
void setSecOptions(std::string const &);
public:
#include "graphics/PreviewLoader.h"
#include "insets/RenderPreview.h"
+#include "insets/InsetListingsParams.h"
#include "support/filetools.h"
#include "support/lstrings.h" // contains
INCLUDE = 0,
VERB = 1,
INPUT = 2,
- VERBAST = 3
+ VERBAST = 3,
+ LISTINGS = 4,
};
return VERB;
if (command_name == "verbatiminput*")
return VERBAST;
+ if (command_name == "lstinputlisting")
+ return LISTINGS;
return INCLUDE;
}
}
+bool isListings(InsetCommandParams const & params)
+{
+ return params.getCmdName() == "lstinputlisting";
+}
+
+
string const masterFilename(Buffer const & buffer)
{
return buffer.getMasterBuffer()->fileName();
case INCLUDE:
temp += buf.B_("Include");
break;
+ case LISTINGS:
+ temp += buf.B_("Program Listing");
+ break;
}
temp += ": ";
/// return the child buffer if the file is a LyX doc and is loaded
Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params)
{
- if (isVerbatim(params))
+ if (isVerbatim(params) || isListings(params))
return 0;
string const included_file = includedFilename(buffer, params).absFilename();
/// return true if the file is or got loaded.
bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
{
- if (isVerbatim(params))
+ if (isVerbatim(params) || isListings(params))
return false;
FileName const included_file = includedFilename(buffer, params);
os << '\\' << from_ascii(params_.getCmdName())
<< '{' << from_utf8(incfile) << '}';
}
+ } else if (type(params_) == LISTINGS) {
+ os << '\\' << from_ascii(params_.getCmdName());
+ string opt = params_.getOptions();
+ // opt is set in QInclude dialog and should have passed validation.
+ InsetListingsParams params(opt);
+ if (!params.params().empty())
+ os << "[" << from_utf8(params.encodedString()) << "]";
+ os << '{' << from_utf8(incfile) << '}';
} else {
runparams.exportdata->addExternalFile(tex_format, writefile,
exportfile);
int InsetInclude::plaintext(Buffer const & buffer, odocstream & os,
OutputParams const &) const
{
- if (isVerbatim(params_)) {
+ if (isVerbatim(params_) || isListings(params_)) {
os << '[' << getScreenLabel(buffer) << '\n';
// FIXME: We don't know the encoding of the file
docstring const str =
runparams.exportdata->addExternalFile("docbook-xml", writefile,
exportfile);
- if (isVerbatim(params_)) {
+ if (isVerbatim(params_) || isListings(params_)) {
os << "<inlinegraphic fileref=\""
<< '&' << include_label << ';'
<< "\" format=\"linespecific\">";
else
writefile = included_file;
- if (!features.runparams().nice && !isVerbatim(params_)) {
+ if (!features.runparams().nice && !isVerbatim(params_) && !isListings(params_)) {
incfile = DocFileName(writefile).mangledFilename();
writefile = makeAbsPath(incfile,
buffer.getMasterBuffer()->temppath()).absFilename();
if (isVerbatim(params_))
features.require("verbatim");
+ else if (isListings(params_))
+ features.require("listings");
// Here we must do the fun stuff...
// Load the file in the include if it needs
--- /dev/null
+/**
+ * \file InsetListings.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "InsetListings.h"
+
+#include "Language.h"
+#include "gettext.h"
+#include "DispatchResult.h"
+#include "FuncRequest.h"
+#include "FuncStatus.h"
+#include "Cursor.h"
+#include "support/lstrings.h"
+
+#include <sstream>
+
+namespace lyx {
+
+using support::token;
+
+using std::auto_ptr;
+using std::istringstream;
+using std::ostream;
+using std::ostringstream;
+using std::string;
+
+
+void InsetListings::init()
+{
+ // FIXME: define Color::listing?
+ Font font(Font::ALL_SANE);
+ font.decSize();
+ font.decSize();
+ font.setColor(Color::foreground);
+ setLabelFont(font);
+ // FIXME: english_language?
+ text_.current_font.setLanguage(english_language);
+ text_.real_current_font.setLanguage(english_language);
+ // FIXME: why I can not make text of source code black with the following two lines?
+ text_.current_font.setColor(Color::foreground);
+ text_.real_current_font.setColor(Color::foreground);
+}
+
+
+InsetListings::InsetListings(BufferParams const & bp, InsetListingsParams const & par)
+ : InsetERT(bp, par.status())
+{
+ init();
+}
+
+
+InsetListings::InsetListings(InsetListings const & in)
+ : InsetERT(in)
+{
+ init();
+}
+
+
+auto_ptr<Inset> InsetListings::doClone() const
+{
+ return auto_ptr<Inset>(new InsetListings(*this));
+}
+
+
+InsetListings::~InsetListings()
+{
+ InsetListingsMailer(*this).hideDialog();
+}
+
+
+bool InsetListings::display() const
+{
+ return !params().isInline();
+}
+
+
+void InsetListings::write(Buffer const & buf, ostream & os) const
+{
+ os << "listings" << "\n";
+ InsetListingsParams const & par = params();
+ // parameter string is encoded to be a valid lyx token.
+ string opt = par.encodedString();
+ if (!opt.empty())
+ os << "lstparams \"" << opt << "\"\n";
+ if (par.isInline())
+ os << "inline true\n";
+ else
+ os << "inline false\n";
+ InsetCollapsable::write(buf, os);
+}
+
+
+void InsetListings::read(Buffer const & buf, Lexer & lex)
+{
+ while (lex.isOK()) {
+ lex.next();
+ string const token = lex.getString();
+ if (token == "lstparams") {
+ lex.next();
+ string const value = lex.getString();
+ params().fromEncodedString(value);
+ } else if (token == "inline") {
+ lex.next();
+ params().setInline(lex.getBool());
+ } else {
+ // no special option, push back 'status' etc
+ lex.pushToken(token);
+ break;
+ }
+ }
+ InsetCollapsable::read(buf, lex);
+}
+
+
+docstring const InsetListings::editMessage() const
+{
+ return _("Opened Listings Inset");
+}
+
+
+int InsetListings::latex(Buffer const &, odocstream & os,
+ OutputParams const &) const
+{
+ string param_string = params().encodedString();
+ // 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 lstinline = params().isInline();
+ if (lstinline) {
+ if (param_string.empty())
+ os << "\\lstinline{";
+ else
+ os << "\\lstinline[" << from_ascii(param_string) << "]{";
+ } else {
+ if (param_string.empty())
+ os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}\n";
+ else
+ os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}[" << from_ascii(param_string) << "]\n";
+ lines += 4;
+ }
+ ParagraphList::const_iterator par = paragraphs().begin();
+ ParagraphList::const_iterator end = paragraphs().end();
+
+ 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;
+ // for the inline case, if there are multiple paragraphs
+ // they are simply joined. Otherwise, expect latex errors.
+ if (par != end && !lstinline) {
+ os << "\n";
+ ++lines;
+ }
+ }
+ if (lstinline)
+ os << "}";
+ else {
+ os << "\n\\end{lstlisting}\n\\endgroup\n";
+ lines += 3;
+ }
+
+ return lines;
+}
+
+
+void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd)
+{
+ switch (cmd.action) {
+
+ case LFUN_INSET_MODIFY: {
+ InsetListingsMailer::string2params(to_utf8(cmd.argument()), params());
+ break;
+ }
+ case LFUN_INSET_DIALOG_UPDATE:
+ InsetListingsMailer(*this).updateDialog(&cur.bv());
+ break;
+ case LFUN_MOUSE_RELEASE: {
+ if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
+ InsetListingsMailer(*this).showDialog(&cur.bv());
+ break;
+ }
+ InsetERT::doDispatch(cur, cmd);
+ break;
+ }
+ default:
+ InsetERT::doDispatch(cur, cmd);
+ break;
+ }
+}
+
+
+bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
+ FuncStatus & status) const
+{
+ switch (cmd.action) {
+ case LFUN_INSET_DIALOG_UPDATE:
+ status.enabled(true);
+ return true;
+ default:
+ return InsetERT::getStatus(cur, cmd, status);
+ }
+}
+
+
+void InsetListings::setButtonLabel()
+{
+ // FIXME UNICODE
+ setLabel(isOpen() ? _("Listings") : getNewLabel(_("Listings")));
+}
+
+
+void InsetListings::validate(LaTeXFeatures & features) const
+{
+ features.require("listings");
+ InsetERT::validate(features);
+}
+
+
+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);
+ // discard "listings", which is only used to determine inset
+ lex.next();
+ params.read(lex);
+}
+
+
+string const
+InsetListingsMailer::params2string(InsetListingsParams const & params)
+{
+ ostringstream data;
+ data << name_ << " ";
+ params.write(data);
+ return data.str();
+}
+
+
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file InsetListings.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef INSETLISTINGS_H
+#define INSETLISTINGS_H
+
+#include "LaTeXFeatures.h"
+#include "InsetERT.h"
+#include "InsetListingsParams.h"
+#include "MailInset.h"
+
+
+namespace lyx {
+
+/** A collapsable text inset for program listings.
+ */
+
+
+class InsetListings : public InsetERT {
+public:
+ ///
+ InsetListings(BufferParams const &, InsetListingsParams const & par = InsetListingsParams());
+ ///
+ ~InsetListings();
+ ///
+ Inset::Code lyxCode() const { return Inset::LISTINGS_CODE; }
+ /// lstinline is inlined, normal listing is displayed
+ virtual bool display() const;
+ ///
+ 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;
+ ///
+ int latex(Buffer const &, odocstream &, OutputParams const &) const;
+ ///
+ void validate(LaTeXFeatures &) const;
+ ///
+ bool showInsetDialog(BufferView *) const;
+ ///
+ void getDrawFont(Font &) const;
+ ///
+ InsetListingsParams const & params() const { return params_; }
+ ///
+ InsetListingsParams & params() { 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();
+ ///
+ 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
--- /dev/null
+/**
+ * \file InsetListingsParams.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "Lexer.h"
+#include "InsetListingsParams.h"
+
+#include "gettext.h"
+#include "Length.h"
+
+#include <sstream>
+#include <boost/assert.hpp>
+
+#include "support/lstrings.h"
+#include "support/convert.h"
+
+using std::vector;
+using std::ostream;
+using std::string;
+using std::exception;
+using lyx::support::trim;
+
+namespace lyx
+{
+
+enum param_type {
+ ALL,
+ TRUEFALSE,
+ INTEGER,
+ LENGTH,
+ ONEOF,
+ SUBSETOF,
+};
+
+
+/** Information about each parameter
+ */
+struct listings_param_info {
+ /// name of the parameter
+ char const * name;
+ /// default value
+ char const * value;
+ // for option with value "true", "false",
+ // if onoff is true,
+ // "true": option
+ // "false":
+ // "other": option="other"
+ // onoff is false,
+ // "true": option=true
+ // "false": option=false
+ bool onoff;
+ /// validator type
+ param_type type;
+ // ALL:
+ // TRUEFALSE:
+ // INTEGER:
+ // LENGTH:
+ // info is ignored.
+ // ONEOF
+ // info is a \n separated string with allowed values
+ // SUBSETOF
+ // info is a string from which par is composed of
+ // (e.g. floatplacement can be one or more of tbph)
+ char const * info;
+ //
+ char const * hint;
+};
+
+
+char const * allowed_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";
+
+char const * style_hint = "Use \\footnotessize, \\small, \\itshape, \\ttfamily or something like that";
+char const * frame_hint = "none, leftline, topline, bottomline, lines, single, shadowbox or subset of trblTRBL";
+char const * frameround_hint = "The foru letters (t or f) attached to top right, bottom right, bottom left and top left corner.";
+char const * color_hint = "Enter something like \\color{white}";
+
+/// options copied from page 26 of listings manual
+// FIXME: add default parameters ... (which is not used now)
+listings_param_info const listings_param_table[] = {
+ { "float", "false", true, SUBSETOF, "tbph", "" },
+ { "floatplacement", "tbp", false, SUBSETOF, "tbph", "" },
+ { "aboveskip", "\\medskipamount", false, LENGTH, "", "" },
+ { "belowskip", "\\medskipamount", false, LENGTH, "", "" },
+ { "lineskip", "", false, LENGTH, "", "" },
+ { "boxpos", "", false, SUBSETOF, "bct", "" },
+ { "print", "", false, TRUEFALSE, "", "" },
+ { "firstline", "", false, INTEGER, "", "" },
+ { "lastline", "", false, INTEGER, "", "" },
+ { "showlines", "", false, TRUEFALSE, "", "" },
+ { "emptylines", "", false, ALL, "", "Expect a number with an optional * before it" },
+ { "gobble", "", false, INTEGER, "", "" },
+ { "style", "", false, ALL, "", "" },
+ { "language", "", false, ONEOF, allowed_languages, "" },
+ { "alsolanguage", "", false, ONEOF, allowed_languages, "" },
+ { "defaultdialect", "", false, ONEOF, allowed_languages, "" },
+ { "printpod", "", false, TRUEFALSE, "", "" },
+ { "usekeywordsintag", "", false, TRUEFALSE, "", "" },
+ { "tagstyle", "", false, ALL, "", style_hint },
+ { "markfirstintag", "", false, ALL, "", style_hint },
+ { "makemacrouse", "", false, TRUEFALSE, "", "" },
+ { "basicstyle", "", false, ALL, "", style_hint },
+ { "identifierstyle", "", false, ALL, "", style_hint },
+ { "commentstyle", "", false, ALL, "", style_hint },
+ { "stringstyle", "", false, ALL, "", style_hint },
+ { "keywordstyle", "", false, ALL, "", style_hint },
+ { "ndkeywordstyle", "", false, ALL, "", style_hint },
+ { "classoffset", "", false, INTEGER, "", "" },
+ { "texcsstyle", "", false, ALL, "", style_hint },
+ { "directivestyle", "", false, ALL, "", style_hint },
+ { "emph", "", false, ALL, "", "" },
+ { "moreemph", "", false, ALL, "", "" },
+ { "deleteemph", "", false, ALL, "", "" },
+ { "emphstyle", "", false, ALL, "", "" },
+ { "delim", "", false, ALL, "", "" },
+ { "moredelim", "", false, ALL, "", "" },
+ { "deletedelim", "", false, ALL, "", "" },
+ { "extendedchars", "", false, TRUEFALSE, "", "" },
+ { "inputencoding", "", false, ALL, "", "" },
+ { "upquote", "", false, TRUEFALSE, "", "" },
+ { "tabsize", "", false, INTEGER, "", "" },
+ { "showtabs", "", false, ALL, "", "" },
+ { "tab", "", false, ALL, "", "" },
+ { "showspaces", "", false, TRUEFALSE, "", "" },
+ { "showstringspaces", "", false, TRUEFALSE, "", "" },
+ { "formfeed", "", false, ALL, "", "" },
+ { "numbers", "", false, ONEOF, "none\nleft\nright", "" },
+ { "stepnumber", "", false, INTEGER, "", "" },
+ { "numberfirstline", "", false, TRUEFALSE, "", "" },
+ { "numberstyle", "", false, ALL, "", style_hint },
+ { "numbersep", "", false, LENGTH, "", "" },
+ { "numberblanklines", "", false, ALL, "", "" },
+ { "firstnumber", "", false, ALL, "", "auto, last or a number" },
+ { "name", "", false, ALL, "", "" },
+ { "thelstnumber", "", false, ALL, "", "" },
+ { "title", "", false, ALL, "", "" },
+ { "caption", "", false, ALL, "", "" },
+ { "label", "", false, ALL, "", "" },
+ { "nolol", "", false, TRUEFALSE, "", "" },
+ { "captionpos", "", false, SUBSETOF, "tb", "" },
+ { "abovecaptionskip", "", false, LENGTH, "", "" },
+ { "belowcaptionskip", "", false, LENGTH, "", "" },
+ { "linewidth", "", false, LENGTH, "", "" },
+ { "xleftmargin", "", false, LENGTH, "", "" },
+ { "xrightmargin", "", false, LENGTH, "", "" },
+ { "resetmargin", "", false, TRUEFALSE, "", "" },
+ { "breaklines", "", false, TRUEFALSE, "", "" },
+ { "prebreak", "", false, ALL, "", "" },
+ { "postbreak", "", false, ALL, "", "" },
+ { "breakindent", "", false, LENGTH, "", "" },
+ { "breakautoindent", "", false, TRUEFALSE, "", "" },
+ { "frame", "", false, ALL, "", frame_hint },
+ { "frameround", "", false, SUBSETOF, "tf", frameround_hint },
+ { "framesep", "", false, LENGTH, "", "" },
+ { "rulesep", "", false, LENGTH, "", "" },
+ { "framerule", "", false, LENGTH, "", "" },
+ { "framexleftmargin", "", false, LENGTH, "", "" },
+ { "framexrightmargin", "", false, LENGTH, "", "" },
+ { "framextopmargin", "", false, LENGTH, "", "" },
+ { "framexbottommargin", "", false, LENGTH, "", "" },
+ { "backgroundcolor", "", false, ALL, "", color_hint },
+ { "rulecolor", "", false, ALL, "", color_hint },
+ { "fillcolor", "", false, ALL, "", color_hint },
+ { "rulesepcolor", "", false, ALL, "", color_hint },
+ { "frameshape", "", false, ALL, "", "" },
+ { "index", "", false, ALL, "", "" },
+ { "moreindex", "", false, ALL, "", "" },
+ { "deleteindex", "", false, ALL, "", "" },
+ { "indexstyle", "", false, ALL, "", "" },
+ { "columns", "", false, ALL, "", "" },
+ { "flexiblecolumns", "", false, ALL, "", "" },
+ { "keepspaces", "", false, TRUEFALSE, "", "" },
+ { "basewidth", "", false, LENGTH, "", "" },
+ { "fontadjust", "", true, TRUEFALSE, "", "" },
+ { "texcl", "", false, TRUEFALSE, "", "" },
+ { "mathescape", "", false, TRUEFALSE, "", "" },
+ { "escapechar", "", false, ALL, "", "" },
+ { "escapeinside", "", false, ALL, "", "" },
+ { "escepeinside", "", false, ALL, "", "" },
+ { "escepebegin", "", false, ALL, "", "" },
+ { "escepeend", "", false, ALL, "", "" },
+ { "fancyvrb", "", false, TRUEFALSE, "", "" },
+ { "fvcmdparams", "", false, ALL, "", "" },
+ { "morefvcmdparams", "", false, ALL, "", "" },
+ { "keywordsprefix", "", false, ALL, "", "" },
+ { "keywords", "", false, ALL, "", "" },
+ { "morekeywords", "", false, ALL, "", "" },
+ { "deletekeywords", "", false, ALL, "", "" },
+ { "ndkeywords", "", false, ALL, "", "" },
+ { "morendkeywords", "", false, ALL, "", "" },
+ { "deletendkeywords", "", false, ALL, "", "" },
+ { "texcs", "", false, ALL, "", "" },
+ { "moretexcs", "", false, ALL, "", "" },
+ { "deletetexcs", "", false, ALL, "", "" },
+ { "directives", "", false, ALL, "", "" },
+ { "moredirectives", "", false, ALL, "", "" },
+ { "deletedirectives", "", false, ALL, "", "" },
+ { "sensitive", "", false, ALL, "", "" },
+ { "alsoletter", "", false, ALL, "", "" },
+ { "alsodigit", "", false, ALL, "", "" },
+ { "alsoother", "", false, ALL, "", "" },
+ { "otherkeywords", "", false, ALL, "", "" },
+ { "tag", "", false, ALL, "", "" },
+ { "string", "", false, ALL, "", "" },
+ { "morestring", "", false, ALL, "", "" },
+ { "deletestring", "", false, ALL, "", "" },
+ { "comment", "", false, ALL, "", "" },
+ { "morecomment", "", false, ALL, "", "" },
+ { "deletecomment", "", false, ALL, "", "" },
+ { "keywordcomment", "", false, ALL, "", "" },
+ { "morekeywordcomment", "", false, ALL, "", "" },
+ { "deletekeywordcomment", "", false, ALL, "", "" },
+ { "keywordcommentsemicolon", "", false, ALL, "", "" },
+ { "podcomment", "", false, ALL, "", "" },
+ { "", "", false, ALL, "", ""}
+};
+
+
+class parValidator
+{
+public:
+ parValidator(string const & name);
+
+ /// validate given parameter
+ /// invalidParam will be thrown if invalid
+ /// parameter is found.
+ void validate(std::string const & par) const;
+
+private:
+ /// parameter name
+ string const & name;
+ ///
+ listings_param_info const * info;
+};
+
+
+parValidator::parValidator(string const & n)
+ : name(n), info(0)
+{
+ if (name.empty())
+ throw invalidParam("Invalid (empty) listings param name.");
+ else if (name == "?") {
+ string pars;
+ size_t idx = 0;
+ while (listings_param_table[idx].name != string()) {
+ if (!pars.empty())
+ pars += ", ";
+ pars += listings_param_table[idx].name;
+ ++idx;
+ }
+ throw invalidParam("Available listings parameters are " + pars);
+ }
+ // locate name in parameter table
+ size_t idx = 0;
+ while (listings_param_table[idx].name != name && listings_param_table[idx].name != string())
+ ++idx;
+ // found the name
+ if (listings_param_table[idx].name != "") {
+ info = &listings_param_table[idx];
+ return;
+ }
+ // otherwise, produce a meaningful error message.
+ string matching_names;
+ for (size_t i = 0; i < idx; ++i) {
+ string n(listings_param_table[i].name);
+ if (n.size() >= name.size() && n.substr(0, name.size()) == name) {
+ if (matching_names.empty())
+ matching_names += n;
+ else
+ matching_names += ", " + n;
+ }
+ }
+ if (matching_names.empty())
+ throw invalidParam("Unknown listings param name: " + name);
+ else
+ throw invalidParam("Parameters starting with '" + name +
+ "': " + matching_names);
+}
+
+
+void parValidator::validate(std::string const & par) const
+{
+ switch (info->type) {
+ case ALL:
+ if (par.empty() && !info->onoff) {
+ if (info->hint != "")
+ throw invalidParam(info->hint);
+ else
+ throw invalidParam("An value is expected");
+ }
+ return;
+ case TRUEFALSE: {
+ if (par.empty() && !info->onoff) {
+ if (info->hint != "")
+ throw invalidParam(info->hint);
+ else
+ throw invalidParam("Please specify true or false");
+ }
+ if (par != "true" && par != "false")
+ throw invalidParam("Only true or false is allowed for parameter" + name);
+ return;
+ }
+ case INTEGER: {
+ if (par.empty() && !info->onoff) {
+ if (info->hint != "")
+ throw invalidParam(info->hint);
+ else
+ throw invalidParam("Please specify an integer value");
+ }
+ if (convert<int>(par) == 0 && par[0] != '0')
+ throw invalidParam("An integer is expected for parameter " + name);
+ return;
+ }
+ case LENGTH: {
+ if (par.empty() && !info->onoff) {
+ if (info->hint != "")
+ throw invalidParam(info->hint);
+ else
+ throw invalidParam("Please specify a latex length expression");
+ }
+ if (!isValidLength(par))
+ throw invalidParam("Invalid latex length expression for parameter " + name);
+ return;
+ }
+ case ONEOF: {
+ if (par.empty() && !info->onoff) {
+ if (info->hint != "")
+ throw invalidParam(info->hint);
+ else
+ throw invalidParam("Please specify one of " + string(info->info));
+ }
+ // break value to allowed strings
+ vector<string> lists;
+ string v;
+ for (size_t i = 0; info->info[i] != '\0'; ++i) {
+ if (info->info[i] == '\n') {
+ lists.push_back(v);
+ v = string();
+ } else
+ v += info->info[i];
+ }
+ if (!v.empty())
+ lists.push_back(v);
+
+ // good, find the string
+ if (std::find(lists.begin(), lists.end(), par) != lists.end())
+ return;
+ // otherwise, produce a meaningful error message.
+ string matching_names;
+ for (vector<string>::iterator it = lists.begin();
+ it != lists.end(); ++it) {
+ if (it->size() >= par.size() && it->substr(0, par.size()) == par) {
+ if (matching_names.empty())
+ matching_names += *it;
+ else
+ matching_names += ", " + *it;
+ }
+ }
+ if (matching_names.empty())
+ throw invalidParam("Try one of " + string(info->info));
+ else
+ throw invalidParam("I guess you mean " + matching_names);
+ return;
+ }
+ case SUBSETOF: {
+ if (par.empty() && !info->onoff) {
+ if (info->hint != "")
+ throw invalidParam(info->hint);
+ else
+ throw invalidParam("Please specify one or more of " + string(info->info));
+ }
+ for (size_t i = 0; i < par.size(); ++i)
+ if (string(info->info).find(par[i], 0) == string::npos)
+ throw invalidParam("Parameter " + name +
+ " should be composed of one or more of " + info->info);
+ return;
+ }
+ }
+}
+
+
+InsetListingsParams::InsetListingsParams() :
+ inline_(false), status_(InsetCollapsable::Open), params_()
+{
+}
+
+
+InsetListingsParams::InsetListingsParams(string const & par, bool in, InsetCollapsable::CollapseStatus s)
+ : inline_(in), status_(s)
+{
+ // this will activate parameter validation.
+ fromEncodedString(par);
+}
+
+
+void InsetListingsParams::write(ostream & os) const
+{
+ if (inline_)
+ os << "true ";
+ else
+ os << "false ";
+ os << status_ << " \"" << encodedString() << "\"";
+}
+
+
+void InsetListingsParams::read(Lexer & lex)
+{
+ lex >> inline_;
+ int s;
+ lex >> s;
+ if (lex)
+ status_ = static_cast<InsetCollapsable::CollapseStatus>(s);
+ string par;
+ lex >> par;
+ fromEncodedString(par);
+}
+
+
+void InsetListingsParams::addParam(string const & key, string const & value)
+{
+ if (key.empty())
+ return;
+ // exception may be thown.
+ parValidator(key.c_str()).validate(value);
+ if (!params_.empty())
+ params_ += ',';
+ if (value.empty())
+ params_ += key;
+ else {
+ // check onoff flag
+ size_t idx = 0;
+ while (listings_param_table[idx].name != key)
+ ++idx;
+ BOOST_ASSERT(listings_param_table[idx].name == key);
+ if (listings_param_table[idx].onoff && value == "false")
+ params_ += key;
+ else
+ params_ += key + '=' + value;
+ }
+}
+
+
+void InsetListingsParams::setParams(string const & par)
+{
+ string key;
+ string value;
+ bool isValue = false;
+ params_.clear();
+ for (size_t i = 0; i < par.size(); ++i) {
+ // end of par
+ if (par[i] == '\n' || par[i] == ',') {
+ addParam(trim(key), trim(value));
+ key = string();
+ value = string();
+ isValue = false;
+ } else if (par[i] == '=')
+ isValue = true;
+ else if (isValue)
+ value += par[i];
+ else
+ key += par[i];
+ }
+ if (!trim(key).empty())
+ addParam(trim(key), trim(value));
+}
+
+
+string InsetListingsParams::encodedString() const
+{
+ // Encode string!
+ // FIXME:
+ // '"' should be handled differently because it will
+ // terminate a lyx token. Right now, it is silently ignored.
+ string par;
+ for (size_t i = 0; i < params_.size(); ++i) {
+ BOOST_ASSERT(params_[i] != '\n');
+ if (params_[i] != '"')
+ par += params_[i];
+ }
+ return par;
+}
+
+
+string InsetListingsParams::separatedParams(bool keepComma) const
+{
+ // , might be used as regular parameter option so
+ // the prcess might be more complicated than what I am doing here
+ string opt;
+ for (size_t i = 0; i < params_.size(); ++i)
+ if (params_[i] == ',') {
+ if (keepComma)
+ opt += ",\n";
+ else
+ opt += "\n";
+ } else
+ opt += params_[i];
+ return opt;
+}
+
+
+void InsetListingsParams::fromEncodedString(string const & in)
+{
+ // Decode string!
+ // Do nothing because " was silently ignored.
+ setParams(in);
+}
+
+
+
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file InsetListingsParams.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef INSETLISTINGSPARAMS_H
+#define INSETLISTINGSPARAMS_H
+
+#include <vector>
+#include <exception>
+#include "Lexer.h"
+#include "InsetCollapsable.h"
+
+namespace lyx {
+
+class InsetListingsParams {
+public:
+ ///
+ InsetListingsParams();
+
+ ///
+ InsetListingsParams(std::string const &, bool in=false,
+ InsetCollapsable::CollapseStatus s = InsetCollapsable::Open);
+
+ /// write parameters to an ostream
+ void write(std::ostream &) const;
+
+ /// read parameters from an ostream
+ void read(Lexer &);
+
+ /// valid parameter string
+ std::string params() const { return params_; }
+
+ /// add key=value to params_
+ void addParam(std::string const & key, std::string const & value);
+
+ /// set params_ with par, throw an exception if par is valid
+ void setParams(std::string const & par);
+
+ /// generate a parameter string that can be safely save and restored
+ /// by lyx' lexer
+ std::string encodedString() const;
+
+ /// newline (\n) separated parameters. comma can be removed.
+ /// One possible complication is that , may appear in option value.
+ std::string separatedParams(bool keepComma = false) const;
+
+ /// get parameter from encoded string
+ void fromEncodedString(std::string const & par);
+
+ ///
+ bool isInline() const { return inline_; }
+
+ ///
+ InsetCollapsable::CollapseStatus status() const { return status_; }
+
+ ///
+ void setInline(bool i) { inline_ = i; }
+
+ ///
+ void clear() { params_.clear(); }
+
+private:
+ /// inline or normal listings
+ bool inline_;
+
+ /// listing parameters, this will always be a *valid* string
+ /// that can be passed to listing packages.
+ std::string params_;
+
+ /// collapsable status
+ InsetCollapsable::CollapseStatus status_;
+};
+
+
+class invalidParam : public std::exception {
+public:
+ invalidParam(std::string const & details) :
+ details_(details)
+ {}
+
+ virtual const char * what() const throw() {
+ return details_.c_str();
+ }
+
+ virtual ~invalidParam() throw() {}
+private:
+ std::string const details_;
+};
+
+
+} // namespace lyx
+
+#endif
InsetLabel.h \
InsetLine.cpp \
InsetLine.h \
+ InsetListings.h \
+ InsetListings.cpp \
+ InsetListingsParams.h \
+ InsetListingsParams.cpp \
InsetMarginal.h \
InsetMarginal.cpp \
InsetNewline.cpp \
LFUN_CLEARPAGE_INSERT, // Ugras 20061125
LFUN_CLEARDOUBLEPAGE_INSERT, // Ugras 20061125
//290
+ LFUN_LISTING_INSERT, // Herbert 20011110, bpeng 20070502
LFUN_LASTACTION // end of the table
};