]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlCitation.h
Merging BRANCH_MVC back into HEAD.
[lyx.git] / src / frontends / controllers / ControlCitation.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  *
11  * \file ControlCitation.h
12  * \author Angus Leeming <a.leeming@ic.ac.uk>
13  */
14
15 #ifndef CONTROLCITATION_H
16 #define CONTROLCITATION_H
17
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
21
22 #include "ControlCommand.h"
23 #include "ButtonController.h"
24 #include "ViewBase.h"
25
26 /** A controller for Citation dialogs. All citation-specific functionality
27     should go in here.
28  */
29 class ControlCitation : public ControlCommand
30 {
31 public:
32         ///
33         typedef std::map<string, string> InfoMap;
34         ///
35         typedef std::map<string, string>::value_type InfoMapValue;
36         ///
37         enum Search {
38                 ///
39                 SIMPLE,
40                 ///
41                 REGEX
42         };
43         ///
44         enum Direction {
45                 ///
46                 FORWARD,
47                 ///
48                 BACKWARD
49         };
50         ///
51         ControlCitation(LyXView &, Dialogs &);
52         /// A vector of bibliography keys
53         std::vector<string> const getBibkeys();
54         /// Returns a reference to the map of stored keys
55         InfoMap const & bibkeysInfo() const { return bibkeysInfo_; }
56         /** Returns the BibTeX data associated with a given key.
57             Empty if no info exists. */
58         string const getBibkeyInfo(string const &);
59 private:
60         /// Clean up, then hide dialog.
61         virtual void hide();
62         /// The info associated with each key
63         InfoMap bibkeysInfo_;
64 };
65
66
67 /** This class instantiates and makes available the GUI-specific
68     ButtonController and View.
69  */
70 template <class GUIview, class GUIbc>
71 class GUICitation : public ControlCitation {
72 public:
73         ///
74         GUICitation(LyXView &, Dialogs &);
75         ///
76         virtual ButtonControllerBase & bc() { return bc_; }
77         ///
78         virtual ViewBase & view() { return view_; }
79
80 private:
81         ///
82         ButtonController<NoRepeatedApplyReadOnlyPolicy, GUIbc> bc_;
83         ///
84         GUIview view_;
85 };
86
87 template <class GUIview, class GUIbc>
88 GUICitation<GUIview, GUIbc>::GUICitation(LyXView & lv, Dialogs & d)
89         : ControlCitation(lv, d),
90           view_(*this)
91 {}
92
93 /** Helper functions, of possible use to all frontends
94  */
95
96 /** Multiple citation keys are stored in InsetCommandParams::contents as a
97     comma-separated string. These two functions convert to/from a vector. */
98 string const getStringFromVector(std::vector<string> const &, char delim=',');
99 ///
100 std::vector<string> const getVectorFromString(string const &, char delim=',');
101
102 /** Search a BibTeX info field for the given key and return the
103     associated field. */
104 string const parseBibTeX(string data, string const & findkey);
105
106 /** Returns an iterator to the first key that meets the search criterion,
107     or end() if unsuccessful.
108
109     User supplies :
110     the controller with the map of bibkeys info,
111     the vector of keys to be searched,
112     the search criterion,
113     an iterator defining the starting point of the search,
114     an enum defining a Simple or Regex search,
115     an enum defining the search direction.
116 */
117
118 std::vector<string>::const_iterator
119 searchKeys(ControlCitation const & controller,
120            std::vector<string> const & keys_to_search,
121            string const & search_expression,
122            std::vector<string>::const_iterator start,
123            ControlCitation::Search,
124            ControlCitation::Direction,
125            bool caseSensitive=false);
126
127 /// Do the dirty work for the search. Should use through the function above
128 std::vector<string>::const_iterator
129 simpleSearch(ControlCitation const & controller,
130              std::vector<string> const & keys_to_search,
131              string const & search_expression,
132              std::vector<string>::const_iterator start,
133              ControlCitation::Direction,
134              bool caseSensitive=false);
135
136 /// Should use through the function above
137 std::vector<string>::const_iterator
138 regexSearch(ControlCitation const & controller,
139             std::vector<string> const & keys_to_search,
140             string const & search_expression,
141             std::vector<string>::const_iterator start,
142             ControlCitation::Direction);
143 #endif // CONTROLCITATION_H
144
145
146