Counter
Name equation
End
+
+Counter
+ Name listing
+End
name = from_ascii("thm");
else if (name == "Foot")
name = from_ascii("fn");
+ else if (name == "listing")
+ name = from_ascii("lst");
if (!name.empty())
text = name.substr(0, 3) + ':' + text;
// FIXME: are "table" and "Table" the correct type and label?
setCaptionLabels(inset, "table", from_ascii("Table"), counters);
}
+ else if (inset.lyxCode() == Inset::LISTINGS_CODE)
+ setCaptionLabels(inset, "listing", from_ascii("Listing"), counters);
}
}
#include <config.h>
#include "support/os.h"
+#include "support/lstrings.h"
#include "QInclude.h"
#include <QLineEdit>
using std::string;
+using std::vector;
using lyx::support::os::internal_path;
-
+using lyx::support::prefixIs;
+using lyx::support::getStringFromVector;
+using lyx::support::getVectorFromString;
namespace lyx {
namespace frontend {
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(captionLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
+ connect(labelLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
connect(listingsED, SIGNAL(textChanged()), this, SLOT(validate_listings_params()));
InsetListingsParams par(fromqstr(listingsED->toPlainText()));
if (!isOK) {
isOK = true;
- // listingsTB->setTextColor("black");
- listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+ listingsTB->setPlainText("Input listings parameters on the right. Enter ? for a list of parameters.");
okPB->setEnabled(true);
}
} catch (invalidParam & e) {
isOK = false;
- // listingsTB->setTextColor("red");
listingsTB->setPlainText(e.what());
okPB->setEnabled(false);
}
previewCB->setEnabled(false);
previewCB->setChecked(false);
listingsGB->setEnabled(false);
- listingsED->setEnabled(false);
break;
//case Input
case 1:
visiblespaceCB->setChecked(false);
previewCB->setEnabled(true);
listingsGB->setEnabled(false);
- listingsED->setEnabled(false);
break;
//case listings
case 3:
visiblespaceCB->setChecked(false);
previewCB->setEnabled(false);
listingsGB->setEnabled(true);
- listingsED->setEnabled(true);
break;
//case Verbatim
default:
previewCB->setEnabled(false);
previewCB->setChecked(false);
listingsGB->setEnabled(false);
- listingsED->setEnabled(false);
break;
}
}
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.");
+ dialog_->listingsTB->setPlainText("Input listings parameters on the right. Enter ? for a list of parameters.");
addCheckedLineEdit(bcview(), dialog_->filenameED, dialog_->filenameLA);
}
dialog_->listingsGB->setEnabled(true);
dialog_->listingsED->setEnabled(true);
InsetListingsParams par(params.getOptions());
- dialog_->listingsED->setPlainText(toqstr(par.separatedParams()));
+ // extract caption and label and put them into their respective editboxes
+ vector<string> pars = getVectorFromString(par.separatedParams(), "\n");
+ for (vector<string>::iterator it = pars.begin();
+ it != pars.end(); ++it) {
+ if (prefixIs(*it, "caption=")) {
+ string cap = it->substr(8);
+ if (cap[0] == '{' && cap[cap.size()-1] == '}')
+ dialog_->captionLE->setText(toqstr(cap.substr(1, cap.size()-2)));
+ else
+ throw invalidParam("caption parameter is not quoted with braces");
+ *it = "";
+ } else if (prefixIs(*it, "label=")) {
+ string lbl = it->substr(6);
+ if (lbl[0] == '{' && lbl[lbl.size()-1] == '}')
+ dialog_->labelLE->setText(toqstr(lbl.substr(1, lbl.size()-2)));
+ else
+ throw invalidParam("label parameter is not quoted with braces");
+ *it = "";
+ }
+ }
+ // the rest is put to the extra edit box.
+ string extra = getStringFromVector(pars);
+ dialog_->listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams()));
}
}
} else if (item == 3) {
params.setCmdName("lstinputlisting");
// the parameter string should have passed validation
- params.setOptions(InsetListingsParams(fromqstr(dialog_->listingsED->toPlainText())).params());
+ InsetListingsParams par(fromqstr(dialog_->listingsED->toPlainText()));
+ string caption = fromqstr(dialog_->captionLE->text());
+ string label = fromqstr(dialog_->labelLE->text());
+ if (!caption.empty())
+ par.addParam("caption", "{" + caption + "}");
+ if (!label.empty())
+ par.addParam("label", "{" + label + "}");
+ params.setOptions(par.params());
} else {
if (dialog_->visiblespaceCB->isChecked())
params.setCmdName("verbatiminput*");
* Licence details can be found in the file COPYING.
*
* \author Bo Peng
+ * \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
connect(breaklinesCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(spaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(extendedcharsCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
- connect(captionLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
- connect(labelLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
connect(listingsED, SIGNAL(textChanged()), this, SLOT(validate_listings_params()));
bool left = numberLeftCB->checkState() == Qt::Checked;
bool right = numberRightCB->checkState() == Qt::Checked;
- string step = fromqstr(numberStepLE->text());
+ string stepnumber = fromqstr(numberStepLE->text());
string numberfontsize = fromqstr(numberFontSizeCO->currentText());
string firstline = fromqstr(firstlineLE->text());
string lastline = fromqstr(lastlineLE->text());
basicstyle += "\\" + fontstyle;
bool breakline = breaklinesCB->checkState() == Qt::Checked;
bool space = spaceCB->checkState() == Qt::Checked;
- bool extendedchar = extendedcharsCB->checkState() == Qt::Checked;
-
- string caption = fromqstr(captionLE->text());
- string label = fromqstr(labelLE->text());
-
+ bool extendedchars = extendedcharsCB->checkState() == Qt::Checked;
string extra = fromqstr(listingsED->toPlainText());
// compose a string
par.addParam("firstline", firstline);
if (!lastline.empty())
par.addParam("lastline", lastline);
- if (basicstyle != "")
+ if (!stepnumber.empty())
+ par.addParam("stepnumber", stepnumber);
+ if (!basicstyle.empty())
par.addParam("basicstyle", basicstyle);
if (breakline)
par.addParam("breaklines", "true");
if (space)
par.addParam("showspaces", "true");
- if (extendedchar)
+ if (extendedchars)
par.addParam("extendedchars", "true");
- if (!caption.empty())
- par.addParam("caption", "{" + caption + "}");
- if (!label.empty())
- par.addParam("label", "{" + label + "}");
par.addParams(extra);
return par.params();
}
InsetListingsParams par(construct_params());
if (!isOK) {
isOK = true;
- // listingsTB->setTextColor("black");
- listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+ listingsTB->setPlainText("Input listings parameters on the right. Enter ? for a list of parameters.");
okPB->setEnabled(true);
}
} catch (invalidParam & e) {
isOK = false;
- // listingsTB->setTextColor("red");
listingsTB->setPlainText(e.what());
okPB->setEnabled(false);
}
bcview().setOK(dialog_->okPB);
bcview().setCancel(dialog_->closePB);
- dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+ dialog_->listingsTB->setPlainText("Input listings parameters on the right. Enter ? for a list of parameters.");
update_contents();
}
dialog_->placementLE->setValidator(new QRegExpValidator(QRegExp("[tbph]*"), this));
//
- dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+ dialog_->listingsTB->setPlainText("Input listings parameters on the right. Enter ? for a list of parameters.");
// set values from param string
InsetListingsParams & params = controller().params();
} else if (prefixIs(*it, "extendedchars=")) {
dialog_->extendedcharsCB->setChecked(contains(*it, "true"));
*it = "";
- } else if (prefixIs(*it, "caption=")) {
- string cap = it->substr(8);
- if ((cap[0] == '{' && cap[cap.size()-1] == '}') ||
- (cap[0] == '"' && cap[cap.size()-1] == '"') )
- dialog_->captionLE->setText(toqstr(cap.substr(1, cap.size()-2)));
- else
- dialog_->captionLE->setText(toqstr(cap));
- *it = "";
- } else if (prefixIs(*it, "label=")) {
- string lbl = it->substr(6);
- if ((lbl[0] == '{' && lbl[lbl.size()-1] == '}') ||
- (lbl[0] == '"' && lbl[lbl.size()-1] == '"') )
- dialog_->labelLE->setText(toqstr(lbl.substr(1, lbl.size()-2)));
- else
- dialog_->labelLE->setText(toqstr(lbl));
- *it = "";
}
}
// parameters that can be handled by widgets are cleared
<rect>
<x>0</x>
<y>0</y>
- <width>389</width>
- <height>385</height>
+ <width>315</width>
+ <height>379</height>
</rect>
</property>
<property name="windowTitle" >
<number>6</number>
</property>
<item>
- <widget class="QTextBrowser" name="listingsTB" >
- <property name="minimumSize" >
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize" >
- <size>
- <width>200</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="cursor" >
- <cursor>0</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" >
+ <layout class="QGridLayout" >
+ <property name="margin" >
<number>0</number>
</property>
- <property name="acceptRichText" >
- <bool>false</bool>
+ <property name="spacing" >
+ <number>6</number>
</property>
- </widget>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="labelLabel" >
+ <property name="text" >
+ <string>Label</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="captionLE" >
+ <property name="minimumSize" >
+ <size>
+ <width>150</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="captionLabel" >
+ <property name="text" >
+ <string>Caption</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QLineEdit" name="labelLE" />
+ </item>
+ </layout>
</item>
<item>
- <widget class="QTextEdit" name="listingsED" >
- <property name="minimumSize" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
<size>
- <width>0</width>
- <height>0</height>
+ <width>20</width>
+ <height>20</height>
</size>
</property>
- </widget>
+ </spacer>
</item>
</layout>
</item>
+ <item>
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>More parameters</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSplitter" name="splitter" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <widget class="QTextBrowser" name="listingsTB" >
+ <property name="minimumSize" >
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize" >
+ <size>
+ <width>200</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="cursor" >
+ <cursor>0</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="minimumSize" >
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </widget>
+ </item>
</layout>
</widget>
</item>
<tabstop>loadPB</tabstop>
<tabstop>visiblespaceCB</tabstop>
<tabstop>previewCB</tabstop>
+ <tabstop>captionLE</tabstop>
+ <tabstop>labelLE</tabstop>
<tabstop>listingsTB</tabstop>
<tabstop>listingsED</tabstop>
</tabstops>
<rect>
<x>0</x>
<y>0</y>
- <width>499</width>
- <height>355</height>
+ <width>511</width>
+ <height>325</height>
</rect>
</property>
<property name="windowTitle" >
<property name="wordWrap" >
<bool>false</bool>
</property>
- <property name="buddy" >
- <cstring>captionLE</cstring>
- </property>
</widget>
</item>
<item row="1" column="0" colspan="2" >
</layout>
</widget>
</item>
- <item row="2" column="0" colspan="3" >
- <widget class="QGroupBox" name="captionGB_3" >
- <property name="title" >
- <string>Display</string>
- </property>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="1" column="0" >
- <widget class="QLabel" name="labelL_4" >
- <property name="text" >
- <string>&Label:</string>
- </property>
- <property name="wordWrap" >
- <bool>false</bool>
- </property>
- <property name="buddy" >
- <cstring>labelLE</cstring>
- </property>
- </widget>
- </item>
- <item row="0" column="0" >
- <widget class="QLabel" name="captionL_4" >
- <property name="text" >
- <string>&Caption:</string>
- </property>
- <property name="wordWrap" >
- <bool>false</bool>
- </property>
- <property name="buddy" >
- <cstring>captionLE</cstring>
- </property>
- </widget>
- </item>
- <item row="0" column="1" >
- <widget class="QLineEdit" name="captionLE" >
- <property name="minimumSize" >
- <size>
- <width>150</width>
- <height>0</height>
- </size>
- </property>
- <property name="toolTip" >
- <string>A caption for the List of Listings</string>
- </property>
- <property name="text" >
- <string/>
- </property>
- </widget>
- </item>
- <item row="1" column="1" >
- <widget class="QLineEdit" name="labelLE" >
- <property name="minimumSize" >
- <size>
- <width>150</width>
- <height>0</height>
- </size>
- </property>
- <property name="toolTip" >
- <string>A Label for the caption</string>
- </property>
- <property name="text" >
- <string/>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
</layout>
</widget>
<widget class="QWidget" name="tab_2" >
<tabstops>
<tabstop>okPB</tabstop>
<tabstop>closePB</tabstop>
- <tabstop>languageCO</tabstop>
+ <tabstop>listingsTW</tabstop>
<tabstop>inlineCB</tabstop>
<tabstop>floatCB</tabstop>
<tabstop>placementLE</tabstop>
+ <tabstop>languageCO</tabstop>
<tabstop>numberLeftCB</tabstop>
<tabstop>numberRightCB</tabstop>
<tabstop>numberStepLE</tabstop>
<tabstop>breaklinesCB</tabstop>
<tabstop>spaceCB</tabstop>
<tabstop>extendedcharsCB</tabstop>
- <tabstop>captionLE</tabstop>
- <tabstop>labelLE</tabstop>
<tabstop>listingsTB</tabstop>
<tabstop>listingsED</tabstop>
</tabstops>
}
+int InsetCaption::getArgument(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
+{
+ return InsetText::latex(buf, os, runparams);
+}
+
+
+int InsetCaption::getOptArg(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
+{
+ return latexOptArgInsets(buf, paragraphs()[0], os, runparams, 1);
+}
+
+
void InsetCaption::computeFullLabel(Buffer const & buf) const
{
if (type_.empty())
///
int docbook(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const;
+ /// return the mandatory argument (LaTeX format) only
+ int getArgument(Buffer const & buf, odocstream & os,
+ OutputParams const &) const;
+ /// return the optional argument(s) only
+ int getOptArg(Buffer const & buf, odocstream & os,
+ OutputParams const &) const;
///
void setCount(int c) { counter_ = c; }
///
* Licence details can be found in the file COPYING.
*
* \author Bo Peng
+ * \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "InsetListings.h"
+#include "InsetCaption.h"
#include "Language.h"
#include "gettext.h"
}
-int InsetListings::latex(Buffer const &, odocstream & os,
- OutputParams const &) const
+int InsetListings::latex(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
{
string param_string = params().encodedString();
// NOTE: I use {} to quote text, which is an experimental feature
else
os << "\\lstinline[" << from_ascii(param_string) << "]{";
} else {
- if (param_string.empty())
+ docstring const caption = getCaption(buf, runparams);
+ if (param_string.empty() && caption.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";
+ else {
+ os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}[";
+ if (!caption.empty()) {
+ os << "caption={" << caption << '}';
+ if (!param_string.empty())
+ os << ',';
+ }
+ os << from_ascii(param_string) << "]\n";
+ }
lines += 4;
}
ParagraphList::const_iterator par = paragraphs().begin();
while (par != end) {
pos_type siz = par->size();
+ bool captionline = false;
for (pos_type i = 0; i < siz; ++i) {
- // ignore all struck out text
- if (par->isDeleted(i))
+ if (i == 0 && par->isInset(i) && i + 1 == siz)
+ captionline = true;
+ // ignore all struck out text and (caption) insets
+ if (par->isDeleted(i) || par->isInset(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) {
+ // they are simply joined. Otherwise, expect latex errors.
+ if (par != end && !lstinline && !captionline) {
os << "\n";
++lines;
}
case LFUN_INSET_DIALOG_UPDATE:
status.enabled(true);
return true;
+ case LFUN_CAPTION_INSERT:
+ status.enabled(!params().isInline());
+ return true;
default:
return InsetERT::getStatus(cur, cmd, status);
}
}
+docstring InsetListings::getCaption(Buffer const & buf,
+ OutputParams const & runparams) const
+{
+ if (paragraphs().empty())
+ return docstring();
+
+ ParagraphList::const_iterator pit = paragraphs().begin();
+ for (; pit != paragraphs().end(); ++pit) {
+ InsetList::const_iterator it = pit->insetlist.begin();
+ for (; it != pit->insetlist.end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == Inset::CAPTION_CODE) {
+ odocstringstream ods;
+ InsetCaption * ins =
+ static_cast<InsetCaption *>(it->inset);
+ ins->getOptArg(buf, ods, runparams);
+ ins->getArgument(buf, ods, runparams);
+ return ods.str();
+ }
+ }
+ }
+ return docstring();
+}
+
+
string const InsetListingsMailer::name_("listings");
InsetListingsMailer::InsetListingsMailer(InsetListings & inset)
///
void setButtonLabel();
///
+ docstring getCaption(Buffer const &, OutputParams const &) const;
+ ///
InsetListingsParams params_;
};
{
enum param_type {
- ALL,
- TRUEFALSE,
- INTEGER,
- LENGTH,
- ONEOF,
- SUBSETOF,
+ ALL, // accept all
+ TRUEFALSE, // accept 'true' or 'false'
+ INTEGER, // accept an integer
+ LENGTH, // accept an latex length
+ ONEOF, // accept one of a few values
+ SUBSETOF, // accept a string composed of given characters
};
{ "name", "", false, ALL, "", "" },
{ "thelstnumber", "", false, ALL, "", "" },
{ "title", "", false, ALL, "", "" },
- { "caption", "", false, ALL, "", "" },
- { "label", "", false, ALL, "", "" },
+ // this option is not handled in the parameter box
+ { "caption", "", false, ALL, "", "This parameter should not be entered here. "
+ "Please use caption editbox (Include dialog) or insert->caption (listings inset)" },
+ // this option is not handled in the parameter box
+ { "label", "", false, ALL, "", "This parameter should not be entered here."
+ "Please use label editbox (Include dialog) or insert->caption (listings inset)"},
{ "nolol", "", false, TRUEFALSE, "", "" },
{ "captionpos", "", false, SUBSETOF, "tb", "" },
{ "abovecaptionskip", "", false, LENGTH, "", "" },