]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCitation.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / GuiCitation.cpp
index fa5099d33f93a67300a7eadfcecaa6fba1a349c6..7ba1dcc4d6fd31fb44978913e0f6392cbec3cd58 100644 (file)
 
 #include "GuiCitation.h"
 
-#include "support/debug.h"
-#include "support/gettext.h"
 #include "qt_helpers.h"
 #include "Buffer.h"
 #include "BufferParams.h"
 
-#include "support/lstrings.h"
-#include "support/docstring.h"
-
 #include "insets/InsetCommand.h"
 
-#include <vector>
-#include <string>
+#include "support/debug.h"
+#include "support/docstring.h"
+#include "support/gettext.h"
+#include "support/lstrings.h"
 
 #include <QCloseEvent>
 #include <QShowEvent>
 
+#include <vector>
+#include <string>
+
 #undef KeyPress
 
 #include <boost/regex.hpp>
@@ -76,13 +76,12 @@ static vector<lyx::docstring> to_docstring_vector(QStringList const & qlist)
 
 
 GuiCitation::GuiCitation(GuiView & lv)
-       : GuiCommand(lv, "citation")
+       : GuiCommand(lv, "citation", qt_("Citation"))
 {
        setupUi(this);
-       setViewTitle(_("Citation"));
 
        connect(citationStyleCO, SIGNAL(activated(int)),
-               this, SLOT(changed()));
+               this, SLOT(on_citationStyleCO_currentIndexChanged(int)));
        connect(fulllistCB, SIGNAL(clicked()),
                this, SLOT(changed()));
        connect(forceuppercaseCB, SIGNAL(clicked()),
@@ -120,7 +119,7 @@ void GuiCitation::closeEvent(QCloseEvent * e)
 {
        clearSelection();
        clearParams();
-       GuiDialog::closeEvent(e);
+       e->accept();
 }
 
 
@@ -188,7 +187,7 @@ void GuiCitation::updateView()
 // called in update() do not need to be called for INTERNAL updates,
 // such as when addPB is pressed, as the list of fields, entries, etc,
 // will not have changed. At the moment, however, the division between
-// fillStyles() and updateStyles() doesn't lend itself to dividing the
+// fillStyles() and updateStyle() doesn't lend itself to dividing the
 // two methods, though they should be divisible.
 void GuiCitation::updateDialog()
 {
@@ -212,9 +211,9 @@ void GuiCitation::updateDialog()
 }
 
 
-void GuiCitation::updateStyle()
+void GuiCitation::updateFormatting(biblio::CiteStyle currentStyle)
 {
-       biblio::CiteEngine const engine = getEngine();
+       biblio::CiteEngine const engine = citeEngine();
        bool const natbib_engine =
                engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
                engine == biblio::ENGINE_NATBIB_NUMERICAL;
@@ -222,15 +221,22 @@ void GuiCitation::updateStyle()
 
        bool const haveSelection = 
                selectedLV->model()->rowCount() > 0;
-       fulllistCB->setEnabled(natbib_engine && haveSelection);
-       forceuppercaseCB->setEnabled(natbib_engine && haveSelection);
-       textBeforeED->setEnabled(!basic_engine && haveSelection);
-       textBeforeLA->setEnabled(!basic_engine && haveSelection);
-       textAfterED->setEnabled(haveSelection);
-       textAfterLA->setEnabled(haveSelection);
-       citationStyleCO->setEnabled(!basic_engine && haveSelection);
-       citationStyleLA->setEnabled(!basic_engine && haveSelection);
 
+       bool const isNocite = currentStyle == biblio::NOCITE;
+
+       fulllistCB->setEnabled(natbib_engine && haveSelection && !isNocite);
+       forceuppercaseCB->setEnabled(natbib_engine && haveSelection && !isNocite);
+       textBeforeED->setEnabled(!basic_engine && haveSelection && !isNocite);
+       textBeforeLA->setEnabled(!basic_engine && haveSelection && !isNocite);
+       textAfterED->setEnabled(haveSelection && !isNocite);
+       textAfterLA->setEnabled(haveSelection && !isNocite);
+       citationStyleCO->setEnabled(haveSelection);
+       citationStyleLA->setEnabled(haveSelection);
+}
+
+
+void GuiCitation::updateStyle()
+{
        string const & command = params_.getCmdName();
 
        // Find the style of the citekeys
@@ -255,9 +261,9 @@ void GuiCitation::updateStyle()
                fulllistCB->setChecked(false);
                forceuppercaseCB->setChecked(false);
        }
+       updateFormatting(cs.style);
 }
 
-
 //This one needs to be called whenever citationStyleCO needs
 //to be updated---and this would be on anything that changes the
 //selection in selectedLV, or on a general update.
@@ -283,12 +289,10 @@ void GuiCitation::fillStyles()
 
        QStringList sty = citationStyles(curr);
 
-       bool const basic_engine = (getEngine() == biblio::ENGINE_BASIC);
+       citationStyleCO->setEnabled(!sty.isEmpty());
+       citationStyleLA->setEnabled(!sty.isEmpty());
 
-       citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
-       citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
-
-       if (sty.isEmpty() || basic_engine)
+       if (sty.isEmpty())
                return;
 
        citationStyleCO->insertItems(0, sty);
@@ -372,15 +376,15 @@ void GuiCitation::findText(QString const & text, bool reset)
        //"All Entry Types" is first.
        index = entriesCO->currentIndex() - 1; 
        vector<docstring> const & entries = availableEntries();
-       docstring entryType;
+       docstring entry_type;
        if (index < 0 || index >= int(entries.size()))
-               entryType = from_ascii("");
+               entry_type = from_ascii("");
        else 
