TOPIC: Escape from an AccessControl
#656
Escape from an AccessControl 3 Years, 6 Months ago
Hi, someone knows a way to close an AccessControl window when I press the ESC key, in alternative to closing its window with the mouse? In the app I'm writing I would move as much as possible to keyboard use and less mouse movement. Keyboard is faster (I remember the good old times of MS-DOS applications... :P ).

Post edited by: Mauro, at: 2007/02/05 21:06
 
 
Mauro
 
#659
Re:Escape from an AccessControl 3 Years, 6 Months ago
You may be able to use the Commands facility. These create "accelerator" keys for commands. These are normally associated with the top level window/control so it is a little more complicated within a Book. AccessControl uses this to get keyboard shortcuts for New, Next, etc.
 
 
andrew
 
#684
Re:Escape from an AccessControl 3 Years, 6 Months ago
Thanks Andrew for the great suggestion. To make ESC-key work for a generic controller window, you only have to add something like:

Code:


Commands()
{
return #( ("Esc", "Escape", ""') )
}
On_Esc()
{
if .Window.CLOSE() isnt 0
.Window.Destroy()
}


You can do a similar mod in the AccessControl code to make it close its window after you press the ESC key. I have added a param for the AccessControl, 'closeOnEscKey', to allow or disallow the window closing after an ESC. This param is checked in the Commands and RedirAccelerators methods of AccessControl:
Code:


RedirAccelerators()
{
// make accelerators work inside book
.Window.Ctrl.Redir('On_New', this)
.Window.Ctrl.Redir('On_Edit', this)
.Window.Ctrl.Redir('On_Next', this)
.Window.Ctrl.Redir('On_Prev', this)
.Window.Ctrl.Redir('On_First', this)
.Window.Ctrl.Redir('On_Last', this)
.Window.Ctrl.Redir('On_Select', this)
if (.closeOnEscKey)
.Window.Ctrl.Redir('On_Esc', this)
}
Commands()
{
commands = Object(
#("New", "Ctrl+N", ""')
#("Edit", "Alt+E", ""')
#("First", "Alt+F", ""')
#("Prev", "Alt+P", ""')
#("Next", "Alt+N", ""')
#("Last", "Alt+L", ""')
#("Select", "Alt+S", ""')
)
if (.closeOnEscKey)
commands.Add( #("Esc", "Escape", ""')
return commands
}
On_Esc()
{
if .Window.CLOSE() isnt 0
.Window.Destroy()
}


The problem here is that this code works anywhere except for the AccessGoTo function. If you open an Access with an AccessGoTo('MyAccess'), the Esc key will not be intercepted and I don't know why. I think this could be because in the AccessGoTo function, the Access is opened inside a Dialog, or maybe that the problem is the wrapper class that is used in the AccessGoTo code. There is a way to make it work?
 
 
Mauro
 
#685
Re:Escape from an AccessControl 3 Years, 6 Months ago
You should be able to get Esc to work in Dialog by adding an On_Cancel method like:

On_Cancel() { .Window.Result(0) }

(The actual result value does not matter.)

Within a dialog you can also specify defaultButton on the button you want to be triggered by Enter.

But for some reason, other accelerators do not work in dialogs. I have tried to fix this a couple of times but have not been successful. But I have not spent a lot of time on it. I am not sure if the problem is in the message loop built into the exe, or in the stdlib code, or in some quirk in Windows itself.

Post edited by: andrew, at: 2007/02/11 17:10
 
 
andrew
 
#686
Re:Escape from an AccessControl 3 Years, 6 Months ago
Thank you very much Andrew! :)
The On_Cancel() in the AccessControl appears to do the trick (albeit I don't have understood what is .Window.Result(0) for).
 
 
Mauro
 
#687
Re:Escape from an AccessControl 3 Years, 6 Months ago
.Window.Result is how you exit from a dialog. It calls the Windows API EndDialog. We probably called it Result instead of just EndDialog because it also handles returning a result from the dialog.
 
 
andrew
 
#689
Re:Escape from an AccessControl 3 Years, 6 Months ago
Thanks. :)
 
 
Mauro