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