]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
Implement CiteItem in the chain
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index d971eebe7b8e797e04836e8976166995cb69472f..cefa3a197921102b1345f9bca57a32eea6250a28 100644 (file)
@@ -1070,13 +1070,6 @@ GuiDocument::GuiDocument(GuiView & lv)
        encodinglist.sort();
        langModule->encodingCO->addItems(encodinglist);
 
-       for (int i = 0; i < quoteparams.stylescount(); ++i) {
-               InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
-               if (qs == InsetQuotesParams::DynamicQuotes)
-                       continue;
-               langModule->quoteStyleCO->addItem(toqstr(quoteparams.getGuiLabel(qs)), qs);
-       }
-
        langModule->languagePackageCO->addItem(
                qt_("Default"), toqstr("default"));
        langModule->languagePackageCO->addItem(
@@ -1130,15 +1123,23 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
                this, SLOT(citeEngineChanged(int)));
        connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
-               this, SLOT(biblioChanged()));
+               this, SLOT(citeStyleChanged()));
        connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
                this, SLOT(biblioChanged()));
        connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
                this, SLOT(bibtexChanged(int)));
        connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
                this, SLOT(biblioChanged()));
-       connect(biblioModule->bibtexStyleLE, SIGNAL(textChanged(QString)),
+       connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
+               this, SLOT(biblioChanged()));
+       connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
                this, SLOT(biblioChanged()));
+       connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
+               this, SLOT(updateResetDefaultBiblio()));
+       connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
+               this, SLOT(rescanBibFiles()));
+       connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
+               this, SLOT(resetDefaultBibfile()));
 
        biblioModule->citeEngineCO->clear();
        for (LyXCiteEngine const & cet : theCiteEnginesList) {
@@ -1150,8 +1151,8 @@ GuiDocument::GuiDocument(GuiView & lv)
 
        biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
                biblioModule->bibtexOptionsLE));
-       biblioModule->bibtexStyleLE->setValidator(new NoNewLineValidator(
-               biblioModule->bibtexStyleLE));
+       biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
+               biblioModule->defaultBiblioCO->lineEdit()));
 
        // NOTE: we do not provide "custom" here for security reasons!
        biblioModule->bibtexCO->clear();
@@ -1753,6 +1754,38 @@ void GuiDocument::deleteBoxBackgroundColor()
 }
 
 
+void GuiDocument::updateQuoteStyles(bool const set)
+{
+       Language const * lang = lyx::languages.getLanguage(
+               fromqstr(langModule->languageCO->itemData(
+                       langModule->languageCO->currentIndex()).toString()));
+
+       InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
+
+       langModule->quoteStyleCO->clear();
+
+       bool has_default = false;
+       for (int i = 0; i < quoteparams.stylescount(); ++i) {
+               InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
+               if (qs == InsetQuotesParams::DynamicQuotes)
+                       continue;
+               bool const langdef = (qs == def);
+               if (langdef) {
+                       // add the default style on top
+                       langModule->quoteStyleCO->insertItem(0,
+                               toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
+                       has_default = true;
+               }
+               else
+                       langModule->quoteStyleCO->addItem(
+                               toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
+       }
+       if (set && has_default)
+               // (re)set to the default style
+               langModule->quoteStyleCO->setCurrentIndex(0);
+}
+
+
 void GuiDocument::languageChanged(int i)
 {
        // some languages only work with polyglossia
@@ -1777,10 +1810,7 @@ void GuiDocument::languageChanged(int i)
        }
 
        // set appropriate quotation mark style
-       if (!lang->quoteStyle().empty()) {
-               langModule->quoteStyleCO->setCurrentIndex(
-                       bp_.getQuoteStyle(lang->quoteStyle()));
-       }
+       updateQuoteStyles(true);
 }
 
 
@@ -2271,41 +2301,58 @@ void GuiDocument::biblioChanged()
 }
 
 
+void GuiDocument::rescanBibFiles()
+{
+       rescanTexStyles("bst");
+}
+
+
+void GuiDocument::resetDefaultBibfile()
+{
+       QString const engine =
+               biblioModule->citeEngineCO->itemData(
+                               biblioModule->citeEngineCO->currentIndex()).toString();
+
+       CiteEngineType const cet =
+               CiteEngineType(biblioModule->citeStyleCO->itemData(
+                                                         biblioModule->citeStyleCO->currentIndex()).toInt());
+
+       updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet));
+}
+
+
 void GuiDocument::citeEngineChanged(int n)
 {
-       QString const engine = biblioModule->citeEngineCO->itemData(n).toString();
+       QString const engine =
+               biblioModule->citeEngineCO->itemData(n).toString();
 
        vector<string> const engs =
                theCiteEnginesList[fromqstr(engine)]->getEngineType();
 
        updateCiteStyles(engs);
+       resetDefaultBibfile();
 
        biblioChanged();
 }
 
 
