Temporarily Disable Mac Menu Item Quit

Just starting out? Need help? Post your questions and find answers here.
KieferThomas
User
User
Posts: 16
Joined: Tue Apr 05, 2016 4:24 pm

Temporarily Disable Mac Menu Item Quit

Post by KieferThomas »

Hello All!,

I have an an application I have been updating to make it more readable and manageable for making changes in it.

After working with my original program for several years there is one thing I never took into account. This was the fact of temporarily disabling the Quit Application menu item when another window other then the main window_0 is open.

I know how to access the Quit Application feature in the Mac menu with the -4 Menu Item but what I really need to know is how to temporarily disable it when any other window is open.

I have searched through the forums only getting examples for menu items which are implicitly created by me; there is nothing on the Mac Menu Items and how to disable them.

Any help would be appreciated,

Thanks in advance,
Kiefer

I had forgot to mention: DisableMenuItem(0, -4, 1) does not disable the Quit Item.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Temporarily Disable Mac Menu Item Quit

Post by kenmo »

Hi, some comments:

1. On Mac there is a constant named #PB_Menu_Quit so you don't need to use a magic number like -4.

2. I don't think you CAN disable that menu item... I think it's a special one generated by the OS.

3. Instead of disabling the menu event itself... can't you just disable your program's response to the event?

Code: Select all

Case #PB_Menu_Quit
  If (InMainWindow)
    Quit()
  Else
    ; Do not quit!
  EndIf

4. I'm not a Mac expert... In a standard Mac program, when you press Cmd-Q to quit a program, is it only expected to work in the main window, or in sub-windows too? I'm not sure.


EDIT: OK, I thought you were talking about the Cmd-Q hotkey but now I think you really mean the "Quit" entry in the menu list... Maybe that can be disabled? But my comments mostly still apply :)
KieferThomas
User
User
Posts: 16
Joined: Tue Apr 05, 2016 4:24 pm

Re: Temporarily Disable Mac Menu Item Quit

Post by KieferThomas »

kenmo wrote:Hi, some comments:

1. On Mac there is a constant named #PB_Menu_Quit so you don't need to use a magic number like -4.

2. I don't think you CAN disable that menu item... I think it's a special one generated by the OS.

3. Instead of disabling the menu event itself... can't you just disable your program's response to the event?

Code: Select all

Case #PB_Menu_Quit
  If (InMainWindow)
    Quit()
  Else
    ; Do not quit!
  EndIf

Hey kenmo,
Thank you! This managed to get me in the right direction.

I made my modifications as follows:

Code: Select all

Case #PB_Event_Menu
      Select EventMenu()
              
           Case #MenuItem_2
               HideWindow(#Window_0,1) 
               HideWindow(#Window_1, 0)
          Case #PB_Menu_Quit CocoaMessage(0, WindowID(#Window_0), "isVisible")
               If  Not IsVisible
                    MessageRequester("You can not close the application with this window open!","")
               Else 
                    appQuit = 1
               EndIf
This keeps the program from Ending until I get back to Window_0.


By the way you are correct about the Mac Menu they are special. I have only been able to find a limited amount of support for them.

Thanks Again,
Kiefer

__________________________________________________
Code tags added
16.01.2018
RSBasic
Post Reply