]> git.lyx.org Git - features.git/commitdiff
some minor lyxaction cleanup
authorJohn Levon <levon@movementarian.org>
Thu, 8 Aug 2002 22:03:30 +0000 (22:03 +0000)
committerJohn Levon <levon@movementarian.org>
Thu, 8 Aug 2002 22:03:30 +0000 (22:03 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4911 a592a061-630c-0410-9148-cb99ea01b6c8

18 files changed:
src/ChangeLog
src/LyXAction.C
src/LyXAction.h
src/MenuBackend.C
src/ToolbarDefaults.C
src/frontends/ChangeLog
src/frontends/Toolbar.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlCommandBuffer.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/Menubar_pimpl.C
src/frontends/qt2/Toolbar_pimpl.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/Menubar_pimpl.C
src/frontends/xforms/Toolbar_pimpl.C
src/lyxfunc.C
src/lyxrc.C
src/toc.C

index 7cf6b7b4d37d41b65a93f1ca2d0484d74395f5f4..58005e0504f538c4923f88fc73c27a237c7583f4 100644 (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>
 
        * BufferView2.C: small cleanup
index 1163df80818de27501d4671668f5347761a91381..03f15b7b3fa1a2ccdb669d3578f7da7554c89cac 100644 (file)
@@ -1,12 +1,8 @@
-/* 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
@@ -37,18 +38,19 @@ using std::endl;
      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,
@@ -81,7 +83,7 @@ void LyXAction::init()
                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 },
@@ -420,13 +422,9 @@ void LyXAction::init()
                { 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;
@@ -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
 {
        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;
@@ -456,7 +451,6 @@ int LyXAction::searchActionArg(kb_action action, string const & arg) const
        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 "
@@ -464,8 +458,7 @@ int LyXAction::searchActionArg(kb_action action, string const & arg) const
                return LFUN_UNKNOWN_ACTION;
        }
 
-       // pseudo action exist
-       lyxerr[Debug::ACTION] << "Pseudoaction exist["
+       lyxerr[Debug::ACTION] << "Pseudoaction exists["
                              << action << '|'
                              << 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) const
+int LyXAction::getPseudoAction(kb_action action, string const & 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.
-// 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);
 
@@ -515,18 +503,17 @@ kb_action LyXAction::retrieveActionArg(int pseudo, string & arg) const
                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;
@@ -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
 {
        kb_action ac;
        string arg;
-
-       ac = retrieveActionArg(action, arg);
+       boost::tie(ac, arg) = retrieveActionArg(action);
        if (!arg.empty())
                arg.insert(0, " ");
 
@@ -612,15 +555,14 @@ 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 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)) {
index 9b93c2744a40d38fe95072293385f02dc30fe083..a2672a07eb8b310673b6ebbfc4b19c643911a585 100644 (file)
@@ -1,4 +1,10 @@
 // -*- 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
@@ -87,33 +86,50 @@ public:
        /// 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
index f88905f28cfa543e0c094243025b45aa860d2983..71ded3f708cfed01ed578778f46fb390d42e9835 100644 (file)
@@ -34,7 +34,6 @@
 #include "support/lyxfunctional.h"
 #include "support/lstrings.h"
 
-extern LyXAction lyxaction;
 extern BufferList bufferlist;
 
 using std::endl;
index 73d9e898b86a80c3751c010956a56d904e78de56..af42a4051ae0e3325ee89fdea5577d43cd0d0816 100644 (file)
@@ -24,7 +24,6 @@
 
 using std::endl;
 
-extern LyXAction lyxaction;
 ToolbarDefaults toolbardefaults;
 
 namespace {
index b2167379d426c4958ad4a4b5b79ca850668bc211..c78464eb2b8cd4c136a133362587a463afe84bad 100644 (file)
@@ -1,3 +1,7 @@
+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
index ad2d95313a358f4891f6101143f17aa70944cce4..c544bb3f916cc711daf47cbc28fd01a7081bf984 100644 (file)
@@ -20,9 +20,6 @@
 
 using std::endl;
 
-extern LyXAction lyxaction;
-
-
 Toolbar::Toolbar(LyXView * o, Dialogs & d,
                 int x, int y, ToolbarDefaults const &tbd)
        : last_textclass_(-1)
index 0e8f029cb8a80f0ef36c4ba04e85d6393dcd1113..384d656a38dcf5d72040991da9fc19f796dfcbe3 100644 (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>
 
        * ControlSpellchecker.C: fix crash when spellchecker doesn't
index 302c2721c32e62f4adbe20cdadf2018a669d842c..f8fd58f9d5bf5f0d4f7cc6f1ef064aa97fcaf5b8 100644 (file)
@@ -24,8 +24,6 @@ using std::back_inserter;
 using std::transform;
 using std::endl;
  
-extern LyXAction lyxaction;
 namespace {
  
 struct prefix_p {
index 80b58c6614382e58b3bd9e7f111e609e5b7b9130..526a10ca45f4a1e3353096b232c4bfc0757871fe 100644 (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>
 
        * QGraphicsDialog.C: enable rotate
index 6d9cfa47c7feed9969767a26813da03709bc825c..afd9da20e9a7142f88c4d517ca82af2298ec6670 100644 (file)
@@ -63,7 +63,6 @@ string const getLabel(MenuItem const & mi)
 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) 
index deee5abc6c7027c8e32ad678b723fdaa99c4e706..ff340b90f2d83eb85ef0023e7a5fc385542256b4 100644 (file)
  
 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 
index 0f140ca8071e8dfee04882c2af0cfaa66e970a48..c902fd66f0f3a734a84ba29f6b9fbf9b91e272c2 100644 (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>
 
        * forms/form_thesaurus.fd: allow Esc to close dialog
index f820fb938d34f73a394b93f27b99e88086ca63ac..9538925585a1db1b247d9a03d3ec3a06bacbb085 100644 (file)
@@ -38,7 +38,6 @@ using std::for_each;
 typedef vector<int>::size_type size_type;
 
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
-extern LyXAction lyxaction;
 
 namespace {
 
index 2d69e24bb5fbbebd3c092232d86a2b21ff41d3ad..501531d7e2f19132060272125328fc8d39c67e2b 100644 (file)
 #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
@@ -251,10 +251,12 @@ extern "C" {
 
 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, ' ','_');
index d301877e395fbff4ef4dbc8fe5814844b45b73bd..53b30fbb43a85186fdfe778fd9c63a7cd2079a88 100644 (file)
@@ -90,6 +90,8 @@
 #include "support/path.h"
 #include "support/lyxfunctional.h"
 
+#include <boost/tuple/tuple.hpp>
 #include <ctime>
 #include <clocale>
 #include <cstdlib>
@@ -114,7 +116,6 @@ extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
 extern void show_symbols_form(LyXFunc *);
 
-extern LyXAction lyxaction;
 // (alkis)
 extern tex_accent_struct get_accent(kb_action action);
 
@@ -275,9 +276,10 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
 
 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));
 }
 
 
@@ -703,9 +705,10 @@ void LyXFunc::dispatch(string const & s, bool verbose)
 
 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);
 }
 
 
index eef41ae2f82d4e608a98ed3d8bf8d1f78092231e..809f71ee64d007d2a676e2ca3233df6ce5bbcf15 100644 (file)
@@ -40,7 +40,6 @@ using std::vector;
 
 class kb_keymap;
 
-extern LyXAction lyxaction;
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
 namespace {
index e0398fb09d208bbf1f4032d86938a17ea6300169..8bca58c227fcceff53274c1b58a231907cee37a1 100644 (file)
--- a/src/toc.C
+++ b/src/toc.C
@@ -34,8 +34,6 @@ using std::max;
 using std::endl;
 using std::ostream;
 
-extern LyXAction lyxaction;
-
 namespace toc
 {