]> git.lyx.org Git - lyx.git/blob - src/LyXAction.h
Point fix, earlier forgotten
[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 <map>
17
18 #include "funcrequest.h"
19 #include <boost/utility.hpp>
20
21 /**
22  * This class is a container for LyX actions. It also
23  * stores and managers "pseudo-actions". Pseudo-actions
24  * are not part of the kb_action enum, but are created
25  * dynamically, for encapsulating a real action and an
26  * argument. They are used for things like the menus.
27  */
28 class LyXAction : boost::noncopyable {
29 private:
30         /// information for an action
31         struct func_info {
32                 /// the action name
33                 string name;
34                 /// the func_attrib values set
35                 unsigned int attrib;
36         };
37
38 public:
39         /// type for map between a function name and its action
40         typedef std::map<string, kb_action> func_map;
41         /// type for map between an action and its info
42         typedef std::map<kb_action, func_info> info_map;
43         /// type for a map between a pseudo-action and its stored action/arg
44         typedef std::map<unsigned int, FuncRequest> pseudo_map;
45         /// map from argument to pseudo-action
46         typedef std::map<string, unsigned int> arg_item;
47         /// map from an action to all its dependent pseudo-actions
48         typedef std::map<kb_action, arg_item> arg_map;
49
50         /// possible "permissions" for an action
51         enum func_attrib {
52                 Noop = 0, //< nothing special about this func
53                 ReadOnly = 1, //< can be used in RO mode (perhaps this should change)
54                 NoBuffer = 2, //< Can be used when there is no document open
55                 Argument = 4 //< Requires argument
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         int LookupFunc(string const & func_name);
66
67         /// Returns a pseudo-action given an action and its argument.
68         int getPseudoAction(kb_action action, string const & arg);
69
70         /**
71          * Given a pseudo-action, return the real action and
72          * associated argument
73          */
74         FuncRequest retrieveActionArg(int pseudo) const;
75
76         /// Search for an existent pseudoaction, return -1 if it doesn't exist.
77         int searchActionArg(kb_action action, string const & arg) const;
78
79         /// Return the name (and argument) associated with the given (pseudo) action
80         string const getActionName(int action) const;
81
82         /// True if the command has `flag' set
83         bool funcHasFlag(kb_action action, func_attrib flag) const;
84
85         /// iterator across all real actions
86         typedef func_map::const_iterator const_func_iterator;
87
88         /// return an iterator to the start of all real actions
89         const_func_iterator func_begin() const;
90
91         /// return an iterator to the end of all real actions
92         const_func_iterator func_end() const;
93
94 private:
95         /// populate the action container with our actions
96         void init();
97         /// add the given action
98         void newFunc(kb_action, string const & name, unsigned int attrib);
99
100         /**
101          * This is a list of all the LyXFunc names with the
102          * coresponding action number. It is usually only used by the
103          * minibuffer or when assigning commands to keys during init.
104          */
105         func_map lyx_func_map;
106
107         /**
108          * This is a mapping from action number to an object holding
109          * info about this action. f.ex. command name (string),
110          * command attributes (ro)
111          */
112         info_map lyx_info_map;
113
114         /**
115          * A mapping from the automatically created pseudo action number
116          * to the real action and its argument.
117          */
118         pseudo_map lyx_pseudo_map;
119
120         /**
121          * A (multi) mapping from the lyx action to all the generated
122          * pseudofuncs and the arguments the action should use.
123          */
124         arg_map lyx_arg_map;
125 };
126
127 /// singleton instance
128 extern LyXAction lyxaction;
129
130 #endif // LYXACTION_H