+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>
* BufferView2.C: small cleanup
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2001 The LyX Team.
- *
- * ====================================================== */
+/**
+ * \file LyXAction.C
+ * Copyright 1995-2002 the LyX Team
+ * Read the file COPYING
+ */
#include <config.h>
#endif
#include "LyXAction.h"
+
#include "debug.h"
#include "gettext.h"
#include "support/lstrings.h"
+#include <boost/tuple/tuple.hpp>
+
using std::ostream;
using std::endl;
+using std::pair;
+using std::make_pair;
/*
NAMING RULES FOR USER-COMMANDS
8) The end of an object is called `end'.
(May 19 1996, 12:04, RvdK)
- */
+*/
-// These are globals.
LyXAction lyxaction;
-// Small helper function
-inline
-bool isPseudoAction(int a)
+namespace {
+
+/// return true if the given action is a pseudo-action
+inline bool isPseudoAction(int a)
{
return a > int(LFUN_LASTACTION);
}
+}
void LyXAction::newFunc(kb_action action, string const & name,
unsigned int attrib;
};
- ev_item items[] = {
+ ev_item const items[] = {
{ LFUN_ACUTE, "accent-acute", "", Noop },
{ LFUN_BREVE, "accent-breve", "", Noop },
{ LFUN_CARON, "accent-caron", "", Noop },
{ LFUN_NOACTION, "", "", Noop }
};
- int i = 0;
- while (items[i].action != LFUN_NOACTION) {
- newFunc(items[i].action,
- items[i].name,
- _(items[i].helpText),
- items[i].attrib);
- ++i;
+ for (int i = 0; items[i].action != LFUN_NOACTION; ++i) {
+ newFunc(items[i].action, items[i].name,
+ _(items[i].helpText), items[i].attrib);
}
init = true;
}
-// Search for an existent pseudoaction, return LFUN_UNKNOWN_ACTION
-// if it doesn't exist.
int LyXAction::searchActionArg(kb_action action, string const & arg) const
{
arg_map::const_iterator pit = lyx_arg_map.find(action);
if (pit == lyx_arg_map.end()) {
- // the action does not have any pseudoactions
lyxerr[Debug::ACTION] << "Action " << action
<< " does not have any pseudo actions."
<< endl;
arg_item::const_iterator aci = pit->second.find(arg);
if (aci == pit->second.end()) {
- // the action does not have any pseudoactions with this arg
lyxerr[Debug::ACTION]
<< "Action " << action
<< "does not have any pseudoactions with arg "
return LFUN_UNKNOWN_ACTION;
}
- // pseudo action exist
- lyxerr[Debug::ACTION] << "Pseudoaction exist["
+ lyxerr[Debug::ACTION] << "Pseudoaction exists["
<< action << '|'
<< arg << "] = " << aci->second << endl;
}
-// Returns a pseudo-action given an action and its argument.
-int LyXAction::getPseudoAction(kb_action action, string const & arg) const
+int LyXAction::getPseudoAction(kb_action action, string const & arg)
{
int const psdaction = searchActionArg(action, arg);
}
-// Retrieves the real action and its argument.
-// perhaps a pair<kb_action, string> should be returned?
-kb_action LyXAction::retrieveActionArg(int pseudo, string & arg) const
+pair<kb_action, string> LyXAction::retrieveActionArg(int pseudo) const
{
- arg.erase(); // clear it to be sure.
-
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);
lyxerr[Debug::ACTION] << "Found the pseudoaction: ["
<< pit->second.action << '|'
<< pit->second.argument << "]\n";
- arg = pit->second.argument;
- return pit->second.action;
+ return make_pair(pit->second.action, pit->second.argument);
} else {
lyxerr << "Lyx Error: Unrecognized pseudo-action "
<< pseudo << endl;
- return LFUN_UNKNOWN_ACTION;
+ return make_pair(LFUN_UNKNOWN_ACTION, 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);
if (func2.empty()) return LFUN_NOACTION;
}
-//#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
{
kb_action ac;
string arg;
-
- ac = retrieveActionArg(action, arg);
+ boost::tie(ac, arg) = retrieveActionArg(action);
+
if (!arg.empty())
arg.insert(0, " ");
}
-// 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 help, arg;
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);
if (ici != lyx_info_map.end()) {
if (lyxerr.debugging(Debug::ACTION)) {
// -*- C++ -*-
+/**
+ * \file LyXAction.h
+ * Copyright 1995-2002 the LyX Team
+ * Read the file COPYING
+ */
+
#ifndef LYXACTION_H
#define LYXACTION_H
#include "funcrequest.h"
#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 {
private:
- ///
+ /// information for an action
struct func_info {
- ///
+ /// the action name
string name;
- ///
+ /// the func_attrib values set
unsigned int attrib;
- ///
+ /// the help text for this action
string helpText;
};
public:
- ///
+ /// type for map between a function name and its action
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;
- ///
+ /// type for a map between a pseudo-action and its stored action/arg
typedef std::map<unsigned int, FuncRequest> pseudo_map;
- ///
+ /// map from argument to pseudo-action
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;
- ///
+ /// possible "permissions" for an action
enum func_attrib {
- /// nothing special about this func
- Noop = 0,
- /// can be used in RO mode (perhaps this should change)
- ReadOnly = 1, // ,
- /// 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...
+ Noop = 0, //< nothing special about this func
+ ReadOnly = 1, //< can be used in RO mode (perhaps this should change)
+ NoBuffer = 2, //< Can be used when there is no document open
+ Argument = 4 //< Requires argument
};
- ///
LyXAction();
- /** Returns an pseudoaction from a string
- If you include arguments in func_name, a new psedoaction will be
- created if needed. */
- int LookupFunc(string const & func_name) const;
-
- /** Returns an action tag which name is the most similar to a string.
- 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 an pseudoaction from a string
+ * If you include arguments in func_name, a new pseudoaction
+ * will be created if needed.
+ */
+ int LookupFunc(string const & func_name);
/// 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.
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;
/// Return one line help text associated with (pseudo)action
/// True if the command has `flag' set
bool funcHasFlag(kb_action action, func_attrib flag) const;
+ /// iterator across all real actions
typedef func_map::const_iterator const_func_iterator;
+
+ /// return an iterator to the start of all real actions
const_func_iterator func_begin() const;
+
+ /// return an iterator to the end of all real actions
const_func_iterator func_end() const;
+
private:
- ///
+ /// populate the action container with our actions
void init();
- ///
+ /// add the given action
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. */
+ /**
+ * 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) */
+ /**
+ * 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;
+ /**
+ * A mapping from the automatically created pseudo action number
+ * 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.
+ */
+ arg_map lyx_arg_map;
};
-#endif
+/// singleton instance
+extern LyXAction lyxaction;
+
+#endif // LYXACTION_H
#include "support/lyxfunctional.h"
#include "support/lstrings.h"
-extern LyXAction lyxaction;
extern BufferList bufferlist;
using std::endl;
using std::endl;
-extern LyXAction lyxaction;
ToolbarDefaults toolbardefaults;
namespace {
+2002-08-08 John Levon <levon@movementarian.org>
+
+ * Toolbar.C:
+
2002-08-06 André Poentiz <poenitz@gmx.net>
* Screen.C: Honor \show_banner lyxrc setting
using std::endl;
-extern LyXAction lyxaction;
-
-
Toolbar::Toolbar(LyXView * o, Dialogs & d,
int x, int y, ToolbarDefaults const &tbd)
: last_textclass_(-1)
+2002-08-08 John Levon <levon@movementarian.org>
+
+ * ControlCommandBuffer.C: LyXAction cleanup
+
2002-08-07 John Levon <levon@movementarian.org>
* ControlSpellchecker.C: fix crash when spellchecker doesn't
using std::transform;
using std::endl;
-extern LyXAction lyxaction;
-
namespace {
struct prefix_p {
+2002-08-08 John Levon <levon@movementarian.org>
+
+ * Toolbar_pimpl.C:
+ * Menubar_pimpl.C: lyxaction cleanup
+
2002-08-08 John Levon <levon@movementarian.org>
* QGraphicsDialog.C: enable rotate
typedef vector<int>::size_type size_type;
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
-extern LyXAction lyxaction;
Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mbe)
using std::endl;
-extern LyXAction lyxaction;
-
namespace {
QPixmap getIconPixmap(int action)
{
+ kb_action act;
string arg;
+ boost::tie(act, arg) = lyxaction.retrieveActionArg(action);
+
+ string const name = lyxaction.getActionName(act);
string xpm_name;
- const kb_action act = lyxaction.retrieveActionArg(action, arg);
- string const name = lyxaction.getActionName(act);
if (!arg.empty())
xpm_name = subst(name + ' ' + arg, ' ','_');
else
+2002-08-08 John Levon <levon@movementarian.org>
+
+ * Menubar_pimpl.C:
+ * Toolbar_pimpl.C: lyxaction cleanup
+
2002-08-08 John Levon <levon@movementarian.org>
* forms/form_thesaurus.fd: allow Esc to close dialog
typedef vector<int>::size_type size_type;
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
-extern LyXAction lyxaction;
namespace {
#include "support/filetools.h"
#include "support/lstrings.h"
+#include <boost/tuple/tuple.hpp>
+
using std::endl;
-extern LyXAction lyxaction;
-
// some constants
const int standardspacing = 2; // the usual space between items
const int sepspace = 6; // extra space
void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
{
- string arg;
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);
if (!arg.empty())
xpm_name = subst(name + ' ' + arg, ' ','_');
#include "support/path.h"
#include "support/lyxfunctional.h"
+#include <boost/tuple/tuple.hpp>
+
#include <ctime>
#include <clocale>
#include <cstdlib>
extern void show_symbols_form(LyXFunc *);
-extern LyXAction lyxaction;
// (alkis)
extern tex_accent_struct get_accent(kb_action action);
FuncStatus LyXFunc::getStatus(int ac) const
{
- string argument;
- kb_action action = lyxaction.retrieveActionArg(ac, argument);
- return getStatus(FuncRequest(action, argument));
+ kb_action action;
+ string arg;
+ boost::tie(action, arg) = lyxaction.retrieveActionArg(ac);
+ return getStatus(FuncRequest(action, arg));
}
void LyXFunc::dispatch(int ac, bool verbose)
{
- string argument;
- kb_action const action = lyxaction.retrieveActionArg(ac, argument);
- dispatch(FuncRequest(action, argument), verbose);
+ kb_action action;
+ string arg;
+ boost::tie(action, arg) = lyxaction.retrieveActionArg(ac);
+ dispatch(FuncRequest(action, arg), verbose);
}
class kb_keymap;
-extern LyXAction lyxaction;
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
namespace {
using std::endl;
using std::ostream;
-extern LyXAction lyxaction;
-
namespace toc
{