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