* Licence details can be found in the file COPYING.
*
* \author Bo Peng
- * \author Jürgen Spitzmüller
+ * \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "GuiListings.h"
-#include "Qt2BC.h"
+
#include "qt_helpers.h"
+
+#include "FuncRequest.h"
+
+#include "insets/InsetListings.h"
#include "insets/InsetListingsParams.h"
-#include "debug.h"
#include "support/convert.h"
+#include "support/debug.h"
+#include "support/gettext.h"
#include "support/lstrings.h"
#include <QLineEdit>
-#include <QCloseEvent>
#include <QPushButton>
#include <QValidator>
#include <QRegExpValidator>
-
-using std::string;
-using std::vector;
-using lyx::support::findToken;
-using lyx::support::getVectorFromString;
-using lyx::support::getStringFromVector;
-using lyx::support::prefixIs;
-using lyx::support::suffixIs;
-using lyx::support::contains;
+using namespace std;
+using namespace lyx::support;
namespace lyx {
namespace frontend {
+
/////////////////////////////////////////////////////////////////////
//
-// GuiListingsDialog
+// GuiListings
//
/////////////////////////////////////////////////////////////////////
char const * languages[] =
{ "no language", "ABAP", "ACSL", "Ada", "ALGOL", "Assembler", "Awk", "bash", "Basic", "C",
"C++", "Caml", "Clean", "Cobol", "Comal 80", "command.com", "Comsol", "csh", "Delphi",
- "Eiffel", "Elan", "Euphoria", "Fortran", "Gnuplot", "Haskell", "HTML", "IDL", "inform",
+ "Eiffel", "Elan", "erlang", "Euphoria", "Fortran", "Gnuplot", "Haskell", "HTML", "IDL", "inform",
"Java", "JVMIS", "ksh", "Lingo", "Lisp", "Logo", "make", "Mathematica", "Matlab", "Mercury",
"MetaPost", "Miranda", "ML", "Modula-2", "MuPAD", "NASTRAN", "Oberon-2", "OCL", "Octave",
"Oz", "Pascal", "Perl", "PHP", "PL/I", "Plasm", "PostScript", "POV", "Prolog", "Promela",
char const * languages_gui[] =
{ N_("No language"), "ABAP", "ACSL", "Ada", "ALGOL", "Assembler", "Awk", "bash", "Basic",
"C", "C++", "Caml", "Clean", "Cobol", "Comal 80", "command.com", "Comsol", "csh", "Delphi",
- "Eiffel", "Elan", "Euphoria", "Fortran", "Gnuplot", "Haskell", "HTML", "IDL", "inform",
+ "Eiffel", "Elan", "Erlang", "Euphoria", "Fortran", "Gnuplot", "Haskell", "HTML", "IDL", "inform",
"Java", "JVMIS", "ksh", "Lingo", "Lisp", "Logo", "make", "Mathematica", "Matlab", "Mercury",
"MetaPost", "Miranda", "ML", "Modula-2", "MuPAD", "NASTRAN", "Oberon-2", "OCL", "Octave",
"Oz", "Pascal", "Perl", "PHP", "PL/I", "Plasm", "PostScript", "POV", "Prolog", "Promela",
-GuiListingsDialog::GuiListingsDialog(GuiListings * form)
- : form_(form)
+GuiListings::GuiListings(GuiView & lv)
+ : GuiDialog(lv, "listings", qt_("Program Listing Settings"))
{
setupUi(this);
- connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
- connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
- connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-
- connect(languageCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor()));
- connect(dialectCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor()));
- connect(inlineCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
- connect(floatCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
- connect(placementLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
- connect(numberSideCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor()));
- connect(numberStepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
- connect(numberFontSizeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor()));
- connect(firstlineLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
- connect(lastlineLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
- connect(fontsizeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor()));
- connect(fontstyleCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor()));
- connect(breaklinesCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
- connect(spaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
- connect(spaceInStringCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
- connect(extendedcharsCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-
- connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
- connect(listingsED, SIGNAL(textChanged()), this, SLOT(set_listings_msg()));
- connect(bypassCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
- connect(bypassCB, SIGNAL(clicked()), this, SLOT(set_listings_msg()));
+ connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
+ connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
+ connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
+
+ connect(languageCO, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(dialectCO, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(inlineCB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
+ connect(floatCB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
+ connect(placementLE, SIGNAL(textChanged(QString)),
+ this, SLOT(change_adaptor()));
+ connect(numberSideCO, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(numberStepLE, SIGNAL(textChanged(QString)),
+ this, SLOT(change_adaptor()));
+ connect(numberFontSizeCO, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(firstlineLE, SIGNAL(textChanged(QString)),
+ this, SLOT(change_adaptor()));
+ connect(lastlineLE, SIGNAL(textChanged(QString)),
+ this, SLOT(change_adaptor()));
+ connect(fontsizeCO, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(fontstyleCO, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(breaklinesCB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
+ connect(spaceCB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
+ connect(spaceInStringCB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
+ connect(tabsizeSB, SIGNAL(valueChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(extendedcharsCB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
+
+ connect(listingsED, SIGNAL(textChanged()),
+ this, SLOT(change_adaptor()));
+ connect(listingsED, SIGNAL(textChanged()),
+ this, SLOT(setListingsMsg()));
+ connect(bypassCB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
+ connect(bypassCB, SIGNAL(clicked()),
+ this, SLOT(setListingsMsg()));
for (int n = 0; languages[n][0]; ++n)
languageCO->addItem(qt_(languages_gui[n]));
firstlineLE->setValidator(new QIntValidator(0, 1000000, this));
lastlineLE->setValidator(new QIntValidator(0, 1000000, this));
placementLE->setValidator(new QRegExpValidator(QRegExp("[\\*tbph]*"), this));
-}
+ bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
+ bc().setOK(okPB);
+ bc().setApply(applyPB);
+ bc().setCancel(closePB);
+ listingsTB->setPlainText(
+ qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
+
+ updateContents();
-void GuiListingsDialog::closeEvent(QCloseEvent * e)
-{
- form_->slotWMHide();
- e->accept();
}
-void GuiListingsDialog::change_adaptor()
+void GuiListings::change_adaptor()
{
- form_->changed();
+ changed();
}
-string GuiListingsDialog::construct_params()
+string GuiListings::construct_params()
{
- string language = languages[languageCO->currentIndex()];
+ string language = languages[qMax(0, languageCO->currentIndex())];
string dialect;
string const dialect_gui = fromqstr(dialectCO->currentText());
if (dialectCO->currentIndex() > 0) {
- for (size_t i = 0; i < nr_dialects; ++i) {
+ for (size_t i = 0; i != nr_dialects; ++i) {
if (dialect_gui == dialects[i].gui
&& dialects[i].language == language
&& !dialects[i].is_default) {
placement = fromqstr(placementLE->text());
string numberSide;
- switch (numberSideCO->currentIndex()) {
+ switch (qMax(0, numberSideCO->currentIndex())) {
case 0:
numberSide = "none";
break;
break;
}
string stepnumber = fromqstr(numberStepLE->text());
- string numberfontsize = font_sizes[numberFontSizeCO->currentIndex()];
+ string numberfontsize = font_sizes[qMax(0, numberFontSizeCO->currentIndex())];
string firstline = fromqstr(firstlineLE->text());
string lastline = fromqstr(lastlineLE->text());
- string fontsize = font_sizes[fontsizeCO->currentIndex()];
- string fontstyle = font_styles[fontstyleCO->currentIndex()];
+ string fontsize = font_sizes[qMax(0, fontsizeCO->currentIndex())];
+ string fontstyle = font_styles[qMax(0, fontstyleCO->currentIndex())];
string basicstyle;
if (fontsize != "default")
basicstyle = "\\" + fontsize;
basicstyle += "\\" + fontstyle;
bool breakline = breaklinesCB->isChecked();
bool space = spaceCB->isChecked();
+ int tabsize = tabsizeSB->value();
bool spaceInString = spaceInStringCB->isChecked();
bool extendedchars = extendedcharsCB->isChecked();
string extra = fromqstr(listingsED->toPlainText());
par.addParam("showspaces", "true");
if (!spaceInString)
par.addParam("showstringspaces", "false");
+ if (tabsize != 8)
+ par.addParam("tabsize", convert<string>(tabsize));
if (extendedchars)
par.addParam("extendedchars", "true");
par.addParams(extra);
}
-docstring GuiListingsDialog::validate_listings_params()
+docstring GuiListings::validate_listings_params()
{
// use a cache here to avoid repeated validation
// of the same parameters
- static string param_cache = string();
- static docstring msg_cache = docstring();
+ static string param_cache;
+ static docstring msg_cache;
if (bypassCB->isChecked())
return docstring();
}
-void GuiListingsDialog::set_listings_msg()
+void GuiListings::setListingsMsg()
{
static bool isOK = true;
docstring msg = validate_listings_params();
}
-void GuiListingsDialog::on_floatCB_stateChanged(int state)
+void GuiListings::on_floatCB_stateChanged(int state)
{
if (state == Qt::Checked) {
inlineCB->setChecked(false);
}
-void GuiListingsDialog::on_inlineCB_stateChanged(int state)
+void GuiListings::on_inlineCB_stateChanged(int state)
{
if (state == Qt::Checked) {
floatCB->setChecked(false);
}
-void GuiListingsDialog::on_numberSideCO_currentIndexChanged(int index)
+void GuiListings::on_numberSideCO_currentIndexChanged(int index)
{
numberStepLE->setEnabled(index > 0);
numberFontSizeCO->setEnabled(index > 0);
}
-void GuiListingsDialog::on_languageCO_currentIndexChanged(int index)
+void GuiListings::on_languageCO_currentIndexChanged(int index)
{
dialectCO->clear();
// 0 is "no dialect"
dialectCO->addItem(qt_("No dialect"));
string const language = languages[index];
- for (size_t i = 0; i < nr_dialects; ++i) {
+ for (size_t i = 0; i != nr_dialects; ++i) {
if (language == dialects[i].language) {
dialectCO->addItem(qt_(dialects[i].gui));
if (dialects[i].is_default)
}
-/////////////////////////////////////////////////////////////////////
-//
-// GuiListings
-//
-/////////////////////////////////////////////////////////////////////
-
-
-GuiListings::GuiListings(Dialog & parent)
- : GuiView<GuiListingsDialog>(parent, _("Program Listing Settings"))
-{
-}
-
-
-void GuiListings::build_dialog()
-{
- dialog_.reset(new GuiListingsDialog(this));
-
- bcview().setOK(dialog_->okPB);
- bcview().setApply(dialog_->applyPB);
- bcview().setCancel(dialog_->closePB);
- dialog_->listingsTB->setPlainText(
- qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
-
- update_contents();
-}
-
-
-void GuiListings::apply()
+void GuiListings::applyView()
{
- InsetListingsParams & params = controller().params();
- params.setInline(dialog_->inlineCB->isChecked());
- params.setParams(dialog_->construct_params());
- controller().setParams(params);
+ params_.setInline(inlineCB->isChecked());
+ params_.setParams(construct_params());
}
-namespace {
-
-string plainParam(std::string const & par)
+static string plainParam(string const & par)
{
// remove enclosing braces
if (prefixIs(par, "{") && suffixIs(par, "}"))
return par;
}
-} //namespace anon
-
-void GuiListings::update_contents()
+void GuiListings::updateContents()
{
// set default values
- dialog_->listingsTB->setPlainText(
+ listingsTB->setPlainText(
qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
- dialog_->languageCO->setCurrentIndex(findToken(languages, "no language"));
- dialog_->dialectCO->setCurrentIndex(0);
- dialog_->floatCB->setChecked(false);
- dialog_->placementLE->clear();
- dialog_->numberSideCO->setCurrentIndex(0);
- dialog_->numberStepLE->clear();
- dialog_->numberFontSizeCO->setCurrentIndex(findToken(font_sizes, "default"));
- dialog_->firstlineLE->clear();
- dialog_->lastlineLE->clear();
- dialog_->fontstyleCO->setCurrentIndex(findToken(font_styles, "default"));
- dialog_->fontsizeCO->setCurrentIndex(findToken(font_sizes, "default"));
- dialog_->breaklinesCB->setChecked(false);
- dialog_->spaceCB->setChecked(false);
- dialog_->spaceInStringCB->setChecked(true);
- dialog_->extendedcharsCB->setChecked(false);
+ languageCO->setCurrentIndex(findToken(languages, "no language"));
+ dialectCO->setCurrentIndex(0);
+ floatCB->setChecked(false);
+ placementLE->clear();
+ numberSideCO->setCurrentIndex(0);
+ numberStepLE->clear();
+ numberFontSizeCO->setCurrentIndex(findToken(font_sizes, "default"));
+ firstlineLE->clear();
+ lastlineLE->clear();
+ fontstyleCO->setCurrentIndex(findToken(font_styles, "default"));
+ fontsizeCO->setCurrentIndex(findToken(font_sizes, "default"));
+ breaklinesCB->setChecked(false);
+ spaceCB->setChecked(false);
+ spaceInStringCB->setChecked(true);
+ tabsizeSB->setValue(8);
+ extendedcharsCB->setChecked(false);
// set values from param string
- InsetListingsParams & params = controller().params();
- dialog_->inlineCB->setChecked(params.isInline());
- if (params.isInline()) {
- dialog_->floatCB->setChecked(false);
- dialog_->placementLE->setEnabled(false);
+ inlineCB->setChecked(params_.isInline());
+ if (params_.isInline()) {
+ floatCB->setChecked(false);
+ placementLE->setEnabled(false);
}
// break other parameters and set values
- vector<string> pars = getVectorFromString(params.separatedParams(), "\n");
+ vector<string> pars = getVectorFromString(params_.separatedParams(), "\n");
// process each of them
for (vector<string>::iterator it = pars.begin();
it != pars.end(); ++it) {
string dialect;
bool in_gui = false;
if (prefixIs(arg, "[") && contains(arg, "]")) {
- string::size_type end_dialect = arg.find("]");
+ size_t end_dialect = arg.find("]");
dialect = arg.substr(1, end_dialect - 1);
language = arg.substr(end_dialect + 1);
- } else
+ } else {
language = arg;
+ }
int n = findToken(languages, language);
if (n >= 0) {
- dialog_->languageCO->setCurrentIndex(n);
+ languageCO->setCurrentIndex(n);
in_gui = true;
}
// on_languageCO_currentIndexChanged should have set dialects
if (!dialect.empty()) {
string dialect_gui;
- for (size_t i = 0; i < nr_dialects; ++i) {
+ for (size_t i = 0; i != nr_dialects; ++i) {
if (dialect == dialects[i].dialect
&& dialects[i].language == language) {
dialect_gui = dialects[i].gui;
break;
}
}
- n = dialog_->dialectCO->findText(qt_(dialect_gui));
+ n = dialectCO->findText(qt_(dialect_gui));
if (n >= 0)
- dialog_->dialectCO->setCurrentIndex(n);
+ dialectCO->setCurrentIndex(n);
else
in_gui = false;
}
if (in_gui)
*it = "";
- dialog_->languageCO->setEnabled(in_gui);
- dialog_->dialectCO->setEnabled(
- in_gui && dialog_->dialectCO->count() > 1);
+ languageCO->setEnabled(in_gui);
+ dialectCO->setEnabled(
+ in_gui && dialectCO->count() > 1);
} else if (prefixIs(*it, "float")) {
- dialog_->floatCB->setChecked(true);
- dialog_->inlineCB->setChecked(false);
- dialog_->placementLE->setEnabled(true);
+ floatCB->setChecked(true);
+ inlineCB->setChecked(false);
+ placementLE->setEnabled(true);
if (prefixIs(*it, "float="))
- dialog_->placementLE->setText(
+ placementLE->setText(
toqstr(plainParam(it->substr(6))));
*it = "";
} else if (prefixIs(*it, "numbers=")) {
n = 1;
else if (s == "right")
n = 2;
- dialog_->numberSideCO->setCurrentIndex(n);
+ numberSideCO->setCurrentIndex(n);
*it = "";
} else if (prefixIs(*it, "stepnumber=")) {
- dialog_->numberStepLE->setText(
+ numberStepLE->setText(
toqstr(plainParam(it->substr(11))));
*it = "";
} else if (prefixIs(*it, "numberstyle=")) {
string par = plainParam(it->substr(12));
int n = findToken(font_sizes, par.substr(1));
if (n >= 0)
- dialog_->numberFontSizeCO->setCurrentIndex(n);
+ numberFontSizeCO->setCurrentIndex(n);
*it = "";
} else if (prefixIs(*it, "firstline=")) {
- dialog_->firstlineLE->setText(
+ firstlineLE->setText(
toqstr(plainParam(it->substr(10))));
*it = "";
} else if (prefixIs(*it, "lastline=")) {
- dialog_->lastlineLE->setText(
+ lastlineLE->setText(
toqstr(plainParam(it->substr(9))));
*it = "";
} else if (prefixIs(*it, "basicstyle=")) {
if (!style.empty()) {
int n = findToken(font_styles, style.substr(1));
if (n >= 0)
- dialog_->fontstyleCO->setCurrentIndex(n);
+ fontstyleCO->setCurrentIndex(n);
}
if (!size.empty()) {
int n = findToken(font_sizes, size.substr(1));
if (n >= 0)
- dialog_->fontsizeCO->setCurrentIndex(n);
+ fontsizeCO->setCurrentIndex(n);
}
*it = "";
}
} else if (prefixIs(*it, "breaklines=")) {
- dialog_->breaklinesCB->setChecked(contains(*it, "true"));
+ breaklinesCB->setChecked(contains(*it, "true"));
*it = "";
} else if (prefixIs(*it, "showspaces=")) {
- dialog_->spaceCB->setChecked(contains(*it, "true"));
+ spaceCB->setChecked(contains(*it, "true"));
*it = "";
} else if (prefixIs(*it, "showstringspaces=")) {
- dialog_->spaceInStringCB->setChecked(contains(*it, "true"));
+ spaceInStringCB->setChecked(contains(*it, "true"));
+ *it = "";
+ } else if (prefixIs(*it, "tabsize=")) {
+ tabsizeSB->setValue(convert<int>(plainParam(it->substr(8))));
*it = "";
} else if (prefixIs(*it, "extendedchars=")) {
- dialog_->extendedcharsCB->setChecked(contains(*it, "true"));
+ extendedcharsCB->setChecked(contains(*it, "true"));
*it = "";
}
}
- dialog_->numberStepLE->setEnabled(dialog_->numberSideCO->currentIndex() > 0);
- dialog_->numberFontSizeCO->setEnabled(dialog_->numberSideCO->currentIndex() > 0);
+ numberStepLE->setEnabled(numberSideCO->currentIndex() > 0);
+ numberFontSizeCO->setEnabled(numberSideCO->currentIndex() > 0);
// parameters that can be handled by widgets are cleared
// the rest is put to the extra edit box.
string extra = getStringFromVector(pars);
- dialog_->listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams()));
+ listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams()));
}
bool GuiListings::isValid()
{
- return dialog_->validate_listings_params().empty();
+ return validate_listings_params().empty();
+}
+
+
+bool GuiListings::initialiseParams(string const & data)
+{
+ InsetListings::string2params(data, params_);
+ return true;
+}
+
+
+void GuiListings::clearParams()
+{
+ params_.clear();
+}
+
+
+void GuiListings::dispatchParams()
+{
+ string const lfun = InsetListings::params2string(params_);
+ dispatch(FuncRequest(getLfun(), lfun));
}
+void GuiListings::setParams(InsetListingsParams const & params)
+{
+ params_ = params;
+}
+
+
+Dialog * createGuiListings(GuiView & lv) { return new GuiListings(lv); }
+
+
} // namespace frontend
} // namespace lyx
-#include "GuiListings_moc.cpp"
+#include "moc_GuiListings.cpp"