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