On Fri, Aug 16, 2002 at 06:26:35PM +0100, Angus Leeming wrote:
> ----------  Forwarded Message  ----------
> 
> Subject: LyXFunc/LyXAction
> Date: 13 Oct 2000 15:48:08 +0200
> From: [EMAIL PROTECTED] (Lars Gullik Bjønnes)
> To: [EMAIL PROTECTED]
> 
> We should make a way to ensure that LyXFunc are called with the
> correct number of arguments and also that the arguments are of the
> correct type. I think I have a nice solution for this...first we
> change the LyXFunc::dispatch to a different type of arg...
> 
> LyXFunc::dispatch(FuncSlot const & funcslot);

Ok, we have that single parameter now, but I _really_ see no big value in
enforcing correct arguments. The "handler" should complain if args are not
to its liking and that's it. KISS.

> class FuncSlot {
> public:
>         FuncSlot(string const & func);
>         FuncSlot & arg(string const & a);
> private:
>         string func_;
>         vector<string> argList;
> };
> 
> to be used like this:
> 
> lyxfunc.dispatch(FuncSlot("buffer-new").arg("newfile"));

[*grin* The _really_ interesting fact is that Lars uses strings for command
names, not the kb_action enum. Anyway...]

I don't think putting _everything_ in a string makes for compact code. Lets
suppose I want to "rethrow" an mouse event as insettext does - with
slightly altered coordinates. So instead of

   dispatch(FuncRequest const & cmd)
   {
      FuncRequest c = cmd;
      c.x -= inset_x; 
      c.y -= inset_y
      dispatch(c);
   } 

we would need something like
   
   dispatch(FuncSlot const & slot)
   {
     string command;
     int x, y;
     slot >> command >> x >> y;
     ostringstream os;
     os << command << x - inset_x << y - inset_y;
     dispatch(FuncSlot(slot.func(), os.str()));
   }

Not Nice(tm).

I believe the current solution of putting in "important" integer parameters
as int is just fine. I find them very convenient to handle.

Now the focus should be on moving functionality to where it belongs (this
should help disentangling the core) and providing LFUNs for stuff that
could be done this way (the edit() call comes to mind).

If nobody complains about the mouse-lfun patch until Monday morning, I'll
take that as permission to go on ;-)  

Andre', off for the weekend now.
 
-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)

Reply via email to