http://bugzilla.lyx.org/show_bug.cgi?id=2322
As advertised, the last patch I have in my tree for 1.4.1.

Jürgen
Index: src/frontends/gtk/GBibtex.C
===================================================================
--- src/frontends/gtk/GBibtex.C	(Revision 13342)
+++ src/frontends/gtk/GBibtex.C	(Arbeitskopie)
@@ -28,8 +28,6 @@
 #include <libglademm.h>
 
 using lyx::support::ChangeExtension;
-using lyx::support::contains;
-using lyx::support::prefixIs;
 using lyx::support::split;
 using lyx::support::trim;
 
@@ -109,20 +107,10 @@ void GBibtex::update()
 		}
 	}
 
-	string bibtotoc = "bibtotoc";
-	string bibstyle(controller().params().getOptions());
-
-	// bibtotoc exists?
-	if (prefixIs(bibstyle, bibtotoc)){
-		// bibstyle exists?
-		if (contains(bibstyle,','))
-			bibstyle = split(bibstyle, bibtotoc, ',');
-		else
-			bibstyle.erase();
-	}
+	string bibstyle(controller().getStylefile());
 
 	bool const bibtopic = controller().usingBibtopic();
-	if (prefixIs(bibstyle, bibtotoc) && !bibtopic)
+	if (controller().bibtotoc() && !bibtopic)
 		toccheck_->set_active(true);
 	else
 		toccheck_->set_active(false);
Index: src/frontends/qt2/QBibtex.C
===================================================================
--- src/frontends/qt2/QBibtex.C	(Revision 13342)
+++ src/frontends/qt2/QBibtex.C	(Arbeitskopie)
@@ -33,8 +33,6 @@
 
 
 using lyx::support::ChangeExtension;
-using lyx::support::contains;
-using lyx::support::prefixIs;
 using lyx::support::split;
 using lyx::support::trim;
 
@@ -98,23 +96,7 @@ void QBibtex::update_contents()
 		dialog_->add_->bibLB->insertItem(toqstr(bibItem));
 	}
 
-	string bibtotoc = "bibtotoc";
-	string bibstyle(controller().params().getOptions());
-
-	// bibtotoc exists?
-	if (prefixIs(bibstyle, bibtotoc)){
-		// bibstyle exists?
-		if (contains(bibstyle,','))
-			bibstyle = split(bibstyle, bibtotoc, ',');
-		else
-			bibstyle.erase();
-	}
-
-	if (prefixIs(bibstyle, bibtotoc) && !bibtopic)
-		dialog_->bibtocCB->setChecked(true);
-	else
-		dialog_->bibtocCB->setChecked(false);
-
+	dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
 	dialog_->bibtocCB->setEnabled(!bibtopic);
 
 	string btprint(controller().params().getSecOptions());
@@ -130,6 +112,7 @@ void QBibtex::update_contents()
 	dialog_->styleCB->clear();
 
 	int item_nr(-1);
+	string bibstyle(controller().getStylefile());
 
 	vector<string> str;
 	controller().getBibStyles(str);
Index: src/frontends/qt4/QBibtex.C
===================================================================
--- src/frontends/qt4/QBibtex.C	(Revision 13342)
+++ src/frontends/qt4/QBibtex.C	(Arbeitskopie)
@@ -32,8 +32,6 @@
 
 
 using lyx::support::ChangeExtension;
-using lyx::support::contains;
-using lyx::support::prefixIs;
 using lyx::support::split;
 using lyx::support::trim;
 
@@ -97,23 +95,9 @@ void QBibtex::update_contents()
 		dialog_->add_->bibLB->insertItem(toqstr(bibItem));
 	}
 
-	string bibtotoc = "bibtotoc";
-	string bibstyle(controller().params().getOptions());
-
-	// bibtotoc exists?
-	if (prefixIs(bibstyle, bibtotoc)){
-		// bibstyle exists?
-		if (contains(bibstyle,','))
-			bibstyle = split(bibstyle, bibtotoc, ',');
-		else
-			bibstyle.erase();
-	}
-
-	if (prefixIs(bibstyle, bibtotoc) && !bibtopic)
-		dialog_->bibtocCB->setChecked(true);
-	else
-		dialog_->bibtocCB->setChecked(false);
+	string bibstyle(controller().getStylefile());
 
+	dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
 	dialog_->bibtocCB->setEnabled(!bibtopic);
 
 	string btprint(controller().params().getSecOptions());
