]> git.lyx.org Git - features.git/commitdiff
frontends/controllers/ControlBibtex.[Ch]: new members bibtotoc(), getStylefile(),
authorJürgen Spitzmüller <spitz@lyx.org>
Mon, 20 Mar 2006 10:24:23 +0000 (10:24 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Mon, 20 Mar 2006 10:24:23 +0000 (10:24 +0000)
which hold functionality that has been moved from the frontends
and implement a method to use a default stylefile for new bibtex
insets (bug 2322).

frontends/gtk/GBibtex.C:
frontends/qt2/QBibtex.C:
frontends/qt4/QBibtex.C:
frontends/xforms/FormBibTex.C: Move parsing of Options (stylefile, bibtotoc) to the
controller (bug 2322).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13427 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ControlBibtex.C
src/frontends/controllers/ControlBibtex.h
src/frontends/gtk/GBibtex.C
src/frontends/qt2/QBibtex.C
src/frontends/qt4/QBibtex.C
src/frontends/xforms/FormBibtex.C

index 0573d240042379777aeb64ffba5574fa0dcd3f5f..76964ac4c3583ca574b67dbcf40428e314514696 100644 (file)
@@ -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() const
 
 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 0dc3d0db628beadd92e488a9777840b238454171..239c05d72b0edc1277ff78a97b175066ed26d73b 100644 (file)
@@ -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
index a96f510e482a974fe29fc0a1dfe8c774bf6a53b0..881fe69be96982cde37cbec998272b4ba443f728 100644 (file)
@@ -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 fe87c707959ffe893cc5b6e3a98b19c2ba776b15..eb80229276c1ffa28a37eef57da82a2b7e8933ae 100644 (file)
@@ -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 8585779fbd08d0777b7d6c91780c20b93659e803..71d56e5ead8666ef6223a52372698ec1ce33d61a 100644 (file)
@@ -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 8152b99c230ff87bacf5999114924bf26a245aab..5ada2bfac017e01e8e48a67968e885f43bc4365a 100644 (file)
@@ -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();