]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCitation.cpp
Show names of debug modes in the debug panel
[lyx.git] / src / frontends / qt4 / GuiCitation.cpp
1
2 /**
3  * \file GuiCitation.cpp
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  * \author Kalle Dalheimer
9  * \author Abdelrazak Younes
10  * \author Richard Heck
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #include <config.h>
16
17 #include "GuiCitation.h"
18
19 #include "GuiSelectionManager.h"
20 #include "LyXToolBox.h"
21 #include "qt_helpers.h"
22
23 #include "Buffer.h"
24 #include "BufferView.h"
25 #include "BiblioInfo.h"
26 #include "BufferParams.h"
27 #include "FuncRequest.h"
28
29 #include "insets/InsetCommand.h"
30
31 #include "support/debug.h"
32 #include "support/docstring.h"
33 #include "support/gettext.h"
34 #include "support/lstrings.h"
35
36 #include <QCloseEvent>
37 #include <QSettings>
38 #include <QShowEvent>
39 #include <QVariant>
40
41 #include <vector>
42 #include <string>
43
44 #undef KeyPress
45
46 #include "support/regex.h"
47
48 #include <algorithm>
49 #include <string>
50 #include <vector>
51
52 using namespace std;
53 using namespace lyx::support;
54
55 namespace lyx {
56 namespace frontend {
57
58 // FIXME THREAD
59 // I am guessing that it would not hurt to make these private members.
60 static vector<string> citeCmds_;
61 static vector<CitationStyle> citeStyles_;
62
63
64 template<typename String>
65 static QStringList to_qstring_list(vector<String> const & v)
66 {
67         QStringList qlist;
68
69         for (size_t i = 0; i != v.size(); ++i) {
70                 if (v[i].empty())
71                         continue;
72                 qlist.append(lyx::toqstr(v[i]));
73         }
74         return qlist;
75 }
76
77
78 static vector<lyx::docstring> to_docstring_vector(QStringList const & qlist)
79 {
80         vector<lyx::docstring> v;
81         for (int i = 0; i != qlist.size(); ++i) {
82                 if (qlist[i].isEmpty())
83                         continue;
84                 v.push_back(lyx::qstring_to_ucs4(qlist[i]));
85         }
86         return v;
87 }
88
89
90 GuiCitation::GuiCitation(GuiView & lv)
91         : DialogView(lv, "citation", qt_("Citation")),
92           params_(insetCode("citation"))
93 {
94         setupUi(this);
95
96         connect(citationStyleCO, SIGNAL(activated(int)),
97                 this, SLOT(on_citationStyleCO_currentIndexChanged(int)));
98         connect(fulllistCB, SIGNAL(clicked()),
99                 this, SLOT(changed()));
100         connect(forceuppercaseCB, SIGNAL(clicked()),
101                 this, SLOT(changed()));
102         connect(textBeforeED, SIGNAL(textChanged(QString)),
103                 this, SLOT(updateStyles()));
104         connect(textAfterED, SIGNAL(textChanged(QString)),
105                 this, SLOT(updateStyles()));
106         connect(findLE, SIGNAL(returnPressed()),
107                 this, SLOT(on_searchPB_clicked()));
108         connect(textBeforeED, SIGNAL(returnPressed()),
109                 this, SLOT(on_okPB_clicked()));
110         connect(textAfterED, SIGNAL(returnPressed()),
111                 this, SLOT(on_okPB_clicked()));
112
113         selectionManager = new GuiSelectionManager(availableLV, selectedLV,
114                         addPB, deletePB, upPB, downPB, &available_model_, &selected_model_);
115         connect(selectionManager, SIGNAL(selectionChanged()),
116                 this, SLOT(setCitedKeys()));
117         connect(selectionManager, SIGNAL(updateHook()),
118                 this, SLOT(updateControls()));
119         connect(selectionManager, SIGNAL(okHook()),
120                 this, SLOT(on_okPB_clicked()));
121
122         setFocusProxy(availableLV);
123 }
124
125
126 GuiCitation::~GuiCitation()
127 {
128         delete selectionManager;
129 }
130
131
132 void GuiCitation::closeEvent(QCloseEvent * e)
133 {
134         clearSelection();
135         DialogView::closeEvent(e);
136 }
137
138
139 void GuiCitation::applyView()
140 {
141         int const choice = max(0, citationStyleCO->currentIndex());
142         style_ = choice;
143         bool const full  = fulllistCB->isChecked();
144         bool const force = forceuppercaseCB->isChecked();
145
146         QString const before = textBeforeED->text();
147         QString const after = textAfterED->text();
148
149         applyParams(choice, full, force, before, after);
150 }
151
152
153 void GuiCitation::showEvent(QShowEvent * e)
154 {
155         findLE->clear();
156         availableLV->setFocus();
157
158         // Set the minimal size of the QToolbox. Without this, the size of the
159         // QToolbox is only determined by values in the ui file (e.g. computed by
160         // qtcreator) and therefore causes portability and localisation issues. Note
161         // that the page widgets must have a layout with layoutSizeContraint =
162         // SetMinimumSize or similar.  KNOWN ISSUE: the calculations are incorrect
163         // the first time the dialog is shown. This problem is mitigated by the fact
164         // that LyX remembers the dialog sizes between sessions.
165         QSize minimum_size = QSize(0,0);
166         // Compute the max of the minimal sizes of the pages
167         QWidget * page;
168         for (int i = 0; (page = citationTB->widget(i)); ++i)
169                 minimum_size = minimum_size.expandedTo(page->minimumSizeHint());
170         // Add the height of the tabs
171         if (citationTB->currentWidget())
172                 minimum_size.rheight() += citationTB->height() -
173                         citationTB->currentWidget()->height();
174         citationTB->setMinimumSize(minimum_size);
175
176         DialogView::showEvent(e);
177 }
178
179
180 void GuiCitation::on_citationTB_currentChanged(int i)
181 {
182         if (i == 0)
183                 findLE->setFocus();
184         else if (citationStyleCO->isEnabled())
185                 citationStyleCO->setFocus();
186         else
187                 textAfterED->setFocus();
188 }
189
190
191 void GuiCitation::on_okPB_clicked()
192 {
193         applyView();
194         clearSelection();
195         hide();
196 }
197
198
199 void GuiCitation::on_cancelPB_clicked()
200 {
201         clearSelection();
202         hide();
203 }
204
205
206 void GuiCitation::on_applyPB_clicked()
207 {
208         applyView();
209 }
210
211
212 void GuiCitation::on_restorePB_clicked()
213 {
214         init();
215 }
216
217
218 void GuiCitation::updateControls()
219 {
220         BiblioInfo const & bi = bibInfo();
221         updateControls(bi);
222 }
223
224
225 // The main point of separating this out is that the fill*() methods
226 // called in update() do not need to be called for INTERNAL updates,
227 // such as when addPB is pressed, as the list of fields, entries, etc,
228 // will not have changed.
229 void GuiCitation::updateControls(BiblioInfo const & bi)
230 {
231         QModelIndex idx = selectionManager->getSelectedIndex();
232         updateInfo(bi, idx);
233         selectionManager->update();
234 }
235
236
237 void GuiCitation::updateFormatting(CitationStyle currentStyle)
238 {
239         bool const force = currentStyle.forceUpperCase;
240         bool const full = currentStyle.fullAuthorList &&
241                 documentBuffer().params().fullAuthorList();
242         bool const textbefore = currentStyle.textBefore;
243         bool const textafter = currentStyle.textAfter;
244
245         bool const haveSelection =
246                 selectedLV->model()->rowCount() > 0;
247
248         forceuppercaseCB->setEnabled(force && haveSelection);
249         fulllistCB->setEnabled(full && haveSelection);
250         textBeforeED->setEnabled(textbefore && haveSelection);
251         textBeforeLA->setEnabled(textbefore && haveSelection);
252         textAfterED->setEnabled(textafter && haveSelection);
253         textAfterLA->setEnabled(textafter && haveSelection);
254         citationStyleCO->setEnabled(haveSelection);
255         citationStyleLA->setEnabled(haveSelection);
256 }
257
258
259 // Update the styles for the style combo, citationStyleCO, and mark the
260 // settings as changed. Called upon changing the cited keys (including
261 // merely reordering the keys) or editing the text before/after fields.
262 void GuiCitation::updateStyles()
263 {
264         BiblioInfo const & bi = bibInfo();
265         updateStyles(bi);
266         changed();
267 }
268
269
270 // Update the styles for the style combo, citationStyleCO.
271 void GuiCitation::updateStyles(BiblioInfo const & bi)
272 {
273         QStringList selected_keys = selected_model_.stringList();
274         int curr = selectedLV->model()->rowCount() - 1;
275
276         if (curr < 0 || selected_keys.empty()) {
277                 citationStyleCO->clear();
278                 citationStyleCO->setEnabled(false);
279                 citationStyleLA->setEnabled(false);
280                 return;
281         }
282
283         static const size_t max_length = 80;
284         QStringList sty = citationStyles(bi, max_length);
285
286         if (sty.isEmpty()) {
287                 // some error
288                 citationStyleCO->setEnabled(false);
289                 citationStyleLA->setEnabled(false);
290                 citationStyleCO->clear();
291                 return;
292         }
293
294         citationStyleCO->blockSignals(true);
295
296         // save old index
297         int const oldIndex = citationStyleCO->currentIndex();
298         citationStyleCO->clear();
299         citationStyleCO->insertItems(0, sty);
300         citationStyleCO->setEnabled(true);
301         citationStyleLA->setEnabled(true);
302         // restore old index
303         if (oldIndex != -1 && oldIndex < citationStyleCO->count())
304                 citationStyleCO->setCurrentIndex(oldIndex);
305
306         citationStyleCO->blockSignals(false);
307 }
308
309
310 void GuiCitation::fillFields(BiblioInfo const & bi)
311 {
312         fieldsCO->blockSignals(true);
313         int const oldIndex = fieldsCO->currentIndex();
314         fieldsCO->clear();
315         QStringList const fields = to_qstring_list(bi.getFields());
316         fieldsCO->insertItem(0, qt_("All fields"));
317         fieldsCO->insertItem(1, qt_("Keys"));
318         fieldsCO->insertItems(2, fields);
319         if (oldIndex != -1 && oldIndex < fieldsCO->count())
320                 fieldsCO->setCurrentIndex(oldIndex);
321         fieldsCO->blockSignals(false);
322 }
323
324
325 void GuiCitation::fillEntries(BiblioInfo const & bi)
326 {
327         entriesCO->blockSignals(true);
328         int const oldIndex = entriesCO->currentIndex();
329         entriesCO->clear();
330         QStringList const entries = to_qstring_list(bi.getEntries());
331         entriesCO->insertItem(0, qt_("All entry types"));
332         entriesCO->insertItems(1, entries);
333         if (oldIndex != -1 && oldIndex < entriesCO->count())
334                 entriesCO->setCurrentIndex(oldIndex);
335         entriesCO->blockSignals(false);
336 }
337
338
339 bool GuiCitation::isSelected(QModelIndex const & idx)
340 {
341         QString const str = idx.data().toString();
342         return selected_model_.stringList().contains(str);
343 }
344
345
346 void GuiCitation::setButtons()
347 {
348         int const srows = selectedLV->model()->rowCount();
349         applyPB->setEnabled(srows > 0);
350         okPB->setEnabled(srows > 0);
351 }
352
353
354 void GuiCitation::updateInfo(BiblioInfo const & bi, QModelIndex const & idx)
355 {
356         if (!idx.isValid() || bi.empty()) {
357                 infoML->document()->clear();
358                 return;
359         }
360
361         QString const keytxt = toqstr(
362                 bi.getInfo(qstring_to_ucs4(idx.data().toString()), documentBuffer(), true));
363         infoML->document()->setHtml(keytxt);
364 }
365
366
367 void GuiCitation::findText(QString const & text, bool reset)
368 {
369         //"All Fields" and "Keys" are the first two
370         int index = fieldsCO->currentIndex() - 2;
371         BiblioInfo const & bi = bibInfo();
372         vector<docstring> const & fields = bi.getFields();
373         docstring field;
374
375         if (index <= -1 || index >= int(fields.size()))
376                 //either "All Fields" or "Keys" or an invalid value
377                 field = from_ascii("");
378         else
379                 field = fields[index];
380
381         //Was it "Keys"?
382         bool const onlyKeys = index == -1;
383
384         //"All Entry Types" is first.
385         index = entriesCO->currentIndex() - 1;
386         vector<docstring> const & entries = bi.getEntries();
387         docstring entry_type;
388         if (index < 0 || index >= int(entries.size()))
389                 entry_type = from_ascii("");
390         else
391                 entry_type = entries[index];
392
393         bool const case_sentitive = caseCB->checkState();
394         bool const reg_exp = regexCB->checkState();
395         findKey(bi, text, onlyKeys, field, entry_type,
396                        case_sentitive, reg_exp, reset);
397         //FIXME
398         //It'd be nice to save and restore the current selection in
399         //availableLV. Currently, we get an automatic reset, since the
400         //model is reset.
401
402         updateControls(bi);
403 }
404
405
406 void GuiCitation::on_fieldsCO_currentIndexChanged(int /*index*/)
407 {
408         findText(findLE->text(), true);
409 }
410
411
412 void GuiCitation::on_entriesCO_currentIndexChanged(int /*index*/)
413 {
414         findText(findLE->text(), true);
415 }
416
417
418 void GuiCitation::on_citationStyleCO_currentIndexChanged(int index)
419 {
420         if (index >= 0 && index < citationStyleCO->count()) {
421                 vector<CitationStyle> const & styles = citeStyles_;
422                 updateFormatting(styles[index]);
423                 changed();
424         }
425 }
426
427
428 void GuiCitation::on_findLE_textChanged(const QString & text)
429 {
430         bool const searchAsWeGo = (asTypeCB->checkState() == Qt::Checked);
431         searchPB->setDisabled(text.isEmpty() || searchAsWeGo);
432         if (!text.isEmpty()) {
433                 if (searchAsWeGo)
434                         findText(findLE->text());
435                 return;
436         }
437         findText(findLE->text());
438         findLE->setFocus();
439 }
440
441 void GuiCitation::on_searchPB_clicked()
442 {
443         findText(findLE->text(), true);
444 }
445
446
447 void GuiCitation::on_caseCB_stateChanged(int)
448 {
449         findText(findLE->text());
450 }
451
452
453 void GuiCitation::on_regexCB_stateChanged(int)
454 {
455         findText(findLE->text());
456 }
457
458
459 void GuiCitation::on_asTypeCB_stateChanged(int)
460 {
461         bool const searchAsWeGo = (asTypeCB->checkState() == Qt::Checked);
462         searchPB->setDisabled(findLE->text().isEmpty() || searchAsWeGo);
463         if (searchAsWeGo)
464                 findText(findLE->text(), true);
465 }
466
467
468 void GuiCitation::changed()
469 {
470         setButtons();
471 }
472
473
474 void GuiCitation::applyParams(int const choice, bool full, bool force,
475         QString before, QString after)
476 {
477         if (cited_keys_.isEmpty())
478                 return;
479
480         vector<CitationStyle> const & styles = citeStyles_;
481
482         CitationStyle cs = styles[choice];
483
484         if (!cs.textBefore)
485                 before.clear();
486         if (!cs.textAfter)
487                 after.clear();
488
489         cs.forceUpperCase &= force;
490         cs.fullAuthorList &= full;
491         string const command = citationStyleToString(cs);
492
493         params_.setCmdName(command);
494         params_["key"] = qstring_to_ucs4(cited_keys_.join(","));
495         params_["before"] = qstring_to_ucs4(before);
496         params_["after"] = qstring_to_ucs4(after);
497         dispatchParams();
498 }
499
500
501 void GuiCitation::clearSelection()
502 {
503         cited_keys_.clear();
504         selected_model_.setStringList(cited_keys_);
505 }
506
507
508 void GuiCitation::init()
509 {
510         // Make the list of all available bibliography keys
511         BiblioInfo const & bi = bibInfo();
512         all_keys_ = to_qstring_list(bi.getKeys());
513         available_model_.setStringList(all_keys_);
514
515         // Ditto for the keys cited in this inset
516         QString str = toqstr(params_["key"]);
517         if (str.isEmpty())
518                 cited_keys_.clear();
519         else
520                 cited_keys_ = str.split(",");
521         selected_model_.setStringList(cited_keys_);
522
523         // Initialize the drop downs
524         fillEntries(bi);
525         fillFields(bi);
526
527         // Initialize the citation formatting
528         string const & cmd = params_.getCmdName();
529         CitationStyle const cs = citationStyleFromString(cmd);
530         forceuppercaseCB->setChecked(cs.forceUpperCase);
531         fulllistCB->setChecked(cs.fullAuthorList &&
532                 documentBuffer().params().fullAuthorList());
533         textBeforeED->setText(toqstr(params_["before"]));
534         textAfterED->setText(toqstr(params_["after"]));
535
536         // Update the interface
537         updateControls(bi);
538         updateStyles(bi);
539         if (selected_model_.rowCount()) {
540                 selectedLV->blockSignals(true);
541                 selectedLV->setFocus();
542                 QModelIndex idx = selected_model_.index(0, 0);
543                 selectedLV->selectionModel()->select(idx,
544                                 QItemSelectionModel::ClearAndSelect);
545                 selectedLV->blockSignals(false);
546
547                 // Find the citation style
548                 vector<string> const & cmds = citeCmds_;
549                 vector<string>::const_iterator cit =
550                         std::find(cmds.begin(), cmds.end(), cs.cmd);
551                 int i = 0;
552                 if (cit != cmds.end())
553                         i = int(cit - cmds.begin());
554
555                 // Set the style combo appropriately
556                 citationStyleCO->blockSignals(true);
557                 citationStyleCO->setCurrentIndex(i);
558                 citationStyleCO->blockSignals(false);
559                 updateFormatting(citeStyles_[i]);
560         } else
561                 availableLV->setFocus();
562
563         applyPB->setEnabled(false);
564         okPB->setEnabled(false);
565 }
566
567
568 void GuiCitation::findKey(BiblioInfo const & bi,
569         QString const & str, bool only_keys,
570         docstring field, docstring entry_type,
571         bool case_sensitive, bool reg_exp, bool reset)
572 {
573         // FIXME THREAD
574         // Used for optimisation: store last searched string.
575         static QString last_searched_string;
576         // Used to disable the above optimisation.
577         static bool last_case_sensitive;
578         static bool last_reg_exp;
579         // Reset last_searched_string in case of changed option.
580         if (last_case_sensitive != case_sensitive
581                 || last_reg_exp != reg_exp) {
582                         LYXERR(Debug::GUI, "GuiCitation::findKey: optimisation disabled!");
583                 last_searched_string.clear();
584         }
585         // save option for next search.
586         last_case_sensitive = case_sensitive;
587         last_reg_exp = reg_exp;
588
589         Qt::CaseSensitivity qtcase = case_sensitive ?
590                         Qt::CaseSensitive: Qt::CaseInsensitive;
591         QStringList keys;
592         // If new string (str) contains the last searched one...
593         if (!reset &&
594                 !last_searched_string.isEmpty() &&
595                 str.size() > 1 &&
596                 str.contains(last_searched_string, qtcase))
597                 // ... then only search within already found list.
598                 keys = available_model_.stringList();
599         else
600                 // ... else search all keys.
601                 keys = all_keys_;
602         // save searched string for next search.
603         last_searched_string = str;
604
605         QStringList result;
606
607         // First, filter by entry_type, which will be faster than
608         // what follows, so we may get to do that on less.
609         vector<docstring> keyVector = to_docstring_vector(keys);
610         filterByEntryType(bi, keyVector, entry_type);
611
612         if (str.isEmpty())
613                 result = to_qstring_list(keyVector);
614         else
615                 result = to_qstring_list(searchKeys(bi, keyVector, only_keys,
616                         qstring_to_ucs4(str), field, case_sensitive, reg_exp));
617
618         available_model_.setStringList(result);
619 }
620
621
622 QStringList GuiCitation::citationStyles(BiblioInfo const & bi, size_t max_size)
623 {
624         docstring const before = qstring_to_ucs4(textBeforeED->text());
625         docstring const after = qstring_to_ucs4(textAfterED->text());
626         vector<docstring> const keys = to_docstring_vector(cited_keys_);
627         vector<CitationStyle> styles = citeStyles_;
628         // FIXME: pass a dictionary instead of individual before, after, dialog, etc.
629         vector<docstring> ret = bi.getCiteStrings(keys, styles, documentBuffer(),
630                 before, after, from_utf8("dialog"), max_size);
631         return to_qstring_list(ret);
632 }
633
634
635 void GuiCitation::setCitedKeys()
636 {
637         cited_keys_ = selected_model_.stringList();
638         updateStyles();
639 }
640
641
642 bool GuiCitation::initialiseParams(string const & data)
643 {
644         InsetCommand::string2params(data, params_);
645         citeCmds_ = documentBuffer().params().citeCommands();
646         citeStyles_ = documentBuffer().params().citeStyles();
647         init();
648         return true;
649 }
650
651
652 void GuiCitation::clearParams()
653 {
654         params_.clear();
655 }
656
657
658 void GuiCitation::filterByEntryType(BiblioInfo const & bi,
659         vector<docstring> & keyVector, docstring entry_type)
660 {
661         if (entry_type.empty())
662                 return;
663
664         vector<docstring>::iterator it = keyVector.begin();
665         vector<docstring>::iterator end = keyVector.end();
666
667         vector<docstring> result;
668         for (; it != end; ++it) {
669                 docstring const key = *it;
670                 BiblioInfo::const_iterator cit = bi.find(key);
671                 if (cit == bi.end())
672                         continue;
673                 if (cit->second.entryType() == entry_type)
674                         result.push_back(key);
675         }
676         keyVector = result;
677 }
678
679
680 // Escape special chars.
681 // All characters are literals except: '.|*?+(){}[]^$\'
682 // These characters are literals when preceded by a "\", which is done here
683 // @todo: This function should be moved to support, and then the test in tests
684 //        should be moved there as well.
685 static docstring escape_special_chars(docstring const & expr)
686 {
687         // Search for all chars '.|*?+(){}[^$]\'
688         // Note that '[', ']', and '\' must be escaped.
689         static const lyx::regex reg("[.|*?+(){}^$\\[\\]\\\\]");
690
691         // $& is an ECMAScript format expression that expands to all
692         // of the current match
693 #if defined(LYX_USE_CXX11) && defined(LYX_USE_STD_REGEX)
694         // To prefix a matched expression with a single literal backslash, we
695         // need to escape it for the C++ compiler and use:
696         // FIXME: UNICODE
697         return from_utf8(lyx::regex_replace(to_utf8(expr), reg, string("\\$&")));
698 #else
699         // A backslash in the format string starts an escape sequence in boost.
700         // Thus, to prefix a matched expression with a single literal backslash,
701         // we need to give two backslashes to the regex engine, and escape both
702         // for the C++ compiler and use:
703         // FIXME: UNICODE
704         return from_utf8(lyx::regex_replace(to_utf8(expr), reg, string("\\\\$&")));
705 #endif
706 }
707
708
709 vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
710         vector<docstring> const & keys_to_search, bool only_keys,
711         docstring const & search_expression, docstring field,
712         bool case_sensitive, bool regex)
713 {
714         vector<docstring> foundKeys;
715
716         docstring expr = trim(search_expression);
717         if (expr.empty())
718                 return foundKeys;
719
720         if (!regex)
721                 // We must escape special chars in the search_expr so that
722                 // it is treated as a simple string by lyx::regex.
723                 expr = escape_special_chars(expr);
724
725         lyx::regex reg_exp;
726         try {
727                 reg_exp.assign(to_utf8(expr), case_sensitive ?
728                         lyx::regex_constants::ECMAScript : lyx::regex_constants::icase);
729         } catch (lyx::regex_error const & e) {
730                 // lyx::regex throws an exception if the regular expression is not
731                 // valid.
732                 LYXERR(Debug::GUI, e.what());
733                 return vector<docstring>();
734         }
735
736         vector<docstring>::const_iterator it = keys_to_search.begin();
737         vector<docstring>::const_iterator end = keys_to_search.end();
738         for (; it != end; ++it ) {
739                 BiblioInfo::const_iterator info = bi.find(*it);
740                 if (info == bi.end())
741                         continue;
742
743                 BibTeXInfo const & kvm = info->second;
744                 string data;
745                 if (only_keys)
746                         data = to_utf8(*it);
747                 else if (field.empty())
748                         data = to_utf8(*it) + ' ' + to_utf8(kvm.allData());
749                 else
750                         data = to_utf8(kvm[field]);
751
752                 if (data.empty())
753                         continue;
754
755                 try {
756                         if (lyx::regex_search(data, reg_exp))
757                                 foundKeys.push_back(*it);
758                 }
759                 catch (lyx::regex_error const & e) {
760                         LYXERR(Debug::GUI, e.what());
761                         return vector<docstring>();
762                 }
763         }
764         return foundKeys;
765 }
766
767
768 void GuiCitation::dispatchParams()
769 {
770         std::string const lfun = InsetCommand::params2string(params_);
771         dispatch(FuncRequest(getLfun(), lfun));
772 }
773
774
775 BiblioInfo const & GuiCitation::bibInfo() const
776 {
777         Buffer const & buf = documentBuffer();
778         buf.reloadBibInfoCache();
779         return buf.masterBibInfo();
780 }
781
782
783 void GuiCitation::saveSession() const
784 {
785         Dialog::saveSession();
786         QSettings settings;
787         settings.setValue(
788                 sessionKey() + "/regex", regexCB->isChecked());
789         settings.setValue(
790                 sessionKey() + "/casesensitive", caseCB->isChecked());
791         settings.setValue(
792                 sessionKey() + "/autofind", asTypeCB->isChecked());
793 }
794
795
796 void GuiCitation::restoreSession()
797 {
798         Dialog::restoreSession();
799         QSettings settings;
800         regexCB->setChecked(
801                 settings.value(sessionKey() + "/regex").toBool());
802         caseCB->setChecked(
803                 settings.value(sessionKey() + "/casesensitive").toBool());
804         asTypeCB->setChecked(
805                 settings.value(sessionKey() + "/autofind").toBool());
806 }
807
808
809 Dialog * createGuiCitation(GuiView & lv) { return new GuiCitation(lv); }
810
811
812 } // namespace frontend
813 } // namespace lyx
814
815 #include "moc_GuiCitation.cpp"
816