]> git.lyx.org Git - features.git/commitdiff
more action work
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 21 Sep 2003 23:00:47 +0000 (23:00 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 21 Sep 2003 23:00:47 +0000 (23:00 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7801 a592a061-630c-0410-9148-cb99ea01b6c8

22 files changed:
src/BufferView_pimpl.C
src/ChangeLog
src/LyXAction.C
src/LyXAction.h
src/MenuBackend.C
src/ToolbarBackend.C
src/boost.C
src/buffer.C
src/buffer.h
src/cursor.C
src/frontends/gtk/GMenubar.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/QLPopupMenu.C
src/funcrequest.C
src/funcrequest.h
src/kbmap.C
src/kbmap.h
src/kbsequence.C
src/kbsequence.h
src/lyx_main.C
src/lyxfunc.C
src/paragraph.C

index c1e05f05cedb625c3d68ddb04699b0e5264192e2..9fd3e0646498a8beffdc083d5c742da3136585e3 100644 (file)
@@ -1324,7 +1324,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                ev.errorMessage(N_("Unknown function!"));
                break;
 
-       default:        
+       default:
                return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_));
        } // end of switch
 
index 8ca3dc7d59ff62852fb37d742c35f82b7579ddc9..d71458e59293d55539dfc50340192428f5e16b9f 100644 (file)
@@ -1,3 +1,47 @@
+2003-09-22  Lars Gullik Bjønnes  <larsbj@gullik.net>
+
+       * lyxfunc.C (processKeySym): adjust
+       (dispatch): adjust
+       (dispatch): change arg name from ev to func, adjust
+       (sendDispatchMessage): ditto
+
+       * lyx_main.C (defaultKeyBindings): adjust keybindings
+       (deadKeyBindings): ditto
+
+       * kbsequence.C (addkey): return a FuncRequest
+
+       * kbmap.h (kb_key): struct var FuncRequest instead of int action. 
+
+       * kbmap.C (bind): take a FuncRequest as arg, adjust
+       (read): adjust
+       (lookup): adjust
+       (defkey): change to take a FuncRequest as arg, adjust
+       (findbinding): take a FuncRequest as arg, adjust. 
+
+       * funcrequest.h (operator=): added
+
+       * funcrequest.C (FuncRequest): default kb_action changed from
+       LFUN_UNKNOWN_ACTION to LFUN_NO_ACTION
+
+       * buffer.C (dispatch): simplify
+       (dispatch): adjust to take a FuncRequest as arg, adjust
+
+       * boost.C (assertion_failed): change assertion message slightly
+
+       * ToolbarBackend.C (read): simplify
+
+       * MenuBackend.C (binding): adjust call to findbinding, add a
+       message if no binding is found.
+       (read): simplify
+       (expandToc): correct by adding a empty FuncRequest
+
+       * LyXAction.C: include <boost/assert.hpp>
+       (isPseudoAction): delete function
+       (LookupFunc): change name to...
+       (lookupFunc): this. change return type to FuncRequest.
+       (getActionName): take kb_action as arg, simplify
+       (funcHasFlag): add an assert, simplify.
+
 2003-09-21  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * toc.C (action): return a FuncRequest, simplify
index a6489053d62a78a797dccff7016a582e0ad38852..d7eee1b91e03e92acbb4571e7c306c1006bebe44 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "support/lstrings.h"
 
+#include <boost/assert.hpp>
+
 using lyx::support::split;
 using lyx::support::trim;
 
@@ -47,16 +49,6 @@ using std::ostream;
 
 LyXAction lyxaction;
 
-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)
@@ -345,29 +337,27 @@ LyXAction::LyXAction()
 
 
 // Returns an action tag from a string.
-kb_action LyXAction::LookupFunc(string const & func)
+FuncRequest LyXAction::lookupFunc(string const & func) const
 {
        string const func2 = trim(func);
-       if (func2.empty()) return LFUN_NOACTION;
 
-       // split action and arg
-       string actstr;
-       string const argstr = split(func2, actstr, ' ');
-       lyxerr[Debug::ACTION] << "Action: " << actstr << '\n'
-                             << "Arg   : " << argstr << endl;
+       if (func2.empty()) {
+               return FuncRequest(LFUN_NOACTION);
+       }
+
+       string cmd;
+       string const arg = split(func2, cmd, ' ');
 
-       func_map::const_iterator fit = lyx_func_map.find(actstr);
+       func_map::const_iterator fit = lyx_func_map.find(cmd);
 
-       return fit != lyx_func_map.end() ? fit->second : LFUN_UNKNOWN_ACTION;
+       return fit != lyx_func_map.end() ? FuncRequest(fit->second, arg) : FuncRequest(LFUN_UNKNOWN_ACTION);
 }
 
 
-string const LyXAction::getActionName(int action) const
+string const LyXAction::getActionName(kb_action action) const
 {
-       info_map::const_iterator const it = lyx_info_map.find(kb_action(action));
-       if (it != lyx_info_map.end())
-               return it->second.name;
-       return string();
+       info_map::const_iterator const it = lyx_info_map.find(action);
+       return it != lyx_info_map.end() ? it->second.name : string();
 }
 
 
