John Levon <[EMAIL PROTECTED]> writes: | Rather than justify any of this, I'll just show it and let people | comment. > | There's lots of things I don't really like (helpful comments are "why | not like this instead" not "this bit sucks"). "big picture" comments are | probably most useful > | comments ?
loose the Tabular -> Table change action -> Action Please describe the functions of handler_base. I need some time to digest this so no rash movements now please. I do not like all the "context"'s ... | Index: action.C | =================================================================== | RCS file: action.C | diff -N action.C | --- /dev/null 1 Jan 1970 00:00:00 -0000 | +++ action.C 31 Jul 2002 17:03:40 -0000 | @@ -0,0 +1,182 @@ | +/** | + * \file action.C | + * Copyright 2002 the LyX Team | + * Read the file COPYING | + * | + * Handling of actions. An action is any event or | + * internal change. | + * | + * \author John Levon <[EMAIL PROTECTED]> | + */ | + | +#include "action.h" | + | +#include "frontends/LyXView.h" | +#include "LyXAction.h" | +#include "BufferView.h" | +#include "buffer.h" | +#include "lyxfunc.h" | +#include "gettext.h" | +#include "debug.h" | + | +#include <algorithm> | + | +using std::endl; | +using std::pair; | +using std::make_pair; | + | +action actions; | +action::context action::next_context = action::buffer_context + 1; | + | + | +action::result::result() | + : failed(false), message(""), post_action(LFUN_NOACTION) | +{ | +} | + | + | +action::result::result(char const * str) | + : failed(false), message(str), post_action(LFUN_NOACTION) | +{ | +} | + | + | +action::result::result(string const & str, bool f, int post) | + : failed(f), message(str), post_action(post) | +{ | +} | + | + | +action::context action::get_context() const | +{ | + return next_context++; ++next_context?? | +} | + | + | +void action::add(action::context context, int action, action::handler_base const * |def) | +{ | + if (find(context, action)) { | + lyxerr << "already defined !" << endl; | + return; | + } | + | + action_map[action][context] = def; This looks just opposite than I usually think about it... [context][action] but you might be right that this is actually more natural | +pair<Inset *, action::handler_base const *> action::find(BufferView | +& bv, int action) typedef the pairs | +action::result action::dispatch(BufferView & bv, int action, string const & arg, |bool & found) | +{ | + pair<Inset *, handler_base const *> h(find(bv, action)); | + | + if (!h.second) | + return result(); | + | + found = true; | + action::result result; | + | + result = (*h.second)(bv, h.first, arg); boost::bind boost::function ?? | + struct handler_base { | + virtual result operator()(BufferView &, Inset *, | + string const &) const { return result(); } I belive that we should use a more descriptive name... "exec" perhaps, then rather use a binder to get to the functor. (bloat perhaps?) | + typedef unsigned int context; | + | + static context const no_context = 0; | + static context const lyxview_context = 1; | + static context const buffer_context = 2; | + static context next_context; Why not let the contexts be strings? Makes a lot of things a bit easier (a bit slower... but not exactly a lot...) -- Lgb