mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-14 20:26:50 +00:00
Clean up natbib, jurabib code as posted to the list last Friday.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8748 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
eea99ecc8b
commit
d8c5a828fa
@ -1,3 +1,11 @@
|
|||||||
|
2004-05-10 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
|
* biblio.[Ch]: create a new biblio::CiteEngine enum. Use it instead of
|
||||||
|
bools usingNatbib, usingJurabib.
|
||||||
|
|
||||||
|
* ControlCitation.[Ch]: simplified code to use the biblio::CiteEngine
|
||||||
|
enum rather than multiple bools, usingNatbib and using Jurabib.
|
||||||
|
|
||||||
2004-04-12 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
2004-04-12 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||||
|
|
||||||
* ControlGraphics.[Ch] (editGraphics): new method
|
* ControlGraphics.[Ch] (editGraphics): new method
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include "ControlCitation.h"
|
#include "ControlCitation.h"
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "bufferparams.h"
|
|
||||||
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
@ -36,7 +35,9 @@ bool ControlCitation::initialiseParams(string const & data)
|
|||||||
vector<pair<string, string> > blist;
|
vector<pair<string, string> > blist;
|
||||||
kernel().buffer().fillWithBibKeys(blist);
|
kernel().buffer().fillWithBibKeys(blist);
|
||||||
|
|
||||||
bool use_styles = (usingNatbib() || usingJurabib());
|
biblio::CiteEngine const engine = biblio::getEngine(kernel().buffer());
|
||||||
|
|
||||||
|
bool use_styles = engine != biblio::ENGINE_BASIC;
|
||||||
|
|
||||||
typedef std::map<string, string>::value_type InfoMapValue;
|
typedef std::map<string, string>::value_type InfoMapValue;
|
||||||
|
|
||||||
@ -47,12 +48,11 @@ bool ControlCitation::initialiseParams(string const & data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (citeStyles_.empty())
|
if (citeStyles_.empty())
|
||||||
citeStyles_ = biblio::getCiteStyles(usingNatbib(), usingJurabib());
|
citeStyles_ = biblio::getCiteStyles(engine);
|
||||||
else {
|
else {
|
||||||
if ((use_styles && citeStyles_.size() == 1) ||
|
if ((use_styles && citeStyles_.size() == 1) ||
|
||||||
(!use_styles && citeStyles_.size() != 1))
|
(!use_styles && citeStyles_.size() != 1))
|
||||||
citeStyles_ = biblio::getCiteStyles(usingNatbib(),
|
citeStyles_ = biblio::getCiteStyles(engine);
|
||||||
usingJurabib());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -73,15 +73,9 @@ biblio::InfoMap const & ControlCitation::bibkeysInfo() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ControlCitation::usingNatbib() const
|
biblio::CiteEngine ControlCitation::getEngine() const
|
||||||
{
|
{
|
||||||
return kernel().buffer().params().use_natbib;
|
return biblio::getEngine(kernel().buffer());
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ControlCitation::usingJurabib() const
|
|
||||||
{
|
|
||||||
return kernel().buffer().params().use_jurabib;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,10 +83,10 @@ vector<string> const ControlCitation::getCiteStrings(string const & key) const
|
|||||||
{
|
{
|
||||||
vector<string> styles;
|
vector<string> styles;
|
||||||
|
|
||||||
vector<biblio::CiteStyle> const cs =
|
biblio::CiteEngine const engine = biblio::getEngine(kernel().buffer());
|
||||||
biblio::getCiteStyles(usingNatbib(), usingJurabib());
|
vector<biblio::CiteStyle> const cs = biblio::getCiteStyles(engine);
|
||||||
|
|
||||||
if (kernel().buffer().params().use_numerical_citations)
|
if (engine == biblio::ENGINE_NATBIB_NUMERICAL)
|
||||||
styles = biblio::getNumericalStrings(key, bibkeysInfo_, cs);
|
styles = biblio::getNumericalStrings(key, bibkeysInfo_, cs);
|
||||||
else
|
else
|
||||||
styles = biblio::getAuthorYearStrings(key, bibkeysInfo_, cs);
|
styles = biblio::getAuthorYearStrings(key, bibkeysInfo_, cs);
|
||||||
|
@ -37,9 +37,8 @@ public:
|
|||||||
biblio::InfoMap const & bibkeysInfo() const;
|
biblio::InfoMap const & bibkeysInfo() const;
|
||||||
|
|
||||||
///
|
///
|
||||||
bool usingNatbib() const;
|
biblio::CiteEngine getEngine() const;
|
||||||
///
|
|
||||||
bool usingJurabib() const;
|
|
||||||
/// Possible citations based on this key
|
/// Possible citations based on this key
|
||||||
std::vector<std::string> const getCiteStrings(std::string const & key) const;
|
std::vector<std::string> const getCiteStrings(std::string const & key) const;
|
||||||
|
|
||||||
|
@ -13,10 +13,12 @@
|
|||||||
|
|
||||||
#include "biblio.h"
|
#include "biblio.h"
|
||||||
|
|
||||||
#include "support/std_sstream.h"
|
#include "buffer.h"
|
||||||
#include "gettext.h" // for _()
|
#include "bufferparams.h"
|
||||||
|
#include "gettext.h"
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
#include "support/std_sstream.h"
|
||||||
|
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
|
|
||||||
@ -560,25 +562,54 @@ string const getCiteCommand(CiteStyle command, bool full, bool forceUCase)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vector<CiteStyle> const getCiteStyles(bool usingNatbib, bool usingJurabib)
|
CiteEngine getEngine(Buffer const & buffer)
|
||||||
{
|
{
|
||||||
unsigned int nStyles = 1;
|
CiteEngine engine = ENGINE_BASIC;
|
||||||
|
|
||||||
|
if (buffer.params().use_natbib) {
|
||||||
|
if (buffer.params().use_numerical_citations) {
|
||||||
|
engine = ENGINE_NATBIB_NUMERICAL;
|
||||||
|
} else {
|
||||||
|
engine = ENGINE_NATBIB_AUTHORYEAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer.params().use_jurabib)
|
||||||
|
engine = ENGINE_JURABIB;
|
||||||
|
|
||||||
|
return engine;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vector<CiteStyle> const getCiteStyles(CiteEngine engine)
|
||||||
|
{
|
||||||
|
unsigned int nStyles = 0;
|
||||||
unsigned int start = 0;
|
unsigned int start = 0;
|
||||||
if (usingNatbib) {
|
|
||||||
|
switch (engine) {
|
||||||
|
case ENGINE_BASIC:
|
||||||
|
nStyles = 1;
|
||||||
|
start = 0;
|
||||||
|
break;
|
||||||
|
case ENGINE_NATBIB_AUTHORYEAR:
|
||||||
|
case ENGINE_NATBIB_NUMERICAL:
|
||||||
nStyles = nCiteStyles - 1;
|
nStyles = nCiteStyles - 1;
|
||||||
start = 1;
|
start = 1;
|
||||||
}
|
break;
|
||||||
if (usingJurabib)
|
case ENGINE_JURABIB:
|
||||||
nStyles = nCiteStyles;
|
nStyles = nCiteStyles;
|
||||||
|
start = 0;
|
||||||
vector<CiteStyle> styles(nStyles);
|
break;
|
||||||
|
|
||||||
vector<CiteStyle>::size_type i = 0;
|
|
||||||
int j = start;
|
|
||||||
for (; i != styles.size(); ++i, ++j) {
|
|
||||||
styles[i] = citeStyles[j];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef vector<CiteStyle> cite_vec;
|
||||||
|
|
||||||
|
cite_vec styles(nStyles);
|
||||||
|
cite_vec::size_type i = 0;
|
||||||
|
int j = start;
|
||||||
|
for (; i != styles.size(); ++i, ++j)
|
||||||
|
styles[i] = citeStyles[j];
|
||||||
|
|
||||||
return styles;
|
return styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,10 +16,21 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class Buffer;
|
||||||
|
|
||||||
/** Functions of use to citation and bibtex GUI controllers and views */
|
/** Functions of use to citation and bibtex GUI controllers and views */
|
||||||
namespace biblio {
|
namespace biblio {
|
||||||
|
|
||||||
///
|
enum CiteEngine {
|
||||||
|
ENGINE_BASIC,
|
||||||
|
ENGINE_NATBIB_AUTHORYEAR,
|
||||||
|
ENGINE_NATBIB_NUMERICAL,
|
||||||
|
ENGINE_JURABIB
|
||||||
|
};
|
||||||
|
|
||||||
|
CiteEngine getEngine(Buffer const &);
|
||||||
|
|
||||||
|
|
||||||
enum CiteStyle {
|
enum CiteStyle {
|
||||||
CITE,
|
CITE,
|
||||||
CITET,
|
CITET,
|
||||||
@ -31,19 +42,15 @@ enum CiteStyle {
|
|||||||
CITEYEARPAR
|
CITEYEARPAR
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
|
||||||
enum Search {
|
enum Search {
|
||||||
///
|
|
||||||
SIMPLE,
|
SIMPLE,
|
||||||
///
|
|
||||||
REGEX
|
REGEX
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
|
||||||
enum Direction {
|
enum Direction {
|
||||||
///
|
|
||||||
FORWARD,
|
FORWARD,
|
||||||
///
|
|
||||||
BACKWARD
|
BACKWARD
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -116,7 +123,7 @@ a flag forcing upper case, e.g. "della Casa" becomes "Della Case"
|
|||||||
std::string const getCiteCommand(CiteStyle, bool full, bool forceUCase);
|
std::string const getCiteCommand(CiteStyle, bool full, bool forceUCase);
|
||||||
|
|
||||||
/// Returns a vector of available Citation styles.
|
/// Returns a vector of available Citation styles.
|
||||||
std::vector<CiteStyle> const getCiteStyles(bool usingNatbib, bool usingJurabib);
|
std::vector<CiteStyle> const getCiteStyles(CiteEngine);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
"Translates" the available Citation Styles into strings for this key.
|
"Translates" the available Citation Styles into strings for this key.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2004-05-10 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
|
* QCitation.C: simplified code to use the biblio::CiteEngine
|
||||||
|
enum rather than multiple bools, usingNatbib and using Jurabib.
|
||||||
|
|
||||||
2004-05-05 Angus Leeming <leeming@lyx.org>
|
2004-05-05 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* QIndexDialog.[Ch] (reject): overload the QDialog::reject function
|
* QIndexDialog.[Ch] (reject): overload the QDialog::reject function
|
||||||
|
@ -125,10 +125,11 @@ void QCitation::fillStyles()
|
|||||||
|
|
||||||
vector<string> const & sty = controller().getCiteStrings(key);
|
vector<string> const & sty = controller().getCiteStrings(key);
|
||||||
|
|
||||||
bool const use_styles = (controller().usingNatbib() ||
|
biblio::CiteEngine const engine = controller().getEngine();
|
||||||
controller().usingJurabib());
|
bool const basic_engine = engine == biblio::ENGINE_BASIC;
|
||||||
dialog_->citationStyleCO->setEnabled(!sty.empty() && use_styles);
|
|
||||||
dialog_->citationStyleLA->setEnabled(!sty.empty() && use_styles);
|
dialog_->citationStyleCO->setEnabled(!sty.empty() && !basic_engine);
|
||||||
|
dialog_->citationStyleLA->setEnabled(!sty.empty() && !basic_engine);
|
||||||
|
|
||||||
for (vector<string>::const_iterator it = sty.begin();
|
for (vector<string>::const_iterator it = sty.begin();
|
||||||
it != sty.end(); ++it) {
|
it != sty.end(); ++it) {
|
||||||
@ -142,12 +143,15 @@ void QCitation::fillStyles()
|
|||||||
|
|
||||||
void QCitation::updateStyle()
|
void QCitation::updateStyle()
|
||||||
{
|
{
|
||||||
bool const natbib = controller().usingNatbib();
|
biblio::CiteEngine const engine = controller().getEngine();
|
||||||
|
bool const natbib_engine =
|
||||||
|
engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
|
||||||
|
engine == biblio::ENGINE_NATBIB_NUMERICAL;
|
||||||
|
bool const basic_engine = engine == biblio::ENGINE_BASIC;
|
||||||
|
|
||||||
dialog_->fulllistCB->setEnabled(natbib);
|
dialog_->fulllistCB->setEnabled(natbib_engine);
|
||||||
dialog_->forceuppercaseCB->setEnabled(natbib);
|
dialog_->forceuppercaseCB->setEnabled(natbib_engine);
|
||||||
dialog_->textBeforeED->setEnabled(natbib ||
|
dialog_->textBeforeED->setEnabled(!basic_engine);
|
||||||
controller().usingJurabib());
|
|
||||||
|
|
||||||
string const & command = controller().params().getCmdName();
|
string const & command = controller().params().getCmdName();
|
||||||
|
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2004-05-10 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
|
* FormCitation.C: simplified code to use the biblio::CiteEngine
|
||||||
|
enum rather than multiple bools, usingNatbib and using Jurabib.
|
||||||
|
|
||||||
2004-05-04 Angus Leeming <leeming@lyx.org>
|
2004-05-04 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* FormRef.C (input): don't activate the Apply buttons when using
|
* FormRef.C (input): don't activate the Apply buttons when using
|
||||||
|
@ -449,11 +449,16 @@ void FormCitation::update()
|
|||||||
// Use the citation command to update the GUI
|
// Use the citation command to update the GUI
|
||||||
updateStyle(dialog_.get(), controller().params().getCmdName());
|
updateStyle(dialog_.get(), controller().params().getCmdName());
|
||||||
|
|
||||||
bool const natbib = controller().usingNatbib();
|
biblio::CiteEngine const engine = controller().getEngine();
|
||||||
setEnabled(dialog_->check_full_author_list, natbib);
|
bool const natbib_engine =
|
||||||
setEnabled(dialog_->check_force_uppercase, natbib);
|
engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
|
||||||
setEnabled(dialog_->choice_style, natbib || controller().usingJurabib());
|
engine == biblio::ENGINE_NATBIB_NUMERICAL;
|
||||||
setEnabled(dialog_->input_before, natbib || controller().usingJurabib());
|
bool const basic_engine = engine == biblio::ENGINE_BASIC;
|
||||||
|
|
||||||
|
setEnabled(dialog_->check_full_author_list, natbib_engine);
|
||||||
|
setEnabled(dialog_->check_force_uppercase, natbib_engine);
|
||||||
|
setEnabled(dialog_->choice_style, !basic_engine);
|
||||||
|
setEnabled(dialog_->input_before, !basic_engine);
|
||||||
|
|
||||||
// No keys have been selected yet, so...
|
// No keys have been selected yet, so...
|
||||||
fl_clear_browser(dialog_->browser_info);
|
fl_clear_browser(dialog_->browser_info);
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2004-05-10 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
|
* insetcite.[Ch]: move the Cache::Style enum to biblio::CiteEngine.
|
||||||
|
Ditto with getStyle, moved to biblio::getEngine.
|
||||||
|
|
||||||
2004-05-07 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
2004-05-07 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||||
|
|
||||||
* insetgraphics.C (validate): remove pre 233 file format stuff,
|
* insetgraphics.C (validate): remove pre 233 file format stuff,
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
#include "funcrequest.h"
|
#include "funcrequest.h"
|
||||||
#include "LaTeXFeatures.h"
|
#include "LaTeXFeatures.h"
|
||||||
|
|
||||||
#include "frontends/controllers/biblio.h"
|
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
using lyx::support::ascii_lowercase;
|
using lyx::support::ascii_lowercase;
|
||||||
@ -275,29 +273,10 @@ string const InsetCitation::generateLabel(Buffer const & buffer) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InsetCitation::Cache::Style InsetCitation::getStyle(Buffer const & buffer) const
|
|
||||||
{
|
|
||||||
Cache::Style style = Cache::BASIC;
|
|
||||||
|
|
||||||
if (buffer.params().use_natbib) {
|
|
||||||
if (buffer.params().use_numerical_citations) {
|
|
||||||
style = Cache::NATBIB_NUM;
|
|
||||||
} else {
|
|
||||||
style = Cache::NATBIB_AY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer.params().use_jurabib)
|
|
||||||
style = Cache::JURABIB;
|
|
||||||
|
|
||||||
return style;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
string const InsetCitation::getScreenLabel(Buffer const & buffer) const
|
string const InsetCitation::getScreenLabel(Buffer const & buffer) const
|
||||||
{
|
{
|
||||||
Cache::Style const style = getStyle(buffer);
|
biblio::CiteEngine const engine = biblio::getEngine(buffer);
|
||||||
if (cache.params == params() && cache.style == style)
|
if (cache.params == params() && cache.engine == engine)
|
||||||
return cache.screen_label;
|
return cache.screen_label;
|
||||||
|
|
||||||
// The label has changed, so we have to re-create it.
|
// The label has changed, so we have to re-create it.
|
||||||
@ -314,7 +293,7 @@ string const InsetCitation::getScreenLabel(Buffer const & buffer) const
|
|||||||
label += "...";
|
label += "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.style = style;
|
cache.engine = engine;
|
||||||
cache.params = params();
|
cache.params = params();
|
||||||
cache.generated_label = glabel;
|
cache.generated_label = glabel;
|
||||||
cache.screen_label = label;
|
cache.screen_label = label;
|
||||||
@ -325,7 +304,8 @@ string const InsetCitation::getScreenLabel(Buffer const & buffer) const
|
|||||||
|
|
||||||
int InsetCitation::plaintext(Buffer const & buffer, ostream & os, int) const
|
int InsetCitation::plaintext(Buffer const & buffer, ostream & os, int) const
|
||||||
{
|
{
|
||||||
if (cache.params == params() && cache.style == getStyle(buffer))
|
if (cache.params == params() &&
|
||||||
|
cache.engine == biblio::getEngine(buffer))
|
||||||
os << cache.generated_label;
|
os << cache.generated_label;
|
||||||
else
|
else
|
||||||
os << generateLabel(buffer);
|
os << generateLabel(buffer);
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "insetcommand.h"
|
#include "insetcommand.h"
|
||||||
|
#include "frontends/controllers/biblio.h"
|
||||||
|
|
||||||
/** Used to insert citations
|
/** Used to insert citations
|
||||||
*/
|
*/
|
||||||
@ -39,23 +40,16 @@ public:
|
|||||||
OutputParams const &) const;
|
OutputParams const &) const;
|
||||||
///
|
///
|
||||||
void validate(LaTeXFeatures &) const;
|
void validate(LaTeXFeatures &) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// This function does the donkey work of creating the pretty label
|
||||||
|
std::string const generateLabel(Buffer const &) const;
|
||||||
|
|
||||||
struct Cache {
|
struct Cache {
|
||||||
///
|
///
|
||||||
enum Style {
|
Cache() : engine(biblio::ENGINE_BASIC) {}
|
||||||
///
|
///
|
||||||
BASIC,
|
biblio::CiteEngine engine;
|
||||||
///
|
|
||||||
NATBIB_AY,
|
|
||||||
///
|
|
||||||
NATBIB_NUM,
|
|
||||||
///
|
|
||||||
JURABIB
|
|
||||||
};
|
|
||||||
///
|
|
||||||
Cache() : style(BASIC) {}
|
|
||||||
///
|
|
||||||
Style style;
|
|
||||||
///
|
///
|
||||||
InsetCommandParams params;
|
InsetCommandParams params;
|
||||||
///
|
///
|
||||||
@ -63,12 +57,6 @@ private:
|
|||||||
///
|
///
|
||||||
std::string screen_label;
|
std::string screen_label;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This function does the donkey work of creating the pretty label
|
|
||||||
std::string const generateLabel(Buffer const &) const;
|
|
||||||
///
|
|
||||||
Cache::Style getStyle(Buffer const & buffer) const;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
mutable Cache cache;
|
mutable Cache cache;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user