On Thu, Mar 01, 2007 at 01:27:17PM +0100, Juergen Spitzmueller wrote:
> Martin Vermeer wrote:
> 
> > Yes, indeed. Still, the question remains, is this sensible.
> 
> No. Numerical needs the styles as well, so it should be supported likewise.
> 
> Jürgen

Attached an updated version of this patch, so it is not forgotten.

I added a pair of FIXMEs to remind that it is the document class that
"knows" whether we have a numerical or author-year ciation style, and
ideally LyX should be told this through a layout file option.

Were there any other issues with this? I would like to check this in, as
it would gain us one user who might become a contributor.

- Martin 
Index: src/insets/insetcite.C
===================================================================
--- src/insets/insetcite.C	(revision 17353)
+++ src/insets/insetcite.C	(working copy)
@@ -335,7 +335,7 @@
 
 docstring const InsetCitation::getScreenLabel(Buffer const & buffer) const
 {
-	biblio::CiteEngine const engine = biblio::getEngine(buffer);
+	biblio::CiteEngine const engine = buffer.params().getEngine();
 	if (cache.params == params() && cache.engine == engine)
 		return cache.screen_label;
 
@@ -368,7 +368,7 @@
 	docstring str;
 
 	if (cache.params == params() &&
-	    cache.engine == biblio::getEngine(buffer))
+	    cache.engine == buffer.params().getEngine())
 		str = cache.generated_label;
 	else
 		str = generateLabel(buffer);
@@ -424,7 +424,15 @@
 int InsetCitation::latex(Buffer const & buffer, odocstream & os,
                          OutputParams const &) const
 {
-	biblio::CiteEngine const cite_engine = buffer.params().cite_engine;
+	BufferParams const & p = buffer.params();
+	biblio::CiteEngine cite_engine;
+	// FIXME the class should also provide 
+	// the numerical/ authoryear choce
+	if (p.getLyXTextClass().provides(LyXTextClass::natbib)
+	   && p.cite_engine != biblio::ENGINE_NATBIB_NUMERICAL)
+		cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
+	else	
+		cite_engine = p.cite_engine;
 	// FIXME UNICODE
 	docstring const cite_str = from_utf8(
 		biblio::asValidLatexCommand(getCmdName(), cite_engine));
Index: src/bufferparams.C
===================================================================
--- src/bufferparams.C	(revision 17353)
+++ src/bufferparams.C	(working copy)
@@ -1482,4 +1482,15 @@
 	return *(language->encoding());
 }
 
+
+biblio::CiteEngine_enum BufferParams::getEngine() const
+{
+	// FIXME the class should provide the numerical/
+	// authoryear choice
+	if (getLyXTextClass().provides(LyXTextClass::natbib)
+	    && cite_engine != biblio::ENGINE_NATBIB_NUMERICAL)
+		return biblio::ENGINE_NATBIB_AUTHORYEAR;
+	return cite_engine;
+}
+
 } // namespace lyx
Index: src/bufferparams.h
===================================================================
--- src/bufferparams.h	(revision 17381)
+++ src/bufferparams.h	(working copy)
@@ -277,6 +277,8 @@
 				     int const & sfscale, int const & ttscale) const;
 	/// path of the current buffer
 	std::string filepath;
+	/// get the appropriate cite engine (natbib handling)
+	biblio::CiteEngine_enum getEngine() const;
 
 private:
 	/** Use the Pimpl idiom to hide those member variables that would otherwise
Index: lib/layouts/egs.layout
===================================================================
--- lib/layouts/egs.layout	(revision 17353)
+++ lib/layouts/egs.layout	(working copy)
@@ -12,6 +12,7 @@
 Columns                 2
 Sides                   1
 PageStyle               Plain
+ProvidesNatbib          1
 
 
 Style Standard
Index: src/frontends/controllers/ControlBibtex.C
===================================================================
--- src/frontends/controllers/ControlBibtex.C	(revision 17353)
+++ src/frontends/controllers/ControlBibtex.C	(working copy)
@@ -134,7 +134,7 @@
 	// the different bibtex packages have (and need) their
 	// own "plain" stylefiles
 	biblio::CiteEngine_enum const & engine =
-		biblio::getEngine(kernel().buffer());
+		kernel().buffer().params().getEngine();
 	docstring defaultstyle;
 	switch (engine) {
 	case biblio::ENGINE_BASIC:
Index: src/frontends/controllers/ControlCitation.C
===================================================================
--- src/frontends/controllers/ControlCitation.C	(revision 17353)
+++ src/frontends/controllers/ControlCitation.C	(working copy)
@@ -39,7 +39,7 @@
 	vector<pair<string, docstring> > blist;
 	kernel().buffer().fillWithBibKeys(blist);
 
-	biblio::CiteEngine const engine = biblio::getEngine(kernel().buffer());
+	biblio::CiteEngine const engine = kernel().buffer().params().getEngine();
 
 	bool use_styles = engine != biblio::ENGINE_BASIC;
 
@@ -79,13 +79,13 @@
 
 biblio::CiteEngine_enum ControlCitation::getEngine() const
 {
-	return biblio::getEngine(kernel().buffer());
+	return kernel().buffer().params().getEngine();
 }
 
 
 vector<docstring> const ControlCitation::getCiteStrings(string const & key) const
 {
-	biblio::CiteEngine const engine = biblio::getEngine(kernel().buffer());
+	biblio::CiteEngine const engine = kernel().buffer().params().getEngine();
 	vector<biblio::CiteStyle> const cs = biblio::getCiteStyles(engine);
 
 	if (engine == biblio::ENGINE_NATBIB_NUMERICAL)
Index: src/frontends/controllers/biblio.C
===================================================================
--- src/frontends/controllers/biblio.C	(revision 17353)
+++ src/frontends/controllers/biblio.C	(working copy)
@@ -688,12 +688,6 @@
 }
 
 
-CiteEngine_enum getEngine(Buffer const & buffer)
-{
-	return buffer.params().cite_engine;
-}
-
-
 vector<CiteStyle> const getCiteStyles(CiteEngine_enum const & engine)
 {
 	unsigned int nStyles = 0;
Index: src/frontends/controllers/biblio.h
===================================================================
--- src/frontends/controllers/biblio.h	(revision 17353)
+++ src/frontends/controllers/biblio.h	(working copy)
@@ -25,9 +25,7 @@
 
 class CiteEngine_enum;
 
-CiteEngine_enum getEngine(Buffer const &);
 
-
 enum CiteStyle {
 	CITE,
 	CITET,

Reply via email to