]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/QBibtex.C
Some string(widget->text()) fixes. Weirdness
[lyx.git] / src / frontends / qt2 / QBibtex.C
index 41d0c3d2e0c5e9a16fbd6685f721ee8ed202de69..3169a1490d5b94fda82a6a9d8c69f467b63c328f 100644 (file)
@@ -1,19 +1,29 @@
 /**
  * \file QBibtex.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon
+ * \author Herbert Voss
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include "support/lstrings.h"
 
 #include "ControlBibtex.h"
 #include "gettext.h"
 #include "debug.h"
 
+#include "support/filetools.h" // ChangeExtension
+#include "support/lstrings.h" // getVectorFromString
+
 #include <qlineedit.h>
 #include <qcombobox.h>
 #include <qpushbutton.h>
 #include "QBibtexDialog.h"
 #include "QBibtex.h"
 #include "Qt2BC.h"
+
+using std::vector;
+
 typedef Qt2CB<ControlBibtex, Qt2DB<QBibtexDialog> > base_class;
 
-QBibtex::QBibtex(ControlBibtex & c)
-       : base_class(c, _("BibTeX"))
+
+QBibtex::QBibtex()
+       : base_class(_("BibTeX"))
 {
 }
 
@@ -40,9 +53,8 @@ void QBibtex::build_dialog()
        bc().setCancel(dialog_->closePB);
        bc().addReadOnly(dialog_->databaseLB);
        bc().addReadOnly(dialog_->databasePB);
-       bc().addReadOnly(dialog_->styleCO);
-       bc().addReadOnly(dialog_->styleED);
        bc().addReadOnly(dialog_->stylePB);
+       bc().addReadOnly(dialog_->styleCB);
        bc().addReadOnly(dialog_->bibtocCB);
        bc().addReadOnly(dialog_->databasePB);
        bc().addReadOnly(dialog_->deletePB);
@@ -58,63 +70,63 @@ void QBibtex::update_contents()
 
        while (!bibs.empty()) {
                bibs = split(bibs, bib, ',');
-               bib = frontStrip(strip(bib));
+               bib = trim(bib);
                if (!bib.empty())
-                       dialog_->databaseLB->inSort(bib.c_str());
+                       dialog_->databaseLB->insertItem(bib.c_str());
        }
 
        string bibtotoc = "bibtotoc";
        string bibstyle(controller().params().getOptions().c_str());
 
        // bibtotoc exists?
-       if (prefixIs(bibstyle,bibtotoc)) {
+       if (prefixIs(bibstyle, bibtotoc)) {
                dialog_->bibtocCB->setChecked(true);
 
                // bibstyle exists?
                if (contains(bibstyle,','))
                        bibstyle = split(bibstyle, bibtotoc, ',');
                else
-                       bibstyle = "";
+                       bibstyle.erase();
        } else
                dialog_->bibtocCB->setChecked(false);
 
-       dialog_->deletePB->setEnabled(false);
-       dialog_->styleED->setEnabled(false);
-       dialog_->stylePB->setEnabled(false);
-
-       if (bibstyle == "plain" || bibstyle.empty())
-               dialog_->styleCO->setCurrentItem(0);
-       else if (bibstyle == "unsrt")
-               dialog_->styleCO->setCurrentItem(1);
-       else if (bibstyle == "alpha")
-               dialog_->styleCO->setCurrentItem(2);
-       else if (bibstyle == "abbrv")
-               dialog_->styleCO->setCurrentItem(3);
-       else {
-               dialog_->styleED->setEnabled(true);
-               dialog_->stylePB->setEnabled(true);
-               dialog_->styleED->setText(bibstyle.c_str());
-               dialog_->styleCO->setCurrentItem(4);
+
+       dialog_->styleCB->clear();
+       int item_nr(-1);
+       vector<string> const str = getVectorFromString(
+               controller().getBibStyles(), "\n");
+       for (vector<string>::const_iterator it = str.begin();
+               it != str.end(); ++it) {
+               string item(ChangeExtension(*it, "")); 
+               if (item == bibstyle)
+                       item_nr = int(it - str.begin());
+               dialog_->styleCB->insertItem(item.c_str());
        }
 
+       if (item_nr == -1) {
+               dialog_->styleCB->insertItem(bibstyle.c_str());
+               item_nr = dialog_->styleCB->count() - 1;
+       }
+
+       dialog_->styleCB->setCurrentItem(item_nr);
 }
 
 
 void QBibtex::apply()
 {
-       string dbs;
+       string dbs(dialog_->databaseLB->text(0).latin1());
 
-       for (unsigned int i = 0; i < dialog_->databaseLB->count(); ++i) {
+       unsigned int maxCount = dialog_->databaseLB->count();
+       for (unsigned int i = 1; i < maxCount; i++) {
+               dbs += ',';
                dbs += dialog_->databaseLB->text(i).latin1();
-               if (i != dialog_->databaseLB->count())
-                       dbs += ",";
        }
-       controller().params().setContents(dbs);
 
-       string bibstyle(dialog_->styleCO->currentText().latin1());
-       if (bibstyle == _("Other ..."))
-               bibstyle = dialog_->styleED->text().latin1();
+       controller().params().setContents(dbs);
 
+       string const bibstyle(dialog_->styleCB->currentText().latin1());
        bool const bibtotoc(dialog_->bibtocCB->isChecked());
 
        if (bibtotoc && (!bibstyle.empty())) {
@@ -123,8 +135,10 @@ void QBibtex::apply()
        } else if (bibtotoc) {
                // bibtotoc and no style
                controller().params().setOptions("bibtotoc");
-       } else if (!bibstyle.empty()){
-               // only style
+       } else {
+               // only style. An empty one is valid, because some
+               // documentclasses have an own \bibliographystyle{}
+               // command!
                controller().params().setOptions(bibstyle);
        }
 }
@@ -132,6 +146,5 @@ void QBibtex::apply()
 
 bool QBibtex::isValid()
 {
-       return dialog_->databaseLB->count() != 0 &&
-               !(dialog_->styleCO->currentItem() == 4 && string(dialog_->styleED->text()).empty());
+       return dialog_->databaseLB->count() != 0;
 }