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