]> git.lyx.org Git - lyx.git/blob - src/LyXAction.h
Small fix.
[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
14 /** This class encapsulates LyX action and user command operations.
15  */
16 class LyXAction {
17 private:
18         ///
19         struct func_info {
20                 string name;
21                 unsigned int attrib;
22                 string helpText;
23         };
24
25         ///
26         struct pseudo_func {
27                 kb_action action;
28                 string arg;
29         };
30 public:
31         ///
32         typedef std::map<string, kb_action> func_map;
33         ///
34         typedef std::map<kb_action, func_info> info_map;
35         ///
36         typedef std::map<unsigned int, pseudo_func> pseudo_map;
37         ///
38         typedef std::map<string, unsigned int> arg_item;
39         ///
40         typedef std::map<kb_action, arg_item> arg_map;
41
42         ///
43         enum func_attrib {
44                 /// nothing special about this func
45                 Noop = 0,
46                 /// can be used in RO mode (perhaps this should change)
47                 ReadOnly = 1, // ,
48                 /// Can be used when there is no document open
49                 NoBuffer = 2,
50                 //Interactive = 2, // Is interactive (requires a GUI)
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 action tag from a string. Returns kb_action.
60           Include arguments in func_name ONLY if you
61           want to create new pseudo actions. */
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 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         /// Check if a value is a pseudo-action. 
82         bool isPseudoAction(int) const;
83     
84         /// Return the name associated with command
85         string getActionName(int action) const;
86
87         /// Return one line help text associated with (pseudo)action
88         string helpText(int action) const;
89
90         /// True if the command has `flag' set
91         bool funcHasFlag(kb_action action, func_attrib flag) const;
92
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
120 /* --------------------   Inlines  ------------------ */
121     
122      
123 inline
124 bool LyXAction::isPseudoAction(int a) const
125
126         return a > int(LFUN_LASTACTION); 
127 }
128      
129 #endif