Tk Source Code

View Ticket
Login
2006-04-11
17:53 Closed ticket [1105284fff]: Scripting of TkAqua application menu commands plus 7 other changes artifact: d3e93d58bf user: das
2006-04-10
17:59 Ticket [1105284fff]: 1 change artifact: a0ac277190 user: das
2005-01-19
15:03 New ticket [1105284fff]. artifact: 3099c5c421 user: alastair_davies

Ticket UUID: 1105284
Title: Scripting of TkAqua application menu commands
Type: RFE Version: None
Submitter: alastair_davies Created on: 2005-01-19 15:03:45
Subsystem: 11. Aqua Menus Assigned To: das
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2006-04-11 17:53:34
Resolution: Fixed Closed By: das
    Closed on: 2006-04-11 10:53:34
Description:
The application menu created by the MacOS X system 
provides (amongst others) "Preferences..." and "Quit" items 
that should be used by applications in preference to 
application-specific menus.  For a Tcl/Tk application based 
on the Wish Shell bundle, it is convenient to allow these 
menu items to be handled by scripted procedures.

In Tk 8.4.9, the Quit menu item is handled by evaluating the 
"exit" command.  The following amended procedure from 
tkMacOSXHLEvents.c first checks if there is a user-defined 
command "::tk::mac::Quit", which is evaluated in 
preference to "exit".  This allows an application-specifc 
script to be run prior to application shutdown.  (This might, 
for example, prompt users to save modified documents.)

Note that on other platforms, the standard application 
shutdown is peformed using the Exit item on the File menu, 
which is, of course, defined by the application. 

static int 
ReallyKillMe(Tcl_Event *eventPtr, int flags) 
{
    Tcl_CmdInfo dummy;
    Tcl_Interp *interp = ((KillEvent *) eventPtr)->interp;
    /*
     * Look for user-defined handler in ::tk::mac::Quit
     * or default to "exit"
     */

    if (interp != NULL) {
      if (Tcl_GetCommandInfo(interp, "::tk::mac::Quit", 
&dummy) != 0) {
            Tcl_GlobalEval(interp, "::tk::mac::Quit");
      } else {
        Tcl_GlobalEval(interp, "exit");
      }
    }
    
    return 1;
}


Handling the "Preferences..." menu item, on the other hand, 
is at present already partially implemented.  The menu item 
is disabled by default, but if it is enabled (see below) by the 
user, the user-defined procedure 
::tk::mac::ShowPreferences is invoked.

To enable the "Preferences..." menu item, it is necessary to 
add a call to the command:

EnableMenuCommand(NULL, kHICommandPreferences);

Ideally, a Tcl/Tk script should have access to this command, 
such as through a procedure called e.g. 
::tk::mac::EnablePreferencesMenuItem  This access would 
complete the implementation of the Tcl/Tk script-level 
handling of the application menu.
User Comments: das added on 2006-04-11 17:53:34:
Logged In: YES 
user_id=90580

committed fix to HEAD and core-8-4-branch, all registered appleevent handlers 
now call a ::tk::mac::* proc (including the quit event).

The 'Preferences' issue has also been fixed, see bug 700316.