]> git.lyx.org Git - features.git/blob - src/LyXAction.h
the FuncRequest changes
[features.git] / src / LyXAction.h
1 // -*- C++ -*-
2 #ifndef LYXACTION_H
3 #define LYXACTION_H
4
5 #ifdef __GNUG__
6 #pragma interface
7 #endif
8
9 #include <map>
10
11 #include "funcrequest.h"
12 #include <boost/utility.hpp>
13
14 /** This class encapsulates LyX action and user command operations.
15  */
16
17 class LyXAction : boost::noncopyable {
18 private:
19         ///
20         struct func_info {
21                 ///
22                 string name;
23                 ///
24                 unsigned int attrib;
25                 ///
26                 string helpText;
27         };
28
29 public:
30         ///
31         typedef std::map<string, kb_action> func_map;
32         ///
33         typedef std::map<kb_action, func_info> info_map;
34         ///
35         typedef std::map<unsigned int, FuncRequest> pseudo_map;
36         ///
37         typedef std::map<string, unsigned int> arg_item;
38         ///
39         typedef std::map<kb_action, arg_item> arg_map;
40
41         ///
42         enum func_attrib {
43                 /// nothing special about this func
44                 Noop = 0,
45                 /// can be used in RO mode (perhaps this should change)
46                 ReadOnly = 1, // ,
47                 /// Can be used when there is no document open
48                 NoBuffer = 2,
49                 //Interactive = 2, // Is interactive (requires a GUI)
50                 ///
51                 Argument = 4      // Requires argument
52                 //MathOnly = 8,    // Only math mode
53                 //EtcEtc = ...     // Or other attributes...
54         };
55
56         ///
57         LyXAction();
58
59         /** Returns an pseudoaction from a string
60           If you include arguments in func_name, a new psedoaction will be
61           created if needed. */
62         int LookupFunc(string const & func_name) const;
63
64         /** Returns an action tag which name is the most similar to a string.
65             Don't include arguments, they would be ignored. */
66         int getApproxFunc(string const & func) const;
67
68         /** Returns an action name the most similar to a string.
69             Don't include arguments, they would be ignored. */
70         string const getApproxFuncName(string const & func) const;
71
72         /// Returns a pseudo-action given an action and its argument.
73         int getPseudoAction(kb_action action, string const & arg) const;
74
75         /// Retrieves the real action and its argument.
76         kb_action retrieveActionArg(int i, string & arg) const;
77
78         /// Search for an existent pseudoaction, return -1 if it doesn't exist.
79         int searchActionArg(kb_action action, string const & arg) const;
80
81         /// Return the name associated with command
82         string const getActionName(int action) const;
83
84         /// Return one line help text associated with (pseudo)action
85         string const helpText(int action) const;
86
87         /// True if the command has `flag' set
88         bool funcHasFlag(kb_action action, func_attrib flag) const;
89
90         typedef func_map::const_iterator const_func_iterator;
91         const_func_iterator func_begin() const;
92         const_func_iterator func_end() const;
93 private:
94         ///
95         void init();
96         ///
97         void newFunc(kb_action, string const & name,
98                      string const & helpText, unsigned int attrib);
99
100         /** This is a list of all the LyXFunc names with the
101           coresponding action number. It is usually only used by the
102           minibuffer or when assigning commands to keys during init. */
103         func_map lyx_func_map;
104
105         /** This is a mapping from action number to an object holding
106           info about this action. f.ex. helptext, command name (string),
107           command attributes (ro) */
108         info_map lyx_info_map;
109
110         /** A mapping from the automatically created pseudo action number
111           to the real action and its argument. */
112         mutable pseudo_map lyx_pseudo_map;
113
114         /** A (multi) mapping from the lyx action to all the generated
115           pseudofuncs and the arguments the action should use. */
116         mutable arg_map lyx_arg_map;
117 };
118
119 #endif