]> git.lyx.org Git - lyx.git/blob - src/LyXAction.h
fix compilation; remove cruft in configure script (I may have removed too much, but...
[lyx.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 "commandtags.h"
12 #include "LString.h"
13 #include <boost/utility.hpp>
14
15 /** This class encapsulates LyX action and user command operations.
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         ///
30         struct pseudo_func {
31                 ///
32                 kb_action action;
33                 ///
34                 string arg;
35         };
36 public:
37         ///
38         typedef std::map<string, kb_action> func_map;
39         ///
40         typedef std::map<kb_action, func_info> info_map;
41         ///
42         typedef std::map<unsigned int, pseudo_func> pseudo_map;
43         ///
44         typedef std::map<string, unsigned int> arg_item;
45         ///
46         typedef std::map<kb_action, arg_item> arg_map;
47
48         ///
49         enum func_attrib {
50                 /// nothing special about this func
51                 Noop = 0,
52                 /// can be used in RO mode (perhaps this should change)
53                 ReadOnly = 1, // ,
54                 /// Can be used when there is no document open
55                 NoBuffer = 2,
56                 //Interactive = 2, // Is interactive (requires a GUI)
57                 ///
58                 Argument = 4      // Requires argument
59                 //MathOnly = 8,    // Only math mode
60                 //EtcEtc = ...     // Or other attributes...
61         };
62
63         ///
64         LyXAction();
65
66         /** Returns an pseudoaction from a string
67           If you include arguments in func_name, a new psedoaction will be
68           created if needed. */
69         int LookupFunc(string const & func_name) const;
70
71         /** Returns an action tag which name is the most similar to a string.
72             Don't include arguments, they would be ignored. */
73         int getApproxFunc(string const & func) const;
74
75         /** Returns an action name the most similar to a string.
76             Don't include arguments, they would be ignored. */
77         string const getApproxFuncName(string const & func) const;
78
79         /// Returns a pseudo-action given an action and its argument.
80         int getPseudoAction(kb_action action, string const & arg) const;
81
82         /// Retrieves the real action and its argument.
83         kb_action retrieveActionArg(int i, string & arg) const;
84
85         /// Search for an existent pseudoaction, return -1 if it doesn't exist.
86         int searchActionArg(kb_action action, string const & arg) const;
87
88         /// Return the name associated with command
89         string const getActionName(int action) const;
90
91         /// Return one line help text associated with (pseudo)action
92         string const helpText(int action) const;
93
94         /// True if the command has `flag' set
95         bool funcHasFlag(kb_action action, func_attrib flag) const;
96
97         typedef func_map::const_iterator const_func_iterator;
98         const_func_iterator func_begin() const;
99         const_func_iterator func_end() const;
100 private:
101         ///
102         void init();
103         ///
104         void newFunc(kb_action, string const & name,
105                      string const & helpText, unsigned int attrib);
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         func_map lyx_func_map;
111
112         /** This is a mapping from action number to an object holding
113           info about this action. f.ex. helptext, command name (string),
114           command attributes (ro) */
115         info_map lyx_info_map;
116
117         /** A mapping from the automatically created pseudo action number
118           to the real action and its argument. */
119         mutable pseudo_map lyx_pseudo_map;
120
121         /** A (multi) mapping from the lyx action to all the generated
122           pseudofuncs and the arguments the action should use. */
123         mutable arg_map lyx_arg_map;
124 };
125
126 #endif