mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-13 20:09:59 +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>
|
||||
|
||||
* ControlGraphics.[Ch] (editGraphics): new method
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "ControlCitation.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "bufferparams.h"
|
||||
|
||||
|
||||
using std::string;
|
||||
@ -36,7 +35,9 @@ bool ControlCitation::initialiseParams(string const & data)
|
||||
vector<pair<string, string> > 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;
|
||||
|
||||
@ -47,12 +48,11 @@ bool ControlCitation::initialiseParams(string const & data)
|
||||
}
|
||||
|
||||
if (citeStyles_.empty())
|
||||
citeStyles_ = biblio::getCiteStyles(usingNatbib(), usingJurabib());
|
||||
citeStyles_ = biblio::getCiteStyles(engine);
|
||||
else {
|
||||
if ((use_styles && citeStyles_.size() == 1) ||
|
||||
(!use_styles && citeStyles_.size() != 1))
|
||||
citeStyles_ = biblio::getCiteStyles(usingNatbib(),
|
||||
usingJurabib());
|
||||
citeStyles_ = biblio::getCiteStyles(engine);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
bool ControlCitation::usingJurabib() const
|
||||
{
|
||||
return kernel().buffer().params().use_jurabib;
|
||||
return biblio::getEngine(kernel().buffer());
|
||||
}
|
||||
|
||||
|
||||
@ -89,10 +83,10 @@ vector<string> const ControlCitation::getCiteStrings(string const & key) const
|
||||
{
|
||||
vector<string> styles;
|
||||
|
||||
vector<biblio::CiteStyle> const cs =
|
||||
biblio::getCiteStyles(usingNatbib(), usingJurabib());
|
||||
biblio::CiteEngine const engine = biblio::getEngine(kernel().buffer());
|
||||
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);
|
||||
else
|
||||
styles = biblio::getAuthorYearStrings(key, bibkeysInfo_, cs);
|
||||
|
@ -37,9 +37,8 @@ public:
|
||||
biblio::InfoMap const & bibkeysInfo() const;
|
||||
|
||||
///
|
||||
bool usingNatbib() const;
|
||||
///
|
||||
bool usingJurabib() const;
|
||||
biblio::CiteEngine getEngine() const;
|
||||
|
||||
/// Possible citations based on this key
|
||||
std::vector<std::string> const getCiteStrings(std::string const & key) const;
|
||||
|
||||
|
@ -13,10 +13,12 @@
|
||||
|
||||
#include "biblio.h"
|
||||
|
||||
#include "support/std_sstream.h"
|
||||
#include "gettext.h" // for _()
|
||||
#include "buffer.h"
|
||||
#include "bufferparams.h"
|
||||
#include "gettext.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/std_sstream.h"
|
||||
|
||||
#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;
|
||||
if (usingNatbib) {
|
||||
|
||||
switch (engine) {
|
||||
case ENGINE_BASIC:
|
||||
nStyles = 1;
|
||||
start = 0;
|
||||
break;
|
||||
case ENGINE_NATBIB_AUTHORYEAR:
|
||||
case ENGINE_NATBIB_NUMERICAL:
|
||||
nStyles = nCiteStyles - 1;
|
||||
start = 1;
|
||||
}
|
||||
if (usingJurabib)
|
||||
break;
|
||||
case ENGINE_JURABIB:
|
||||
nStyles = nCiteStyles;
|
||||
|
||||
vector<CiteStyle> styles(nStyles);
|
||||
|
||||
vector<CiteStyle>::size_type i = 0;
|
||||
int j = start;
|
||||
for (; i != styles.size(); ++i, ++j) {
|
||||
styles[i] = citeStyles[j];
|
||||
start = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,21 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Buffer;
|
||||
|
||||
/** Functions of use to citation and bibtex GUI controllers and views */
|
||||
namespace biblio {
|
||||
|
||||
///
|
||||
enum CiteEngine {
|
||||
ENGINE_BASIC,
|
||||
ENGINE_NATBIB_AUTHORYEAR,
|
||||
ENGINE_NATBIB_NUMERICAL,
|
||||
ENGINE_JURABIB
|
||||
};
|
||||
|
||||
CiteEngine getEngine(Buffer const &);
|
||||
|
||||
|
||||
enum CiteStyle {
|
||||
CITE,
|
||||
CITET,
|
||||
@ -31,19 +42,15 @@ enum CiteStyle {
|
||||
CITEYEARPAR
|
||||
};
|
||||
|
||||
///
|
||||
|
||||
enum Search {
|
||||
///
|
||||
SIMPLE,
|
||||
///
|
||||
REGEX
|
||||
};
|
||||
|
||||
///
|
||||
|
||||
enum Direction {
|
||||
///
|
||||
FORWARD,
|
||||
///
|
||||
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);
|
||||
|
||||
/// 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.
|
||||
|
@ -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>
|
||||
|
||||
* QIndexDialog.[Ch] (reject): overload the QDialog::reject function
|
||||
|
@ -125,10 +125,11 @@ void QCitation::fillStyles()
|
||||
|
||||
vector<string> const & sty = controller().getCiteStrings(key);
|
||||
|
||||
bool const use_styles = (controller().usingNatbib() ||
|
||||
controller().usingJurabib());
|
||||
dialog_->citationStyleCO->setEnabled(!sty.empty() && use_styles);
|
||||
dialog_->citationStyleLA->setEnabled(!sty.empty() && use_styles);
|
||||
biblio::CiteEngine const engine = controller().getEngine();
|
||||
bool const basic_engine = engine == biblio::ENGINE_BASIC;
|
||||
|
||||
dialog_->citationStyleCO->setEnabled(!sty.empty() && !basic_engine);
|
||||
dialog_->citationStyleLA->setEnabled(!sty.empty() && !basic_engine);
|
||||
|
||||
for (vector<string>::const_iterator it = sty.begin();
|
||||
it != sty.end(); ++it) {
|
||||
@ -142,12 +143,15 @@ void QCitation::fillStyles()
|
||||
|
||||
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_->forceuppercaseCB->setEnabled(natbib);
|
||||
dialog_->textBeforeED->setEnabled(natbib ||
|
||||
controller().usingJurabib());
|
||||
dialog_->fulllistCB->setEnabled(natbib_engine);
|
||||
dialog_->forceuppercaseCB->setEnabled(natbib_engine);
|
||||
dialog_->textBeforeED->setEnabled(!basic_engine);
|
||||
|
||||
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>
|
||||
|
||||
* 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
|
||||
updateStyle(dialog_.get(), controller().params().getCmdName());
|
||||
|
||||
bool const natbib = controller().usingNatbib();
|
||||
setEnabled(dialog_->check_full_author_list, natbib);
|
||||
setEnabled(dialog_->check_force_uppercase, natbib);
|
||||
setEnabled(dialog_->choice_style, natbib || controller().usingJurabib());
|
||||
setEnabled(dialog_->input_before, natbib || controller().usingJurabib());
|
||||
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;
|
||||
|
||||
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...
|
||||
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>
|
||||
|
||||
* insetgraphics.C (validate): remove pre 233 file format stuff,
|
||||
|
@ -20,8 +20,6 @@
|
||||
#include "funcrequest.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
|
||||
#include "frontends/controllers/biblio.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
|
||||
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
|
||||
{
|
||||
Cache::Style const style = getStyle(buffer);
|
||||
if (cache.params == params() && cache.style == style)
|
||||
biblio::CiteEngine const engine = biblio::getEngine(buffer);
|
||||
if (cache.params == params() && cache.engine == engine)
|
||||
return cache.screen_label;
|
||||
|
||||
// The label has changed, so we have to re-create it.
|
||||
@ -314,7 +293,7 @@ string const InsetCitation::getScreenLabel(Buffer const & buffer) const
|
||||
label += "...";
|
||||
}
|
||||
|
||||
cache.style = style;
|
||||
cache.engine = engine;
|
||||
cache.params = params();
|
||||
cache.generated_label = glabel;
|
||||
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
|
||||
{
|
||||
if (cache.params == params() && cache.style == getStyle(buffer))
|
||||
if (cache.params == params() &&
|
||||
cache.engine == biblio::getEngine(buffer))
|
||||
os << cache.generated_label;
|
||||
else
|
||||
os << generateLabel(buffer);
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
|
||||
#include "insetcommand.h"
|
||||
#include "frontends/controllers/biblio.h"
|
||||
|
||||
/** Used to insert citations
|
||||
*/
|
||||
@ -39,23 +40,16 @@ public:
|
||||
OutputParams const &) const;
|
||||
///
|
||||
void validate(LaTeXFeatures &) const;
|
||||
|
||||
private:
|
||||
/// This function does the donkey work of creating the pretty label
|
||||
std::string const generateLabel(Buffer const &) const;
|
||||
|
||||
struct Cache {
|
||||
///
|
||||
enum Style {
|
||||
///
|
||||
BASIC,
|
||||
///
|
||||
NATBIB_AY,
|
||||
///
|
||||
NATBIB_NUM,
|
||||
///
|
||||
JURABIB
|
||||
};
|
||||
Cache() : engine(biblio::ENGINE_BASIC) {}
|
||||
///
|
||||
Cache() : style(BASIC) {}
|
||||
///
|
||||
Style style;
|
||||
biblio::CiteEngine engine;
|
||||
///
|
||||
InsetCommandParams params;
|
||||
///
|
||||
@ -63,12 +57,6 @@ private:
|
||||
///
|
||||
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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user