Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Files /
Chapter 1 - Introduction to File Management / Using Files


Adjusting the File Menu

Your application should dim any File menu commands that are not available at the time the user pulls down the File menu. For example, if your application does not yet have a document window open, then the Save, Save As, and Revert commands should be dimmed. You can adjust the File menu easily using the technique shown in Listing 1-19.

Listing 1-19 Adjusting the File menu

PROCEDURE DoAdjustFileMenu;
VAR
   myWindow:   WindowPtr;
   myMenu:     MenuHandle;
   myData:     MyDocRecHnd;               {handle to window data}

BEGIN
   myWindow := FrontWindow;
   IF myWindow = NIL THEN
      BEGIN
         myMenu := GetMHandle(mFile);
         DisableItem(myMenu, iSave);      {disable Save}
         DisableItem(myMenu, iSaveAs);    {disable Save As}
         DisableItem(myMenu, iRevert);    {disable Revert}
         DisableItem(myMenu, iClose);     {disable Close}
      END
   ELSE IF MyGetWindowType(myWindow) = kMyDocWindow THEN
      BEGIN
         myData := MyDocRecHnd(GetWRefCon(myWindow));
         myMenu := GetMHandle(mFile);
         EnableItem(myMenu, iSaveAs);     {enable Save As}
         EnableItem(myMenu, iClose);      {enable Close}

         IF myData^^.windowDirty THEN
            BEGIN
               EnableItem(myMenu, iSave);       {enable Save}
               EnableItem(myMenu, iRevert);     {enable Revert}
            END
         ELSE
            BEGIN
               DisableItem(myMenu, iSave);      {disable Save}
               DisableItem(myMenu, iRevert);    {disable Revert}
            END;
      END;
END;
Your application should call DoAdjustFileMenu whenever it receives a mouse-down event in the menu bar. (No doubt you want to include code appropriate for enabling and disabling other menu items too.) See the chapter "Menu Manager" in Inside Macintosh: Macintosh Toolbox Essentials for details on the menu enabling and disabling procedures used in Listing 1-19.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996