]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiCitation.cpp
Move Lexer to support/ directory (and lyx::support namespace)
[lyx.git] / src / frontends / qt / GuiCitation.cpp
index 951bad86129a1522d898424b1c02e0d1bb05fe8a..de39ce769871fe45d74a415126eeab076632c7e2 100644 (file)
@@ -7,7 +7,7 @@
  * \author Angus Leeming
  * \author Kalle Dalheimer
  * \author Abdelrazak Younes
- * \author Richard Heck
+ * \author Richard Kimberly Heck
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "GuiCitation.h"
 
+#include "FancyLineEdit.h"
 #include "GuiApplication.h"
 #include "GuiSelectionManager.h"
+#include "GuiView.h"
 #include "qt_helpers.h"
 
 #include "Buffer.h"
 #include "BufferView.h"
-#include "BiblioInfo.h"
 #include "BufferParams.h"
+#include "Citation.h"
+#include "Cursor.h"
 #include "TextClass.h"
 #include "FuncRequest.h"
 
 #include <QStandardItemModel>
 #include <QVariant>
 
-#include <vector>
-#include <string>
-
 #undef KeyPress
 
-#include "support/regex.h"
-
 #include <algorithm>
+#include <regex>
 #include <string>
 #include <vector>
 
@@ -99,10 +98,7 @@ GuiCitation::GuiCitation(GuiView & lv)
 
        // The filter bar
        filter_ = new FancyLineEdit(this);
-       filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
-       filter_->setButtonVisible(FancyLineEdit::Right, true);
-       filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
-       filter_->setAutoHideButton(FancyLineEdit::Right, true);
+       filter_->setClearButton(true);
        filter_->setPlaceholderText(qt_("All avail. citations"));
 
        filterBarL->addWidget(filter_, 0);
@@ -144,6 +140,8 @@ GuiCitation::GuiCitation(GuiView & lv)
                        addPB, deletePB, upPB, downPB, &available_model_, &selected_model_, 1);
        connect(selectionManager, SIGNAL(selectionChanged()),
                this, SLOT(setCitedKeys()));
+       connect(selectionManager, SIGNAL(updateHook()),
+               this, SLOT(setCitedKeys()));
        connect(selectionManager, SIGNAL(updateHook()),
                this, SLOT(updateControls()));
        connect(selectionManager, SIGNAL(okHook()),
@@ -155,13 +153,8 @@ GuiCitation::GuiCitation(GuiView & lv)
                this, SLOT(filterChanged(QString)));
        connect(filter_, SIGNAL(returnPressed()),
                this, SLOT(filterPressed()));
-#if (QT_VERSION < 0x050000)
-       connect(filter_, SIGNAL(downPressed()),
-               availableLV, SLOT(setFocus()));
-#else
        connect(filter_, &FancyLineEdit::downPressed,
-               availableLV, [=](){ focusAndHighlight(availableLV); });
-#endif
+               availableLV, [this](){ focusAndHighlight(availableLV); });
        connect(regexp_, SIGNAL(triggered()),
                this, SLOT(regexChanged()));
        connect(casesense_, SIGNAL(triggered()),
@@ -169,11 +162,7 @@ GuiCitation::GuiCitation(GuiView & lv)
        connect(instant_, SIGNAL(triggered(bool)),
                this, SLOT(instantChanged(bool)));
 
-#if (QT_VERSION < 0x050000)
-       selectedLV->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
-#else
        selectedLV->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
-#endif
 
        selectedLV->setToolTip(qt_("Ordered list of all cited references.\n"
                                   "You can reorder, add and remove references with the buttons on the left."));
@@ -199,6 +188,7 @@ void GuiCitation::applyView()
        QString const after = textAfterED->text();
 
        applyParams(choice, full, force, before, after);
+       connectToNewInset();
 }
 
 
@@ -836,6 +826,10 @@ void GuiCitation::init()
 
        buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
        buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+
+       // apply filter
+       if (!filter_->text().isEmpty())
+               findText(filter_->text(), true);
 }
 
 
@@ -959,7 +953,7 @@ void GuiCitation::clearParams()
 
 
 void GuiCitation::filterByEntryType(BiblioInfo const & bi,
-       vector<docstring> & keyVector, docstring entry_type)
+       vector<docstring> & keyVector, docstring const & entry_type)
 {
        if (entry_type.empty())
                return;
@@ -989,30 +983,21 @@ static docstring escape_special_chars(docstring const & expr)
 {
        // Search for all chars '.|*?+(){}[^$]\'
        // Note that '[', ']', and '\' must be escaped.
-       static const lyx::regex reg("[.|*?+(){}^$\\[\\]\\\\]");
+       static const regex reg("[.|*?+(){}^$\\[\\]\\\\]");
 
        // $& is an ECMAScript format expression that expands to all
        // of the current match
-#ifdef LYX_USE_STD_REGEX
        // To prefix a matched expression with a single literal backslash, we
        // need to escape it for the C++ compiler and use:
        // FIXME: UNICODE
-       return from_utf8(lyx::regex_replace(to_utf8(expr), reg, string("\\$&")));
-#else
-       // A backslash in the format string starts an escape sequence in boost.
-       // Thus, to prefix a matched expression with a single literal backslash,
-       // we need to give two backslashes to the regex engine, and escape both
-       // for the C++ compiler and use:
-       // FIXME: UNICODE
-       return from_utf8(lyx::regex_replace(to_utf8(expr), reg, string("\\\\$&")));
-#endif
+       return from_utf8(regex_replace(to_utf8(expr), reg, string("\\$&")));
 }
 
 
 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)
+       docstring const & search_expression, docstring const & field,
+       bool case_sensitive, bool re)
 {
        vector<docstring> foundKeys;
 
@@ -1020,17 +1005,17 @@ vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
        if (expr.empty())
                return foundKeys;
 
-       if (!regex)
+       if (!re)
                // We must escape special chars in the search_expr so that
-               // it is treated as a simple string by lyx::regex.
+               // it is treated as a simple string by regex.
                expr = escape_special_chars(expr);
 
-       lyx::regex reg_exp;
+       regex reg_exp;
        try {
                reg_exp.assign(to_utf8(expr), case_sensitive ?
-                       lyx::regex_constants::ECMAScript : lyx::regex_constants::icase);
-       } catch (lyx::regex_error const & e) {
-               // lyx::regex throws an exception if the regular expression is not
+                       regex_constants::ECMAScript : regex_constants::icase);
+       } catch (regex_error const & e) {
+               // regex throws an exception if the regular expression is not
                // valid.
                LYXERR(Debug::GUI, e.what());
                return vector<docstring>();
@@ -1056,10 +1041,10 @@ vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
                        continue;
 
                try {
-                       if (lyx::regex_search(sdata, reg_exp))
+                       if (regex_search(sdata, reg_exp))
                                foundKeys.push_back(*it);
                }
-               catch (lyx::regex_error const & e) {
+               catch (regex_error const & e) {
                        LYXERR(Debug::GUI, e.what());
                        return vector<docstring>();
                }
@@ -1113,9 +1098,6 @@ void GuiCitation::restoreSession()
 }
 
 
-Dialog * createGuiCitation(GuiView & lv) { return new GuiCitation(lv); }
-
-
 } // namespace frontend
 } // namespace lyx