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