Index: src/frontends/xforms/FormBibtex.C
===================================================================
--- src/frontends/xforms/FormBibtex.C	(Revision 13342)
+++ src/frontends/xforms/FormBibtex.C	(Arbeitskopie)
@@ -34,12 +34,10 @@ namespace lyx {
 
 using support::ChangeExtension;
 using support::compare;
-using support::contains;
 using support::FileFilterList;
 using support::getStringFromVector;
 using support::getVectorFromString;
 using support::OnlyFilename;
-using support::prefixIs;
 using support::split;
 
 namespace frontend {
@@ -179,20 +177,13 @@ void FormBibtex::update()
 	fl_set_input(dialog_->input_database,
 		     controller().params().getContents().c_str());
 
-	string bibtotoc = "bibtotoc";
-	string bibstyle = controller().params().getOptions();
+	string bibstyle = controller().getStylefile();
 
 	bool const bibtopic = controller().usingBibtopic();
-	bool const bibtotoc_exists = prefixIs(bibstyle, bibtotoc);
-	fl_set_button(dialog_->check_bibtotoc, bibtotoc_exists && !bibtopic);
+	fl_set_button(dialog_->check_bibtotoc,
+		controller().bibtotoc() && !bibtopic);
 	setEnabled(dialog_->check_bibtotoc, !bibtopic);
-	if (bibtotoc_exists) {
-		if (contains(bibstyle, ',')) { // bibstyle exists?
-			bibstyle = split(bibstyle, bibtotoc, ',');
-		} else {
-			bibstyle.erase();
-		}
-	}
+
 	fl_set_input(dialog_->input_style, bibstyle.c_str());
 
 	string btprint = controller().params().getSecOptions();
Index: src/frontends/controllers/ControlBibtex.C
===================================================================
--- src/frontends/controllers/ControlBibtex.C	(Revision 13342)
+++ src/frontends/controllers/ControlBibtex.C	(Arbeitskopie)
@@ -13,6 +13,7 @@
 #include <config.h>
 
 #include "ControlBibtex.h"
+#include "biblio.h"
 
 #include "buffer.h"
 #include "bufferparams.h"
@@ -24,6 +25,7 @@
 
 #include "support/filefilterlist.h"
 #include "support/filetools.h"
+#include "support/lstrings.h"
 
 using std::pair;
 using std::string;
@@ -32,8 +34,11 @@ using std::vector;
 
 namespace lyx {
 
+using support::contains;
 using support::FileFilterList;
 using support::OnlyFilename;
+using support::prefixIs;
+using support::split;
 
 namespace frontend {
 
@@ -112,7 +117,55 @@ void ControlBibtex::rescanBibStyles() co
 
 bool ControlBibtex::usingBibtopic() const
 {
-    return kernel().buffer().params().use_bibtopic;
+	return kernel().buffer().params().use_bibtopic;
+}
+
+
+bool ControlBibtex::bibtotoc() const
+{
+	return prefixIs(params().getOptions(), "bibtotoc");
+}
+
+
+string const ControlBibtex::getStylefile() const
+{
+	// the different bibtex packages have (and need) their
+	// own "plain" stylefiles
+	biblio::CiteEngine_enum const & engine =
+		biblio::getEngine(kernel().buffer());
+	string defaultstyle;
+	switch (engine) {
+	case biblio::ENGINE_BASIC:
+		defaultstyle = "plain";
+		break;
+	case biblio::ENGINE_NATBIB_AUTHORYEAR:
+		defaultstyle = "plainnat";
+		break;
+	case biblio::ENGINE_NATBIB_NUMERICAL:
+		defaultstyle = "plainnat";
+		break;
+	case biblio::ENGINE_JURABIB:
+		defaultstyle = "jurabib";
+		break;
+	}
+
+	string bst = params().getOptions();
+	if (bibtotoc()){
+		// bibstyle exists?
+		if (contains(bst,',')) {
+			string bibtotoc = "bibtotoc";
+			bst = split(bst, bibtotoc, ',');
+		} else
+			bst.erase();
+	}
+
+	// propose default style file for new insets
+	// existing insets might have (legally) no bst files
+	// (if the class already provides a style)
+	if (bst.empty() && params().getContents().empty())
+		bst = defaultstyle;
+
+	return bst;
 }
 
 } // namespace frontend
Index: src/frontends/controllers/ControlBibtex.h
===================================================================
--- src/frontends/controllers/ControlBibtex.h	(Revision 13342)
+++ src/frontends/controllers/ControlBibtex.h	(Arbeitskopie)
@@ -48,6 +48,10 @@ public:
 	void rescanBibStyles() const;
 	/// do we use bibtopic (for sectioned bibliography)?
 	bool usingBibtopic() const;
+	/// should we put the bibliography to the TOC?
+	bool bibtotoc() const;
+	/// which stylefile do we use?
+	std::string const getStylefile() const;
 };
 
 } // namespace frontend

Reply via email to