-void GuiDocument::bibtexChanged(int n)
+void GuiDocument::citeStyleChanged()
 {
-       biblioModule->bibtexOptionsLE->setEnabled(
-               biblioModule->bibtexCO->itemData(n).toString() != "default");
-       biblioChanged();
-}
-
+       QString const engine =
+               biblioModule->citeEngineCO->itemData(
+                               biblioModule->citeEngineCO->currentIndex()).toString();
+       if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(
+                               fromqstr(biblioModule->defaultBiblioCO->currentText())))
+               resetDefaultBibfile();
 
-void GuiDocument::setAuthorYear(bool authoryear)
-{
-       if (authoryear)
-               biblioModule->citeStyleCO->setCurrentIndex(
-                       biblioModule->citeStyleCO->findData(ENGINE_TYPE_AUTHORYEAR));
        biblioChanged();
 }
 
 
-void GuiDocument::setNumerical(bool numerical)
+void GuiDocument::bibtexChanged(int n)
 {
-       if (numerical)
-               biblioModule->citeStyleCO->setCurrentIndex(
-                       biblioModule->citeStyleCO->findData(ENGINE_TYPE_NUMERICAL));
+       biblioModule->bibtexOptionsLE->setEnabled(
+               biblioModule->bibtexCO->itemData(n).toString() != "default");
        biblioChanged();
 }
 
@@ -2617,7 +2664,7 @@ void GuiDocument::applyView()
        bp_.use_bibtopic =
                biblioModule->bibtopicCB->isChecked();
 
-       bp_.biblio_style = fromqstr(biblioModule->bibtexStyleLE->text());
+       bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
 
        string const bibtex_command =
                fromqstr(biblioModule->bibtexCO->itemData(
@@ -3040,7 +3087,7 @@ void GuiDocument::paramsToDialog()
        biblioModule->bibtopicCB->setChecked(
                bp_.use_bibtopic);
 
-       biblioModule->bibtexStyleLE->setText(toqstr(bp_.biblio_style));
+       updateDefaultBiblio(bp_.defaultBiblioStyle());
 
        string command;
        string options =
@@ -3073,6 +3120,8 @@ void GuiDocument::paramsToDialog()
                bp_.language->lang()));
        langModule->languageCO->setCurrentIndex(pos);
 
+       updateQuoteStyles();
+
        langModule->quoteStyleCO->setCurrentIndex(
                bp_.quotes_style);
        langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
@@ -3626,6 +3675,59 @@ void GuiDocument::updateIncludeonlys()
 }
 
 
+void GuiDocument::updateDefaultBiblio(string const & style)
+{
+       QString const bibstyle = toqstr(style);
+       biblioModule->defaultBiblioCO->clear();
+
+       int item_nr = -1;
+
+       QStringList str = texFileList("bstFiles.lst");
+       // test whether we have a valid list, otherwise run rescan
+       if (str.isEmpty()) {
+               rescanTexStyles("bst");
+               str = texFileList("bstFiles.lst");
+       }
+       for (int i = 0; i != str.size(); ++i)
+               str[i] = onlyFileName(str[i]);
+       // sort on filename only (no path)
+       str.sort();
+
+       for (int i = 0; i != str.count(); ++i) {
+               QString item = changeExtension(str[i], "");
+               if (item == bibstyle)
+                       item_nr = i;
+               biblioModule->defaultBiblioCO->addItem(item);
+       }
+
+       if (item_nr == -1 && !bibstyle.isEmpty()) {
+               biblioModule->defaultBiblioCO->addItem(bibstyle);
+               item_nr = biblioModule->defaultBiblioCO->count() - 1;
+       }
+
+       if (item_nr != -1)
+               biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
+       else
+               biblioModule->defaultBiblioCO->clearEditText();
+
+       updateResetDefaultBiblio();
+}
+
+
+void GuiDocument::updateResetDefaultBiblio()
+{
+       QString const engine =
+               biblioModule->citeEngineCO->itemData(
+                               biblioModule->citeEngineCO->currentIndex()).toString();
+       CiteEngineType const cet =
+               CiteEngineType(biblioModule->citeStyleCO->itemData(
+                                                         biblioModule->citeStyleCO->currentIndex()).toInt());
+       biblioModule->resetDefaultBiblioPB->setEnabled(
+               theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet)
+                       != fromqstr(biblioModule->defaultBiblioCO->currentText()));
+}
+
+
 void GuiDocument::updateContents()
 {
        // Nothing to do here as the document settings is not cursor dependant.