]> git.lyx.org Git - features.git/blob - src/LyXAction.h
Replace LString.h with support/std_string.h,
[features.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 "support/std_string.h"
19 #include <boost/utility.hpp>
20 #include <map>
21
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                 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<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         /// type for a map between a pseudo-action and its stored action/arg
48         typedef std::map<unsigned int, FuncRequest> pseudo_map;
49         /// map from argument to pseudo-action
50         typedef std::map<string, unsigned int> arg_item;
51         /// map from an action to all its dependent pseudo-actions
52         typedef std::map<kb_action, arg_item> arg_map;
53
54         /// possible "permissions" for an action
55         enum func_attrib {
56                 Noop = 0, //< nothing special about this func
57                 ReadOnly = 1, //< can be used in RO mode (perhaps this should change)
58                 NoBuffer = 2, //< Can be used when there is no document open
59                 Argument = 4 //< Requires argument
60         };
61
62         LyXAction();
63
64         /**
65          * Returns an pseudoaction from a string
66          * If you include arguments in func_name, a new pseudoaction
67          * will be created if needed.
68          */
69         int LookupFunc(string const & func_name);
70
71         /// Returns a pseudo-action given an action and its argument.
72         int getPseudoAction(kb_action action, string const & arg);
73
74         /**
75          * Given a pseudo-action, return the real action and
76          * associated argument
77          */
78         FuncRequest retrieveActionArg(int pseudo) const;
79
80         /// Search for an existent pseudoaction, return -1 if it doesn't exist.
81         int searchActionArg(kb_action action, string const & arg) const;
82
83         /// Return the name (and argument) associated with the given (pseudo) action
84         string const getActionName(int action) const;
85
86         /// True if the command has `flag' set
87         bool funcHasFlag(kb_action action, func_attrib flag) const;
88
89         /// iterator across all real actions
90         typedef func_map::const_iterator const_func_iterator;
91
92         /// return an iterator to the start of all real actions
93         const_func_iterator func_begin() const;
94
95         /// return an iterator to the end of all real actions
96         const_func_iterator func_end() const;
97
98 private:
99         /// populate the action container with our actions
100         void init();
101         /// add the given action
102         void newFunc(kb_action, string const & name, unsigned int attrib);
103
104         /**
105          * This is a list of all the LyXFunc names with the
106          * coresponding action number. It is usually only used by the
107          * minibuffer or when assigning commands to keys during init.
108          */
109         func_map lyx_func_map;
110
111         /**
112          * This is a mapping from action number to an object holding
113          * info about this action. f.ex. command name (string),
114          * command attributes (ro)
115          */
116         info_map lyx_info_map;
117
118         /**
119          * A mapping from the automatically created pseudo action number
120          * to the real action and its argument.
121          */
122         pseudo_map lyx_pseudo_map;
123
124         /**
125          * A (multi) mapping from the lyx action to all the generated
126          * pseudofuncs and the arguments the action should use.
127          */
128         arg_map lyx_arg_map;
129 };
130
131 /// singleton instance
132 extern LyXAction lyxaction;
133
134 #endif // LYXACTION_H