Author Topic: Using "ENTER" key in "edit-box"  (Read 1508 times)

0 Members and 1 Guest are viewing this topic.

ymg

  • Swamp Rat
  • Posts: 725
Using "ENTER" key in "edit-box"
« on: October 09, 2015, 05:40:41 am »
Maybe there is  a better way to do it, but here goes.

Code - Auto/Visual Lisp: [Select]
  1. ;;                                                                            ;
  2. ;; Action_Focus    by ymg                                                     ;
  3. ;;                                                                            ;
  4. ;; Given a list of "Tile Key" will create necessaries "action-tile"           ;
  5. ;; be able to use "ENTER" key in "edit-box" of a dialogue.                    ;
  6. ;;                                                                            ;
  7. ;; The Dialogue file must not contain any "is_default = true;"                ;
  8. ;;                                                                            ;
  9.  
  10. (defun Action_Focus (l)
  11.   (setq l (append l '("accept")))
  12.   (mode_tile (car l) 3)
  13.   (mapcar '(lambda (a b)
  14.      (action_tile a (strcat  "(if (= $reason 1)"
  15.      "   (mode_tile \"" b "\" " (itoa 2) ")"
  16.                                      "   (setq  a  $val)"
  17.      ")" ))) l (cdr l)
  18.   )
  19. )                          
  20.  

I find it somewhat perplexing that we cannot use the "ENTER" key to enter
simple data in "edit-box"

The only solution I could find was a suggestion by MSasu at CadTutor to use
something like the following:
Code - Auto/Visual Lisp: [Select]
  1. (mode_tile "EditBox1st" 2)                                  ;set initial focus to first edit box
  2. (action_tile "EditBox1st" "(mode_tile \"EditBox2nd\" 2)")   ;switch focus from first to second
  3. (action_tile "EditBox2nd" "(mode_tile \"EditBox3rd\" 2)")   ;switch focus from second to third
  4. (action_tile "EditBox3rd" "(mode_tile \"accept\" 2)")       ;set final focus from third to OK
  5.  

The problem with this method is that you must go through all the boxes in order to
even be able to cancel or accept the dialogue, as the "action-tile" gets fired before
"cancel" or "accept" and focus is tranfered to the next tile.

The proposed "action-focus" routine get rid of this problem, by testing the value
of  $reason.  If value is equal to "1", we either pressed "ENTER" or Selected another
tile. All we do at this point is to accept anything that was entered and do not change
focus.

Seems to work OK, but maybe somebody knows a better way.

ymg
« Last Edit: October 09, 2015, 09:51:40 am by ymg »

roy_043

  • Swamp Rat
  • Posts: 1428
  • BricsCAD 16
Re: Using "ENTER" key in "edit-box"
« Reply #1 on: October 09, 2015, 06:23:25 am »
If the edit_box has the allow_accept attribute set to 'true' hitting enter should trigger the default button in the dialog.
See: http://docs.autodesk.com/ACD/2011/ENU/filesALG/WS73099cc142f4875516d84be10ebc87a53f-7b1b.htm
« Last Edit: October 09, 2015, 06:27:31 am by roy_043 »

ymg

  • Swamp Rat
  • Posts: 725
Re: Using "ENTER" key in "edit-box"
« Reply #2 on: October 09, 2015, 08:14:47 am »
Roy,

I do not want to trigger the default button, but instead be
able to use either "ENTER" or "TAB" to go from one box
to the other.

In other word doing "ENTER" is the same as doing "TAB",
any value in the edit box is accepted.

ymg
« Last Edit: October 09, 2015, 09:49:15 am by ymg »

roy_043

  • Swamp Rat
  • Posts: 1428
  • BricsCAD 16
Re: Using "ENTER" key in "edit-box"
« Reply #3 on: October 12, 2015, 03:59:56 am »
You are right, I have misunderstood.

roy_043

  • Swamp Rat
  • Posts: 1428
  • BricsCAD 16
Re: Using "ENTER" key in "edit-box"
« Reply #4 on: October 12, 2015, 04:57:57 am »
Thanks for sharing this clever idea.

I don't think there is a problem with "is_default = true;". The default button clusters all have this feature and in BricsCAD there is no problem with the ok_cancel cluster.

Your explanation of the $reason values is not completely accurate. Only if you press enter can $reason be 1. And only in that case does the code change the focus.

I think you want (setq a $val) to also execute in $reason=1. Either that or remove it and have the "accept" action read all the input.

ymg

  • Swamp Rat
  • Posts: 725
Re: Using "ENTER" key in "edit-box"
« Reply #5 on: October 12, 2015, 11:27:15 am »
Roy,

Quote
Your explanation of the $reason values is not completely accurate.

In the case of other action say Tab or I click on another edit_box, the $val is accepted,
and the focus change.

So I don't need to do anything else I think.

ymg

roy_043

  • Swamp Rat
  • Posts: 1428
  • BricsCAD 16
Re: Using "ENTER" key in "edit-box"
« Reply #6 on: October 12, 2015, 02:11:57 pm »
Things may be different in BricsCAD (the CAD program I use), but if a user hits Enter (setq a $val) does not execute. This seems strange. Maybe in AutoCAD there are two callbacks in that case, one with $reason=1 and one with $reason=2?

If value is equal to "1", we either pressed "ENTER" or Selected another tile.
In BricsCAD if $reason is 1, the user must have pressed Enter. If the user selects another tile $reason is 2.

roy_043

  • Swamp Rat
  • Posts: 1428
  • BricsCAD 16
Re: Using "ENTER" key in "edit-box"
« Reply #7 on: October 12, 2015, 02:47:47 pm »
I think the lambda should be:
Code - Auto/Visual Lisp: [Select]
  1. '(lambda (a b)
  2.    a
  3.    (strcat
  4.      "(setq " a " $value)"
  5.      "(if (= 1 $reason) (mode_tile \"" b "\" 2))"
  6.    )
  7.  )
  8. )

ymg

  • Swamp Rat
  • Posts: 725
Re: Using "ENTER" key in "edit-box"
« Reply #8 on: October 13, 2015, 03:56:52 am »
Roy,

You got a point there, but both our methods for the lambda
sets $val on every firing of the action.

I believe we don't need that we could go with only:

Code - Auto/Visual Lisp: [Select]
  1. (defun Action_Focus (l)
  2.   (setq l (append l '("accept")))
  3.   (mode_tile (car l) 3)
  4.   (mapcar '(lambda (a b)
  5.      (action_tile a (strcat  "(if (= $reason 1)"
  6.      "   (mode_tile \"" b "\" " (itoa 2) ")"
  7.      ")" ))) l (cdr l)
  8.   )
  9. )          
  10.  

The change of focus takes care of the setting of $val.

According to my test, it works as advertised.

ymg
« Last Edit: October 13, 2015, 04:08:16 am by ymg »

roy_043

  • Swamp Rat
  • Posts: 1428
  • BricsCAD 16
Re: Using "ENTER" key in "edit-box"
« Reply #9 on: October 13, 2015, 04:25:21 am »
Note that BricsCAD recognizes $value and not $val.
I think that (setq a $value) does not work as you expect it to. With that code you set a Lisp variable 'a' to the current string value in the edit_box. You do not need it for the DCL side of things.