-               entryType = entries[index];
+               entry_type = entries[index];
        
        bool const case_sentitive = caseCB->checkState();
        bool const reg_exp = regexCB->checkState();
-       findKey(text, onlyKeys, field, entryType, 
+       findKey(text, onlyKeys, field, entry_type, 
                       case_sentitive, reg_exp, reset);
        //FIXME
        //It'd be nice to save and restore the current selection in 
@@ -403,6 +407,15 @@ void GuiCitation::on_entriesCO_currentIndexChanged(int /*index*/)
 }
 
 
+void GuiCitation::on_citationStyleCO_currentIndexChanged(int index)
+{
+       if (index >= 0 && index < citationStyleCO->count()) {
+               vector<biblio::CiteStyle> const & styles = citeStyles_;
+               updateFormatting(styles[index]);
+       }
+}
+
+
 void GuiCitation::on_findLE_textChanged(const QString & text)
 {
        clearPB->setDisabled(text.isEmpty());
@@ -426,19 +439,24 @@ void GuiCitation::on_regexCB_stateChanged(int)
 
 void GuiCitation::changed()
 {
-       fillStyles();
        setButtons();
 }
 
 
-void GuiCitation::apply(int const choice, bool const full, bool const force,
+void GuiCitation::apply(int const choice, bool full, bool force,
        QString before, QString after)
 {
        if (cited_keys_.isEmpty())
                return;
 
        vector<biblio::CiteStyle> const & styles = citeStyles_;
-
+       if (styles[choice] == biblio::NOCITE) {
+               full = false;
+               force = false;
+               before.clear();
+               after.clear();
+       }
+       
        string const command =
                biblio::CitationStyle(styles[choice], full, force)
                .asLatexStr();
@@ -487,7 +505,7 @@ void GuiCitation::init()
 
 
 void GuiCitation::findKey(QString const & str, bool only_keys,
-       docstring field, docstring entryType,
+       docstring field, docstring entry_type,
        bool case_sensitive, bool reg_exp, bool reset)
 {
        // Used for optimisation: store last searched string.
@@ -523,10 +541,10 @@ void GuiCitation::findKey(QString const & str, bool only_keys,
 
        QStringList result;
        
-       // First, filter by entryType, which will be faster than 
+       // First, filter by entry_type, which will be faster than 
        // what follows, so we may get to do that on less.
        vector<docstring> keyVector = to_docstring_vector(keys);
-       filterByEntryType(keyVector, entryType);
+       filterByEntryType(keyVector, entry_type);
        
        if (str.isEmpty())
                result = to_qstring_list(keyVector);
@@ -571,22 +589,10 @@ void GuiCitation::setCitedKeys()
 
 bool GuiCitation::initialiseParams(string const & data)
 {
-       InsetCommandMailer::string2params(lfun_name_, data, params_);
-
-       biblio::CiteEngine const engine = buffer().params().getEngine();
-
-       bool use_styles = engine != biblio::ENGINE_BASIC;
-
+       InsetCommand::string2params(lfun_name_, data, params_);
+       biblio::CiteEngine const engine = buffer().params().citeEngine();
        bibkeysInfo_.fillWithBibKeys(&buffer());
-       
-       if (citeStyles_.empty())
-               citeStyles_ = biblio::getCiteStyles(engine);
-       else {
-               if ((use_styles && citeStyles_.size() == 1) ||
-                   (!use_styles && citeStyles_.size() != 1))
-                       citeStyles_ = biblio::getCiteStyles(engine);
-       }
-
+       citeStyles_ = biblio::getCiteStyles(engine);
        return true;
 }
 
@@ -598,28 +604,28 @@ void GuiCitation::clearParams()
 }
 
 
-vector<docstring> const GuiCitation::availableKeys() const
+vector<docstring> GuiCitation::availableKeys() const
 {
        return bibkeysInfo_.getKeys();
 }
 
 
-vector<docstring> const GuiCitation::availableFields() const
+vector<docstring> GuiCitation::availableFields() const
 {
        return bibkeysInfo_.getFields();
 }
 
 
-vector<docstring> const GuiCitation::availableEntries() const
+vector<docstring> GuiCitation::availableEntries() const
 {
        return bibkeysInfo_.getEntries();
 }
 
 
 void GuiCitation::filterByEntryType(
-       vector<docstring> & keyVector, docstring entryType) 
+       vector<docstring> & keyVector, docstring entry_type) 
 {
-       if (entryType.empty())
+       if (entry_type.empty())
                return;
        
        vector<docstring>::iterator it = keyVector.begin();
@@ -631,16 +637,16 @@ void GuiCitation::filterByEntryType(
                BiblioInfo::const_iterator cit = bibkeysInfo_.find(key);
                if (cit == bibkeysInfo_.end())
                        continue;
-               if (cit->second.entryType == entryType)
+               if (cit->second.entryType() == entry_type)
                        result.push_back(key);
        }
        keyVector = result;
 }
 
 
-biblio::CiteEngine GuiCitation::getEngine() const
+biblio::CiteEngine GuiCitation::citeEngine() const
 {
-       return buffer().params().getEngine();
+       return buffer().params().citeEngine();
 }
 
 
@@ -715,7 +721,7 @@ vector<docstring> GuiCitation::searchKeys(
                if (only_keys)
                        data = to_utf8(*it);
                else if (field.empty())
-                       data = to_utf8(*it) + ' ' + to_utf8(kvm.allData);
+                       data = to_utf8(*it) + ' ' + to_utf8(kvm.allData());
                else if (kvm.hasField(field))
                        data = to_utf8(kvm.getValueForField(field));