1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
1999-11-15 12:01:38 +00:00
|
|
|
#ifndef LYXACTION_H
|
|
|
|
#define LYXACTION_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
#include <map>
|
1999-11-25 13:15:52 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "commandtags.h"
|
1999-11-22 16:19:48 +00:00
|
|
|
#include "LString.h"
|
2000-08-07 20:58:24 +00:00
|
|
|
#include "support/utility.hpp"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/** This class encapsulates LyX action and user command operations.
|
|
|
|
*/
|
2000-08-07 20:58:24 +00:00
|
|
|
class LyXAction : public noncopyable {
|
1999-11-22 16:19:48 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
struct func_info {
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-11-22 16:19:48 +00:00
|
|
|
string name;
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-11-22 16:19:48 +00:00
|
|
|
unsigned int attrib;
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-11-22 16:19:48 +00:00
|
|
|
string helpText;
|
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
struct pseudo_func {
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-11-22 16:19:48 +00:00
|
|
|
kb_action action;
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-11-22 16:19:48 +00:00
|
|
|
string arg;
|
|
|
|
};
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
typedef std::map<string, kb_action> func_map;
|
1999-11-22 16:19:48 +00:00
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
typedef std::map<kb_action, func_info> info_map;
|
1999-11-22 16:19:48 +00:00
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
typedef std::map<unsigned int, pseudo_func> pseudo_map;
|
1999-11-22 16:19:48 +00:00
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
typedef std::map<string, unsigned int> arg_item;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
typedef std::map<kb_action, arg_item> arg_map;
|
1999-11-22 16:19:48 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
enum func_attrib {
|
|
|
|
/// nothing special about this func
|
|
|
|
Noop = 0,
|
1999-12-17 14:16:05 +00:00
|
|
|
/// can be used in RO mode (perhaps this should change)
|
1999-11-22 16:19:48 +00:00
|
|
|
ReadOnly = 1, // ,
|
|
|
|
/// Can be used when there is no document open
|
|
|
|
NoBuffer = 2,
|
|
|
|
//Interactive = 2, // Is interactive (requires a GUI)
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
|
|
|
Argument = 4 // Requires argument
|
1999-11-22 16:19:48 +00:00
|
|
|
//MathOnly = 8, // Only math mode
|
|
|
|
//EtcEtc = ... // Or other attributes...
|
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
LyXAction();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/** Returns an action tag from a string. Returns kb_action.
|
|
|
|
Include arguments in func_name ONLY if you
|
|
|
|
want to create new pseudo actions. */
|
1999-11-22 16:19:48 +00:00
|
|
|
int LookupFunc(string const & func_name) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/** Returns an action tag which name is the most similar to a string.
|
|
|
|
Don't include arguments, they would be ignored. */
|
1999-11-22 16:19:48 +00:00
|
|
|
int getApproxFunc(string const & func) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/** Returns an action name the most similar to a string.
|
|
|
|
Don't include arguments, they would be ignored. */
|
1999-11-22 16:19:48 +00:00
|
|
|
string getApproxFuncName(string const & func) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Returns a pseudo-action given an action and its argument.
|
1999-11-22 16:19:48 +00:00
|
|
|
int getPseudoAction(kb_action action, string const & arg) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Retrieves the real action and its argument.
|
1999-11-22 16:19:48 +00:00
|
|
|
kb_action retrieveActionArg(int i, string & arg) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Search for an existent pseudoaction, return -1 if it doesn't exist.
|
1999-11-22 16:19:48 +00:00
|
|
|
int searchActionArg(kb_action action, string const & arg) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Check if a value is a pseudo-action.
|
1999-11-22 16:19:48 +00:00
|
|
|
bool isPseudoAction(int) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Return the name associated with command
|
1999-11-22 16:19:48 +00:00
|
|
|
string getActionName(int action) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
/// Return one line help text associated with (pseudo)action
|
|
|
|
string helpText(int action) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
/// True if the command has `flag' set
|
|
|
|
bool funcHasFlag(kb_action action, func_attrib flag) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
private:
|
1999-11-22 16:19:48 +00:00
|
|
|
///
|
|
|
|
void init();
|
|
|
|
///
|
|
|
|
void newFunc(kb_action, string const & name,
|
|
|
|
string const & helpText, unsigned int attrib);
|
|
|
|
|
|
|
|
/** This is a list of all the LyXFunc names with the
|
|
|
|
coresponding action number. It is usually only used by the
|
|
|
|
minibuffer or when assigning commands to keys during init. */
|
|
|
|
func_map lyx_func_map;
|
|
|
|
|
|
|
|
/** This is a mapping from action number to an object holding
|
|
|
|
info about this action. f.ex. helptext, command name (string),
|
|
|
|
command attributes (ro) */
|
|
|
|
info_map lyx_info_map;
|
|
|
|
|
|
|
|
/** A mapping from the automatically created pseudo action number
|
|
|
|
to the real action and its argument. */
|
|
|
|
mutable pseudo_map lyx_pseudo_map;
|
|
|
|
|
|
|
|
/** A (multi) mapping from the lyx action to all the generated
|
|
|
|
pseudofuncs and the arguments the action should use. */
|
|
|
|
mutable arg_map lyx_arg_map;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------- Inlines ------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
1999-11-22 16:19:48 +00:00
|
|
|
bool LyXAction::isPseudoAction(int a) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
return a > int(LFUN_LASTACTION);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|