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