some minor lyxaction cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4911 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2002-08-08 22:03:30 +00:00
parent 7d23c29dee
commit 0472bb3509
18 changed files with 152 additions and 173 deletions

View File

@ -1,3 +1,13 @@
2002-08-08 John Levon <levon@movementarian.org>
* LyXAction.h:
* LyXAction.C:
* MenuBackend.C:
* ToolbarDefaults.C:
* lyxfunc.C:
* lyxrc.C:
* toc.C: lyxaction cleanup
2002-08-08 John Levon <levon@movementarian.org> 2002-08-08 John Levon <levon@movementarian.org>
* BufferView2.C: small cleanup * BufferView2.C: small cleanup

View File

@ -1,12 +1,8 @@
/* This file is part of /**
* ====================================================== * \file LyXAction.C
* * Copyright 1995-2002 the LyX Team
* LyX, The Document Processor * Read the file COPYING
* */
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 The LyX Team.
*
* ====================================================== */
#include <config.h> #include <config.h>
@ -15,12 +11,17 @@
#endif #endif
#include "LyXAction.h" #include "LyXAction.h"
#include "debug.h" #include "debug.h"
#include "gettext.h" #include "gettext.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include <boost/tuple/tuple.hpp>
using std::ostream; using std::ostream;
using std::endl; using std::endl;
using std::pair;
using std::make_pair;
/* /*
NAMING RULES FOR USER-COMMANDS NAMING RULES FOR USER-COMMANDS
@ -37,18 +38,19 @@ using std::endl;
8) The end of an object is called `end'. 8) The end of an object is called `end'.
(May 19 1996, 12:04, RvdK) (May 19 1996, 12:04, RvdK)
*/ */
// These are globals.
LyXAction lyxaction; LyXAction lyxaction;
// Small helper function namespace {
inline
bool isPseudoAction(int a) /// return true if the given action is a pseudo-action
inline bool isPseudoAction(int a)
{ {
return a > int(LFUN_LASTACTION); return a > int(LFUN_LASTACTION);
} }
}
void LyXAction::newFunc(kb_action action, string const & name, void LyXAction::newFunc(kb_action action, string const & name,
@ -81,7 +83,7 @@ void LyXAction::init()
unsigned int attrib; unsigned int attrib;
}; };
ev_item items[] = { ev_item const items[] = {
{ LFUN_ACUTE, "accent-acute", "", Noop }, { LFUN_ACUTE, "accent-acute", "", Noop },
{ LFUN_BREVE, "accent-breve", "", Noop }, { LFUN_BREVE, "accent-breve", "", Noop },
{ LFUN_CARON, "accent-caron", "", Noop }, { LFUN_CARON, "accent-caron", "", Noop },
@ -420,13 +422,9 @@ void LyXAction::init()
{ LFUN_NOACTION, "", "", Noop } { LFUN_NOACTION, "", "", Noop }
}; };
int i = 0; for (int i = 0; items[i].action != LFUN_NOACTION; ++i) {
while (items[i].action != LFUN_NOACTION) { newFunc(items[i].action, items[i].name,
newFunc(items[i].action, _(items[i].helpText), items[i].attrib);
items[i].name,
_(items[i].helpText),
items[i].attrib);
++i;
} }
init = true; init = true;
@ -439,14 +437,11 @@ LyXAction::LyXAction()
} }
// Search for an existent pseudoaction, return LFUN_UNKNOWN_ACTION
// if it doesn't exist.
int LyXAction::searchActionArg(kb_action action, string const & arg) const int LyXAction::searchActionArg(kb_action action, string const & arg) const
{ {
arg_map::const_iterator pit = lyx_arg_map.find(action); arg_map::const_iterator pit = lyx_arg_map.find(action);
if (pit == lyx_arg_map.end()) { if (pit == lyx_arg_map.end()) {
// the action does not have any pseudoactions
lyxerr[Debug::ACTION] << "Action " << action lyxerr[Debug::ACTION] << "Action " << action
<< " does not have any pseudo actions." << " does not have any pseudo actions."
<< endl; << endl;
@ -456,7 +451,6 @@ int LyXAction::searchActionArg(kb_action action, string const & arg) const
arg_item::const_iterator aci = pit->second.find(arg); arg_item::const_iterator aci = pit->second.find(arg);
if (aci == pit->second.end()) { if (aci == pit->second.end()) {
// the action does not have any pseudoactions with this arg
lyxerr[Debug::ACTION] lyxerr[Debug::ACTION]
<< "Action " << action << "Action " << action
<< "does not have any pseudoactions with arg " << "does not have any pseudoactions with arg "
@ -464,8 +458,7 @@ int LyXAction::searchActionArg(kb_action action, string const & arg) const
return LFUN_UNKNOWN_ACTION; return LFUN_UNKNOWN_ACTION;
} }
// pseudo action exist lyxerr[Debug::ACTION] << "Pseudoaction exists["
lyxerr[Debug::ACTION] << "Pseudoaction exist["
<< action << '|' << action << '|'
<< arg << "] = " << aci->second << endl; << arg << "] = " << aci->second << endl;
@ -473,8 +466,7 @@ int LyXAction::searchActionArg(kb_action action, string const & arg) const
} }
// Returns a pseudo-action given an action and its argument. int LyXAction::getPseudoAction(kb_action action, string const & arg)
int LyXAction::getPseudoAction(kb_action action, string const & arg) const
{ {
int const psdaction = searchActionArg(action, arg); int const psdaction = searchActionArg(action, arg);
@ -500,14 +492,10 @@ int LyXAction::getPseudoAction(kb_action action, string const & arg) const
} }
// Retrieves the real action and its argument. pair<kb_action, string> LyXAction::retrieveActionArg(int pseudo) const
// perhaps a pair<kb_action, string> should be returned?
kb_action LyXAction::retrieveActionArg(int pseudo, string & arg) const
{ {
arg.erase(); // clear it to be sure.
if (!isPseudoAction(pseudo)) if (!isPseudoAction(pseudo))
return static_cast<kb_action>(pseudo); return make_pair(static_cast<kb_action>(pseudo), string());
pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo); pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo);
@ -515,18 +503,17 @@ kb_action LyXAction::retrieveActionArg(int pseudo, string & arg) const
lyxerr[Debug::ACTION] << "Found the pseudoaction: [" lyxerr[Debug::ACTION] << "Found the pseudoaction: ["
<< pit->second.action << '|' << pit->second.action << '|'
<< pit->second.argument << "]\n"; << pit->second.argument << "]\n";
arg = pit->second.argument; return make_pair(pit->second.action, pit->second.argument);
return pit->second.action;
} else { } else {
lyxerr << "Lyx Error: Unrecognized pseudo-action " lyxerr << "Lyx Error: Unrecognized pseudo-action "
<< pseudo << endl; << pseudo << endl;
return LFUN_UNKNOWN_ACTION; return make_pair(LFUN_UNKNOWN_ACTION, string());
} }
} }
// Returns an action tag from a string. // Returns an action tag from a string.
int LyXAction::LookupFunc(string const & func) const int LyXAction::LookupFunc(string const & func)
{ {
string const func2 = trim(func); string const func2 = trim(func);
if (func2.empty()) return LFUN_NOACTION; if (func2.empty()) return LFUN_NOACTION;
@ -548,56 +535,12 @@ int LyXAction::LookupFunc(string const & func) const
} }
//#ifdef WITH_WARNINGS
//#warning Not working as it should.
//#endif
// I have no clue what is wrong with it... (Lgb)
int LyXAction::getApproxFunc(string const & func) const
// This func should perhaps also be able to return a list of all
// actions that has func as a prefix. That should actually be quite
// easy, just let it return a vector<int> or something.
{
int action = LookupFunc(func);
if (action == LFUN_UNKNOWN_ACTION) {
// func is not an action, but perhaps it is
// part of one...check if it is prefix if one of the
// actions.
// Checking for prefix is not so simple, but
// using a simple bounding function gives
// a similar result. [ale 19981103]
func_map::const_iterator fit =
lyx_func_map.lower_bound(func);
if (fit != lyx_func_map.end()) {
action = fit->second;
}
} else { // Go get the next function
func_map::const_iterator fit =
lyx_func_map.upper_bound(func);
if (fit != lyx_func_map.end()) {
action = fit->second;
}
}
return action;
}
string const LyXAction::getApproxFuncName(string const & func) const
{
int const f = getApproxFunc(func);
// This will return empty string if f isn't an action.
return getActionName(f);
}
string const LyXAction::getActionName(int action) const string const LyXAction::getActionName(int action) const
{ {
kb_action ac; kb_action ac;
string arg; string arg;
boost::tie(ac, arg) = retrieveActionArg(action);
ac = retrieveActionArg(action, arg);
if (!arg.empty()) if (!arg.empty())
arg.insert(0, " "); arg.insert(0, " ");
@ -612,14 +555,13 @@ string const LyXAction::getActionName(int action) const
} }
// Returns one line help associated with a (pseudo)action, i.e. appends
// the argument of the action if necessary
string const LyXAction::helpText(int pseudoaction) const string const LyXAction::helpText(int pseudoaction) const
{ {
string help, arg;
kb_action action; kb_action action;
string arg;
boost::tie(action, arg) = retrieveActionArg(pseudoaction);
action = retrieveActionArg(pseudoaction, arg); string help;
info_map::const_iterator ici = lyx_info_map.find(action); info_map::const_iterator ici = lyx_info_map.find(action);
if (ici != lyx_info_map.end()) { if (ici != lyx_info_map.end()) {

View File

@ -1,4 +1,10 @@
// -*- C++ -*- // -*- C++ -*-
/**
* \file LyXAction.h
* Copyright 1995-2002 the LyX Team
* Read the file COPYING
*/
#ifndef LYXACTION_H #ifndef LYXACTION_H
#define LYXACTION_H #define LYXACTION_H
@ -11,74 +17,67 @@
#include "funcrequest.h" #include "funcrequest.h"
#include <boost/utility.hpp> #include <boost/utility.hpp>
/** This class encapsulates LyX action and user command operations. /**
* This class is a container for LyX actions. It also
* stores and managers "pseudo-actions". Pseudo-actions
* are not part of the kb_action enum, but are created
* dynamically, for encapsulating a real action and an
* argument. They are used for things like the menus.
*/ */
class LyXAction : boost::noncopyable { class LyXAction : boost::noncopyable {
private: private:
/// /// information for an action
struct func_info { struct func_info {
/// /// the action name
string name; string name;
/// /// the func_attrib values set
unsigned int attrib; unsigned int attrib;
/// /// the help text for this action
string helpText; string helpText;
}; };
public: public:
/// /// type for map between a function name and its action
typedef std::map<string, kb_action> func_map; typedef std::map<string, kb_action> func_map;
/// /// type for map between an action and its info
typedef std::map<kb_action, func_info> info_map; typedef std::map<kb_action, func_info> info_map;
/// /// type for a map between a pseudo-action and its stored action/arg
typedef std::map<unsigned int, FuncRequest> pseudo_map; typedef std::map<unsigned int, FuncRequest> pseudo_map;
/// /// map from argument to pseudo-action
typedef std::map<string, unsigned int> arg_item; typedef std::map<string, unsigned int> arg_item;
/// /// map from an action to all its dependent pseudo-actions
typedef std::map<kb_action, arg_item> arg_map; typedef std::map<kb_action, arg_item> arg_map;
/// /// possible "permissions" for an action
enum func_attrib { enum func_attrib {
/// nothing special about this func Noop = 0, //< nothing special about this func
Noop = 0, ReadOnly = 1, //< can be used in RO mode (perhaps this should change)
/// can be used in RO mode (perhaps this should change) NoBuffer = 2, //< Can be used when there is no document open
ReadOnly = 1, // , Argument = 4 //< Requires argument
/// Can be used when there is no document open
NoBuffer = 2,
//Interactive = 2, // Is interactive (requires a GUI)
///
Argument = 4 // Requires argument
//MathOnly = 8, // Only math mode
//EtcEtc = ... // Or other attributes...
}; };
///
LyXAction(); LyXAction();
/** Returns an pseudoaction from a string /**
If you include arguments in func_name, a new psedoaction will be * Returns an pseudoaction from a string
created if needed. */ * If you include arguments in func_name, a new pseudoaction
int LookupFunc(string const & func_name) const; * will be created if needed.
*/
/** Returns an action tag which name is the most similar to a string. int LookupFunc(string const & func_name);
Don't include arguments, they would be ignored. */
int getApproxFunc(string const & func) const;
/** Returns an action name the most similar to a string.
Don't include arguments, they would be ignored. */
string const getApproxFuncName(string const & func) const;
/// Returns a pseudo-action given an action and its argument. /// Returns a pseudo-action given an action and its argument.
int getPseudoAction(kb_action action, string const & arg) const; int getPseudoAction(kb_action action, string const & arg);
/// Retrieves the real action and its argument. /**
kb_action retrieveActionArg(int i, string & arg) const; * Given a pseudo-action, return the real action and
* associated argument
*/
std::pair<kb_action, string> retrieveActionArg(int pseudo) const;
/// Search for an existent pseudoaction, return -1 if it doesn't exist. /// Search for an existent pseudoaction, return -1 if it doesn't exist.
int searchActionArg(kb_action action, string const & arg) const; int searchActionArg(kb_action action, string const & arg) const;
/// Return the name associated with command /// Return the name (and argument) associated with the given (pseudo) action
string const getActionName(int action) const; string const getActionName(int action) const;
/// Return one line help text associated with (pseudo)action /// Return one line help text associated with (pseudo)action
@ -87,33 +86,50 @@ public:
/// True if the command has `flag' set /// True if the command has `flag' set
bool funcHasFlag(kb_action action, func_attrib flag) const; bool funcHasFlag(kb_action action, func_attrib flag) const;
/// iterator across all real actions
typedef func_map::const_iterator const_func_iterator; typedef func_map::const_iterator const_func_iterator;
/// return an iterator to the start of all real actions
const_func_iterator func_begin() const; const_func_iterator func_begin() const;
/// return an iterator to the end of all real actions
const_func_iterator func_end() const; const_func_iterator func_end() const;
private: private:
/// /// populate the action container with our actions
void init(); void init();
/// /// add the given action
void newFunc(kb_action, string const & name, void newFunc(kb_action, string const & name,
string const & helpText, unsigned int attrib); 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 * This is a list of all the LyXFunc names with the
minibuffer or when assigning commands to keys during init. */ * coresponding action number. It is usually only used by the
* minibuffer or when assigning commands to keys during init.
*/
func_map lyx_func_map; 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), * This is a mapping from action number to an object holding
command attributes (ro) */ * info about this action. f.ex. helptext, command name (string),
* command attributes (ro)
*/
info_map lyx_info_map; info_map lyx_info_map;
/** A mapping from the automatically created pseudo action number /**
to the real action and its argument. */ * A mapping from the automatically created pseudo action number
mutable pseudo_map lyx_pseudo_map; * to the real action and its argument.
*/
pseudo_map lyx_pseudo_map;
/** A (multi) mapping from the lyx action to all the generated /**
pseudofuncs and the arguments the action should use. */ * A (multi) mapping from the lyx action to all the generated
mutable arg_map lyx_arg_map; * pseudofuncs and the arguments the action should use.
*/
arg_map lyx_arg_map;
}; };
#endif /// singleton instance
extern LyXAction lyxaction;
#endif // LYXACTION_H

View File

@ -34,7 +34,6 @@
#include "support/lyxfunctional.h" #include "support/lyxfunctional.h"
#include "support/lstrings.h" #include "support/lstrings.h"
extern LyXAction lyxaction;
extern BufferList bufferlist; extern BufferList bufferlist;
using std::endl; using std::endl;

View File

@ -24,7 +24,6 @@
using std::endl; using std::endl;
extern LyXAction lyxaction;
ToolbarDefaults toolbardefaults; ToolbarDefaults toolbardefaults;
namespace { namespace {

View File

@ -1,3 +1,7 @@
2002-08-08 John Levon <levon@movementarian.org>
* Toolbar.C:
2002-08-06 André Poentiz <poenitz@gmx.net> 2002-08-06 André Poentiz <poenitz@gmx.net>
* Screen.C: Honor \show_banner lyxrc setting * Screen.C: Honor \show_banner lyxrc setting

View File

@ -20,9 +20,6 @@
using std::endl; using std::endl;
extern LyXAction lyxaction;
Toolbar::Toolbar(LyXView * o, Dialogs & d, Toolbar::Toolbar(LyXView * o, Dialogs & d,
int x, int y, ToolbarDefaults const &tbd) int x, int y, ToolbarDefaults const &tbd)
: last_textclass_(-1) : last_textclass_(-1)

View File

@ -1,3 +1,7 @@
2002-08-08 John Levon <levon@movementarian.org>
* ControlCommandBuffer.C: LyXAction cleanup
2002-08-07 John Levon <levon@movementarian.org> 2002-08-07 John Levon <levon@movementarian.org>
* ControlSpellchecker.C: fix crash when spellchecker doesn't * ControlSpellchecker.C: fix crash when spellchecker doesn't

View File

@ -24,8 +24,6 @@ using std::back_inserter;
using std::transform; using std::transform;
using std::endl; using std::endl;
extern LyXAction lyxaction;
namespace { namespace {
struct prefix_p { struct prefix_p {

View File

@ -1,3 +1,8 @@
2002-08-08 John Levon <levon@movementarian.org>
* Toolbar_pimpl.C:
* Menubar_pimpl.C: lyxaction cleanup
2002-08-08 John Levon <levon@movementarian.org> 2002-08-08 John Levon <levon@movementarian.org>
* QGraphicsDialog.C: enable rotate * QGraphicsDialog.C: enable rotate

View File

@ -63,7 +63,6 @@ string const getLabel(MenuItem const & mi)
typedef vector<int>::size_type size_type; typedef vector<int>::size_type size_type;
extern boost::scoped_ptr<kb_keymap> toplevel_keymap; extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
extern LyXAction lyxaction;
Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mbe) Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mbe)

View File

@ -36,17 +36,17 @@
using std::endl; using std::endl;
extern LyXAction lyxaction;
namespace { namespace {
QPixmap getIconPixmap(int action) QPixmap getIconPixmap(int action)
{ {
kb_action act;
string arg; string arg;
boost::tie(act, arg) = lyxaction.retrieveActionArg(action);
string const name = lyxaction.getActionName(act);
string xpm_name; string xpm_name;
const kb_action act = lyxaction.retrieveActionArg(action, arg);
string const name = lyxaction.getActionName(act);
if (!arg.empty()) if (!arg.empty())
xpm_name = subst(name + ' ' + arg, ' ','_'); xpm_name = subst(name + ' ' + arg, ' ','_');
else else

View File

@ -1,3 +1,8 @@
2002-08-08 John Levon <levon@movementarian.org>
* Menubar_pimpl.C:
* Toolbar_pimpl.C: lyxaction cleanup
2002-08-08 John Levon <levon@movementarian.org> 2002-08-08 John Levon <levon@movementarian.org>
* forms/form_thesaurus.fd: allow Esc to close dialog * forms/form_thesaurus.fd: allow Esc to close dialog

View File

@ -38,7 +38,6 @@ using std::for_each;
typedef vector<int>::size_type size_type; typedef vector<int>::size_type size_type;
extern boost::scoped_ptr<kb_keymap> toplevel_keymap; extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
extern LyXAction lyxaction;
namespace { namespace {

View File

@ -36,9 +36,9 @@
#include "support/filetools.h" #include "support/filetools.h"
#include "support/lstrings.h" #include "support/lstrings.h"
using std::endl; #include <boost/tuple/tuple.hpp>
extern LyXAction lyxaction; using std::endl;
// some constants // some constants
const int standardspacing = 2; // the usual space between items const int standardspacing = 2; // the usual space between items
@ -251,10 +251,12 @@ extern "C" {
void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height) void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
{ {
string arg;
string xpm_name; string xpm_name;
const kb_action act = lyxaction.retrieveActionArg(action, arg); kb_action act;
string arg;
boost::tie(act, arg) = lyxaction.retrieveActionArg(action);
string const name = lyxaction.getActionName(act); string const name = lyxaction.getActionName(act);
if (!arg.empty()) if (!arg.empty())
xpm_name = subst(name + ' ' + arg, ' ','_'); xpm_name = subst(name + ' ' + arg, ' ','_');

View File

@ -90,6 +90,8 @@
#include "support/path.h" #include "support/path.h"
#include "support/lyxfunctional.h" #include "support/lyxfunctional.h"
#include <boost/tuple/tuple.hpp>
#include <ctime> #include <ctime>
#include <clocale> #include <clocale>
#include <cstdlib> #include <cstdlib>
@ -114,7 +116,6 @@ extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
extern void show_symbols_form(LyXFunc *); extern void show_symbols_form(LyXFunc *);
extern LyXAction lyxaction;
// (alkis) // (alkis)
extern tex_accent_struct get_accent(kb_action action); extern tex_accent_struct get_accent(kb_action action);
@ -275,9 +276,10 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
FuncStatus LyXFunc::getStatus(int ac) const FuncStatus LyXFunc::getStatus(int ac) const
{ {
string argument; kb_action action;
kb_action action = lyxaction.retrieveActionArg(ac, argument); string arg;
return getStatus(FuncRequest(action, argument)); boost::tie(action, arg) = lyxaction.retrieveActionArg(ac);
return getStatus(FuncRequest(action, arg));
} }
@ -703,9 +705,10 @@ void LyXFunc::dispatch(string const & s, bool verbose)
void LyXFunc::dispatch(int ac, bool verbose) void LyXFunc::dispatch(int ac, bool verbose)
{ {
string argument; kb_action action;
kb_action const action = lyxaction.retrieveActionArg(ac, argument); string arg;
dispatch(FuncRequest(action, argument), verbose); boost::tie(action, arg) = lyxaction.retrieveActionArg(ac);
dispatch(FuncRequest(action, arg), verbose);
} }

View File

@ -40,7 +40,6 @@ using std::vector;
class kb_keymap; class kb_keymap;
extern LyXAction lyxaction;
extern boost::scoped_ptr<kb_keymap> toplevel_keymap; extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
namespace { namespace {

View File

@ -34,8 +34,6 @@ using std::max;
using std::endl; using std::endl;
using std::ostream; using std::ostream;
extern LyXAction lyxaction;
namespace toc namespace toc
{ {