@@ -376,14 +366,9 @@ bool LyXAction::funcHasFlag(kb_action action,
 {
        info_map::const_iterator ici = lyx_info_map.find(action);
 
-       if (ici != lyx_info_map.end()) {
-               return ici->second.attrib & flag;
-       } else {
-               // it really should exist, but...
-               lyxerr << "LyXAction::funcHasFlag: "
-                       "No info about kb_action: " << action << '\n';
-               return false;
-       }
+       BOOST_ASSERT(ici != lyx_info_map.end());
+
+       return ici->second.attrib & flag;
 }
 
 
index d59666d698bfdf9041f54d654272fcc2693c6efa..3e0241acbd4ca124a50c4aeee7d679344be69c92 100644 (file)
@@ -60,10 +60,10 @@ public:
         * If you include arguments in func_name, a new pseudoaction
         * will be created if needed.
         */
-       kb_action LookupFunc(string const & func_name);
+       FuncRequest lookupFunc(string const & func_name) const;
 
        /// Return the name (and argument) associated with the given (pseudo) action
-       string const getActionName(int action) const;
+       string const getActionName(kb_action action) const;
 
        /// True if the command has `flag' set
        bool funcHasFlag(kb_action action, func_attrib flag) const;
index 7c6d0363705be48d57edebc622876a5b125b086b..d3b9e8a205f3bbc2df90f7c86d4d2cb7ad384a4e 100644 (file)
@@ -115,12 +115,17 @@ string const MenuItem::binding() const
 
        // Get the keys bound to this action, but keep only the
        // first one later
-       string bindings = toplevel_keymap->findbinding(func_.action);
+       string bindings = toplevel_keymap->findbinding(func_);
 
        if (!bindings.empty()) {
                return bindings.substr(1, bindings.find(']') - 1);
-       } else
+       } else {
+               lyxerr << "No bindings for "
+                      << lyxaction.getActionName(func_.action)
+                      << '(' << func_.argument << ')' << endl;
                return string();
+       }
+
 }
 
 
@@ -238,20 +243,8 @@ Menu & Menu::read(LyXLex & lex)
                        string const name = _(lex.getString());
                        lex.next(true);
                        string const command = lex.getString();
-                       string::size_type sp = command.find(' ');
-                       if (sp != string::npos) {
-                               string const cmd = command.substr(0, sp);
-                               string const arg =command.substr(sp + 1,
-                                                                string::npos);
-                               kb_action act = lyxaction.LookupFunc(cmd);
-                               add(MenuItem(MenuItem::Command, name,
-                                            FuncRequest(act, arg), optional));
-                       } else {
-                               kb_action act = lyxaction.LookupFunc(command);
-                               add(MenuItem(MenuItem::Command, name,
-                                            FuncRequest(act), optional));
-                       }
-
+                       FuncRequest func = lyxaction.lookupFunc(command);
+                       add(MenuItem(MenuItem::Command, name, func, optional));
                        optional = false;
                        break;
                }
@@ -620,7 +613,8 @@ void expandToc(Menu & tomenu, LyXView const * view)
        cit = toc_list.find("TOC");
        if (cit == end) {
                tomenu.add(MenuItem(MenuItem::Command,
-                                   _("No Table of contents")),
+                                   _("No Table of contents"),
+                                   FuncRequest()),
                           view);
        } else {
                expandToc2(tomenu, cit->second, 0, cit->second.size(), 0);
index 8d91fca37647ff2857e27d577960b9d440763f4c..01cad0b86b886240f6ae501aa18297975547540f 100644 (file)
@@ -93,26 +93,10 @@ void ToolbarBackend::read(LyXLex & lex)
                                lyxerr[Debug::PARSER]
                                        << "ToolbarBackend::read TO_ADD func: `"
                                        << func_arg << '\'' << endl;
-                               // Split func_arg in function and arg.
-                               string::size_type sp = func_arg.find(' ');
-                               if (sp != string::npos) {
-
-                                       string const func =
-                                               func_arg.substr(0, sp);
-                                       string const arg =
-                                            func_arg.substr(sp + 1,
-                                                            string::npos);
-
-                                       kb_action const tf =
-                                               lyxaction.LookupFunc(func);
-
-                                       add(tb, FuncRequest(tf, arg), tooltip);
-                               } else {
-                                       kb_action const tf = lyxaction.LookupFunc(func_arg);
-                                       add(tb, FuncRequest(tf), tooltip);
-
-                               }
 
+                               FuncRequest func =
+                                       lyxaction.lookupFunc(func_arg);
+                               add(tb, func, tooltip);
                        }
                        break;
 
index b6b4ae38ceb09d71545ffa5da396e1d225aa9bec..440b4ffd931aa6cd99d44b0e8c1d370b5eab121a 100644 (file)
@@ -49,8 +49,9 @@ void emergencyCleanup()
 void assertion_failed(char const * expr, char const * function,
                      char const * file, long line)
 {
-       lyxerr << "Assertion triggered in " << function << " by \"" <<
-               expr << " in file " << file << ":" << line << endl;
+       lyxerr << "Assertion triggered in " << function
+              << " by failing check \"" << expr << "\""
+              << " in file " << file << ":" << line << endl;
        emergencyCleanup();
        lyx::support::abort();
 }
index 2a080bc442143dce21eaed75a66ac8a432f47fb6..3d3fb2c897d82ef602725b993ab4be1232d7d933 100644 (file)
@@ -22,6 +22,7 @@
 #include "errorlist.h"
 #include "exporter.h"
 #include "format.h"
+#include "funcrequest.h"
 #include "gettext.h"
 #include "iterators.h"
 #include "language.h"
@@ -2199,22 +2200,17 @@ void Buffer::markDepClean(string const & name)
 
 bool Buffer::dispatch(string const & command, bool * result)
 {
-       // Split command string into command and argument
-       string cmd;
-       string line = ltrim(command);
-       string const arg = trim(split(line, cmd, ' '));
-
-       return dispatch(lyxaction.LookupFunc(cmd), arg, result);
+       return dispatch(lyxaction.lookupFunc(command), result);
 }
 
 
