]> git.lyx.org Git - lyx.git/blob - src/LyXAction.h
Style. Enum names and typedefs are almost always CamelCase in the LyX
[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 class LyXErr;
26
27 /**
28  * This class is a container for LyX actions. It associates a name to
29  * most of them and describes some of their properties.
30  */
31 class LyXAction {
32 public:
33         /// category of an action, used in the Shortcuts dialog
34         enum FuncType {
35                 Hidden,  //< Not listed for configuration
36                 Edit,    //< Cursor and mouse movement, copy/paste etc
37                 Math,    //< Mathematics
38                 Buffer,  //< Buffer and window related
39                 Layout,  //< Font, Layout and textclass related
40                 System,  //< Lyx preference, server etc
41         };
42
43 private:
44         /// information for an action
45         struct FuncInfo {
46                 /// the action name
47                 std::string name;
48                 /// the func_attrib values set
49                 unsigned int attrib;
50                 /// the category of this func
51                 FuncType type;
52         };
53         /// type for map between a function name and its action
54         typedef std::map<std::string, FuncCode> FuncMap;
55         /// type for map between an action and its info
56         typedef std::map<FuncCode, FuncInfo> InfoMap;
57
58
59 public:
60         /// noncopyable
61         LyXAction(LyXAction const &);
62         void operator=(LyXAction const &);
63
64         /// possible "permissions" for an action
65         enum FuncAttribs {
66                 Noop = 0, //< Nothing special about this func
67                 ReadOnly = 1, //< Can be used in RO mode (perhaps this should change); no automatic markDirty
68                 NoBuffer = 2, //< Can be used when there is no document open
69                 Argument = 4, //< Requires argument
70                 NoUpdate = 8, //< Does not (usually) require update
71                 SingleParUpdate = 16, //< Usually only requires this par updated
72                 AtPoint = 32, //< dispatch first to inset at cursor if there is one
73                 NoInternal = 64, //< Cannot be used for internal, non-document Buffers
74         };
75
76         LyXAction();
77
78         /**
79          * Creates a FuncRequest from a string of the form:
80          *   lyx-function [argument]
81          * where the argument is optional and "lyx-function" is in the form you'd
82          * enter it in the mini-buffer. 
83          */
84         FuncRequest lookupFunc(std::string const & func_name) const;
85
86         /// Return the command name associated with the given action
87         /// Thus: getActionName(LFUN_ERT_INSERT) --> "ert-insert".
88         std::string const getActionName(FuncCode action) const;
89         ///
90         FuncType getActionType(FuncCode action) const;
91
92         /// True if the command has `flag' set
93         bool funcHasFlag(FuncCode action, FuncAttribs flag) const;
94
95         /// iterator across all real actions
96         typedef FuncMap::const_iterator const_func_iterator;
97
98         /// return an iterator to the start of all real actions
99         const_func_iterator func_begin() const;
100
101         /// return an iterator to the end of all real actions
102         const_func_iterator func_end() const;
103
104 private:
105         /// populate the action container with our actions
106         void init();
107         /// add the given action
108         void newFunc(FuncCode, std::string const & name, unsigned int attrib, FuncType type);
109
110         /**
111          * This is a list of all the LyXFunc names with the
112          * coresponding action number. It is usually only used by the
113          * minibuffer or when assigning commands to keys during init.
114          */
115         FuncMap lyx_func_map;
116
117         /**
118          * This is a mapping from action number to an object holding
119          * info about this action. f.ex. command name (string),
120          * command attributes (ro)
121          */
122         InfoMap lyx_info_map;
123 };
124
125 LyXErr & operator<<(LyXErr &, FuncCode);
126
127 /// singleton instance
128 extern LyXAction lyxaction;
129
130
131 } // namespace lyx
132
133 #endif // LYXACTION_H