]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCitation.h
basic context menu for InsetExternal.
[lyx.git] / src / frontends / qt4 / GuiCitation.h
1 // -*- C++ -*-
2 /**
3  * \file GuiCitation.h
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 #ifndef GUICITATION_H
16 #define GUICITATION_H
17
18 #include "GuiDialog.h"
19 #include "GuiSelectionManager.h"
20 #include "ui_CitationUi.h"
21
22 #include "BiblioInfo.h"
23 #include "Citation.h"
24
25 #include "insets/InsetCommandParams.h"
26
27 #include <QStringList>
28 #include <QStringListModel>
29
30 namespace lyx {
31 namespace frontend {
32
33 class GuiCitation : public GuiDialog, public Ui::CitationUi
34 {
35         Q_OBJECT
36
37 public:
38         ///
39         GuiCitation(GuiView & lv);
40
41         ///
42         void applyView();
43
44 public Q_SLOTS:
45         /// Update the display of the dialog whilst it is still visible.
46         void updateView();
47
48 private:
49         ///
50         void showEvent(QShowEvent * e);
51         ///
52         void closeEvent(QCloseEvent * e);
53         /// prepares a call to GuiCitation::searchKeys when we
54         /// are ready to search the BibTeX entries
55         void findText(QString const & text, bool reset = false);
56         /// check whether key is already selected
57         bool isSelected(const QModelIndex &);
58         /// update the display of BibTeX information
59         void updateInfo(QModelIndex const &);
60
61 private Q_SLOTS:
62         void cleanUp();
63         void on_okPB_clicked();
64         void on_cancelPB_clicked();
65         void on_restorePB_clicked();
66         void on_applyPB_clicked();
67         void on_searchPB_clicked();
68         void on_findLE_textChanged(const QString & text);
69         void on_fieldsCO_currentIndexChanged(int index);
70         void on_entriesCO_currentIndexChanged(int index);
71         void on_citationStyleCO_currentIndexChanged(int index);
72         void on_caseCB_stateChanged(int);
73         void on_regexCB_stateChanged(int);
74         void on_asTypeCB_stateChanged(int);
75         void changed();
76         ///
77         void setCitedKeys();
78         /// performs a limited update, suitable for internal call
79         void updateDialog();
80         
81 private:
82         /// enable/disable buttons
83         void setButtons();
84         /// fill the styles combo
85         void fillStyles();
86         /// fill the fields combo
87         void fillFields();
88         /// fill the entries combo
89         void fillEntries();
90         /// set the styles combo
91         void updateStyle();
92         /// set the formatting widgets
93         void updateFormatting(CiteStyle currentStyle);
94         /// last used citation style
95         int style_;
96         
97         GuiSelectionManager * selectionManager;
98
99         ///
100         void init();
101         /// Available keys
102         QStringListModel * available() { return &available_model_; }
103         /// Selected keys
104         QStringListModel * selected() { return &selected_model_; }
105         /// Text before cite
106         QString textBefore();
107         /// Text after cite
108         QString textAfter();
109         /// Get key description
110         QString getKeyInfo(QString const &);
111         /// Clear selected keys
112         void clearSelection();
113         /// Return a list of available fields 
114         QStringList getFieldsAsQStringList();
115         /// Return a list of available fields 
116         QStringList getEntriesAsQStringList();
117         
118         /// Find keys containing a string.
119         void findKey(
120                 QString const & str, //< string expression
121                 bool only_keys, //< set to true if only keys shall be searched.
122                 docstring field, //<field to search, empty for all fields
123                 docstring entryType, //<entry type to display, empty for all
124                 bool case_sensitive, //< set to true for case sensitive search.
125                 bool reg_exp, //< set to true if \c str is a regular expression.
126                 bool reset = false //< whether to reset and search all keys
127                 );
128
129         /// List of example cite strings
130         QStringList citationStyles(int);
131
132         /// Set the Params variable for the Controller.
133         void apply(int const choice, bool const full, bool const force,
134                                           QString before, QString after);
135         ///
136         bool initialiseParams(std::string const & data);
137         /// clean-up on hide.
138         void clearParams();
139         /// clean-up on hide.
140         void dispatchParams();
141         ///
142         bool isBufferDependent() const { return true; }
143
144 private:
145         /// available keys.
146         QStringListModel available_model_;
147         /// selected keys.
148         QStringListModel selected_model_;
149         /// All keys.
150         QStringList all_keys_;
151         /// Cited keys.
152         QStringList cited_keys_;
153         ///
154         InsetCommandParams params_;
155
156         /** Disconnect from the inset when the Apply button is pressed.
157          *  Allows easy insertion of multiple citations.
158          */
159         bool disconnectOnApply() const { return true; }
160
161         /// \return the list of all available bibliography keys.
162         std::vector<docstring> availableKeys() const;
163         /// \return the list of all used BibTeX fields
164         std::vector<docstring> availableFields() const;
165         /// \return the list of all used BibTeX entry types
166         std::vector<docstring> availableEntries() const;
167         ///
168         void filterByEntryType(
169                 std::vector<docstring> & keyVector, docstring entryType);
170         ///
171         CiteEngine citeEngine() const;
172
173         /// \return information for this key.
174         docstring getInfo(docstring const & key) const;
175
176         /// Search a given string within the passed keys.
177         /// \return the vector of matched keys.
178         std::vector<docstring> searchKeys(
179                 std::vector<docstring> const & keys_to_search, //< Keys to search.
180                 bool only_keys, //< whether to search only the keys
181                 docstring const & search_expression, //< Search expression (regex possible)
182                 docstring field, //< field to search, empty for all fields
183                 bool case_sensitive = false, //< set to true is the search should be case sensitive
184                 bool regex = false //< \set to true if \c search_expression is a regex
185                 ); //
186
187 private:
188         /// The BibTeX information available to the dialog
189         BiblioInfo const & bibInfo() const;
190 };
191
192 } // namespace frontend
193 } // namespace lyx
194
195 #endif // GUICITATION_H