]> git.lyx.org Git - lyx.git/blob - src/LyXAction.h
Fixed some lines that were too long. It compiled afterwards.
[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
24 namespace lyx {
25
26 class FuncRequest;
27
28 /**
29  * This class is a container for LyX actions. It also
30  * stores and managers "pseudo-actions". Pseudo-actions
31  * are not part of the kb_action enum, but are created
32  * dynamically, for encapsulating a real action and an
33  * argument. They are used for things like the menus.
34  */
35 class LyXAction : boost::noncopyable {
36 private:
37         /// information for an action
38         struct func_info {
39                 /// the action name
40                 std::string name;
41                 /// the func_attrib values set
42                 unsigned int attrib;
43         };
44
45 public:
46         /// type for map between a function name and its action
47         typedef std::map<std::string, kb_action> func_map;
48         /// type for map between an action and its info
49         typedef std::map<kb_action, func_info> info_map;
50
51         /// possible "permissions" for an action
52         enum func_attrib {
53                 Noop = 0, //< nothing special about this func
54                 ReadOnly = 1, //< can be used in RO mode (perhaps this should change)
55                 NoBuffer = 2, //< Can be used when there is no document open
56                 Argument = 4, //< Requires argument
57                 NoUpdate = 8, //< Does not (usually) require update
58                 SingleParUpdate = 16 //< Usually only requires this par updated
59         };
60
61         LyXAction();
62
63         /**
64          * Returns an pseudoaction from a string
65          * If you include arguments in func_name, a new pseudoaction
66          * will be created if needed.
67          */
68         FuncRequest lookupFunc(std::string const & func_name) const;
69
70         /// Return the name (and argument) associated with the given (pseudo) action
71         std::string const getActionName(kb_action action) const;
72
73         /// True if the command has `flag' set
74         bool funcHasFlag(kb_action action, func_attrib flag) const;
75
76         /// iterator across all real actions
77         typedef func_map::const_iterator const_func_iterator;
78
79         /// return an iterator to the start of all real actions
80         const_func_iterator func_begin() const;
81
82         /// return an iterator to the end of all real actions
83         const_func_iterator func_end() const;
84
85 private:
86         /// populate the action container with our actions
87         void init();
88         /// add the given action
89         void newFunc(kb_action, std::string const & name, unsigned int attrib);
90
91         /**
92          * This is a list of all the LyXFunc names with the
93          * coresponding action number. It is usually only used by the
94          * minibuffer or when assigning commands to keys during init.
95          */
96         func_map lyx_func_map;
97
98         /**
99          * This is a mapping from action number to an object holding
100          * info about this action. f.ex. command name (string),
101          * command attributes (ro)
102          */
103         info_map lyx_info_map;
104 };
105
106 /// singleton instance
107 extern LyXAction lyxaction;
108
109
110 } // namespace lyx
111
112 #endif // LYXACTION_H