4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
8 * \author Kalle Dalheimer
9 * \author Abdelrazak Younes
10 * \author Richard Heck
12 * Full author contact details are available in file CREDITS.
18 #include "DialogView.h"
19 #include "ui_CitationUi.h"
20 #include "FancyLineEdit.h"
22 #include "insets/InsetCommandParams.h"
24 #include "BiblioInfo.h"
27 #include <QAbstractListModel>
28 #include <QStandardItemModel>
29 #include <QStringList>
30 #include <QStringListModel>
36 class GuiSelectionManager;
39 class GuiCitation : public DialogView, public Ui::CitationUi
45 GuiCitation(GuiView & lv);
48 void on_buttonBox_accepted();
49 void on_buttonBox_rejected();
50 void on_buttonBox_clicked(QAbstractButton *);
51 void on_literalCB_clicked();
53 void filterChanged(const QString & text);
54 void on_fieldsCO_currentIndexChanged(int index);
55 void on_entriesCO_currentIndexChanged(int index);
56 void on_citationStyleCO_currentIndexChanged(int index);
60 void instantChanged(bool checked);
62 /// set the citation keys, mark as changed
64 /// update the styles for the style combo, mark as changed
66 /// performs a limited update, suitable for internal call
67 void updateControls();
71 /// Dialog inherited methods
73 void applyView() override;
74 void updateView() override {}
75 bool initialiseParams(std::string const & data) override;
76 void clearParams() override;
77 void dispatchParams() override;
78 bool isBufferDependent() const override { return true; }
79 void saveSession(QSettings & settings) const override;
80 void restoreSession() override;
81 /** Disconnect from the inset when the Apply button is pressed.
82 * Allows easy insertion of multiple citations.
84 bool disconnectOnApply() const override { return true; }
88 void showEvent(QShowEvent * e) override;
90 void closeEvent(QCloseEvent * e) override;
91 /// prepares a call to GuiCitation::searchKeys when we
92 /// are ready to search the BibTeX entries
93 void findText(QString const & text, bool reset = false);
94 /// check whether key is already selected
95 bool isSelected(const QModelIndex &);
96 /// update the display of BibTeX information
97 void updateInfo(BiblioInfo const & bi, QModelIndex const &);
98 /// enable/disable buttons
100 /// fill the fields combo
101 void fillFields(BiblioInfo const & bi);
102 /// fill the entries combo
103 void fillEntries(BiblioInfo const & bi);
104 /// set the styles combo
105 void updateStyles(BiblioInfo const & bi);
106 /// set the formatting widgets
107 void updateFormatting(CitationStyle const & currentStyle);
109 void updateControls(BiblioInfo const & bi);
110 /// Set the appropriate hinting text on the filter bar
111 void updateFilterHint();
114 /// Clear selected keys
115 void clearSelection();
117 /// Set selected keys
118 void setSelectedKeys(QStringList const &);
119 /// Get selected keys
120 QStringList selectedKeys();
121 /// Set pre texts of qualified lists
122 void setPreTexts(std::vector<docstring> const & m);
123 /// Get pre texts of qualified lists
124 std::vector<docstring> getPreTexts();
125 /// Set post texts of qualified lists
126 void setPostTexts(std::vector<docstring> const & m);
127 /// Get post texts of qualified lists
128 std::vector<docstring> getPostTexts();
130 /// Find keys containing a string.
132 BiblioInfo const & bi, //< optimize by passing this
133 QString const & str, //< string expression
134 bool only_keys, //< set to true if only keys shall be searched.
135 docstring field, //<field to search, empty for all fields
136 docstring entryType, //<entry type to display, empty for all
137 bool case_sensitive, //< set to true for case sensitive search.
138 bool reg_exp, //< set to true if \c str is a regular expression.
139 bool reset = false //< whether to reset and search all keys
142 /// List of example cite strings and their correlating lyx name
143 BiblioInfo::CiteStringMap citationStyles(BiblioInfo const & bi,
146 /// Set the Params variable for the Controller.
147 void applyParams(int const choice, bool const full, bool const force,
148 QString before, QString after);
151 void filterByEntryType(BiblioInfo const & bi,
152 std::vector<docstring> & keyVector, docstring entryType);
154 /// Search a given string within the passed keys.
155 /// \return the vector of matched keys.
156 std::vector<docstring> searchKeys(
157 BiblioInfo const & bi, //< optimize by passing this
158 std::vector<docstring> const & keys_to_search, //< Keys to search.
159 bool only_keys, //< whether to search only the keys
160 docstring const & search_expression, //< Search expression (regex possible)
161 docstring field, //< field to search, empty for all fields
162 bool case_sensitive = false, //< set to true is the search should be case sensitive
163 bool regex = false //< \set to true if \c search_expression is a regex
166 /// The BibTeX information available to the dialog
167 /// Calls to this method will lead to checks of modification times and
168 /// the like, so it should be avoided.
169 BiblioInfo const & bibInfo() const;
171 /// contains the search box
172 FancyLineEdit * filter_;
176 /// Case sensitive action
177 QAction * casesense_;
178 /// Search as you type action
181 /// last used citation style
183 /// this is the last style chosen in the current dialog
184 QString last_chosen_style_;
186 GuiSelectionManager * selectionManager;
188 QStringListModel available_model_;
190 QStandardItemModel selected_model_;
192 QStringList all_keys_;
194 QStringList cited_keys_;
196 InsetCommandParams params_;
199 } // namespace frontend
202 #endif // GUICITATION_H