]> git.lyx.org Git - lyx.git/blob - src/LyXAction.h
Use Gtk::ComboBoxText::clear() instead of clear_items(), which only exists in newer...
[lyx.git] / src / LyXAction.h
1 // -*- C++ -*-
2 /**
3  * \file LyXAction.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef LYXACTION_H
14 #define LYXACTION_H
15
16 #include "lfuns.h"
17
18 #include <boost/utility.hpp>
19
20 #include <map>
21 #include <string>
22
23 class FuncRequest;
24
25 /**
26  * This class is a container for LyX actions. It also
27  * stores and managers "pseudo-actions". Pseudo-actions
28  * are not part of the kb_action enum, but are created
29  * dynamically, for encapsulating a real action and an
30  * argument. They are used for things like the menus.
31  */
32 class LyXAction : boost::noncopyable {
33 private:
34         /// information for an action
35         struct func_info {
36                 /// the action name
37                 std::string name;
38                 /// the func_attrib values set
39                 unsigned int attrib;
40         };
41
42 public:
43         /// type for map between a function name and its action
44         typedef std::map<std::string, kb_action> func_map;
45         /// type for map between an action and its info
46         typedef std::map<kb_action, func_info> info_map;
47
48         /// possible "permissions" for an action
49         enum func_attrib {
50                 Noop = 0, //< nothing special about this func
51                 ReadOnly = 1, //< can be used in RO mode (perhaps this should change)
52                 NoBuffer = 2, //< Can be used when there is no document open
53                 Argument = 4, //< Requires argument
54                 NoUpdate = 8, //< Does not (usually) require update
55                 SingleParUpdate = 16 //< Usually only requires this par updated
56         };
57
58         LyXAction();
59
60         /**
61          * Returns an pseudoaction from a string
62          * If you include arguments in func_name, a new pseudoaction
63          * will be created if needed.
64          */
65         FuncRequest lookupFunc(std::string const & func_name) const;
66
67         /// Return the name (and argument) associated with the given (pseudo) action
68         std::string const getActionName(kb_action action) const;
69
70         /// True if the command has `flag' set
71         bool funcHasFlag(kb_action action, func_attrib flag) const;
72
73         /// iterator across all real actions
74         typedef func_map::const_iterator const_func_iterator;
75
76         /// return an iterator to the start of all real actions
77         const_func_iterator func_begin() const;
78
79         /// return an iterator to the end of all real actions
80         const_func_iterator func_end() const;
81
82 private:
83         /// populate the action container with our actions
84         void init();
85         /// add the given action
86         void newFunc(kb_action, std::string const & name, unsigned int attrib);
87
88         /**
89          * This is a list of all the LyXFunc names with the
90          * coresponding action number. It is usually only used by the
91          * minibuffer or when assigning commands to keys during init.
92          */
93         func_map lyx_func_map;
94
95         /**
96          * This is a mapping from action number to an object holding
97          * info about this action. f.ex. command name (string),
98          * command attributes (ro)
99          */
100         info_map lyx_info_map;
101 };
102
103 /// singleton instance
104 extern LyXAction lyxaction;
105
106 #endif // LYXACTION_H