@apottsDRQ8Z
Here are my comments Scot:
You are correct if you want to restrict the callback trigger actions on the edit_box.
I've added these options to your code commenting out the ones not used:
(action_tile "Edi1" "(if (= $reason 1) (Edi_Search $value))") ; pass entered value to Edi_Search function
; (action_tile "Edi1" "(Edi_Search)") ; both enter & tab triggers
; (action_tile "Edi1" "(if (= $reason 1) (Edi_Search))") ; only enter triggers
; (action_tile "Edi1" "(if (= $reason 2) (Edi_Search))") ; other methods like tab to leave triggers
Notice I added an argument to pass the $value which represents the current text entered into the edit_box onto the Edi_Search function and I made some additional modifications to that Edi_Search function as well:
;==== Function Edit Box [Enter] to start query and move to List Box ========
; Argument:
; val = value from edit box
(defun Edi_Search ( val / idx ) ; arguments & localize variables
(alert val)
; (alert (get_tile "Edi1"))
(mode_tile "Lis1" 0) ;enable tile
(start_list "Lis1")(mapcar 'add_list (setq a (list "Apple" "Orange" "Peach")))(end_list)
(if (setq idx (vl-position val a)) ; chk if entered value matches with an index item in list
(set_tile "Lis1" (itoa idx)) ; then when matches set position as entered value by converting index # to string
(progn ; else when no match
(setq idx 0) ; set position as first item
(set_tile "Lis1" (itoa idx)) ; select item on list
(set_tile "Edi1" (nth idx a)) ; change edit box value to use selected item
)
) ; if
(mode_tile "Lis1" 2) ;set focus to this tile
(mode_tile "insert" 0) ;enable tile
);end Edi_Search
I then updated the "But1" callback function to reflect this change to the Edi_Search function:
(action_tile "But1" "(Edi_Search (get_tile \"Edi1\"))")
; (action_tile "But1" "(Edi_Search)")
Instead of having to deal with the issue of having to locate a separate dcl file in the same folder as the lsp file I added a function that writes your dcl file on the fly to the temp folder which is what gets loaded:
;==== Function writes dcl on the fly
; Argument:
; fil = dcl file name
(defun wri_dcl ( fil / dcl-fn dcl-fp dcl-fn )
(if (and (setq dcl-fn (vl-filename-mktemp fil)) (setq dcl-fp (open dcl-fn "w")))
(mapcar
'(lambda (x)(write-line x dcl-fp))
(list
"//"
"// test-EditBox-Enter.DCL"
"//"
"swh0 :spacer {width=0.0; height=0.0;}"
"rfwtac :row {fixed_width=true; alignment=centered; height=3.5;}"
"but12 :button {fixed_width=true; width=12.0;}"
"//"
"EdiBox"
":dialog {label=\"Edit and List Box Exercise\";"
" swh0;"
" :text_part {key=\"Tex1\"; width=23.0; alignment=centered;}"
"// :edit_box {key=\"Edi1\"; fixed_width=true; width=23.0; alignment=centered;}"
" :edit_box {key=\"Edi1\"; label=\"S&earch\"; fixed_width=true; width=23.0; alignment=centered; is_default = true;}"
" swh0;"
" :but12 {key=\"But1\"; label=\"&Search\"; alignment=centered;}"
" swh0;"
"// :list_box {key=\"Lis1\"; fixed_width=true; width=26.2; alignment=centered;}"
" :list_box {key=\"Lis1\"; label=\"Select Ite&m\"; fixed_width=true; width=26.2; alignment=centered;}"
" :rfwtac {"
" swh0;"
" :but12 {key=\"insert\"; label=\"&Insert <\";}"
" swh0;"
" :but12 {key=\"cancel\"; label=\"&Cancel\"; is_cancel=true;}"
" swh0;"
" }"
"}"
)
)
)
(if dcl-fp (progn (close dcl-fp) dcl-fn)) ; return filename if successful
)
;==== DASHBOARD ============================================================
(princ "Test Edit and List Box Behavior ")
(setq sd 0) ;Initialize flag to enter main program
(setq dcl (wri_dcl "test-EditBox-Enter.dcl")) ; write dcl on the fly
(if dcl
(progn
(EdiBox_Dialog) ;Get User Input
(vl-file-delete dcl) ; delete dcl
(if (and sd (> sd 0)) ;Enter "Main Program"
(progn
;*** Execute or send to function(s) ***
(alert a)
(princ)
);progn
; else alert user
(alert "Cancel Button Selected")
);if
)
(alert "Failed to Write DCL")
)
;
Also I made the following minor changes:
(defun c:EdiBox
; localize functions & variables
( / a dcl Edi_List Edi_Search EdiBox_Dialog sd wri_dcl )
; ( / a sd )
;
(vl-load-com) ; load vl functions
; the following line not necessary since these variables are localized at beginnning
; (setq a nil sd nil)
As for the dcl, I did not encounter any differences with or without the "is_default=true".
In either case I could not get a double click to work on the edit_box.
The double click on the list_box as you have it in the code with $reason works fine.
I did make the following changes to your dcl by adding labels so you can use the Alt+mnemonic key to jump to those locations:
//
// test-EditBox-Enter.DCL
//
swh0 :spacer {width=0.0; height=0.0;}
rfwtac :row {fixed_width=true; alignment=centered; height=3.5;}
but12 :button {fixed_width=true; width=12.0;}
//
EdiBox
:dialog {label="Edit and List Box Exercise";
swh0;
:text_part {key="Tex1"; width=23.0; alignment=centered;}
// :edit_box {key="Edi1"; fixed_width=true; width=23.0; alignment=centered;}
:edit_box {key="Edi1"; label="S&earch"; fixed_width=true; width=23.0; alignment=centered; is_default = true;}
swh0;
:but12 {key="But1"; label="&Search"; alignment=centered;}
swh0;
// :list_box {key="Lis1"; fixed_width=true; width=26.2; alignment=centered;}
:list_box {key="Lis1"; label="Select Ite&m"; fixed_width=true; width=26.2; alignment=centered;}
:rfwtac {
swh0;
:but12 {key="insert"; label="&Insert <";}
swh0;
:but12 {key="cancel"; label="&Cancel"; is_cancel=true;}
swh0;
}
}
Like you I also prefer assigning "action_tile" in the LSP over "action" inside the DCL along with others like the list items that would go into a list_box.
As for preference on using "mnemonic=" vs "&Accept"; I've actually used both. But in most instances I do prefer "mnemonic=" because then the actual label like "Accept" is not interrupted with "&Accept" so when I do a search for "Accept" it can be found.
I've attached both the updated lsp & dcl along with the lsp routine I use to convert dcl to lsp: DCL2LSP.lsp
This function can be executed by entering the following at the command prompt:
(load "DCL2LSP")
(DCL2LSP)