]> git.lyx.org Git - lyx.git/blob - src/LyXAction.h
include sys/time.h
[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 #include <map>
12
13 #include "funcrequest.h"
14 #include <boost/utility.hpp>
15
16 /**
17  * This class is a container for LyX actions. It also
18  * stores and managers "pseudo-actions". Pseudo-actions
19  * are not part of the kb_action enum, but are created
20  * dynamically, for encapsulating a real action and an
21  * argument. They are used for things like the menus.
22  */
23 class LyXAction : boost::noncopyable {
24 private:
25         /// information for an action
26         struct func_info {
27                 /// the action name
28                 string name;
29                 /// the func_attrib values set
30                 unsigned int attrib;
31                 /// the help text for this action
32                 string helpText;
33         };
34
35 public:
36         /// type for map between a function name and its action
37         typedef std::map<string, kb_action> func_map;
38         /// type for map between an action and its info
39         typedef std::map<kb_action, func_info> info_map;
40         /// type for a map between a pseudo-action and its stored action/arg
41         typedef std::map<unsigned int, FuncRequest> pseudo_map;
42         /// map from argument to pseudo-action
43         typedef std::map<string, unsigned int> arg_item;
44         /// map from an action to all its dependent pseudo-actions
45         typedef std::map<kb_action, arg_item> arg_map;
46
47         /// possible "permissions" for an action
48         enum func_attrib {
49                 Noop = 0, //< nothing special about this func
50                 ReadOnly = 1, //< can be used in RO mode (perhaps this should change)
51                 NoBuffer = 2, //< Can be used when there is no document open
52                 Argument = 4 //< Requires argument
53         };
54
55         LyXAction();
56
57         /**
58          * Returns an pseudoaction from a string
59          * If you include arguments in func_name, a new pseudoaction
60          * will be created if needed.
61          */
62         int LookupFunc(string const & func_name);
63
64         /// Returns a pseudo-action given an action and its argument.
65         int getPseudoAction(kb_action action, string const & arg);
66
67         /**
68          * Given a pseudo-action, return the real action and
69          * associated argument
70          */
71         FuncRequest retrieveActionArg(int pseudo) const;
72
73         /// Search for an existent pseudoaction, return -1 if it doesn't exist.
74         int searchActionArg(kb_action action, string const & arg) const;
75
76         /// Return the name (and argument) associated with the given (pseudo) action
77         string const getActionName(int action) const;
78
79         /// Return one line help text associated with (pseudo)action
80         string const helpText(int action) const;
81
82         /// True if the command has `flag' set
83         bool funcHasFlag(kb_action action, func_attrib flag) const;
84
85         /// iterator across all real actions
86         typedef func_map::const_iterator const_func_iterator;
87
88         /// return an iterator to the start of all real actions
89         const_func_iterator func_begin() const;
90
91         /// return an iterator to the end of all real actions
92         const_func_iterator func_end() const;
93
94 private:
95         /// populate the action container with our actions
96         void init();
97         /// add the given action
98         void newFunc(kb_action, string const & name,
99                      string const & helpText, unsigned int attrib);
100
101         /**
102          * This is a list of all the LyXFunc names with the
103          * coresponding action number. It is usually only used by the
104          * minibuffer or when assigning commands to keys during init.
105          */
106         func_map lyx_func_map;
107
108         /**
109          * This is a mapping from action number to an object holding
110          * info about this action. f.ex. helptext, command name (string),
111          * command attributes (ro)
112          */
113         info_map lyx_info_map;
114
115         /**
116          * A mapping from the automatically created pseudo action number
117          * to the real action and its argument.
118          */
119         pseudo_map lyx_pseudo_map;
120
121         /**
122          * A (multi) mapping from the lyx action to all the generated
123          * pseudofuncs and the arguments the action should use.
124          */
125         arg_map lyx_arg_map;
126 };
127
128 /// singleton instance
129 extern LyXAction lyxaction;
130
131 #endif // LYXACTION_H