support for second \cite option.

Natbib users can now use the before field.
file format is up to 230.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8479 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2004-03-05 14:49:10 +00:00
parent 6f4ac88ac8
commit 891bb08e37
19 changed files with 308 additions and 152 deletions

View File

@ -1,6 +1,15 @@
LyX file-format changes
-----------------------
2004-02-23 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* format incremented to 230.
* Support for a second optional argument in insetcommand.
currently, citation uses this to support natbibs second
optional argument \cite[before][after]{key}.
I think there's nothing to convert upwards. Downwards, the
commands need to be converted to ERT I suppose.
2003-12-29 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* format incremented to 229.

View File

@ -1,3 +1,7 @@
2004-02-25 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* lyx2lyx: up the format to 230.
2004-02-04 José Matos <jamatos@lyx.org>
* lyxconvert_210.py: add two new transforms:
remove_empty_insets and remove_formula_latex

View File

@ -40,7 +40,7 @@ opt.quiet = 0
format = re.compile(r"(\d)[\.,]?(\d\d)")
fileformat = re.compile(r"\\lyxformat\s*(\S*)")
lst_ft = [210, 215, 216, 217, 218, 220, 221, 223, 224, 225, 226, 227, 228, 229]
lst_ft = [210, 215, 216, 217, 218, 220, 221, 223, 224, 225, 226, 227, 228, 229, 230]
def usage():
print """Usage: lyx2lyx [options] [file]

View File

@ -0,0 +1,29 @@
# This file is part of lyx2lyx
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import sys
from parser_tools import find_token
def convert(header, body):
pass
if __name__ == "__main__":
pass

View File

@ -0,0 +1,29 @@
# This file is part of lyx2lyx
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import sys
from parser_tools import find_token
def convert(header, body):
pass
if __name__ == "__main__":
pass

View File

@ -192,6 +192,8 @@ src/paragraph.C
src/paragraph_funcs.C
src/rowpainter.C
src/support/globbing.C
src/support/path_defines.C
src/tex2lyx/lengthcommon.C
src/text.C
src/text2.C
src/text3.C

View File

@ -1,3 +1,7 @@
2004-03-05 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* buffer.C: increment file format to 230.
2004-03-04 Alfredo Braunstein <abraunst@lyx.org>
* cursor.C (dispatch): avoid infinite loops

View File

@ -133,7 +133,7 @@ extern BufferList bufferlist;
namespace {
const int LYX_FORMAT = 229;
const int LYX_FORMAT = 230;
} // namespace anon

View File

@ -1,5 +1,8 @@
2004-03-05 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* QCitation.C:
* ui/QCitationDialogBase.ui: Support second \cite option.
* QDocumentDialog.C (branches): Don't deselect branch
after button press.
* QBranch.C: fix off-by-one-error.

View File

@ -60,6 +60,9 @@ void QCitation::apply()
controller().params().setCmdName(command);
controller().params().setContents(getStringFromVector(citekeys));
string const before = fromqstr(dialog_->textBeforeED->text());
controller().params().setSecOptions(before);
string const after = fromqstr(dialog_->textAfterED->text());
controller().params().setOptions(after);
@ -95,8 +98,7 @@ void QCitation::build_dialog()
bcview().addReadOnly(dialog_->citationStyleCO);
bcview().addReadOnly(dialog_->forceuppercaseCB);
bcview().addReadOnly(dialog_->fulllistCB);
// add when enabled !
//bcview().addReadOnly(dialog_->textBeforeED);
bcview().addReadOnly(dialog_->textBeforeED);
bcview().addReadOnly(dialog_->textAfterED);
open_find_ = true;
@ -143,6 +145,7 @@ void QCitation::updateStyle()
dialog_->fulllistCB->setEnabled(natbib);
dialog_->forceuppercaseCB->setEnabled(natbib);
dialog_->textBeforeED->setEnabled(natbib);
string const & command = controller().params().getCmdName();
@ -185,7 +188,10 @@ void QCitation::update_contents()
dialog_->infoML->clear();
dialog_->setButtons();
dialog_->textAfterED->setText(toqstr(controller().params().getOptions()));
dialog_->textBeforeED->setText(
toqstr(controller().params().getSecOptions()));
dialog_->textAfterED->setText(
toqstr(controller().params().getOptions()));
fillStyles();
updateStyle();

View File

@ -13,8 +13,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>404</width>
<height>287</height>
<width>400</width>
<height>310</height>
</rect>
</property>
<property stdset="1">
@ -71,123 +71,6 @@
<string>Citation entry</string>
</property>
</widget>
<widget row="1" column="1" >
<class>QGroupBox</class>
<property stdset="1">
<name>name</name>
<cstring>GroupBox8</cstring>
</property>
<property stdset="1">
<name>title</name>
<string>Style</string>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>11</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="0" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>citationStyleLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Citation &amp;style:</string>
</property>
<property>
<name>buddy</name>
<cstring>citationStyleCO</cstring>
</property>
</widget>
<widget row="1" column="1" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>textAfterED</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property>
<name>toolTip</name>
<string>Text to place after citation</string>
</property>
</widget>
<widget row="2" column="0" rowspan="1" colspan="2" >
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>fulllistCB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Full author list</string>
</property>
<property>
<name>toolTip</name>
<string>List all authors</string>
</property>
</widget>
<widget row="0" column="1" >
<class>QComboBox</class>
<property stdset="1">
<name>name</name>
<cstring>citationStyleCO</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property>
<name>toolTip</name>
<string>Natbib citation style to use</string>
</property>
</widget>
<widget row="1" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>textAfterLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Text after:</string>
</property>
<property>
<name>buddy</name>
<cstring>textAfterED</cstring>
</property>
</widget>
<widget row="3" column="0" rowspan="1" colspan="2" >
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>forceuppercaseCB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Force &amp;upper case</string>
</property>
<property>
<name>toolTip</name>
<string>Force upper case in citation</string>
</property>
</widget>
</grid>
</widget>
<widget row="0" column="0" rowspan="2" colspan="1" >
<class>QLayoutWidget</class>
<property stdset="1">
@ -446,6 +329,156 @@
</widget>
</hbox>
</widget>
<widget row="1" column="1" >
<class>QGroupBox</class>
<property stdset="1">
<name>name</name>
<cstring>GroupBox8</cstring>
</property>
<property stdset="1">
<name>title</name>
<string>Style</string>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>11</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="0" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>citationStyleLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Citation &amp;style:</string>
</property>
<property>
<name>buddy</name>
<cstring>citationStyleCO</cstring>
</property>
</widget>
<widget row="0" column="1" >
<class>QComboBox</class>
<property stdset="1">
<name>name</name>
<cstring>citationStyleCO</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property>
<name>toolTip</name>
<string>Natbib citation style to use</string>
</property>
</widget>
<widget row="4" column="0" rowspan="1" colspan="2" >
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>forceuppercaseCB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Force &amp;upper case</string>
</property>
<property>
<name>toolTip</name>
<string>Force upper case in citation</string>
</property>
</widget>
<widget row="2" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>textAfterLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Text after:</string>
</property>
<property>
<name>buddy</name>
<cstring>textAfterED</cstring>
</property>
</widget>
<widget row="2" column="1" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>textAfterED</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property>
<name>toolTip</name>
<string>Text to place after citation</string>
</property>
</widget>
<widget row="1" column="1" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>textBeforeED</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property>
<name>toolTip</name>
<string>Text to place after citation</string>
</property>
</widget>
<widget row="1" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>textBeforeLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Text &amp;before:</string>
</property>
<property>
<name>buddy</name>
<cstring>textAfterED</cstring>
</property>
</widget>
<widget row="3" column="0" rowspan="1" colspan="2" >
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>fulllistCB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Full author list</string>
</property>
<property>
<name>toolTip</name>
<string>List all authors</string>
</property>
</widget>
</grid>
</widget>
</grid>
</widget>
<images>
@ -477,6 +510,12 @@
<receiver>QCitationDialogBase</receiver>
<slot>changed_adaptor()</slot>
</connection>
<connection>
<sender>textBeforeED</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>QCitationDialogBase</receiver>
<slot>changed_adaptor()</slot>
</connection>
<connection>
<sender>textAfterED</sender>
<signal>textChanged(const QString&amp;)</signal>
@ -529,6 +568,7 @@
<tabstop>addPB</tabstop>
<tabstop>deletePB</tabstop>
<tabstop>citationStyleCO</tabstop>
<tabstop>textBeforeED</tabstop>
<tabstop>textAfterED</tabstop>
<tabstop>fulllistCB</tabstop>
<tabstop>forceuppercaseCB</tabstop>

View File

@ -1,3 +1,7 @@
2004-03-05 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* FormCitation.C: Support second \cite option.
2004-03-05 Martin Vermeer <martin.vermeer@hut.fi>
* FormDocument.C: fix user interface to branch activation

View File

@ -115,6 +115,9 @@ void FormCitation::apply()
controller().params().setCmdName(command);
controller().params().setContents(getStringFromVector(citekeys));
string const before = getString(dialog_->input_before);
controller().params().setSecOptions(before);
string const after = getString(dialog_->input_after);
controller().params().setOptions(after);
}
@ -450,6 +453,7 @@ void FormCitation::update()
setEnabled(dialog_->check_full_author_list, natbib);
setEnabled(dialog_->check_force_uppercase, natbib);
setEnabled(dialog_->choice_style, natbib);
setEnabled(dialog_->input_before, natbib);
// No keys have been selected yet, so...
fl_clear_browser(dialog_->browser_info);
@ -457,12 +461,11 @@ void FormCitation::update()
setCiteButtons(OFF);
// Natbib can have comments before and after the citation.
// This is not yet supported. After only.
fl_set_input(dialog_->input_after,
controller().params().getOptions().c_str());
fl_set_input(dialog_->input_before, _("Not yet supported").c_str());
setEnabled(dialog_->input_before, false);
fl_set_input(dialog_->input_before,
controller().params().getSecOptions().c_str());
}

View File

@ -1,3 +1,10 @@
2004-03-05 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* insetcite.C: Support second \cite option.
* insetcommand.[Ch]:
* insetcommandparams.[Ch]: add second optional argument.
2004-03-03 Alfredo Braunstein <abraunst@lyx.org>
* insetcollapsable.C (lfunMouseRelease): right mouse button only

View File

@ -221,7 +221,7 @@ InsetCitation::InsetCitation(InsetCommandParams const & p)
string const InsetCitation::generateLabel(Buffer const & buffer) const
{
string const before = string();
string const before = getSecOptions();
string const after = getOptions();
string label;
@ -275,7 +275,7 @@ string const InsetCitation::getScreenLabel(Buffer const & buffer) const
return cache.screen_label;
// The label has changed, so we have to re-create it.
string const before = string();
string const before = getSecOptions();
string const after = getOptions();
string const glabel = generateLabel(buffer);
@ -320,25 +320,13 @@ int InsetCitation::latex(Buffer const & buffer, ostream & os,
else
os << "cite";
#warning What is this code supposed to do? (Lgb)
// my guess is that this is just waiting for when we support before,
// so it's a oneliner. But this is very silly ! - jbl
#if 1
// The current strange code
string const before = string();
string const before = getSecOptions();
string const after = getOptions();
if (!before.empty() && buffer.params().use_natbib)
os << '[' << before << "][" << after << ']';
else if (!after.empty())
os << '[' << after << ']';
#else
// and the cleaned up equvalent, should it just be changed? (Lgb)
string const after = getOptions();
if (!after.empty())
os << '[' << after << ']';
#endif
string::const_iterator it = getContents().begin();
string::const_iterator end = getContents().end();
// Paranoia check: make sure that there is no whitespace in here

View File

@ -30,7 +30,7 @@ using std::ostringstream;
InsetCommand::InsetCommand(InsetCommandParams const & p,
string const & mailer_name)
: p_(p.getCmdName(), p.getContents(), p.getOptions()),
: p_(p.getCmdName(), p.getContents(), p.getOptions(), p.getSecOptions()),
mailer_name_(mailer_name),
set_label_(false)
{}

View File

@ -70,6 +70,8 @@ public:
///
std::string const & getOptions() const { return p_.getOptions(); }
///
std::string const & getSecOptions() const { return p_.getSecOptions(); }
///
RenderButton & button() const { return button_; }
protected:
@ -84,6 +86,8 @@ protected:
///
void setOptions(std::string const & o) { p_.setOptions(o); }
///
void setSecOptions(std::string const & s) { p_.setSecOptions(s); }
///
void setParams(InsetCommandParams const &);
/// This should provide the text for the button
virtual std::string const getScreenLabel(Buffer const &) const = 0;

View File

@ -27,30 +27,34 @@ InsetCommandParams::InsetCommandParams()
InsetCommandParams::InsetCommandParams(string const & n,
string const & c,
string const & o)
: cmdname(n), contents(c), options(o), preview_(false)
string const & o,
string const & s)
: cmdname(n), contents(c), options(o), sec_options(s),
preview_(false)
{}
void InsetCommandParams::scanCommand(string const & cmd)
{
string tcmdname, toptions, tcontents;
string tcmdname, toptions, tsecoptions, tcontents;
if (cmd.empty()) return;
enum { WS, CMDNAME, OPTION, CONTENT } state = WS;
enum { WS, CMDNAME, OPTION, SECOPTION, CONTENT } state = WS;
// Used to handle things like \command[foo[bar]]{foo{bar}}
int nestdepth = 0;
for (string::size_type i = 0; i < cmd.length(); ++i) {
char c = cmd[i];
char b = cmd[i-1];
if ((state == CMDNAME && c == ' ') ||
(state == CMDNAME && c == '[') ||
(state == CMDNAME && c == '{')) {
state = WS;
}
if ((state == OPTION && c == ']') ||
(state == SECOPTION && c == ']') ||
(state == CONTENT && c == '}')) {
if (nestdepth == 0) {
state = WS;
@ -59,19 +63,24 @@ void InsetCommandParams::scanCommand(string const & cmd)
}
}
if ((state == OPTION && c == '[') ||
(state == SECOPTION && c == '[') ||
(state == CONTENT && c == '{')) {
++nestdepth;
}
switch (state) {
case CMDNAME: tcmdname += c; break;
case OPTION: toptions += c; break;
case SECOPTION: tsecoptions += c; break;
case CONTENT: tcontents += c; break;
case WS:
if (c == '\\') {
state = CMDNAME;
} else if (c == '[') {
} else if (c == '[' && b != ']') {
state = OPTION;
nestdepth = 0; // Just to be sure
} else if (c == '[' && b == ']') {
state = SECOPTION;
nestdepth = 0; // Just to be sure
} else if (c == '{') {
state = CONTENT;
nestdepth = 0; // Just to be sure
@ -83,6 +92,7 @@ void InsetCommandParams::scanCommand(string const & cmd)
// Don't mess with this.
if (!tcmdname.empty()) setCmdName(tcmdname);
if (!toptions.empty()) setOptions(toptions);
if (!tsecoptions.empty()) setSecOptions(tsecoptions);
if (!tcontents.empty()) setContents(tcontents);
if (lyxerr.debugging(Debug::PARSER))
@ -90,7 +100,8 @@ void InsetCommandParams::scanCommand(string const & cmd)
<< "> == <" << getCommand()
<< "> == <" << getCmdName()
<< '|' << getContents()
<< '|' << getOptions() << '>' << endl;
<< '|' << getOptions()
<< '|' << getSecOptions() << '>' << endl;
}
@ -133,6 +144,11 @@ string const InsetCommandParams::getCommand() const
string s;
if (!getCmdName().empty()) s += '\\' + getCmdName();
if (!getOptions().empty()) s += '[' + getOptions() + ']';
if (!getSecOptions().empty()) {
// for cases like \command[][sec_option]{arg}
if (getOptions().empty()) s += "[]";
s += '[' + getSecOptions() + ']';
}
s += '{' + getContents() + '}';
return s;
}
@ -144,6 +160,7 @@ bool operator==(InsetCommandParams const & o1,
return o1.getCmdName() == o2.getCmdName()
&& o1.getContents() == o2.getContents()
&& o1.getOptions() == o2.getOptions()
&& o1.getSecOptions() == o2.getSecOptions()
&& o1.preview() == o2.preview();
}

View File

@ -26,7 +26,8 @@ public:
///
explicit InsetCommandParams(std::string const & n,
std::string const & c = std::string(),
std::string const & o = std::string());
std::string const & o = std::string(),
std::string const & s = std::string());
///
void read(LyXLex &);
/// Parse the command
@ -40,12 +41,16 @@ public:
///
std::string const & getOptions() const { return options; }
///
std::string const & getSecOptions() const { return sec_options; }
///
std::string const & getContents() const { return contents; }
///
void setCmdName(std::string const & n) { cmdname = n; }
///
void setOptions(std::string const & o) { options = o; }
///
void setSecOptions(std::string const & s) { sec_options = s; }
///
void setContents(std::string const & c) { contents = c; }
///
bool preview() const { return preview_; }
@ -60,6 +65,8 @@ private:
///
std::string options;
///
std::string sec_options;
///
bool preview_;
};