]> git.lyx.org Git - lyx.git/blob - src/LyXAction.h
de.po updated
[lyx.git] / src / LyXAction.h
1 // -*- C++ -*-
2 /**
3  * \file LyXAction.h
4  * Copyright 1995-2002 the LyX Team
5  * Read the file COPYING
6  */
7
8 #ifndef LYXACTION_H
9 #define LYXACTION_H
10
11 #ifdef __GNUG__
12 #pragma interface
13 #endif
14
15 #include <map>
16
17 #include "funcrequest.h"
18 #include <boost/utility.hpp>
19
20 /**
21  * This class is a container for LyX actions. It also
22  * stores and managers "pseudo-actions". Pseudo-actions
23  * are not part of the kb_action enum, but are created
24  * dynamically, for encapsulating a real action and an
25  * argument. They are used for things like the menus.
26  */
27 class LyXAction : boost::noncopyable {
28 private:
29         /// information for an action
30         struct func_info {
31                 /// the action name
32                 string name;
33                 /// the func_attrib values set
34                 unsigned int attrib;
35                 /// the help text for this action
36                 string helpText;
37         };
38
39 public:
40         /// type for map between a function name and its action
41         typedef std::map<string, kb_action> func_map;
42         /// type for map between an action and its info
43         typedef std::map<kb_action, func_info> info_map;
44         /// type for a map between a pseudo-action and its stored action/arg
45         typedef std::map<unsigned int, FuncRequest> pseudo_map;
46         /// map from argument to pseudo-action
47         typedef std::map<string, unsigned int> arg_item;
48         /// map from an action to all its dependent pseudo-actions
49         typedef std::map<kb_action, arg_item> arg_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         };
58
59         LyXAction();
60
61         /**
62          * Returns an pseudoaction from a string
63          * If you include arguments in func_name, a new pseudoaction
64          * will be created if needed.
65          */
66         int LookupFunc(string const & func_name);
67
68         /// Returns a pseudo-action given an action and its argument.
69         int getPseudoAction(kb_action action, string const & arg);
70
71         /**
72          * Given a pseudo-action, return the real action and
73          * associated argument
74          */
75         FuncRequest retrieveActionArg(int pseudo) const;
76
77         /// Search for an existent pseudoaction, return -1 if it doesn't exist.
78         int searchActionArg(kb_action action, string const & arg) const;
79
80         /// Return the name (and argument) associated with the given (pseudo) action
81         string const getActionName(int action) const;
82
83         /// Return one line help text associated with (pseudo)action
84         string const helpText(int action) const;
85
86         /// True if the command has `flag' set
87         bool funcHasFlag(kb_action action, func_attrib flag) const;
88
89         /// iterator across all real actions
90         typedef func_map::const_iterator const_func_iterator;
91
92         /// return an iterator to the start of all real actions
93         const_func_iterator func_begin() const;
94
95         /// return an iterator to the end of all real actions
96         const_func_iterator func_end() const;
97
98 private:
99         /// populate the action container with our actions
100         void init();
101         /// add the given action
102         void newFunc(kb_action, string const & name,
103                      string const & helpText, unsigned int attrib);
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. helptext, command name (string),
115          * command attributes (ro)
116          */
117         info_map lyx_info_map;
118
119         /**
120          * A mapping from the automatically created pseudo action number
121          * to the real action and its argument.
122          */
123         pseudo_map lyx_pseudo_map;
124
125         /**
126          * A (multi) mapping from the lyx action to all the generated
127          * pseudofuncs and the arguments the action should use.
128          */
129         arg_map lyx_arg_map;
130 };
131
132 /// singleton instance
133 extern LyXAction lyxaction;
134
135 #endif // LYXACTION_H