]> git.lyx.org Git - lyx.git/blob - src/LyXAction.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / LyXAction.h
1 // -*- C++ -*-
2 /**
3  * \file LyXAction.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef LYXACTION_H
14 #define LYXACTION_H
15
16 #include "FuncCode.h"
17
18 #include <map>
19 #include <string>
20
21
22 namespace lyx {
23
24 // current LFUN format
25 static unsigned int const LFUN_FORMAT = 5; // spitz: 2.4.x changes
26
27 class FuncRequest;
28 class LyXErr;
29
30 /**
31  * This class is a container for LyX actions. It associates a name to
32  * most of them and describes some of their properties.
33  */
34 class LyXAction {
35 public:
36         /// category of an action, used in the Shortcuts dialog
37         enum FuncType {
38                 Hidden,  //< Not listed for configuration
39                 Edit,    //< Cursor and mouse movement, copy/paste etc
40                 Math,    //< Mathematics
41                 Buffer,  //< Buffer and window related
42                 Layout,  //< Font, Layout and textclass related
43                 System   //< Lyx preference, server etc
44         };
45
46 private:
47         /// information for an action
48         struct FuncInfo {
49                 /// the action name
50                 std::string name;
51                 /// the FuncAttribs values set
52                 unsigned int attrib;
53                 /// the category of this func
54                 FuncType type;
55         };
56         /// type for map between a function name and its action
57         typedef std::map<std::string, FuncCode> FuncMap;
58         /// type for map between an action and its info
59         typedef std::map<FuncCode, FuncInfo> InfoMap;
60
61 public:
62         /// possible "permissions" for an action
63         enum FuncAttribs {
64                 Noop = 0, //< Nothing special about this func
65                 ReadOnly = 1, //< Can be used in RO mode (perhaps this should change)
66                 NoBuffer = 2, //< Can be used when there is no document open
67                 Argument = 4, //< Requires argument
68                 NoUpdate = 8, //< Does not (usually) require update
69                 SingleParUpdate = 16, //< Usually only requires this par updated
70                 AtPoint = 32, //< dispatch first to inset at cursor if there is one
71                 NoInternal = 64 //< Cannot be used for internal, non-document Buffers
72         };
73
74         LyXAction();
75
76         /**
77          * Creates a FuncRequest from a string of the form:
78          *   lyx-function [argument]
79          * where the argument is optional and "lyx-function" is in the form you'd
80          * enter it in the mini-buffer.
81          */
82         FuncRequest lookupFunc(std::string const & func_name) const;
83
84         /// Return the command name associated with the given action
85         /// Thus: getActionName(LFUN_ERT_INSERT) --> "ert-insert".
86         std::string const getActionName(FuncCode action) const;
87         ///
88         FuncType getActionType(FuncCode action) const;
89
90         /// True if the command has `flag' set
91         bool funcHasFlag(FuncCode action, FuncAttribs flag) const;
92
93         /// iterator across all LFUNs
94         typedef FuncMap::const_iterator const_iterator;
95
96         /// return an iterator to the start of the list of LFUNs
97         const_iterator begin() const;
98
99         /// return an iterator to one past the end of the list of LFUNs
100         const_iterator end() const;
101
102 private:
103         /// noncopyable
104         LyXAction(LyXAction const &);
105         void operator=(LyXAction const &);
106
107         /// populate the action container with our actions
108         void init();
109         /// add the given action
110         void newFunc(FuncCode, std::string const & name, unsigned int attrib, FuncType type);
111
112         /**
113          * This maps LyX function names to function codes, e.g.:
114          *   lyx_func_map["ert-insert"] == LFUN_ERT_INSERT
115          */
116         FuncMap lyx_func_map;
117
118         /**
119          * This maps function codes to objects holding info about the corresponding
120          * action. E.g., if
121          *   FuncInfo const & ert = lyx_info_map[LFUN_ERT_INSERT];
122          * then:
123          *   ert.name   == "ert-insert"'
124          *   ert.attrib == Noop
125          *   ert.type   == Edit
126          */
127         InfoMap lyx_info_map;
128 };
129
130 LyXErr & operator<<(LyXErr &, FuncCode);
131
132 /// singleton instance
133 extern LyXAction lyxaction;
134
135
136 } // namespace lyx
137
138 #endif // LYXACTION_H