* qt_helpers.cpp:
[lyx.git] / src / LyXAction.h
blob5203bc4fcd62338098f481f240fb8e7283953e34
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.
7 * \author Lars Gullik Bjønnes
8 * \author John Levon
10 * Full author contact details are available in file CREDITS.
13 #ifndef LYXACTION_H
14 #define LYXACTION_H
16 #include "FuncCode.h"
18 #include <map>
19 #include <string>
22 namespace lyx {
24 class FuncRequest;
25 class LyXErr;
27 /**
28 * This class is a container for LyX actions. It associates a name to
29 * most of them and describes some of their properties.
31 class LyXAction {
32 public:
33 /// category of an action, used in the Shortcuts dialog
34 enum func_type {
35 Hidden, //< Not listed for configuration
36 Edit, //< Cursor and mouse movement, copy/paste etc
37 Math, //< Mathematics
38 Buffer, //< Buffer and window related
39 Layout, //< Font, Layout and textclass related
40 System, //< Lyx preference, server etc
43 private:
44 /// information for an action
45 struct FuncInfo {
46 /// the action name
47 std::string name;
48 /// the func_attrib values set
49 unsigned int attrib;
50 /// the category of this func
51 func_type type;
54 public:
55 /// noncopyable
56 LyXAction(LyXAction const &);
57 void operator=(LyXAction const &);
59 /// type for map between a function name and its action
60 typedef std::map<std::string, FuncCode> func_map;
61 /// type for map between an action and its info
62 typedef std::map<FuncCode, FuncInfo> info_map;
64 /// possible "permissions" for an action
65 enum func_attrib {
66 Noop = 0, //< Nothing special about this func
67 ReadOnly = 1, //< Can be used in RO mode (perhaps this should change); no automatic markDirty
68 NoBuffer = 2, //< Can be used when there is no document open
69 Argument = 4, //< Requires argument
70 NoUpdate = 8, //< Does not (usually) require update
71 SingleParUpdate = 16, //< Usually only requires this par updated
72 AtPoint = 32, //< dispatch first to inset at cursor if there is one
75 LyXAction();
77 /**
78 * Returns an pseudoaction from a string
79 * If you include arguments in func_name, a new pseudoaction
80 * will be created if needed.
82 FuncRequest lookupFunc(std::string const & func_name) const;
84 /// Return the name (and argument) associated with the given (pseudo) action
85 std::string const getActionName(FuncCode action) const;
87 func_type getActionType(FuncCode action) const;
89 /// True if the command has `flag' set
90 bool funcHasFlag(FuncCode action, func_attrib flag) const;
92 /// iterator across all real actions
93 typedef func_map::const_iterator const_func_iterator;
95 /// return an iterator to the start of all real actions
96 const_func_iterator func_begin() const;
98 /// return an iterator to the end of all real actions
99 const_func_iterator func_end() const;
101 private:
102 /// populate the action container with our actions
103 void init();
104 /// add the given action
105 void newFunc(FuncCode, std::string const & name, unsigned int attrib, func_type type);
108 * This is a list of all the LyXFunc names with the
109 * coresponding action number. It is usually only used by the
110 * minibuffer or when assigning commands to keys during init.
112 func_map lyx_func_map;
115 * This is a mapping from action number to an object holding
116 * info about this action. f.ex. command name (string),
117 * command attributes (ro)
119 info_map lyx_info_map;
122 LyXErr & operator<<(LyXErr &, FuncCode);
124 /// singleton instance
125 extern LyXAction lyxaction;
128 } // namespace lyx
130 #endif // LYXACTION_H