]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlCitation.h
Implementation of controller-view split for FormCharacter.
[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 2001 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
24 /** A controller for Citation dialogs. All citation-specific functionality
25     should go in here.
26  */
27 class ControlCitation : public ControlCommand
28 {
29 public:
30         ///
31         typedef std::map<string, string> InfoMap;
32         ///
33         typedef std::map<string, string>::value_type InfoMapValue;
34         ///
35         enum Search {
36                 ///
37                 SIMPLE,
38                 ///
39                 REGEX
40         };
41         ///
42         enum Direction {
43                 ///
44                 FORWARD,
45                 ///
46                 BACKWARD
47         };
48         ///
49         ControlCitation(LyXView &, Dialogs &);
50         /// A vector of bibliography keys
51         std::vector<string> const getBibkeys();
52         /// Returns a reference to the map of stored keys
53         InfoMap const & bibkeysInfo() const { return bibkeysInfo_; }
54         /** Returns the BibTeX data associated with a given key.
55             Empty if no info exists. */
56         string const getBibkeyInfo(string const &);
57 private:
58         /// Clean up, then hide dialog.
59         virtual void hide();
60         /// The info associated with each key
61         InfoMap bibkeysInfo_;
62 };
63
64
65 /** This class instantiates and makes available the GUI-specific
66     ButtonController and View.
67  */
68 template <class GUIview, class GUIbc>
69 class GUICitation : public ControlCitation {
70 public:
71         ///
72         GUICitation(LyXView &, Dialogs &);
73         ///
74         virtual ButtonControllerBase & bc() { return bc_; }
75         ///
76         virtual ViewBase & view() { return view_; }
77
78 private:
79         ///
80         ButtonController<NoRepeatedApplyReadOnlyPolicy, GUIbc> bc_;
81         ///
82         GUIview view_;
83 };
84
85 template <class GUIview, class GUIbc>
86 GUICitation<GUIview, GUIbc>::GUICitation(LyXView & lv, Dialogs & d)
87         : ControlCitation(lv, d),
88           view_(*this)
89 {}
90
91 /** Helper functions, of possible use to all frontends
92  */
93
94 /** Search a BibTeX info field for the given key and return the
95     associated field. */
96 string const parseBibTeX(string data, string const & findkey);
97
98 /** Returns an iterator to the first key that meets the search criterion,
99     or end() if unsuccessful.
100
101     User supplies :
102     the controller with the map of bibkeys info,
103     the vector of keys to be searched,
104     the search criterion,
105     an iterator defining the starting point of the search,
106     an enum defining a Simple or Regex search,
107     an enum defining the search direction.
108 */
109
110 std::vector<string>::const_iterator
111 searchKeys(ControlCitation const & controller,
112            std::vector<string> const & keys_to_search,
113            string const & search_expression,
114            std::vector<string>::const_iterator start,
115            ControlCitation::Search,
116            ControlCitation::Direction,
117            bool caseSensitive=false);
118
119 /// Do the dirty work for the search. Should use through the function above
120 std::vector<string>::const_iterator
121 simpleSearch(ControlCitation const & controller,
122              std::vector<string> const & keys_to_search,
123              string const & search_expression,
124              std::vector<string>::const_iterator start,
125              ControlCitation::Direction,
126              bool caseSensitive=false);
127
128 /// Should use through the function above
129 std::vector<string>::const_iterator
130 regexSearch(ControlCitation const & controller,
131             std::vector<string> const & keys_to_search,
132             string const & search_expression,
133             std::vector<string>::const_iterator start,
134             ControlCitation::Direction);
135 #endif // CONTROLCITATION_H
136
137
138