-bool Buffer::dispatch(int action, string const & argument, bool * result)
+bool Buffer::dispatch(FuncRequest const & func, bool * result)
 {
        bool dispatched = true;
 
-       switch (action) {
+       switch (func.action) {
                case LFUN_EXPORT: {
-                       bool const tmp = Exporter::Export(this, argument, false);
+                       bool const tmp = Exporter::Export(this, func.argument, false);
                        if (result)
                                *result = tmp;
                        break;
index 4bd9f8ebb5e00179e44e6006935e9260c5f9faf2..3e8ab31b8580d3e406001cc3a7456cbe5cc2d7bd 100644 (file)
@@ -31,6 +31,7 @@
 
 class BufferParams;
 class ErrorItem;
+class FuncRequest;
 class LyXFont;
 class LyXLex;
 class LyXRC;
@@ -75,7 +76,7 @@ public:
        bool dispatch(string const & command, bool * result = 0);
 
        /// Maybe we know the function already by number...
-       bool dispatch(int ac, string const & argument, bool * result = 0);
+       bool dispatch(FuncRequest const & func, bool * result = 0);
 
        /// Load the autosaved file.
        void loadAutoSaveFile();
index 11070ca67f0d6b0b7f9a78cdd9b6223a11ebe08a..fb07ee137d4007d4700556de7176dcd3f318f3ca 100644 (file)
@@ -38,7 +38,7 @@ void buildCursor(Cursor & cursor, BufferView & bv)
        lyxerr << "\nbuildCursor: " << inset << std::endl;
        if (!inset)
                return;
-       
+
        inset = inset->getLockingInset();
 
        bool ok = false;
@@ -47,7 +47,7 @@ void buildCursor(Cursor & cursor, BufferView & bv)
        for ( ; pit != end && !ok; ++pit) {
                InsetList::iterator     it = pit->insetlist.begin();
                InsetList::iterator     iend = pit->insetlist.end();
-               for ( ; it != iend && !ok; ++it) 
+               for ( ; it != iend && !ok; ++it)
                        if (it->inset == inset || it->inset == inset->owner())
                                ok = true;
        }
@@ -57,7 +57,7 @@ void buildCursor(Cursor & cursor, BufferView & bv)
                return;
        }
 
-       vector<ParagraphList::iterator> pits; 
+       vector<ParagraphList::iterator> pits;
        vector<ParagraphList const *>   plists;
        vector<LyXText *>               texts;
 /*
index ac1daf27f30788119178a77265c6b5a53ee415cf..f1677cf736a70f2037f2885ea049f067f7b7a078 100644 (file)
@@ -179,11 +179,11 @@ void GMenubar::onSubMenuActivate(MenuItem const * item,
                        break;
                case MenuItem::Command:
                {
+                       #warning Bindings are not inserted into the menu labels here. (Lgb)
                        FuncStatus const flag =
                                view_->getLyXFunc().getStatus(i->func());
-                       bool on, off;
-                       on = flag.onoff(true);
-                       off = flag.onoff(false);
+                       bool on = flag.onoff(true);
+                       bool off = flag.onoff(false);
 
                        if (on || off) {
                                gmenu->items().push_back(
index d0c61fc0cdab2f75dc8f18c6ce8abf6431cdb52d..7cfdd749308eb7c0893a351d9014cfba09916c7b 100644 (file)
@@ -1,7 +1,12 @@
+2003-09-22  Lars Gullik Bjønnes  <larsbj@gullik.net>
+
+       * QLPopupMenu.C (getLabel): fix so that bindings are added even if
+       shortcut is missing.
+
 2003-09-21  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * QtView.C (activated): change to take a FuncRequest, not a slot
-       anymore. 
+       anymore.
 
        * QLToolbar.C (update): adjust
        (add): change to take a FuncRequest
index 662f766cdcefec222aab764443b5b96fd741cdcc..5f8bb90234dc408ecc70dd1aa3f95c96838dce10 100644 (file)
@@ -34,13 +34,11 @@ string const getLabel(MenuItem const & mi)
        string const shortcut = mi.shortcut();
        string label = subst(mi.label(), "&", "&&");
 
-       if (shortcut.empty())
-               return label;
-
-       string::size_type pos = label.find(shortcut);
-       if (pos == string::npos)
-               return label;
-       label.insert(pos, 1, '&');
+       if (!shortcut.empty()) {
+               string::size_type pos = label.find(shortcut);
+               if (pos != string::npos)
+                       label.insert(pos, 1, '&');
+       }
 
        if (mi.kind() == MenuItem::Command) {
                string const binding(mi.binding());
index 6192a79f57ab7bce0e1e29cdb241497963fff500..18e8ed01bc2ff17232ab3e135ab3d4508dbdb8c2 100644 (file)
@@ -25,7 +25,7 @@ using std::vector;
 
 
 FuncRequest::FuncRequest()
-       : view_(0), action(LFUN_UNKNOWN_ACTION), x(0), y(0), button_(mouse_button::none)
+       : view_(0), action(LFUN_NOACTION), x(0), y(0), button_(mouse_button::none)
 {}
 
 
index 439671b7803bc97d876271efa5082208c4386116..8a1d5acc01259e69702cb186d5074735c9fc7ee0 100644 (file)
@@ -75,4 +75,11 @@ public:  // should be private, too...
        mouse_button::state button_;
 };
 
+
+inline
+bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
+{
+       return lhs.action == rhs.action && lhs.argument == rhs.argument;
+}
+
 #endif // FUNCREQUEST_H
index e68e62eb0c1a7cad2fb29939b46612e2cd3ba281..1d7839cf27d051ad7d692023b46d657b0ca950a5 100644 (file)
@@ -27,6 +27,7 @@
 using std::endl;
 using lyx::support::i18nLibFileSearch;
 
+
 string const kb_keymap::printKeysym(LyXKeySymPtr key,
                                    key_modifier::state mod)
 {
@@ -52,19 +53,19 @@ string const kb_keymap::printKey(kb_key const & key) const
 }
 
 
-string::size_type kb_keymap::bind(string const & seq, int action)
+string::size_type kb_keymap::bind(string const & seq, FuncRequest const & func)
 {
        if (lyxerr.debugging(Debug::KBMAP)) {
                lyxerr << "BIND: Sequence `"
                       << seq << "' Action `"
-                      << action << '\'' << endl;
+                      << func.action << '\'' << endl;
        }
 
        kb_sequence k(0, 0);
 
        string::size_type const res = k.parse(seq);
        if (res == string::npos) {
-               defkey(&k, action);
+               defkey(&k, func);
        } else {
                lyxerr[Debug::KBMAP] << "Parse error at position " << res
                                     << " in key sequence '" << seq << "'."
@@ -137,15 +138,15 @@ bool kb_keymap::read(string const & bind_file)
                                break;
                        }
 
-                       int action = lyxaction.LookupFunc(cmd);
-                       if (!action == LFUN_UNKNOWN_ACTION) {
+                       FuncRequest func = lyxaction.lookupFunc(cmd);
+                       if (func. action == LFUN_UNKNOWN_ACTION) {
                                lexrc.printError("BN_BIND: Unknown LyX"
                                                 " function `$$Token'");
                                error = true;
                                break;
                        }
 
-                       bind(seq, kb_action(action));
+                       bind(seq, func);
                        break;
                }
                case BN_BINDFILE:
@@ -169,13 +170,16 @@ bool kb_keymap::read(string const & bind_file)
 }
 
 
-int kb_keymap::lookup(LyXKeySymPtr key,
-                     key_modifier::state mod, kb_sequence * seq) const
+FuncRequest const &
+kb_keymap::lookup(LyXKeySymPtr key,
+                 key_modifier::state mod, kb_sequence * seq) const
 {
+       static FuncRequest const unknown(LFUN_UNKNOWN_ACTION);
+
        if (table.empty()) {
                seq->curmap = seq->stdmap;
                seq->mark_deleted();
-               return LFUN_UNKNOWN_ACTION;
+               return unknown;
        }
 
        Table::const_iterator end = table.end();
@@ -189,12 +193,13 @@ int kb_keymap::lookup(LyXKeySymPtr key,
                        if (cit->table.get()) {
                                // this is a prefix key - set new map
                                seq->curmap = cit->table.get();
-                               return LFUN_PREFIX;
+                               static FuncRequest prefix(LFUN_PREFIX);
+                               return prefix;
                        } else {
                                // final key - reset map
                                seq->curmap = seq->stdmap;
                                seq->mark_deleted();
-                               return cit->action;
+                               return cit->func;
                        }
                }
        }
@@ -202,7 +207,8 @@ int kb_keymap::lookup(LyXKeySymPtr key,
        // error - key not found:
        seq->curmap = seq->stdmap;
        seq->mark_deleted();
-       return LFUN_UNKNOWN_ACTION;
+
+       return unknown;
 }
 
 
@@ -218,7 +224,8 @@ string const kb_keymap::print() const
 }
 
 
-void kb_keymap::defkey(kb_sequence * seq, int action, unsigned int r)
+void kb_keymap::defkey(kb_sequence * seq,
+                      FuncRequest const & func, unsigned int r)
 {
        LyXKeySymPtr code = seq->sequence[r];
        if (!code->isOK())
@@ -243,7 +250,7 @@ void kb_keymap::defkey(kb_sequence * seq, int action, unsigned int r)
                                if (it->table.get()) {
                                        it->table.reset();
                                }
-                               it->action = action;
+                               it->func = func;
                                return;
                        } else if (!it->table.get()) {
                                lyxerr << "Error: New binding for '" << seq->print()
@@ -251,7 +258,7 @@ void kb_keymap::defkey(kb_sequence * seq, int action, unsigned int r)
                                               << endl;
                                return;
                        } else {
-                               it->table->defkey(seq, action, r + 1);
+                               it->table->defkey(seq, func, r + 1);
                                return;
                        }
                }
@@ -261,18 +268,19 @@ void kb_keymap::defkey(kb_sequence * seq, int action, unsigned int r)
        newone->code = code;
        newone->mod = seq->modifiers[r];
        if (r + 1 == seq->length()) {
-               newone->action = action;
+               newone->func = func;
                newone->table.reset();
                return;
        } else {
                newone->table.reset(new kb_keymap);
-               newone->table->defkey(seq, action, r + 1);
+               newone->table->defkey(seq, func, r + 1);
                return;
        }
 }
 
 
-string const kb_keymap::findbinding(int act, string const & prefix) const
+string const kb_keymap::findbinding(FuncRequest const & func,
+                                   string const & prefix) const
 {
        string res;
        if (table.empty()) return res;
@@ -281,15 +289,16 @@ string const kb_keymap::findbinding(int act, string const & prefix) const
        for (Table::const_iterator cit = table.begin();
            cit != end; ++cit) {
                if (cit->table.get()) {
-                       res += cit->table->findbinding(act,
+                       res += cit->table->findbinding(func,
                                                       prefix
                                                       + printKey((*cit))
                                                       + ' ');
-               } else if (cit->action == act) {
+               } else if (cit->func == func) {
                        res += '[';
                        res += prefix + printKey((*cit));
                        res += "] ";
                }
        }
+
        return res;
 }
index 38516d8644bc512fbab831eab05721cd7bd9e8da..40c1b3847cfd760cb757fb1666e55b67f83ae0fa 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef KBMAP_H
 #define KBMAP_H
 
+#include "funcrequest.h"
+
 #include "frontends/key_state.h"
 
 #include <boost/shared_ptr.hpp>
@@ -33,10 +35,10 @@ public:
         * occurs.
         * See kb_sequence::parse for the syntax of the seq string
         */
-       string::size_type bind(string const & seq, int action);
+       string::size_type bind(string const & seq, FuncRequest const & func);
 
        // Parse a bind file
-       bool kb_keymap::read(string const & bind_file);
+       bool read(string const & bind_file);
 
        /// print all available keysyms
        string const print() const;
@@ -50,11 +52,12 @@ public:
         * @param seq the current key sequence so far
         * @return the action / LFUN_PREFIX / LFUN_UNKNOWN_ACTION
         */
-       int lookup(LyXKeySymPtr key,
-                  key_modifier::state mod, kb_sequence * seq) const;
+       FuncRequest const &
+       lookup(LyXKeySymPtr key,
+              key_modifier::state mod, kb_sequence * seq) const;
 
        /// Given an action, find all keybindings.
-       string const findbinding(int action,
+       string const findbinding(FuncRequest const & func,
                                 string const & prefix = string()) const;
 
        /**
@@ -80,14 +83,15 @@ private:
                boost::shared_ptr<kb_keymap> table;
 
                /// Action for !prefix keys
-               int action;
+               FuncRequest func;
        };
 
        /**
         * Define an action for a key sequence.
         * @param r internal recursion level
         */
-       void defkey(kb_sequence * seq, int action, unsigned int r = 0);
+       void defkey(kb_sequence * seq, FuncRequest const & func,
+                   unsigned int r = 0);
 
        ///  Returns a string of the given key
        string const printKey(kb_key const & key) const;
index dc4fc71b9c7f55b2df25238a95fc865b961db51f..2cae7938db17f0f892c18f35896030cc78a2c15a 100644 (file)
@@ -24,8 +24,9 @@
 using std::make_pair;
 
 
-int kb_sequence::addkey(LyXKeySymPtr key,
-                       key_modifier::state mod, key_modifier::state nmod)
+FuncRequest const &
+kb_sequence::addkey(LyXKeySymPtr key,
+                   key_modifier::state mod, key_modifier::state nmod)
 {
        // adding a key to a deleted sequence
        // starts a new sequence
@@ -42,7 +43,8 @@ int kb_sequence::addkey(LyXKeySymPtr key,
                return curmap->lookup(key, mod, this);
        }
 
-       return LFUN_UNKNOWN_ACTION;
+       static FuncRequest unknown(LFUN_UNKNOWN_ACTION);
+       return unknown;
 }
 
 
index 8b090cf8ab2462aa3fc7021b4ace2f5362ab0197..5bb5139862f93bddd4650c5d3a6ee2fbe651199d 100644 (file)
@@ -22,6 +22,7 @@
 
 class kb_keymap;
 class LyXKeySym;
+class FuncRequest;
 
 /// Holds a key sequence and the current and standard keymaps
 class kb_sequence {
@@ -43,8 +44,9 @@ public:
         * @param nmod which modifiers to mask out for equality test
         * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION
         */
-       int addkey(LyXKeySymPtr keysym, key_modifier::state mod,
-                  key_modifier::state nmod = key_modifier::none);
+       FuncRequest const &
+       addkey(LyXKeySymPtr keysym, key_modifier::state mod,
+              key_modifier::state nmod = key_modifier::none);
 
        /**
         * Add a sequence of keys from a string to the sequence
index 776dec52eea8df3e3e24247fd8810b0dba3e7120..32024aea4abee57c47ca087c4ee9698c81cdacd3 100644 (file)
@@ -333,59 +333,59 @@ void LyX::init(bool gui)
 
 void LyX::defaultKeyBindings(kb_keymap  * kbmap)
 {
-       kbmap->bind("Right", LFUN_RIGHT);
-       kbmap->bind("Left", LFUN_LEFT);
-       kbmap->bind("Up", LFUN_UP);
-       kbmap->bind("Down", LFUN_DOWN);
+       kbmap->bind("Right", FuncRequest(LFUN_RIGHT));
+       kbmap->bind("Left", FuncRequest(LFUN_LEFT));
+       kbmap->bind("Up", FuncRequest(LFUN_UP));
+       kbmap->bind("Down", FuncRequest(LFUN_DOWN));
 
-       kbmap->bind("Tab", LFUN_CELL_FORWARD);
-       kbmap->bind("ISO_Left_Tab", LFUN_CELL_FORWARD); // jbl 2001-23-02
+       kbmap->bind("Tab", FuncRequest(LFUN_CELL_FORWARD));
+       kbmap->bind("ISO_Left_Tab", FuncRequest(LFUN_CELL_FORWARD));
 
-       kbmap->bind("Home", LFUN_HOME);
-       kbmap->bind("End", LFUN_END);
-       kbmap->bind("Prior", LFUN_PRIOR);
-       kbmap->bind("Next", LFUN_NEXT);
+       kbmap->bind("Home", FuncRequest(LFUN_HOME));
+       kbmap->bind("End", FuncRequest(LFUN_END));
+       kbmap->bind("Prior", FuncRequest(LFUN_PRIOR));
+       kbmap->bind("Next", FuncRequest(LFUN_NEXT));
 
-       kbmap->bind("Return", LFUN_BREAKPARAGRAPH);
-       //kbmap->bind("~C-~S-~M-nobreakspace", LFUN_PROTECTEDSPACE);
+       kbmap->bind("Return", FuncRequest(LFUN_BREAKPARAGRAPH));
+       //kbmap->bind("~C-~S-~M-nobreakspace", FuncRequest(LFUN_PROTECTEDSPACE));
 
-       kbmap->bind("Delete", LFUN_DELETE);
-       kbmap->bind("BackSpace", LFUN_BACKSPACE);
+       kbmap->bind("Delete", FuncRequest(LFUN_DELETE));
+       kbmap->bind("BackSpace", FuncRequest(LFUN_BACKSPACE));
 
        // sub- and superscript -MV
-       kbmap->bind("~S-underscore", LFUN_SUBSCRIPT);
-       kbmap->bind("~S-asciicircum", LFUN_SUPERSCRIPT);
+       kbmap->bind("~S-underscore", FuncRequest(LFUN_SUBSCRIPT));
+       kbmap->bind("~S-asciicircum", FuncRequest(LFUN_SUPERSCRIPT));
 
        // kbmap->bindings to enable the use of the numeric keypad
        // e.g. Num Lock set
-       //kbmap->bind("KP_0", LFUN_SELFINSERT);
-       //kbmap->bind("KP_Decimal", LFUN_SELFINSERT);
-       kbmap->bind("KP_Enter", LFUN_BREAKPARAGRAPH);
-       //kbmap->bind("KP_1", LFUN_SELFINSERT);
-       //kbmap->bind("KP_2", LFUN_SELFINSERT);
-       //kbmap->bind("KP_3", LFUN_SELFINSERT);
-       //kbmap->bind("KP_4", LFUN_SELFINSERT);
-       //kbmap->bind("KP_5", LFUN_SELFINSERT);
-       //kbmap->bind("KP_6", LFUN_SELFINSERT);
-       //kbmap->bind("KP_Add", LFUN_SELFINSERT);
-       //kbmap->bind("KP_7", LFUN_SELFINSERT);
-       //kbmap->bind("KP_8", LFUN_SELFINSERT);
-       //kbmap->bind("KP_9", LFUN_SELFINSERT);
-       //kbmap->bind("KP_Divide", LFUN_SELFINSERT);
-       //kbmap->bind("KP_Multiply", LFUN_SELFINSERT);
-       //kbmap->bind("KP_Subtract", LFUN_SELFINSERT);
-       kbmap->bind("KP_Right", LFUN_RIGHT);
-       kbmap->bind("KP_Left", LFUN_LEFT);
-       kbmap->bind("KP_Up", LFUN_UP);
-       kbmap->bind("KP_Down", LFUN_DOWN);
-       kbmap->bind("KP_Home", LFUN_HOME);
-       kbmap->bind("KP_End", LFUN_END);
-       kbmap->bind("KP_Prior", LFUN_PRIOR);
-       kbmap->bind("KP_Next", LFUN_NEXT);
-
-       kbmap->bind("C-Tab", LFUN_CELL_SPLIT);  // ale970515
-       kbmap->bind("S-Tab", LFUN_CELL_BACKWARD);  // jug20000522
-       kbmap->bind("S-ISO_Left_Tab", LFUN_CELL_BACKWARD); // jbl 2001-23-02
+       //kbmap->bind("KP_0", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_Decimal", FuncRequest(LFUN_SELFINSERT));
+       kbmap->bind("KP_Enter", FuncRequest(LFUN_BREAKPARAGRAPH));
+       //kbmap->bind("KP_1", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_2", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_3", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_4", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_5", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_6", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_Add", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_7", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_8", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_9", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_Divide", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_Multiply", FuncRequest(LFUN_SELFINSERT));
+       //kbmap->bind("KP_Subtract", FuncRequest(LFUN_SELFINSERT));
+       kbmap->bind("KP_Right", FuncRequest(LFUN_RIGHT));
+       kbmap->bind("KP_Left", FuncRequest(LFUN_LEFT));
+       kbmap->bind("KP_Up", FuncRequest(LFUN_UP));
+       kbmap->bind("KP_Down", FuncRequest(LFUN_DOWN));
+       kbmap->bind("KP_Home", FuncRequest(LFUN_HOME));
+       kbmap->bind("KP_End", FuncRequest(LFUN_END));
+       kbmap->bind("KP_Prior", FuncRequest(LFUN_PRIOR));
+       kbmap->bind("KP_Next", FuncRequest(LFUN_NEXT));
+
+       kbmap->bind("C-Tab", FuncRequest(LFUN_CELL_SPLIT));
+       kbmap->bind("S-Tab", FuncRequest(LFUN_CELL_BACKWARD));
+       kbmap->bind("S-ISO_Left_Tab", FuncRequest(LFUN_CELL_BACKWARD));
 }
 
 
@@ -406,25 +406,25 @@ void LyX::deadKeyBindings(kb_keymap * kbmap)
 {
        // bindKeyings for transparent handling of deadkeys
        // The keysyms are gotten from XFree86 X11R6
-       kbmap->bind("~C-~S-~M-dead_acute", LFUN_ACUTE);
-       kbmap->bind("~C-~S-~M-dead_breve", LFUN_BREVE);
-       kbmap->bind("~C-~S-~M-dead_caron", LFUN_CARON);
-       kbmap->bind("~C-~S-~M-dead_cedilla", LFUN_CEDILLA);
-       kbmap->bind("~C-~S-~M-dead_abovering", LFUN_CIRCLE);
-       kbmap->bind("~C-~S-~M-dead_circumflex", LFUN_CIRCUMFLEX);
-       kbmap->bind("~C-~S-~M-dead_abovedot", LFUN_DOT);
-       kbmap->bind("~C-~S-~M-dead_grave", LFUN_GRAVE);
-       kbmap->bind("~C-~S-~M-dead_doubleacute", LFUN_HUNG_UMLAUT);
-       kbmap->bind("~C-~S-~M-dead_macron", LFUN_MACRON);
+       kbmap->bind("~C-~S-~M-dead_acute", FuncRequest(LFUN_ACUTE));
+       kbmap->bind("~C-~S-~M-dead_breve", FuncRequest(LFUN_BREVE));
+       kbmap->bind("~C-~S-~M-dead_caron", FuncRequest(LFUN_CARON));
+       kbmap->bind("~C-~S-~M-dead_cedilla", FuncRequest(LFUN_CEDILLA));
+       kbmap->bind("~C-~S-~M-dead_abovering", FuncRequest(LFUN_CIRCLE));
+       kbmap->bind("~C-~S-~M-dead_circumflex", FuncRequest(LFUN_CIRCUMFLEX));
+       kbmap->bind("~C-~S-~M-dead_abovedot", FuncRequest(LFUN_DOT));
+       kbmap->bind("~C-~S-~M-dead_grave", FuncRequest(LFUN_GRAVE));
+       kbmap->bind("~C-~S-~M-dead_doubleacute", FuncRequest(LFUN_HUNG_UMLAUT));
+       kbmap->bind("~C-~S-~M-dead_macron", FuncRequest(LFUN_MACRON));
        // nothing with this name
        // kbmap->bind("~C-~S-~M-dead_special_caron", LFUN_SPECIAL_CARON);
-       kbmap->bind("~C-~S-~M-dead_tilde", LFUN_TILDE);
-       kbmap->bind("~C-~S-~M-dead_diaeresis", LFUN_UMLAUT);
+       kbmap->bind("~C-~S-~M-dead_tilde", FuncRequest(LFUN_TILDE));
+       kbmap->bind("~C-~S-~M-dead_diaeresis", FuncRequest(LFUN_UMLAUT));
        // nothing with this name either...
-       //kbmap->bind("~C-~S-~M-dead_underbar", LFUN_UNDERBAR);
-       kbmap->bind("~C-~S-~M-dead_belowdot", LFUN_UNDERDOT);
-       kbmap->bind("~C-~S-~M-dead_tie", LFUN_TIE);
-       kbmap->bind("~C-~S-~M-dead_ogonek", LFUN_OGONEK);
+       //kbmap->bind("~C-~S-~M-dead_underbar", FuncRequest(LFUN_UNDERBAR));
+       kbmap->bind("~C-~S-~M-dead_belowdot", FuncRequest(LFUN_UNDERDOT));
+       kbmap->bind("~C-~S-~M-dead_tie", FuncRequest(LFUN_TIE));
+       kbmap->bind("~C-~S-~M-dead_ogonek",FuncRequest(LFUN_OGONEK));
 }
 
 
index ac8e3beb0b6d39ebf9d1fe4fdbf341a11a010fea..3ffa92e641c03c147067818cc38b8fb25a6366d6 100644 (file)
@@ -194,30 +194,30 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
        // cancel and meta-fake keys. RVDK_PATCH_5
        cancel_meta_seq.reset();
 
-       int action = cancel_meta_seq.addkey(keysym, state);
-       lyxerr[Debug::KEY] << "action first set to [" << action << ']' << endl;
+       FuncRequest func = cancel_meta_seq.addkey(keysym, state);
+       lyxerr[Debug::KEY] << "action first set to [" << func.action << ']' << endl;
 
        // When not cancel or meta-fake, do the normal lookup.
        // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
        // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
-       if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
+       if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_FAKE)) {
                // remove Caps Lock and Mod2 as a modifiers
-               action = keyseq.addkey(keysym, (state | meta_fake_bit));
+               func = keyseq.addkey(keysym, (state | meta_fake_bit));
                lyxerr[Debug::KEY] << "action now set to ["
-                       << action << ']' << endl;
+                       << func.action << ']' << endl;
        }
 
        // Dont remove this unless you know what you are doing.
        meta_fake_bit = key_modifier::none;
 
        // can this happen now ?
-       if (action == LFUN_NOACTION) {
-               action = LFUN_PREFIX;
+       if (func.action == LFUN_NOACTION) {
+               func = FuncRequest(LFUN_PREFIX);
        }
 
        if (lyxerr.debugging(Debug::KEY)) {
                lyxerr << "Key [action="
-                      << action << "]["
+                      << func.action << "]["
                       << keyseq.print() << ']'
                       << endl;
        }
@@ -233,19 +233,20 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
 
        // Maybe user can only reach the key via holding down shift.
        // Let's see. But only if shift is the only modifier
-       if (action == LFUN_UNKNOWN_ACTION && state == key_modifier::shift) {
+       if (func.action == LFUN_UNKNOWN_ACTION &&
+           state == key_modifier::shift) {
                lyxerr[Debug::KEY] << "Trying without shift" << endl;
-               action = keyseq.addkey(keysym, key_modifier::none);
-               lyxerr[Debug::KEY] << "Action now " << action << endl;
+               func = keyseq.addkey(keysym, key_modifier::none);
+               lyxerr[Debug::KEY] << "Action now " << func.action << endl;
        }
 
-       if (action == LFUN_UNKNOWN_ACTION) {
+       if (func.action == LFUN_UNKNOWN_ACTION) {
                // Hmm, we didn't match any of the keysequences. See
                // if it's normal insertable text not already covered
                // by a binding
                if (keysym->isText() && keyseq.length() == 1) {
                        lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
-                       action = LFUN_SELFINSERT;
+                       func = FuncRequest(LFUN_SELFINSERT);
                } else {
                        lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
                        owner->message(_("Unknown function."));
@@ -253,7 +254,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
                }
        }
 
-       if (action == LFUN_SELFINSERT) {
+       if (func.action == LFUN_SELFINSERT) {
                if (encoded_last_key != 0) {
                        string arg;
                        arg += encoded_last_key;
@@ -264,7 +265,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
                                   << argument << "']" << endl;
                }
        } else {
-               dispatch(FuncRequest(kb_action(action)));
+               dispatch(func);
        }
 }
 
@@ -803,7 +804,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        // solution, we consider only the first action of the sequence
        if (ev.action == LFUN_SEQUENCE) {
                // argument contains ';'-terminated commands
-               flag = getStatus(FuncRequest(lyxaction.LookupFunc(token(ev.argument, ';', 0))));
+#warning LyXAction arguements not handled here.
+               flag = getStatus(FuncRequest(lyxaction.lookupFunc(token(ev.argument, ';', 0))));
        }
 
        return flag;
@@ -812,14 +814,14 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
 
 void LyXFunc::dispatch(string const & s, bool verbose)
 {
-       int const action = lyxaction.LookupFunc(s);
+       FuncRequest func = lyxaction.lookupFunc(s);
 
-       if (action == LFUN_UNKNOWN_ACTION) {
+       if (func.action == LFUN_UNKNOWN_ACTION) {
                owner->message(bformat(_("Unknown function (%1$s)"), s));
                return;
        }
 
-       dispatch(FuncRequest(kb_action(action)), verbose);
+       dispatch(func, verbose);
 }
 
 
@@ -847,10 +849,13 @@ namespace {
 } //namespace anon
 
 
-void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
+void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
 {
-       lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << ev.action
-                             <<"] arg[" << ev.argument << ']' << endl;
+       string argument = func.argument;
+       kb_action action = func.action;
+
+       lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << action
+                             <<"] arg[" << argument << ']' << endl;
 
        // we have not done anything wrong yet.
        errorstat = false;
@@ -865,11 +870,8 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
 
        selection_possible = false;
 
-       string argument = ev.argument;
-       kb_action action = ev.action;
-
        // We cannot use this function here
-       if (getStatus(ev).disabled()) {
+       if (getStatus(func).disabled()) {
                lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
                       << lyxaction.getActionName(action)
                       << " [" << action << "] is disabled at this location"
@@ -885,7 +887,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
        {
                Cursor cursor;
                buildCursor(cursor, *view());
-               if (cursor.dispatch(FuncRequest(ev, view())) == DISPATCHED) {
+               if (cursor.dispatch(FuncRequest(func, view())) == DISPATCHED) {
                        lyxerr << "dispatched by Cursor::dispatch()\n";
                        goto exit_with_message;
                }
@@ -917,7 +919,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                        // if we've just done LFUN_ESCAPE (which
                        // injects an LFUN_PARAGRAPH_UPDATE)
                        if (action == LFUN_PARAGRAPH_UPDATE) {
-                               view()->dispatch(ev);
+                               view()->dispatch(func);
                                goto exit_with_message;
                        }
 
@@ -1439,8 +1441,8 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                break;
 
        case LFUN_DIALOG_SHOW: {
-               string const name = ev.getArg(0);
-               string data = trim(ev.argument.substr(name.size()));
+               string const name = func.getArg(0);
+               string data = trim(func.argument.substr(name.size()));
 
                if (name == "character") {
                        data = freefont2string();
@@ -1505,7 +1507,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                InsetBase * inset = owner->getDialogs().getOpenInset(name);
                if (inset) {
                        FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
-                                      ev.argument);
+                                      func.argument);
                        inset->localDispatch(fr);
                } else if (name == "paragraph") {
                        dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
@@ -1658,9 +1660,9 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
        default:
                // Then if it was none of the above
                // Trying the BufferView::pimpl dispatch:
-               if (!view()->dispatch(ev))
+               if (!view()->dispatch(func))
                        lyxerr << "A truly unknown func ["
-                              << lyxaction.getActionName(ev.action) << "]!"
+                              << lyxaction.getActionName(func.action) << "]!"
                               << endl;
                break;
        } // end of switch
@@ -1676,22 +1678,23 @@ exit_with_message:
                }
 
                // If we executed a mutating lfun, mark the buffer as dirty
-               if (!getStatus(ev).disabled()
-                   && !lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)
-                   && !lyxaction.funcHasFlag(ev.action, LyXAction::ReadOnly))
+               if (!getStatus(func).disabled()
+                   && !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer)
+                   && !lyxaction.funcHasFlag(func.action, LyXAction::ReadOnly))
                        view()->buffer()->markDirty();
        }
 
-       sendDispatchMessage(getMessage(), ev, verbose);
+       sendDispatchMessage(getMessage(), func, verbose);
 }
 
 
-void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & ev, bool verbose)
+void LyXFunc::sendDispatchMessage(string const & msg,
+                                 FuncRequest const & func, bool verbose)
 {
        owner->updateMenubar();
        owner->updateToolbar();
 
-       if (ev.action == LFUN_SELFINSERT || !verbose) {
+       if (func.action == LFUN_SELFINSERT || !verbose) {
                lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
                if (!msg.empty())
                        owner->message(msg);
@@ -1702,23 +1705,23 @@ void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & ev, bo
        if (!dispatch_msg.empty())
                dispatch_msg += ' ';
 
-       string comname = lyxaction.getActionName(ev.action);
+       string comname = lyxaction.getActionName(func.action);
 
        bool argsadded = false;
 
-       if (!ev.argument.empty()) {
-               if (ev.action != LFUN_UNKNOWN_ACTION) {
-                       comname += ' ' + ev.argument;
+       if (!func.argument.empty()) {
+               if (func.action != LFUN_UNKNOWN_ACTION) {
+                       comname += ' ' + func.argument;
                        argsadded = true;
                }
        }
 
-       string const shortcuts = toplevel_keymap->findbinding(ev.action);
+       string const shortcuts = toplevel_keymap->findbinding(func);
 
        if (!shortcuts.empty()) {
                comname += ": " + shortcuts;
-       } else if (!argsadded && !ev.argument.empty()) {
-               comname += ' ' + ev.argument;
+       } else if (!argsadded && !func.argument.empty()) {
+               comname += ' ' + func.argument;
        }
 
        if (!comname.empty()) {
index e8a0827ba1f1f8b4df0d32b641e1b5f69d55d870..54119f7f540e1a24ad81b2ced94df12c6a3563fb 100644 (file)
@@ -726,7 +726,7 @@ string const corrected_env(string const & suffix, string const & env,
                output += env;
        return output + "}";
 }
+
 } // namespace anon