From: Lars Gullik Bjønnes Date: Sun, 21 Sep 2003 23:00:47 +0000 (+0000) Subject: more action work X-Git-Tag: 1.6.10~16048 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=495cd0eea03f9f5471a247e60ce70abfd1114ada;p=features.git more action work git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7801 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index c1e05f05ce..9fd3e06464 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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 diff --git a/src/ChangeLog b/src/ChangeLog index 8ca3dc7d59..d71458e592 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,47 @@ +2003-09-22 Lars Gullik Bjønnes + + * 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 + (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 * toc.C (action): return a FuncRequest, simplify diff --git a/src/LyXAction.C b/src/LyXAction.C index a6489053d6..d7eee1b91e 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -20,6 +20,8 @@ #include "support/lstrings.h" +#include + 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; } diff --git a/src/LyXAction.h b/src/LyXAction.h index d59666d698..3e0241acbd 100644 --- a/src/LyXAction.h +++ b/src/LyXAction.h @@ -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; diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 7c6d036370..d3b9e8a205 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -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); diff --git a/src/ToolbarBackend.C b/src/ToolbarBackend.C index 8d91fca376..01cad0b86b 100644 --- a/src/ToolbarBackend.C +++ b/src/ToolbarBackend.C @@ -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; diff --git a/src/boost.C b/src/boost.C index b6b4ae38ce..440b4ffd93 100644 --- a/src/boost.C +++ b/src/boost.C @@ -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(); } diff --git a/src/buffer.C b/src/buffer.C index 2a080bc442..3d3fb2c897 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -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; diff --git a/src/buffer.h b/src/buffer.h index 4bd9f8ebb5..3e8ab31b85 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -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(); diff --git a/src/cursor.C b/src/cursor.C index 11070ca67f..fb07ee137d 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -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 pits; + vector pits; vector plists; vector texts; /* diff --git a/src/frontends/gtk/GMenubar.C b/src/frontends/gtk/GMenubar.C index ac1daf27f3..f1677cf736 100644 --- a/src/frontends/gtk/GMenubar.C +++ b/src/frontends/gtk/GMenubar.C @@ -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( diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index d0c61fc0cd..7cfdd74930 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,7 +1,12 @@ +2003-09-22 Lars Gullik Bjønnes + + * QLPopupMenu.C (getLabel): fix so that bindings are added even if + shortcut is missing. + 2003-09-21 Lars Gullik Bjønnes * QtView.C (activated): change to take a FuncRequest, not a slot - anymore. + anymore. * QLToolbar.C (update): adjust (add): change to take a FuncRequest diff --git a/src/frontends/qt2/QLPopupMenu.C b/src/frontends/qt2/QLPopupMenu.C index 662f766cdc..5f8bb90234 100644 --- a/src/frontends/qt2/QLPopupMenu.C +++ b/src/frontends/qt2/QLPopupMenu.C @@ -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()); diff --git a/src/funcrequest.C b/src/funcrequest.C index 6192a79f57..18e8ed01bc 100644 --- a/src/funcrequest.C +++ b/src/funcrequest.C @@ -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) {} diff --git a/src/funcrequest.h b/src/funcrequest.h index 439671b780..8a1d5acc01 100644 --- a/src/funcrequest.h +++ b/src/funcrequest.h @@ -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 diff --git a/src/kbmap.C b/src/kbmap.C index e68e62eb0c..1d7839cf27 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -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; } diff --git a/src/kbmap.h b/src/kbmap.h index 38516d8644..40c1b3847c 100644 --- a/src/kbmap.h +++ b/src/kbmap.h @@ -14,6 +14,8 @@ #ifndef KBMAP_H #define KBMAP_H +#include "funcrequest.h" + #include "frontends/key_state.h" #include @@ -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 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; diff --git a/src/kbsequence.C b/src/kbsequence.C index dc4fc71b9c..2cae7938db 100644 --- a/src/kbsequence.C +++ b/src/kbsequence.C @@ -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; } diff --git a/src/kbsequence.h b/src/kbsequence.h index 8b090cf8ab..5bb5139862 100644 --- a/src/kbsequence.h +++ b/src/kbsequence.h @@ -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 diff --git a/src/lyx_main.C b/src/lyx_main.C index 776dec52ee..32024aea4a 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -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)); } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index ac8e3beb0b..3ffa92e641 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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()) { diff --git a/src/paragraph.C b/src/paragraph.C index e8a0827ba1..54119f7f54 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -726,7 +726,7 @@ string const corrected_env(string const & suffix, string const & env, output += env; return output + "}"; } - + } // namespace anon