From 2994fe551121614948dcb68d6f4953ee3bbb694d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sun, 21 Sep 2003 18:57:15 +0000 Subject: [PATCH] Get rid of Pseudo Actions git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7799 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 37 ++++++++ src/LyXAction.C | 91 +----------------- src/LyXAction.h | 32 +------ src/MenuBackend.C | 133 ++++++++++++--------------- src/MenuBackend.h | 24 +++-- src/ToolbarBackend.C | 54 ++++++----- src/ToolbarBackend.h | 15 +-- src/frontends/ChangeLog | 6 +- src/frontends/LyXView.C | 3 +- src/frontends/Toolbar.h | 2 +- src/frontends/gtk/ChangeLog | 9 ++ src/frontends/gtk/GMenubar.C | 6 +- src/frontends/gtk/GToolbar.C | 28 +++--- src/frontends/gtk/GToolbar.h | 6 +- src/frontends/qt2/ChangeLog | 13 +++ src/frontends/qt2/QLPopupMenu.C | 22 ++++- src/frontends/qt2/QLPopupMenu.h | 10 ++ src/frontends/qt2/QLToolbar.C | 17 ++-- src/frontends/qt2/QLToolbar.h | 4 +- src/frontends/qt2/QtView.C | 4 +- src/frontends/qt2/QtView.h | 5 +- src/frontends/xforms/ChangeLog | 6 ++ src/frontends/xforms/XFormsMenubar.C | 30 +++--- src/frontends/xforms/XFormsMenubar.h | 7 +- src/frontends/xforms/XFormsToolbar.C | 35 ++++--- src/frontends/xforms/XFormsToolbar.h | 10 +- src/funcrequest.C | 2 +- src/funcrequest.h | 2 +- src/lyxfunc.C | 29 ++---- src/lyxfunc.h | 6 -- src/toc.C | 5 +- src/toc.h | 3 +- 32 files changed, 318 insertions(+), 338 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index dd567ef2ee..8ca3dc7d59 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,42 @@ 2003-09-21 Lars Gullik Bjønnes + * toc.C (action): return a FuncRequest, simplify + + * lyxfunc.C (processKeySym): adjust + (getStatus): delete version that takes an int. + (getStatus): adjust + (dispatch): delete version that takes action as int + (dispatch): adjust + (sendDispatchMessage): simplify and adjust + + * funcrequest.C (getArg): take unsigned int as arg + + * ToolbarBackend.C (read): adjust + (add): delete version that takes func as a string. + (getIton): take a FuncRequest as arg + + * MenuBackend.h (MenuItem): store a FuncRequest instead of an int + action. + + * MenuBackend.C (MenuItem): add a new construct that only takes a + Kind, simplify the constructor use for submenus. + (add): adjust + (expandLastfiles): adjust + (expandDocuments): adjust + (expandFormats): adjust + (expandFloatListInsert): adjust + (expandFloatInsert): adjust + (expandToc2,expandToc,expandPasteRecent,expandBranches): adjust + + * LyXAction.h: remove typdefs pseudo_map, arg_item and arg_map. + Remove class variables lyx_pseudo_map and lyx_arg_map + + * LyXAction.C (searchActionArg): delete function + (getPseudoAction): delete function + (retrieveActionArg): delete function + (LookupFunc): make it return kb_action, simplify. + (getActionName): simplify + * factory.C (createInset): fix new bug 2003-09-19 Angus Leeming diff --git a/src/LyXAction.C b/src/LyXAction.C index 42979e0c2f..a6489053d6 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -344,83 +344,8 @@ LyXAction::LyXAction() } -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()) { - lyxerr[Debug::ACTION] << "Action " << action - << " does not have any pseudo actions." - << endl; - return LFUN_UNKNOWN_ACTION; - } - - arg_item::const_iterator aci = pit->second.find(arg); - - if (aci == pit->second.end()) { - lyxerr[Debug::ACTION] - << "Action " << action - << "does not have any pseudoactions with arg " - << arg << endl; - return LFUN_UNKNOWN_ACTION; - } - - lyxerr[Debug::ACTION] << "Pseudoaction exists[" - << action << '|' - << arg << "] = " << aci->second << endl; - - return aci->second; -} - - -int LyXAction::getPseudoAction(kb_action action, string const & arg) -{ - int const psdaction = searchActionArg(action, arg); - - if (isPseudoAction(psdaction)) return psdaction; - - static unsigned int pseudo_counter = LFUN_LASTACTION; - - // Create new pseudo action. - lyx_pseudo_map[++pseudo_counter] = FuncRequest(0, action, arg); - - // First ensure that the action is in lyx_arg_map; - lyx_arg_map[action]; - // get the arg_item map - arg_map::iterator ami = lyx_arg_map.find(action); - // put the new pseudo function in it - ami->second[arg] = pseudo_counter; - - lyxerr[Debug::ACTION] << "Creating new pseudoaction " - << pseudo_counter << " for [" << action - << '|' << arg << "]\n"; - - return pseudo_counter; -} - - -FuncRequest LyXAction::retrieveActionArg(int pseudo) const -{ - if (!isPseudoAction(pseudo)) - return FuncRequest(static_cast(pseudo)); - - pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo); - - if (pit != lyx_pseudo_map.end()) { - lyxerr[Debug::ACTION] << "Found the pseudoaction: [" - << pit->second.action << '|' - << pit->second.argument << "]" << endl; - return pit->second; - } else { - lyxerr << "Lyx Error: Unrecognized pseudo-action " - << pseudo << endl; - return FuncRequest(LFUN_UNKNOWN_ACTION); - } -} - - // Returns an action tag from a string. -int LyXAction::LookupFunc(string const & func) +kb_action LyXAction::LookupFunc(string const & func) { string const func2 = trim(func); if (func2.empty()) return LFUN_NOACTION; @@ -433,25 +358,15 @@ int LyXAction::LookupFunc(string const & func) func_map::const_iterator fit = lyx_func_map.find(actstr); - if (!argstr.empty() && fit != lyx_func_map.end()) { - // might be pseudo (or create one) - return getPseudoAction(fit->second, argstr); - } - return fit != lyx_func_map.end() ? fit->second : LFUN_UNKNOWN_ACTION; } string const LyXAction::getActionName(int action) const { - FuncRequest ev = retrieveActionArg(action); - if (!ev.argument.empty()) - ev.argument.insert(string::size_type(0), 1, ' '); - - info_map::const_iterator const it = lyx_info_map.find(ev.action); - + info_map::const_iterator const it = lyx_info_map.find(kb_action(action)); if (it != lyx_info_map.end()) - return it->second.name + ev.argument; + return it->second.name; return string(); } diff --git a/src/LyXAction.h b/src/LyXAction.h index d1892d8737..d59666d698 100644 --- a/src/LyXAction.h +++ b/src/LyXAction.h @@ -44,12 +44,6 @@ public: typedef std::map func_map; /// type for map between an action and its info typedef std::map info_map; - /// type for a map between a pseudo-action and its stored action/arg - typedef std::map pseudo_map; - /// map from argument to pseudo-action - typedef std::map arg_item; - /// map from an action to all its dependent pseudo-actions - typedef std::map arg_map; /// possible "permissions" for an action enum func_attrib { @@ -66,19 +60,7 @@ public: * 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); - - /** - * Given a pseudo-action, return the real action and - * associated argument - */ - FuncRequest 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; + kb_action LookupFunc(string const & func_name); /// Return the name (and argument) associated with the given (pseudo) action string const getActionName(int action) const; @@ -114,18 +96,6 @@ private: * command attributes (ro) */ info_map lyx_info_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; }; /// singleton instance diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 028d0ce0dd..7c6d036370 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -66,45 +66,23 @@ extern boost::scoped_ptr toplevel_keymap; MenuBackend menubackend; -MenuItem::MenuItem(Kind kind, string const & label, - string const & command, bool optional) - : kind_(kind), label_(label), optional_(optional) -{ - switch (kind) { - case Separator: - case Documents: - case Lastfiles: - case Toc: - case ViewFormats: - case UpdateFormats: - case ExportFormats: - case ImportFormats: - case FloatListInsert: - case FloatInsert: - case PasteRecent: - case Branches: - break; - case Command: - action_ = lyxaction.LookupFunc(command); +MenuItem::MenuItem(Kind kind) + : kind_(kind), optional_(false) +{} - if (action_ == LFUN_UNKNOWN_ACTION) { - lyxerr << "MenuItem(): LyX command `" - << command << "' does not exist." << endl; - } - if (optional_) - lyxerr[Debug::GUI] << "Optional item " - << command << endl; - break; - case Submenu: - submenuname_ = command; - break; - } + +MenuItem::MenuItem(Kind kind, string const & label, + string const & submenu, bool optional) + : kind_(kind), label_(label), + submenuname_(submenu), optional_(optional) +{ + BOOST_ASSERT(kind == Submenu); } -MenuItem::MenuItem(Kind kind, string const & label, int action, bool optional) - : kind_(kind), label_(label), action_(action), submenuname_(), - optional_(optional) +MenuItem::MenuItem(Kind kind, string const & label, + FuncRequest const & func, bool optional) + : kind_(kind), label_(label), func_(func), optional_(optional) {} @@ -129,6 +107,7 @@ string const MenuItem::shortcut() const return token(label_, '|', 1); } + string const MenuItem::binding() const { if (kind_ != Command) @@ -136,7 +115,7 @@ string const MenuItem::binding() const // Get the keys bound to this action, but keep only the // first one later - string bindings = toplevel_keymap->findbinding(action_); + string bindings = toplevel_keymap->findbinding(func_.action); if (!bindings.empty()) { return bindings.substr(1, bindings.find(']') - 1); @@ -156,7 +135,7 @@ Menu & Menu::add(MenuItem const & i, LyXView const * view) case MenuItem::Command: { FuncStatus status = - view->getLyXFunc().getStatus(i.action()); + view->getLyXFunc().getStatus(i.func()); if (status.unknown() || (status.disabled() && i.optional())) break; @@ -259,8 +238,20 @@ Menu & Menu::read(LyXLex & lex) string const name = _(lex.getString()); lex.next(true); string const command = lex.getString(); - add(MenuItem(MenuItem::Command, name, - command, optional)); + 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)); + } + optional = false; break; } @@ -398,10 +389,7 @@ void expandLastfiles(Menu & tomenu, LyXView const * view) string const label = tostr(ii) + ". " + MakeDisplayPath((*lfit), 30) + '|' + tostr(ii); - int const action = lyxaction. - getPseudoAction(LFUN_FILE_OPEN, - (*lfit)); - tomenu.add(MenuItem(MenuItem::Command, label, action), view); + tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit))), view); } } @@ -412,7 +400,7 @@ void expandDocuments(Menu & tomenu, LyXView const * view) if (names.empty()) { tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"), - LFUN_NOACTION), view); + FuncRequest(LFUN_NOACTION)), view); return; } @@ -420,12 +408,10 @@ void expandDocuments(Menu & tomenu, LyXView const * view) Strings::const_iterator docit = names.begin(); Strings::const_iterator end = names.end(); for (; docit != end; ++docit, ++ii) { - int const action = - lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *docit); string label = MakeDisplayPath(*docit, 20); if (ii < 10) label = tostr(ii) + ". " + label + '|' + tostr(ii); - tomenu.add(MenuItem(MenuItem::Command, label, action), view); + tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_SWITCHBUFFER, *docit)), view); } } @@ -434,7 +420,8 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, LyXView const * view) { if (!view->buffer() && kind != MenuItem::ImportFormats) { tomenu.add(MenuItem(MenuItem::Command, - _("No Documents Open!"), LFUN_NOACTION), + _("No Documents Open!"), + FuncRequest(LFUN_NOACTION)), view); return; } @@ -483,9 +470,9 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, LyXView const * view) } if (!(*fit)->shortcut().empty()) label += '|' + (*fit)->shortcut(); - int const action2 = lyxaction. - getPseudoAction(action, (*fit)->name()); - tomenu.add(MenuItem(MenuItem::Command, label, action2), + + tomenu.add(MenuItem(MenuItem::Command, label, + FuncRequest(action, (*fit)->name())), view); } } @@ -495,7 +482,8 @@ void expandFloatListInsert(Menu & tomenu, LyXView const * view) { if (!view->buffer()) { tomenu.add(MenuItem(MenuItem::Command, - _("No Documents Open!"), LFUN_NOACTION), + _("No Documents Open!"), + FuncRequest(LFUN_NOACTION)), view); return; } @@ -505,10 +493,10 @@ void expandFloatListInsert(Menu & tomenu, LyXView const * view) FloatList::const_iterator cit = floats.begin(); FloatList::const_iterator end = floats.end(); for (; cit != end; ++cit) { - int const action = lyxaction - .getPseudoAction(LFUN_FLOAT_LIST, cit->second.type()); tomenu.add(MenuItem(MenuItem::Command, - _(cit->second.listName()), action), + _(cit->second.listName()), + FuncRequest(LFUN_FLOAT_LIST, + cit->second.type())), view); } } @@ -518,7 +506,8 @@ void expandFloatInsert(Menu & tomenu, LyXView const * view) { if (!view->buffer()) { tomenu.add(MenuItem(MenuItem::Command, - _("No Documents Open!"), LFUN_NOACTION), + _("No Documents Open!"), + FuncRequest(LFUN_NOACTION)), view); return; } @@ -529,11 +518,10 @@ void expandFloatInsert(Menu & tomenu, LyXView const * view) FloatList::const_iterator end = floats.end(); for (; cit != end; ++cit) { // normal float - int const action = - lyxaction.getPseudoAction(LFUN_INSET_FLOAT, - cit->second.type()); string const label = _(cit->second.name()); - tomenu.add(MenuItem(MenuItem::Command, label, action), + tomenu.add(MenuItem(MenuItem::Command, label, + FuncRequest(LFUN_INSET_FLOAT, + cit->second.type())), view); } } @@ -549,14 +537,14 @@ void expandToc2(Menu & tomenu, int shortcut_count = 0; if (to - from <= max_number_of_items) { for (lyx::toc::Toc::size_type i = from; i < to; ++i) { - int const action = toc_list[i].action(); string label(4 * max(0, toc_list[i].depth - depth),' '); label += limit_string_length(toc_list[i].str); if (toc_list[i].depth == depth && ++shortcut_count <= 9) { label += '|' + tostr(shortcut_count); } - tomenu.add(MenuItem(MenuItem::Command, label, action)); + tomenu.add(MenuItem(MenuItem::Command, label, + FuncRequest(toc_list[i].action()))); } } else { lyx::toc::Toc::size_type pos = from; @@ -566,7 +554,6 @@ void expandToc2(Menu & tomenu, toc_list[new_pos].depth > depth) ++new_pos; - int const action = toc_list[pos].action(); string label(4 * max(0, toc_list[pos].depth - depth), ' '); label += limit_string_length(toc_list[pos].str); if (toc_list[pos].depth == depth && @@ -575,7 +562,7 @@ void expandToc2(Menu & tomenu, if (new_pos == pos + 1) { tomenu.add(MenuItem(MenuItem::Command, - label, action)); + label, FuncRequest(toc_list[pos].action()))); } else { MenuItem item(MenuItem::Submenu, label); item.submenu(new Menu); @@ -598,7 +585,8 @@ void expandToc(Menu & tomenu, LyXView const * view) if (!view->buffer()) { tomenu.add(MenuItem(MenuItem::Command, - _("No Documents Open!"), LFUN_NOACTION), + _("No Documents Open!"), + FuncRequest(LFUN_NOACTION)), view); return; } @@ -618,7 +606,8 @@ void expandToc(Menu & tomenu, LyXView const * view) for (; ccit != eend; ++ccit) { string const label = limit_string_length(ccit->str); menu->add(MenuItem(MenuItem::Command, - label, ccit->action())); + label, + FuncRequest(ccit->action()))); } string const & floatName = cit->first; // Is the _(...) really needed here? (Lgb) @@ -651,9 +640,8 @@ void expandPasteRecent(Menu & tomenu, LyXView const * view) vector::const_iterator end = selL.end(); for (unsigned int index = 0; cit != end; ++cit, ++index) { - int const action = lyxaction.getPseudoAction(LFUN_PASTE, - tostr(index)); - tomenu.add(MenuItem(MenuItem::Command, *cit, action)); + tomenu.add(MenuItem(MenuItem::Command, *cit, + FuncRequest(LFUN_PASTE, tostr(index)))); } } @@ -670,12 +658,11 @@ void expandBranches(Menu & tomenu, LyXView const * view) for (int ii = 1; cit != end; ++cit, ++ii) { string label = cit->getBranch(); - int const action = lyxaction. - getPseudoAction(LFUN_INSERT_BRANCH, - (cit->getBranch())); if (ii < 10) label = tostr(ii) + ". " + label + "|" + tostr(ii); - tomenu.add(MenuItem(MenuItem::Command, label, action), view); + tomenu.add(MenuItem(MenuItem::Command, label, + FuncRequest(LFUN_INSERT_BRANCH, + cit->getBranch())), view); } } diff --git a/src/MenuBackend.h b/src/MenuBackend.h index f6746e08bb..2d9bfa887e 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -13,14 +13,15 @@ #ifndef MENUBACKEND_H #define MENUBACKEND_H +#include "FuncStatus.h" +#include "funcrequest.h" + #include "support/std_string.h" #include #include -#include "FuncStatus.h" - class LyXLex; class LyXView; class Menu; @@ -68,14 +69,17 @@ public: /** Available branches in document */ Branches }; - /// Create a Command type MenuItem - MenuItem(Kind kind, - string const & label = string(), - string const & command = string(), - bool optional = false); + + explicit MenuItem(Kind kind); + MenuItem(Kind kind, string const & label, - int action, + string const & command = string(), + bool optional = false); + + MenuItem(Kind kind, + string const & label, + FuncRequest const & func, bool optional = false); /// This one is just to please boost::shared_ptr<> @@ -89,7 +93,7 @@ public: /// The kind of entry Kind kind() const { return kind_; } /// the action (if relevant) - int action() const { return action_; } + FuncRequest const & func() const { return func_; } /// returns true if the entry should be ommited when disabled bool optional() const { return optional_; } /// returns the status of the lfun associated with this entry @@ -116,7 +120,7 @@ private: /// string label_; /// - int action_; + FuncRequest func_; /// string submenuname_; /// diff --git a/src/ToolbarBackend.C b/src/ToolbarBackend.C index 4ef1df0eed..8d91fca376 100644 --- a/src/ToolbarBackend.C +++ b/src/ToolbarBackend.C @@ -89,24 +89,43 @@ void ToolbarBackend::read(LyXLex & lex) if (lex.next(true)) { string const tooltip = _(lex.getString()); lex.next(true); - string const func = lex.getString(); + string const func_arg = lex.getString(); lyxerr[Debug::PARSER] << "ToolbarBackend::read TO_ADD func: `" - << func << '\'' << endl; - add(tb, func, tooltip); + << 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); + + } + } break; case TO_MINIBUFFER: - add(tb, MINIBUFFER); + add(tb, FuncRequest(kb_action(MINIBUFFER))); break; case TO_SEPARATOR: - add(tb, SEPARATOR); + add(tb, FuncRequest(kb_action(SEPARATOR))); break; case TO_LAYOUTS: - add(tb, LAYOUTS); + add(tb, FuncRequest(kb_action(LAYOUTS))); break; case TO_ENDTOOLBAR: @@ -193,29 +212,16 @@ void ToolbarBackend::readToolbars(LyXLex & lex) } -void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip) +void ToolbarBackend::add(Toolbar & tb, + FuncRequest const & func, string const & tooltip) { - tb.items.push_back(make_pair(action, tooltip)); + tb.items.push_back(make_pair(func, tooltip)); } -void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip) -{ - int const tf = lyxaction.LookupFunc(func); - - if (tf == -1) { - lyxerr << "ToolbarBackend::add: no LyX command called `" - << func << "' exists!" << endl; - } else { - add(tb, tf, tooltip); - } -} - - -string const ToolbarBackend::getIcon(int action) +string const ToolbarBackend::getIcon(FuncRequest const & f) { string fullname; - FuncRequest f = lyxaction.retrieveActionArg(action); if (f.action == LFUN_INSERT_MATH) { if (!f.argument.empty()) @@ -245,6 +251,6 @@ string const ToolbarBackend::getIcon(int action) lyxerr[Debug::GUI] << "Cannot find icon for command \"" << lyxaction.getActionName(f.action) - << ' ' << f.argument << '"' << endl; + << '(' << f.argument << ")\"" << endl; return LibFileSearch("images", "unknown", "xpm"); } diff --git a/src/ToolbarBackend.h b/src/ToolbarBackend.h index f5651db881..58a88765be 100644 --- a/src/ToolbarBackend.h +++ b/src/ToolbarBackend.h @@ -13,12 +13,15 @@ #ifndef TOOLBAR_BACKEND_H #define TOOLBAR_BACKEND_H +#include "funcrequest.h" + #include #include "support/std_string.h" class LyXLex; + /// class ToolbarBackend { public: @@ -33,10 +36,10 @@ public: }; /// action, tooltip - typedef std::pair Item; + typedef std::pair Item; /// the toolbar items - typedef std::vector > Items; + typedef std::vector Items; /// toolbar flags enum Flags { @@ -82,14 +85,12 @@ public: void readToolbars(LyXLex &); /// return a full path of an XPM for the given action - static string const getIcon(int action); + static string const getIcon(FuncRequest const &); private: /// add the given lfun with tooltip if relevant - void add(Toolbar & tb, int, string const & tooltip = string()); - - /// add the given lfun with tooltip if relevant - void add(Toolbar & tb, string const &, string const & tooltip); + void add(Toolbar & tb, FuncRequest const &, + string const & tooltip = string()); /// all the toolbars Toolbars toolbars; diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 557a1f84ef..2d38f585d4 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,5 +1,9 @@ +2003-09-21 Lars Gullik Bjønnes + + * LyXView.C (updateToolbar): adjust + 2003-09-18 Angus Leeming - + * Painter.C: * Painter.h: * lyx_gui.h: rename EnumLColor as LColor_color. diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index f13928fd03..ac51db295b 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -106,7 +106,7 @@ void LyXView::updateToolbar() { bool const math = mathcursor; bool const table = - !getLyXFunc().getStatus(LFUN_LAYOUT_TABULAR).disabled(); + !getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).disabled(); toolbar_->update(math, table); } @@ -191,3 +191,4 @@ void LyXView::dispatch(FuncRequest const & req) r.setView(view().get()); getLyXFunc().dispatch(r); } +10 diff --git a/src/frontends/Toolbar.h b/src/frontends/Toolbar.h index 38ece3165f..68ea1d5f75 100644 --- a/src/frontends/Toolbar.h +++ b/src/frontends/Toolbar.h @@ -32,7 +32,7 @@ public: virtual ~Toolbar(); /// Initialize toolbar from backend - void init(); + void init(); /// update the state of the toolbars void update(bool in_math, bool in_table); diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 9f0235a5d1..ca1487fecb 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,5 +1,14 @@ 2003-09-21 Lars Gullik Bjønnes + * GToolbar.C (add): Make it take a ToobarBackend::Item as arg, + adjust. + (onButtonClicked): take a FuncRequest + (update): adjust + + * GMenubar.C (submenuDisabled): pass FuncRequest to getStatus. + (onSubMenuActivate): ditto + (onCommandActivate): pass MenuItem::func to dispatch + * LyXKeySymFactory.C (create): fix new bug * GView.C (GView): fix new bug diff --git a/src/frontends/gtk/GMenubar.C b/src/frontends/gtk/GMenubar.C index 3c10348960..ac1daf27f3 100644 --- a/src/frontends/gtk/GMenubar.C +++ b/src/frontends/gtk/GMenubar.C @@ -137,7 +137,7 @@ bool GMenubar::submenuDisabled(MenuItem const * item) case MenuItem::Command: { FuncStatus const flag = - view_->getLyXFunc().getStatus(i->action()); + view_->getLyXFunc().getStatus(i->func()); if (!flag.disabled()) return false; break; @@ -180,7 +180,7 @@ void GMenubar::onSubMenuActivate(MenuItem const * item, case MenuItem::Command: { FuncStatus const flag = - view_->getLyXFunc().getStatus(i->action()); + view_->getLyXFunc().getStatus(i->func()); bool on, off; on = flag.onoff(true); off = flag.onoff(false); @@ -224,5 +224,5 @@ void GMenubar::onSubMenuActivate(MenuItem const * item, void GMenubar::onCommandActivate(MenuItem const * item, Gtk::MenuItem * /*gitem*/) { - view_->getLyXFunc().dispatch(item->action(), true); + view_->getLyXFunc().dispatch(item->func(), true); } diff --git a/src/frontends/gtk/GToolbar.C b/src/frontends/gtk/GToolbar.C index b88d8a0455..91a31d23f0 100644 --- a/src/frontends/gtk/GToolbar.C +++ b/src/frontends/gtk/GToolbar.C @@ -81,7 +81,7 @@ void GToolbar::add(ToolbarBackend::Toolbar const & tb) ToolbarBackend::item_iterator it = tb.items.begin(); ToolbarBackend::item_iterator end = tb.items.end(); for (; it != end; ++it) - add(toolbar, it->first, it->second); + add(toolbar, *it); toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS); toolbar->show(); vbox_.children().push_back( @@ -92,10 +92,11 @@ void GToolbar::add(ToolbarBackend::Toolbar const & tb) void GToolbar::add(Gtk::Toolbar * toolbar, - int action, - string const & tooltip) + ToolbarBackend::Item const & item) { - switch (action) { + FuncRequest const & func = item.first; + string const & tooltip = item.second; + switch (func.action) { case ToolbarBackend::SEPARATOR: toolbar->tools().push_back(Gtk::Toolbar_Helpers::Space()); break; @@ -109,20 +110,20 @@ void GToolbar::add(Gtk::Toolbar * toolbar, Gtk::Toolbar_Helpers::Element(combo_)); toolbar->tools().back().get_widget()->set_data( gToolData, - reinterpret_cast(LFUN_LAYOUT)); + reinterpret_cast(&const_cast(item))); break; } default: { Glib::ustring xpmName = - Glib::locale_to_utf8(toolbarbackend.getIcon(action)); + Glib::locale_to_utf8(toolbarbackend.getIcon(func)); Glib::ustring tip = Glib::locale_to_utf8(tooltip); if (xpmName.size() == 0) { toolbar->tools().push_back( Gtk::Toolbar_Helpers::ButtonElem( "", SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked), - action), + FuncRequest(func)), tip)); } else { Gtk::Image * image = @@ -133,21 +134,21 @@ void GToolbar::add(Gtk::Toolbar * toolbar, "", *image, SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked), - action), + FuncRequest(func)), tip)); } toolbar->tools().back().get_content()->set_data( gToolData, - reinterpret_cast(action)); + reinterpret_cast(&const_cast(item))); break; } } } -void GToolbar::onButtonClicked(int action) +void GToolbar::onButtonClicked(FuncRequest func) { - view_->getLyXFunc().dispatch(action, true); + view_->getLyXFunc().dispatch(func, true); } @@ -202,10 +203,11 @@ void GToolbar::update() default: widget = it->get_content(); } - int action = reinterpret_cast( + ToolbarBackend::Item * item = + reinterpret_cast( widget->get_data(gToolData)); FuncStatus const status = view_-> - getLyXFunc().getStatus(action); + getLyXFunc().getStatus(item->first); bool sensitive = !status.disabled(); widget->set_sensitive(sensitive); if (it->get_type() != Gtk::TOOLBAR_CHILD_BUTTON) diff --git a/src/frontends/gtk/GToolbar.h b/src/frontends/gtk/GToolbar.h index 0cd8fdf867..3d04909ab2 100644 --- a/src/frontends/gtk/GToolbar.h +++ b/src/frontends/gtk/GToolbar.h @@ -17,6 +17,7 @@ #include "ToolbarBackend.h" #include "support/std_string.h" + class GToolbar : public Toolbar, public SigC::Object { public: @@ -29,8 +30,7 @@ public: /// add a new button to the toolbar. void add(Gtk::Toolbar * toolbar, - int action, - string const & tooltip); + ToolbarBackend::Item const & item); /// display toolbar, not implemented void displayToolbar(ToolbarBackend::Toolbar const & tb, bool show); @@ -50,7 +50,7 @@ public: /// Erase the layout list void clearLayoutList(); private: - void onButtonClicked(int action); + void onButtonClicked(FuncRequest); void onLayoutSelected(); Gtk::VBox vbox_; std::vector toolbars_; diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index eaab5084c2..d0c61fc0cd 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,5 +1,18 @@ 2003-09-21 Lars Gullik Bjønnes + * QtView.C (activated): change to take a FuncRequest, not a slot + anymore. + + * QLToolbar.C (update): adjust + (add): change to take a FuncRequest + + * QLPopupMenu.C (createMenu): constify id + (QLPopupMenu): connect to local class func fire instead of to + QtView::activated. + (fire): new class function + (populate): change to store a cache of FuncRequest for the menu + items, adjust + * QContentPane.C (keyPressEvent): fix new bug * LyXKeySymFactory.C (create): fix new bug diff --git a/src/frontends/qt2/QLPopupMenu.C b/src/frontends/qt2/QLPopupMenu.C index cae1a1a5cf..662f766cdc 100644 --- a/src/frontends/qt2/QLPopupMenu.C +++ b/src/frontends/qt2/QLPopupMenu.C @@ -61,7 +61,7 @@ createMenu(QMenuData * parent, MenuItem const * item, QLMenubar * owner, { // FIXME: leaks ?? QLPopupMenu * pm = new QLPopupMenu(owner, item->submenuname(), is_toplevel); - int id = parent->insertItem(toqstr(getLabel(*item)), pm); + int const id = parent->insertItem(toqstr(getLabel(*item)), pm); return make_pair(id, pm); } @@ -73,12 +73,20 @@ QLPopupMenu::QLPopupMenu(QLMenubar * owner, if (toplevel) connect(this, SIGNAL(aboutToShow()), this, SLOT(showing())); connect(this, SIGNAL(activated(int)), - owner_->view(), SLOT(activated(int))); + this, SLOT(fire(int))); +} + + +void QLPopupMenu::fire(int index) +{ + owner_->view()->activated(funcs_[index]); } void QLPopupMenu::populate(Menu * menu) { + funcs_.clear(); + Menu::const_iterator m = menu->begin(); Menu::const_iterator end = menu->end(); for (; m != end; ++m) { @@ -92,9 +100,13 @@ void QLPopupMenu::populate(Menu * menu) } else { FuncStatus const status = m->status(); - insertItem(toqstr(getLabel(*m)), m->action()); - setItemEnabled(m->action(), !status.disabled()); - setItemChecked(m->action(), status.onoff(true)); + Funcs::iterator fit = + funcs_.insert(funcs_.end(), m->func()); + int const index = std::distance(funcs_.begin(), fit); + + insertItem(toqstr(getLabel(*m)), index); + setItemEnabled(index, !status.disabled()); + setItemChecked(index, status.onoff(true)); } } } diff --git a/src/frontends/qt2/QLPopupMenu.h b/src/frontends/qt2/QLPopupMenu.h index 8f1491e72d..cf1279cc2c 100644 --- a/src/frontends/qt2/QLPopupMenu.h +++ b/src/frontends/qt2/QLPopupMenu.h @@ -15,8 +15,11 @@ #include +#include "funcrequest.h" + #include "support/std_string.h" +#include #include class MenuBackend; @@ -43,12 +46,19 @@ public: public slots: /// populate the toplevel menu and all children void showing(); + /// + void fire(int); private: /// our owning menubar QLMenubar * owner_; /// the name of this menu string name_; + + /// + typedef std::vector Funcs; + /// + Funcs funcs_; }; #endif // QLPOPUPMENU_H diff --git a/src/frontends/qt2/QLToolbar.C b/src/frontends/qt2/QLToolbar.C index f9bfe50f5a..f88e416d55 100644 --- a/src/frontends/qt2/QLToolbar.C +++ b/src/frontends/qt2/QLToolbar.C @@ -62,17 +62,17 @@ void QLToolbar::update() for (; p != end; ++p) { QToolButton * button = p->first; - int action = p->second; + FuncRequest const & func = p->second; FuncStatus const status = - owner_->getLyXFunc().getStatus(action); + owner_->getLyXFunc().getStatus(func); button->setToggleButton(true); button->setOn(status.onoff(true)); button->setEnabled(!status.disabled()); } - bool const enable = !owner_->getLyXFunc().getStatus(LFUN_LAYOUT).disabled(); + bool const enable = !owner_->getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT)).disabled(); // Workaround for Qt bug where setEnabled(true) closes // the popup @@ -225,9 +225,10 @@ void QLToolbar::add(ToolbarBackend::Toolbar const & tb) } -void QLToolbar::add(QToolBar * tb, int action, string const & tooltip) +void QLToolbar::add(QToolBar * tb, + FuncRequest const & func, string const & tooltip) { - switch (action) { + switch (func.action) { case ToolbarBackend::SEPARATOR: tb->addSeparator(); break; @@ -247,14 +248,14 @@ void QLToolbar::add(QToolBar * tb, int action, string const & tooltip) tb->setHorizontalStretchable(true); break; default: { - if (owner_->getLyXFunc().getStatus(action).unknown()) + if (owner_->getLyXFunc().getStatus(func).unknown()) break; - QPixmap p = QPixmap(toolbarbackend.getIcon(action).c_str()); + QPixmap p = QPixmap(toolbarbackend.getIcon(func).c_str()); QToolButton * button = new QToolButton(p, toqstr(tooltip), "", proxy_.get(), SLOT(button_selected()), tb); - map_[button] = action; + map_[button] = func; break; } } diff --git a/src/frontends/qt2/QLToolbar.h b/src/frontends/qt2/QLToolbar.h index b71ffdeb1a..1701523f27 100644 --- a/src/frontends/qt2/QLToolbar.h +++ b/src/frontends/qt2/QLToolbar.h @@ -41,7 +41,7 @@ public: void add(ToolbarBackend::Toolbar const & tb); /// add an item to a toolbar - void add(QToolBar * tb, int action, string const & tooltip); + void add(QToolBar * tb, FuncRequest const &, string const & tooltip); /// show or hide a toolbar void displayToolbar(ToolbarBackend::Toolbar const & tb, bool show); @@ -70,7 +70,7 @@ private: QLComboBox * combo_; - typedef std::map ButtonMap; + typedef std::map ButtonMap; ButtonMap map_; }; diff --git a/src/frontends/qt2/QtView.C b/src/frontends/qt2/QtView.C index e0242ce9e7..3d467365da 100644 --- a/src/frontends/qt2/QtView.C +++ b/src/frontends/qt2/QtView.C @@ -129,9 +129,9 @@ void QtView::update_view_state() } -void QtView::activated(int id) +void QtView::activated(FuncRequest const & func) { - getLyXFunc().dispatch(id, true); + getLyXFunc().dispatch(func, true); } diff --git a/src/frontends/qt2/QtView.h b/src/frontends/qt2/QtView.h index 9f3dcf5807..00d291def8 100644 --- a/src/frontends/qt2/QtView.h +++ b/src/frontends/qt2/QtView.h @@ -22,6 +22,7 @@ #include class QCommandBuffer; +class FuncRequest; /** * QtView - Qt implementation of LyXView @@ -51,10 +52,10 @@ public: /// add the command buffer void addCommandBuffer(QWidget * parent); -public slots: /// menu item has been selected - void activated(int id); + void activated(FuncRequest const &); +public slots: /// idle timeout void update_view_state_qt(); protected: diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 557bb8cf5b..bd4a9213b5 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,5 +1,11 @@ 2003-09-21 Lars Gullik Bjønnes + * XFormsToolbar.C: adjust + + * XFormsMenubar.C (create_submenu): change to update a cache of + FuncRequest for the MenuItems. + (MenuCallback): adjust + * lyx_gui.C (parse_init): fix new bug * XFormsToolbar.C (XFormsToolbar): fix new bug diff --git a/src/frontends/xforms/XFormsMenubar.C b/src/frontends/xforms/XFormsMenubar.C index a839c72624..0bd5360782 100644 --- a/src/frontends/xforms/XFormsMenubar.C +++ b/src/frontends/xforms/XFormsMenubar.C @@ -192,9 +192,10 @@ string const fixlabel(string const & str) int XFormsMenubar::create_submenu(Window win, XFormsView * view, - Menu const & menu, vector & smn) + Menu const & menu, + vector & smn, Funcs & funcs) { - const int menuid = get_new_submenu(smn, win); + int const menuid = get_new_submenu(smn, win); lyxerr[Debug::GUI] << "XFormsMenubar::create_submenu: creating " << menu.name() << " as menuid=" << menuid << endl; @@ -226,7 +227,7 @@ int XFormsMenubar::create_submenu(Window win, XFormsView * view, ++count; // add a More... submenu if the menu is too long (but // not just for one extra entry!) - if (count > max_number_of_items && (i+1) != end) { + if (count > max_number_of_items && (i + 1) != end) { int tmpmenuid = get_new_submenu(smn, win); lyxerr[Debug::GUI] << "Too many items, creating " << "new menu " << tmpmenuid << endl; @@ -258,7 +259,7 @@ int XFormsMenubar::create_submenu(Window win, XFormsView * view, } // Is there a separator after the item? - if ((i+1) != end + if ((i + 1) != end && (i + 1)->kind() == MenuItem::Separator) label += "%l"; @@ -282,7 +283,7 @@ int XFormsMenubar::create_submenu(Window win, XFormsView * view, // create the submenu submenuid = create_submenu(win, view, - *item.submenu(), smn); + *item.submenu(), smn, funcs); if (submenuid == -1) return -1; label += "%x" + tostr(smn.size()); @@ -292,10 +293,16 @@ int XFormsMenubar::create_submenu(Window win, XFormsView * view, << "), "; } else { // Add the action - label += "%x" + tostr(item.action() - + action_offset); + Funcs::iterator fit = + funcs.insert(funcs.end(), item.func()); + int const action_count = + std::distance(funcs.begin(), fit); + + label += "%x" + tostr(action_count + action_offset); lyxerr[Debug::GUI] << "Action: \"" - << item.action() << "\", "; + << item.func().action + << "(" << item.func().argument + << ")\", "; } // Add everything to the menu @@ -353,9 +360,10 @@ void XFormsMenubar::MenuCallback(FL_OBJECT * ob, long button) Menu tomenu; Menu const frommenu = menubackend_->getMenu(item->submenuname()); menubackend_->expand(frommenu, tomenu, view); + Funcs funcs; vector submenus; int menu = iteminfo->menubar_->create_submenu(FL_ObjWin(ob), view, - tomenu, submenus); + tomenu, submenus, funcs); if (menu != -1) { // place popup fl_setpup_position(view->getForm()->x + ob->x, @@ -370,8 +378,8 @@ void XFormsMenubar::MenuCallback(FL_OBJECT * ob, long button) // If the action value is too low, then it is not a // valid action, but something else. - if (choice >= action_offset + 1) { - view->getLyXFunc().dispatch(choice - action_offset, true); + if (choice >= action_offset) { + view->getLyXFunc().dispatch(funcs[choice - action_offset], true); } else { lyxerr[Debug::GUI] << "MenuCallback: ignoring bogus action " diff --git a/src/frontends/xforms/XFormsMenubar.h b/src/frontends/xforms/XFormsMenubar.h index 8d01d077ca..04775b3ea0 100644 --- a/src/frontends/xforms/XFormsMenubar.h +++ b/src/frontends/xforms/XFormsMenubar.h @@ -12,6 +12,7 @@ #ifndef XFORMSMENUBAR_H #define XFORMSMENUBAR_H +#include "funcrequest.h" #include "frontends/Menubar.h" #include @@ -22,6 +23,7 @@ #include "support/std_string.h" #include + class LyXView; class XFormsView; class Menu; @@ -30,6 +32,8 @@ class MenuBackend; class XFormsMenubar : public Menubar { public: + /// + typedef std::vector Funcs; /// XFormsMenubar(LyXView *, MenuBackend const &); /// @@ -53,7 +57,8 @@ private: std::vector & smn, Window win); /// int create_submenu(Window win, XFormsView * view, - Menu const & menu, std::vector & smn); + Menu const & menu, + std::vector & smn, Funcs & funcs); // void makeMenubar(Menu const & menu); diff --git a/src/frontends/xforms/XFormsToolbar.C b/src/frontends/xforms/XFormsToolbar.C index 5f4e7c9947..34ab67c845 100644 --- a/src/frontends/xforms/XFormsToolbar.C +++ b/src/frontends/xforms/XFormsToolbar.C @@ -40,7 +40,7 @@ const int buttonwidth = 30; // the standard button width const int height = 30; // the height of all items in the toolbar XFormsToolbar::toolbarItem::toolbarItem() - : action(LFUN_NOACTION), icon(0) + : icon(0) {} @@ -81,7 +81,7 @@ XFormsToolbar::toolbarItem::operator=(toolbarItem const & ti) // But we don't copy the icon from ti kill_icon(); - action = ti.action; + func = ti.func; return *this; } @@ -113,10 +113,10 @@ void XFormsToolbar::update() ToolbarList::const_iterator p = toollist_.begin(); ToolbarList::const_iterator end = toollist_.end(); for (; p != end; ++p) { - if (p->action == ToolbarBackend::LAYOUTS && combox_) { + if (p->func.action == int(ToolbarBackend::LAYOUTS) && combox_) { LyXFunc const & lf = owner_->getLyXFunc(); bool const disable = - lf.getStatus(LFUN_LAYOUT).disabled(); + lf.getStatus(FuncRequest(LFUN_LAYOUT)).disabled(); setEnabled(combox_, !disable); continue; } @@ -124,7 +124,7 @@ void XFormsToolbar::update() if (!p->icon) continue; - FuncStatus const status = owner_->getLyXFunc().getStatus(p->action); + FuncStatus const status = owner_->getLyXFunc().getStatus(p->func); if (status.onoff(true)) { // I'd like to use a different color // here, but then the problem is to @@ -249,9 +249,12 @@ namespace { void ToolbarCB(FL_OBJECT * ob, long ac) { - XFormsView * owner = static_cast(ob->u_vdata); + if (!ob || !ob->u_vdata) + return; - owner->getLyXFunc().dispatch(int(ac), true); + XFormsToolbar * ptr = static_cast(ob->u_vdata); + XFormsView * owner = ptr->owner_; + owner->getLyXFunc().dispatch(ptr->funcs[ac], true); } @@ -273,6 +276,8 @@ void XFormsToolbar::add(ToolbarBackend::Toolbar const & tb) if (!toollist_.empty()) return; + funcs.clear(); + ToolbarBackend::item_iterator it = tb.items.begin(); ToolbarBackend::item_iterator end = tb.items.end(); for (; it != end; ++it) @@ -280,12 +285,12 @@ void XFormsToolbar::add(ToolbarBackend::Toolbar const & tb) } -void XFormsToolbar::add(int action, string const & tooltip) +void XFormsToolbar::add(FuncRequest const & func, string const & tooltip) { toolbarItem item; - item.action = action; + item.func = func; - switch (action) { + switch (func.action) { case ToolbarBackend::SEPARATOR: xpos += sepspace; break; @@ -322,17 +327,19 @@ void XFormsToolbar::add(int action, string const & tooltip) fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity); - fl_set_object_callback(obj, C_Toolbar_ToolbarCB, - static_cast(action)); + + Funcs::iterator fit = funcs.insert(funcs.end(), func); + int const index = std::distance(funcs.begin(), fit); + fl_set_object_callback(obj, C_Toolbar_ToolbarCB, index); // Remove the blue feedback rectangle fl_set_pixmapbutton_focus_outline(obj, 0); tooltip_->init(obj, tooltip); // The view that this object belongs to. - obj->u_vdata = owner_; + obj->u_vdata = this; - string const xpm = toolbarbackend.getIcon(action); + string const xpm = toolbarbackend.getIcon(func); fl_set_pixmapbutton_file(obj, xpm.c_str()); // we must remember to update the positions diff --git a/src/frontends/xforms/XFormsToolbar.h b/src/frontends/xforms/XFormsToolbar.h index 9da0a3d774..f0a5084730 100644 --- a/src/frontends/xforms/XFormsToolbar.h +++ b/src/frontends/xforms/XFormsToolbar.h @@ -36,7 +36,7 @@ public: void add(ToolbarBackend::Toolbar const & tb); /// add an item to a toolbar - void add(int action, string const & tooltip); + void add(FuncRequest const &, string const & tooltip); /// display toolbar, not implemented void displayToolbar(ToolbarBackend::Toolbar const & tb, bool show); @@ -67,12 +67,16 @@ public: /// deallocate icon void kill_icon(); - /// lyx action number - int action; + /// lyx action + FuncRequest func; /// icon for this item FL_OBJECT * icon; }; + typedef std::vector Funcs; + + Funcs funcs; + typedef std::vector ToolbarList; /// The list containing all the buttons diff --git a/src/funcrequest.C b/src/funcrequest.C index d916a4c620..6192a79f57 100644 --- a/src/funcrequest.C +++ b/src/funcrequest.C @@ -127,7 +127,7 @@ void split(vector & args, string str) } -string FuncRequest::getArg(int i) const +string FuncRequest::getArg(unsigned int i) const { vector args; split(args, argument); diff --git a/src/funcrequest.h b/src/funcrequest.h index 5ebe6fa9d1..439671b780 100644 --- a/src/funcrequest.h +++ b/src/funcrequest.h @@ -57,7 +57,7 @@ public: void errorMessage(string const & msg) const; /// argument parsing, extract argument i as string - string getArg(int i) const; + string getArg(unsigned int i) const; private: /// the BufferView we are talking to diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 43b1d9010e..ac8e3beb0b 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -264,17 +264,11 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, << argument << "']" << endl; } } else { - dispatch(action); + dispatch(FuncRequest(kb_action(action))); } } -FuncStatus LyXFunc::getStatus(int ac) const -{ - return getStatus(lyxaction.retrieveActionArg(ac)); -} - - FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const { FuncStatus flag; @@ -809,7 +803,7 @@ 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(lyxaction.LookupFunc(token(ev.argument, ';', 0))); + flag = getStatus(FuncRequest(lyxaction.LookupFunc(token(ev.argument, ';', 0)))); } return flag; @@ -825,15 +819,10 @@ void LyXFunc::dispatch(string const & s, bool verbose) return; } - dispatch(action, verbose); + dispatch(FuncRequest(kb_action(action)), verbose); } -void LyXFunc::dispatch(int ac, bool verbose) -{ - dispatch(lyxaction.retrieveActionArg(ac), verbose); -} - namespace { bool ensureBufferClean(BufferView * bv) { @@ -1093,7 +1082,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) meta_fake_bit = key_modifier::none; if (view()->available()) // cancel any selection - dispatch(LFUN_MARK_OFF); + dispatch(FuncRequest(LFUN_MARK_OFF)); setMessage(N_("Cancel")); break; @@ -1715,22 +1704,16 @@ void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & ev, bo string comname = lyxaction.getActionName(ev.action); - int pseudoaction = ev.action; bool argsadded = false; if (!ev.argument.empty()) { - // the pseudoaction is useful for the bindings - pseudoaction = lyxaction.searchActionArg(ev.action, ev.argument); - - if (pseudoaction == LFUN_UNKNOWN_ACTION) { - pseudoaction = ev.action; - } else { + if (ev.action != LFUN_UNKNOWN_ACTION) { comname += ' ' + ev.argument; argsadded = true; } } - string const shortcuts = toplevel_keymap->findbinding(pseudoaction); + string const shortcuts = toplevel_keymap->findbinding(ev.action); if (!shortcuts.empty()) { comname += ": " + shortcuts; diff --git a/src/lyxfunc.h b/src/lyxfunc.h index b67b5c5821..e71f0ef33f 100644 --- a/src/lyxfunc.h +++ b/src/lyxfunc.h @@ -49,9 +49,6 @@ public: /// Dispatch via a string argument void dispatch(string const & s, bool verbose = false); - /// Dispatch via a pseudo action, also displaying shortcut/command name - void dispatch(int ac, bool verbose = false); - /// return the status bar state string string const view_status_message(); @@ -60,9 +57,6 @@ public: /// void processKeySym(LyXKeySymPtr key, key_modifier::state state); - /// we need one internal which is called from inside LyXAction and - /// can contain the string argument. - FuncStatus getStatus(int ac) const; /// FuncStatus getStatus(FuncRequest const & action) const; diff --git a/src/toc.C b/src/toc.C index 0338f3f98a..8861cc4c08 100644 --- a/src/toc.C +++ b/src/toc.C @@ -47,10 +47,9 @@ void TocItem::goTo(LyXView & lv_) const } -int TocItem::action() const +FuncRequest TocItem::action() const { - return lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH, - tostr(id_)); + return FuncRequest(LFUN_GOTO_PARAGRAPH, tostr(id_)); } diff --git a/src/toc.h b/src/toc.h index 91aeaacc41..5ca643da72 100644 --- a/src/toc.h +++ b/src/toc.h @@ -22,6 +22,7 @@ class Buffer; class LyXView; class Paragraph; +class FuncRequest; /** Nice functions and objects to handle TOCs */ @@ -37,7 +38,7 @@ struct TocItem { /// set cursor in LyXView to this TocItem void goTo(LyXView & lv_) const; /// the action corresponding to the goTo above - int action() const; + FuncRequest action() const; /// Paragraph ID containing this item int id_; /// nesting depth