]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCitation.cpp
The View->Source pane resets the format every time you click into
[lyx.git] / src / frontends / qt4 / GuiCitation.cpp
index 4bab50a204181afdb6adb82b92f5413afc6be666..54f9ceb936cfaeb7d9ed050738ab1a3aef0fec8d 100644 (file)
@@ -20,6 +20,7 @@
 #include "qt_helpers.h"
 
 #include "Buffer.h"
+#include "BufferView.h"
 #include "BiblioInfo.h"
 #include "BufferParams.h"
 #include "FuncRequest.h"
@@ -41,7 +42,7 @@
 
 #undef KeyPress
 
-#include <boost/regex.hpp>
+#include "support/regex.h"
 
 #include <algorithm>
 #include <string>
@@ -98,14 +99,14 @@ GuiCitation::GuiCitation(GuiView & lv)
                this, SLOT(changed()));
        connect(textAfterED, SIGNAL(textChanged(QString)),
                this, SLOT(changed()));
-       connect(findLE, SIGNAL(returnPressed()), 
+       connect(findLE, SIGNAL(returnPressed()),
                this, SLOT(on_searchPB_clicked()));
        connect(textBeforeED, SIGNAL(returnPressed()),
                this, SLOT(on_okPB_clicked()));
        connect(textAfterED, SIGNAL(returnPressed()),
                this, SLOT(on_okPB_clicked()));
 
-       selectionManager = new GuiSelectionManager(availableLV, selectedLV, 
+       selectionManager = new GuiSelectionManager(availableLV, selectedLV,
                        addPB, deletePB, upPB, downPB, &available_model_, &selected_model_);
        connect(selectionManager, SIGNAL(selectionChanged()),
                this, SLOT(setCitedKeys()));
@@ -114,8 +115,7 @@ GuiCitation::GuiCitation(GuiView & lv)
        connect(selectionManager, SIGNAL(okHook()),
                this, SLOT(on_okPB_clicked()));
 
-       // FIXME: the sizeHint() for this is _way_ too high
-       infoML->setFixedHeight(60);
+       setFocusProxy(availableLV);
 }
 
 
@@ -287,16 +287,16 @@ void GuiCitation::fillStyles(BiblioInfo const & bi)
 
        QStringList sty = citationStyles(bi, curr);
 
-       if (sty.isEmpty()) { 
+       if (sty.isEmpty()) {
                // some error
                citationStyleCO->setEnabled(false);
                citationStyleLA->setEnabled(false);
                citationStyleCO->clear();
                return;
        }
-       
+
        citationStyleCO->blockSignals(true);
-       
+
        // save old index
        int const oldIndex = citationStyleCO->currentIndex();
        citationStyleCO->clear();
@@ -364,46 +364,46 @@ void GuiCitation::updateInfo(BiblioInfo const & bi, QModelIndex const & idx)
        }
 
        QString const keytxt = toqstr(
-               bi.getInfo(qstring_to_ucs4(idx.data().toString())));
-       infoML->document()->setPlainText(keytxt);
+               bi.getInfo(qstring_to_ucs4(idx.data().toString()), documentBuffer(), true));
+       infoML->document()->setHtml(keytxt);
 }
 
 
 void GuiCitation::findText(QString const & text, bool reset)
 {
        //"All Fields" and "Keys" are the first two
-       int index = fieldsCO->currentIndex() - 2; 
+       int index = fieldsCO->currentIndex() - 2;
        BiblioInfo const & bi = bibInfo();
        vector<docstring> const & fields = bi.getFields();
        docstring field;
-       
+
        if (index <= -1 || index >= int(fields.size()))
                //either "All Fields" or "Keys" or an invalid value
                field = from_ascii("");
        else
                field = fields[index];
-       
+
        //Was it "Keys"?
        bool const onlyKeys = index == -1;
-       
+
        //"All Entry Types" is first.
-       index = entriesCO->currentIndex() - 1; 
+       index = entriesCO->currentIndex() - 1;
        vector<docstring> const & entries = bi.getEntries();
        docstring entry_type;
        if (index < 0 || index >= int(entries.size()))
                entry_type = from_ascii("");
-       else 
+       else
                entry_type = entries[index];
-       
+
        bool const case_sentitive = caseCB->checkState();
        bool const reg_exp = regexCB->checkState();
-       findKey(bi, text, onlyKeys, field, entry_type, 
+       findKey(bi, text, onlyKeys, field, entry_type,
                       case_sentitive, reg_exp, reset);
        //FIXME
-       //It'd be nice to save and restore the current selection in 
+       //It'd be nice to save and restore the current selection in
        //availableLV. Currently, we get an automatic reset, since the
        //model is reset.
-       
+
        updateControls(bi);
 }
 
@@ -528,10 +528,10 @@ void GuiCitation::init()
                selectedLV->blockSignals(true);
                selectedLV->setFocus();
                QModelIndex idx = selected_model_.index(0, 0);
-               selectedLV->selectionModel()->select(idx, 
+               selectedLV->selectionModel()->select(idx,
                                QItemSelectionModel::ClearAndSelect);
                selectedLV->blockSignals(false);
-               
+
                // set the style combo appropriately
                string const & command = params_.getCmdName();
                vector<CiteStyle> const & styles = citeStyles_;
@@ -591,18 +591,18 @@ void GuiCitation::findKey(BiblioInfo const & bi,
        last_searched_string = str;
 
        QStringList result;
-       
-       // First, filter by entry_type, 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(bi, keyVector, entry_type);
-       
+
        if (str.isEmpty())
                result = to_qstring_list(keyVector);
        else
-               result = to_qstring_list(searchKeys(bi, keyVector, only_keys, 
+               result = to_qstring_list(searchKeys(bi, keyVector, only_keys,
                        qstring_to_ucs4(str), field, case_sensitive, reg_exp));
-       
+
        available_model_.setStringList(result);
 }
 
@@ -610,11 +610,11 @@ void GuiCitation::findKey(BiblioInfo const & bi,
 QStringList GuiCitation::citationStyles(BiblioInfo const & bi, int sel)
 {
        docstring const key = qstring_to_ucs4(cited_keys_[sel]);
-       return to_qstring_list(bi.getCiteStrings(key, buffer()));
+       return to_qstring_list(bi.getCiteStrings(key, documentBuffer()));
 }
 
 
-void GuiCitation::setCitedKeys() 
+void GuiCitation::setCitedKeys()
 {
        cited_keys_ = selected_model_.stringList();
 }
@@ -622,8 +622,8 @@ void GuiCitation::setCitedKeys()
 
 bool GuiCitation::initialiseParams(string const & data)
 {
-       InsetCommand::string2params("citation", data, params_);
-       CiteEngine const engine = buffer().params().citeEngine();
+       InsetCommand::string2params(data, params_);
+       CiteEngine const engine = citeEngine();
        citeStyles_ = citeStyles(engine);
        init();
        return true;
@@ -637,11 +637,11 @@ void GuiCitation::clearParams()
 
 
 void GuiCitation::filterByEntryType(BiblioInfo const & bi,
-       vector<docstring> & keyVector, docstring entry_type) 
+       vector<docstring> & keyVector, docstring entry_type)
 {
        if (entry_type.empty())
                return;
-       
+
        vector<docstring>::iterator it = keyVector.begin();
        vector<docstring>::iterator end = keyVector.end();
 
@@ -660,7 +660,7 @@ void GuiCitation::filterByEntryType(BiblioInfo const & bi,
 
 CiteEngine GuiCitation::citeEngine() const
 {
-       return buffer().params().citeEngine();
+       return documentBuffer().params().citeEngine();
 }
 
 
@@ -673,9 +673,9 @@ static docstring escape_special_chars(docstring const & expr)
 {
        // Search for all chars '.|*?+(){}[^$]\'
        // Note that '[' and '\' must be escaped.
-       // This is a limitation of boost::regex, but all other chars in BREs
+       // This is a limitation of lyx::regex, but all other chars in BREs
        // are assumed literal.
-       static const boost::regex reg("[].|*?+(){}^$\\[\\\\]");
+       static const lyx::regex reg("[].|*?+(){}^$\\[\\\\]");
 
        // $& is a perl-like expression that expands to all
        // of the current match
@@ -683,11 +683,11 @@ static docstring escape_special_chars(docstring const & expr)
        // boost to treat it as a literal.
        // Thus, to prefix a matched expression with '\', we use:
        // FIXME: UNICODE
-       return from_utf8(boost::regex_replace(to_utf8(expr), reg, "\\\\$&"));
+       return from_utf8(lyx::regex_replace(to_utf8(expr), reg, string("\\\\$&")));
 }
 
 
-vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,       
+vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
        vector<docstring> const & keys_to_search, bool only_keys,
        docstring const & search_expression, docstring field,
        bool case_sensitive, bool regex)
@@ -700,15 +700,15 @@ vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
 
        if (!regex)
                // We must escape special chars in the search_expr so that
-               // it is treated as a simple string by boost::regex.
+               // it is treated as a simple string by lyx::regex.
                expr = escape_special_chars(expr);
 
-       boost::regex reg_exp;
+       lyx::regex reg_exp;
        try {
                reg_exp.assign(to_utf8(expr), case_sensitive ?
-                       boost::regex_constants::normal : boost::regex_constants::icase);
-       } catch (boost::regex_error & e) {
-               // boost::regex throws an exception if the regular expression is not
+                       lyx::regex_constants::ECMAScript : lyx::regex_constants::icase);
+       } catch (lyx::regex_error & e) {
+               // lyx::regex throws an exception if the regular expression is not
                // valid.
                LYXERR(Debug::GUI, e.what());
                return vector<docstring>();
@@ -720,24 +720,24 @@ vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
                BiblioInfo::const_iterator info = bi.find(*it);
                if (info == bi.end())
                        continue;
-               
+
                BibTeXInfo const & kvm = info->second;
                string data;
                if (only_keys)
                        data = to_utf8(*it);
                else if (field.empty())
                        data = to_utf8(*it) + ' ' + to_utf8(kvm.allData());
-               else 
+               else
                        data = to_utf8(kvm[field]);
-               
+
                if (data.empty())
                        continue;
 
                try {
-                       if (boost::regex_search(data, reg_exp))
+                       if (lyx::regex_search(data, reg_exp))
                                foundKeys.push_back(*it);
                }
-               catch (boost::regex_error & e) {
+               catch (lyx::regex_error & e) {
                        LYXERR(Debug::GUI, e.what());
                        return vector<docstring>();
                }
@@ -748,15 +748,16 @@ vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
 
 void GuiCitation::dispatchParams()
 {
-       std::string const lfun = InsetCommand::params2string("citation", params_);
+       std::string const lfun = InsetCommand::params2string(params_);
        dispatch(FuncRequest(getLfun(), lfun));
 }
 
 
 BiblioInfo const & GuiCitation::bibInfo() const
 {
-       buffer().checkBibInfoCache();
-       return buffer().masterBibInfo();
+       Buffer const & buf = documentBuffer();
+       buf.reloadBibInfoCache();
+       return buf.masterBibInfo();
 }