+
+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)
+{
+ vector<docstring> foundKeys;
+
+ docstring expr = trim(search_expression);
+ if (expr.empty())
+ return foundKeys;
+
+ if (!regex)
+ // We must escape special chars in the search_expr so that
+ // it is treated as a simple string by boost::regex.
+ expr = escape_special_chars(expr);
+
+ boost::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
+ // valid.
+ LYXERR(Debug::GUI, e.what());
+ return vector<docstring>();
+ }
+
+ vector<docstring>::const_iterator it = keys_to_search.begin();
+ vector<docstring>::const_iterator end = keys_to_search.end();
+ for (; it != end; ++it ) {
+ 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
+ data = to_utf8(kvm[field]);
+
+ if (data.empty())
+ continue;
+
+ try {
+ if (boost::regex_search(data, reg_exp))
+ foundKeys.push_back(*it);
+ }
+ catch (boost::regex_error & e) {
+ LYXERR(Debug::GUI, e.what());
+ return vector<docstring>();
+ }
+ }
+ return foundKeys;
+}
+
+
+void GuiCitation::dispatchParams()
+{
+ std::string const lfun = InsetCommand::params2string("citation", params_);
+ dispatch(FuncRequest(getLfun(), lfun));
+}
+
+
+BiblioInfo const & GuiCitation::bibInfo() const
+{
+ buffer().checkBibInfoCache();
+ return buffer().masterBibInfo();
+}
+
+
+void GuiCitation::saveSession() const
+{
+ Dialog::saveSession();
+ QSettings settings;
+ settings.setValue(
+ sessionKey() + "/regex", regexCB->isChecked());
+ settings.setValue(
+ sessionKey() + "/casesensitive", caseCB->isChecked());
+ settings.setValue(
+ sessionKey() + "/autofind", asTypeCB->isChecked());
+}
+
+
+void GuiCitation::restoreSession()
+{
+ Dialog::restoreSession();
+ QSettings settings;
+ regexCB->setChecked(
+ settings.value(sessionKey() + "/regex").toBool());
+ caseCB->setChecked(
+ settings.value(sessionKey() + "/casesensitive").toBool());
+ asTypeCB->setChecked(
+ settings.value(sessionKey() + "/autofind").toBool());
+}
+
+
+Dialog * createGuiCitation(GuiView & lv) { return new GuiCitation(lv); }
+
+