Lisp HUG Maillist Archive

CAPI best practice question

This question is really for those of you who have been programming CAPI 
for a while...

I have a very common occurrence in my code where I'll have a pretty 
generic action I want to perform on the "backend" of my application. 
Completely contrived example incoming...

(defun delete-thing (pane) ...)

Now, let's say I want to call delete-thing whenever the object is double 
clicked. So, I subclass the pane and add that functionality...

(defclass my-pane (output-pane)
   ()
   (:default-initargs
    :input-model '(((:button :second-press) delete-thing))))

But, now I have a problem. The input-model callback will also pass along 
the x and y coordinates of where the click took place. But, other places 
in code will want to call delete-thing as well.

I've been toying with two different solutions:

* Add &optional x y parameters to the delete-thing function.
* Have :input-model call a different function, which in-turn calls 
delete-thing.

But work fine, but I'm wondering if - as my projects grow - is one going 
to be considerably better long-term? Is there another solution that I'm 
not seeing?

Jeff M.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: CAPI best practice question

Jeffrey Massung wrote on Fri, 10 Jan 2014 08:15:04 -0600 18:15:

| I have a very common occurrence in my code where I'll have a pretty
| generic action I want to perform on the "backend" of my application.
| Completely contrived example incoming...
|
| (defun delete-thing (pane) ...)
|...snip...|

I would suggest to follow a model-view-controller approach. Separate
operations on model objects from handlers for GUI widgets. For example:

;;; Model
(defgeneric delete-thing (object) ...)

;;; View
(defclass my-pane (output-pane)
    ()
    (:default-initargs
     :input-model '(((:button :second-press) handle-second-press))))

;;; Controller
(defgeneric handle-second-press (pane x y)
 (:method ((pane my-pane) x y)
  (delete-thing (my-object my-pane))))
--
Sincerely,
Dmitry Ivanov
lisp.ystok.ru

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:34 UTC