]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCitation.h
0adf0d4c3a24589f858946c1f9f2edec4a25dd11
[lyx.git] / src / insets / InsetCitation.h
1 // -*- C++ -*-
2 /**
3  * \file InsetCitation.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 Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef INSET_CITATION_H
14 #define INSET_CITATION_H
15
16 #include "InsetCommand.h"
17
18 namespace lyx {
19
20 class BufferParams;
21 class CitationStyle;
22
23 /////////////////////////////////////////////////////////////////////////
24 //
25 // InsetCitation
26 //
27 /////////////////////////////////////////////////////////////////////////
28
29 /// Used to insert citations
30 class InsetCitation : public InsetCommand
31 {
32 public:
33         ///
34         InsetCitation(Buffer * buf, InsetCommandParams const &);
35         ///
36         ~InsetCitation();
37
38         ///
39         bool addKey(std::string const & key);
40
41         /// \name Public functions inherited from Inset class
42         //@{
43         ///
44         bool isLabeled() const override { return true; }
45         ///
46         bool hasSettings() const override { return true; }
47         ///
48         docstring toolTip(BufferView const & bv, int x, int y) const override;
49         ///
50         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
51         ///
52         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const override;
53         ///
54         InsetCode lyxCode() const override { return CITE_CODE; }
55         ///
56         void latex(otexstream &, OutputParams const &) const override;
57         ///
58         int plaintext(odocstringstream & ods, OutputParams const & op,
59                       size_t max_length = INT_MAX) const override;
60         ///
61         void docbook(XMLStream &, OutputParams const &) const override;
62         ///
63         docstring xhtml(XMLStream &, OutputParams const &) const override;
64         ///
65         void toString(odocstream &) const override;
66         ///
67         void forOutliner(docstring &, size_t const, bool const) const override;
68         ///
69         void updateBuffer(ParIterator const & it, UpdateType, bool const deleted = false) override;
70         ///
71         void addToToc(DocIterator const & di, bool output_active,
72                                   UpdateType utype, TocBackend & backend) const override;
73         ///
74         std::string contextMenuName() const override;
75         ///
76         bool forceLTR(OutputParams const &) const override;
77         //@}
78
79         /// \name Static public methods obligated for InsetCommand derived classes
80         //@{
81         ///
82         static ParamInfo const & findInfo(std::string const &);
83         ///
84         static std::string defaultCommand() { return "cite"; }
85         ///
86         static bool isCompatibleCommand(std::string const &);
87         //@}
88         ///
89         typedef std::vector<std::pair<docstring, docstring>> QualifiedList;
90         ///
91         void redoLabel() { cache.recalculate = true; }
92         ///
93         CitationStyle getCitationStyle(BufferParams const & bp, std::string const & input,
94                                        std::vector<CitationStyle> const & valid_styles) const;
95         ///
96         QualifiedList getQualifiedLists(docstring const & p) const;
97         ///
98         static bool last_literal;
99         /// Check whether citation contains necessary url/file entries
100         /// or external search script is available
101         bool openCitationPossible() const;
102         /// search and open citation source
103         void openCitation();
104         ///
105         std::pair<int, int> isWords() const override;
106
107 private:
108         /// tries to make a pretty label and makes a basic one if not
109         docstring generateLabel(bool for_xhtml = false) const;
110         /// makes a pretty label
111         docstring complexLabel(bool for_xhtml = false) const;
112         /// makes a very basic label, in case we can't make a pretty one
113         docstring basicLabel(bool for_xhtml = false) const;
114         /// trims the keys
115         void cleanKeys();
116
117         /// \name Private functions inherited from Inset class
118         //@{
119         ///
120         Inset * clone() const override { return new InsetCitation(*this); }
121         //@}
122
123         /// \name Private functions inherited from InsetCommand class
124         //@{
125         ///
126         docstring screenLabel() const override;
127         //@}
128
129         ///
130         struct Cache {
131                 Cache() : recalculate(true) {}
132                 ///
133                 bool recalculate;
134                 ///
135                 docstring generated_label;
136                 ///
137                 docstring screen_label;
138         };
139         ///
140         mutable Cache cache;
141 };
142
143
144 } // namespace lyx
145
146 #endif // INSET_CITATION_H