From 891bb08e37c88aac4368838572c7a9281495ece9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Fri, 5 Mar 2004 14:49:10 +0000 Subject: [PATCH] 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 --- development/FORMAT | 9 + lib/lyx2lyx/ChangeLog | 4 + lib/lyx2lyx/lyx2lyx | 2 +- lib/lyx2lyx/lyxconvert_229.py | 29 ++ lib/lyx2lyx/lyxrevert_230.py | 29 ++ po/POTFILES.in | 2 + src/ChangeLog | 4 + src/buffer.C | 2 +- src/frontends/qt2/ChangeLog | 3 + src/frontends/qt2/QCitation.C | 12 +- src/frontends/qt2/ui/QCitationDialogBase.ui | 278 +++++++++++--------- src/frontends/xforms/ChangeLog | 4 + src/frontends/xforms/FormCitation.C | 9 +- src/insets/ChangeLog | 7 + src/insets/insetcite.C | 20 +- src/insets/insetcommand.C | 2 +- src/insets/insetcommand.h | 4 + src/insets/insetcommandparams.C | 31 ++- src/insets/insetcommandparams.h | 9 +- 19 files changed, 308 insertions(+), 152 deletions(-) create mode 100644 lib/lyx2lyx/lyxconvert_229.py create mode 100644 lib/lyx2lyx/lyxrevert_230.py diff --git a/development/FORMAT b/development/FORMAT index f50a4146c2..9e55641877 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,15 @@ LyX file-format changes ----------------------- +2004-02-23 Jürgen Spitzmüller + + * 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 * format incremented to 229. diff --git a/lib/lyx2lyx/ChangeLog b/lib/lyx2lyx/ChangeLog index 231029c529..5311540769 100644 --- a/lib/lyx2lyx/ChangeLog +++ b/lib/lyx2lyx/ChangeLog @@ -1,3 +1,7 @@ +2004-02-25 Jürgen Spitzmüller + + * lyx2lyx: up the format to 230. + 2004-02-04 José Matos * lyxconvert_210.py: add two new transforms: remove_empty_insets and remove_formula_latex diff --git a/lib/lyx2lyx/lyx2lyx b/lib/lyx2lyx/lyx2lyx index d4333283bc..a7d86d6e13 100755 --- a/lib/lyx2lyx/lyx2lyx +++ b/lib/lyx2lyx/lyx2lyx @@ -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] diff --git a/lib/lyx2lyx/lyxconvert_229.py b/lib/lyx2lyx/lyxconvert_229.py new file mode 100644 index 0000000000..22c7fc658b --- /dev/null +++ b/lib/lyx2lyx/lyxconvert_229.py @@ -0,0 +1,29 @@ +# This file is part of lyx2lyx +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2003 José Matos +# +# 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 diff --git a/lib/lyx2lyx/lyxrevert_230.py b/lib/lyx2lyx/lyxrevert_230.py new file mode 100644 index 0000000000..22c7fc658b --- /dev/null +++ b/lib/lyx2lyx/lyxrevert_230.py @@ -0,0 +1,29 @@ +# This file is part of lyx2lyx +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2003 José Matos +# +# 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 diff --git a/po/POTFILES.in b/po/POTFILES.in index 3a80162074..e2a9c1d57a 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -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 diff --git a/src/ChangeLog b/src/ChangeLog index 61ec77f516..8945585c89 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2004-03-05 Jürgen Spitzmüller + + * buffer.C: increment file format to 230. + 2004-03-04 Alfredo Braunstein * cursor.C (dispatch): avoid infinite loops diff --git a/src/buffer.C b/src/buffer.C index 567c168afb..45672b850a 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -133,7 +133,7 @@ extern BufferList bufferlist; namespace { -const int LYX_FORMAT = 229; +const int LYX_FORMAT = 230; } // namespace anon diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 0e182c3ec6..50e2c0e71a 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,5 +1,8 @@ 2004-03-05 Jürgen Spitzmüller + * 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. diff --git a/src/frontends/qt2/QCitation.C b/src/frontends/qt2/QCitation.C index 83e8632511..4c73aecee5 100644 --- a/src/frontends/qt2/QCitation.C +++ b/src/frontends/qt2/QCitation.C @@ -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(); diff --git a/src/frontends/qt2/ui/QCitationDialogBase.ui b/src/frontends/qt2/ui/QCitationDialogBase.ui index 6e1110b856..4b78a84edc 100644 --- a/src/frontends/qt2/ui/QCitationDialogBase.ui +++ b/src/frontends/qt2/ui/QCitationDialogBase.ui @@ -13,8 +13,8 @@ 0 0 - 404 - 287 + 400 + 310 @@ -71,123 +71,6 @@ Citation entry - - QGroupBox - - name - GroupBox8 - - - title - Style - - - - margin - 11 - - - spacing - 6 - - - QLabel - - name - citationStyleLA - - - text - Citation &style: - - - buddy - citationStyleCO - - - - QLineEdit - - name - textAfterED - - - sizePolicy - - 5 - 0 - - - - toolTip - Text to place after citation - - - - QCheckBox - - name - fulllistCB - - - text - &Full author list - - - toolTip - List all authors - - - - QComboBox - - name - citationStyleCO - - - sizePolicy - - 3 - 0 - - - - toolTip - Natbib citation style to use - - - - QLabel - - name - textAfterLA - - - text - &Text after: - - - buddy - textAfterED - - - - QCheckBox - - name - forceuppercaseCB - - - text - Force &upper case - - - toolTip - Force upper case in citation - - - - QLayoutWidget @@ -446,6 +329,156 @@ + + QGroupBox + + name + GroupBox8 + + + title + Style + + + + margin + 11 + + + spacing + 6 + + + QLabel + + name + citationStyleLA + + + text + Citation &style: + + + buddy + citationStyleCO + + + + QComboBox + + name + citationStyleCO + + + sizePolicy + + 3 + 0 + + + + toolTip + Natbib citation style to use + + + + QCheckBox + + name + forceuppercaseCB + + + text + Force &upper case + + + toolTip + Force upper case in citation + + + + QLabel + + name + textAfterLA + + + text + &Text after: + + + buddy + textAfterED + + + + QLineEdit + + name + textAfterED + + + sizePolicy + + 5 + 0 + + + + toolTip + Text to place after citation + + + + QLineEdit + + name + textBeforeED + + + sizePolicy + + 5 + 0 + + + + toolTip + Text to place after citation + + + + QLabel + + name + textBeforeLA + + + text + Text &before: + + + buddy + textAfterED + + + + QCheckBox + + name + fulllistCB + + + text + &Full author list + + + toolTip + List all authors + + + + @@ -477,6 +510,12 @@ QCitationDialogBase changed_adaptor() + + textBeforeED + textChanged(const QString&) + QCitationDialogBase + changed_adaptor() + textAfterED textChanged(const QString&) @@ -529,6 +568,7 @@ addPB deletePB citationStyleCO + textBeforeED textAfterED fulllistCB forceuppercaseCB diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 7f9995349c..bbd95b11ed 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,7 @@ +2004-03-05 Jürgen Spitzmüller + + * FormCitation.C: Support second \cite option. + 2004-03-05 Martin Vermeer * FormDocument.C: fix user interface to branch activation diff --git a/src/frontends/xforms/FormCitation.C b/src/frontends/xforms/FormCitation.C index 4cca278c06..7e59ae279c 100644 --- a/src/frontends/xforms/FormCitation.C +++ b/src/frontends/xforms/FormCitation.C @@ -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()); } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 91b8410b48..4012f6883a 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,10 @@ +2004-03-05 Jürgen Spitzmüller + + * insetcite.C: Support second \cite option. + + * insetcommand.[Ch]: + * insetcommandparams.[Ch]: add second optional argument. + 2004-03-03 Alfredo Braunstein * insetcollapsable.C (lfunMouseRelease): right mouse button only diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index bbb874d4f2..3d755fccbe 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -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 diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index dd1f782f48..0bb66e3e23 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -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) {} diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index 6bb797ed1e..4311621fe0 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -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; diff --git a/src/insets/insetcommandparams.C b/src/insets/insetcommandparams.C index 996bf0502a..b21d050771 100644 --- a/src/insets/insetcommandparams.C +++ b/src/insets/insetcommandparams.C @@ -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(); } diff --git a/src/insets/insetcommandparams.h b/src/insets/insetcommandparams.h index e863a3772d..d6c5b10748 100644 --- a/src/insets/insetcommandparams.h +++ b/src/insets/insetcommandparams.h @@ -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_; }; -- 2.39.5