2 Replies
      Latest reply on May 15, 2019 6:35 AM by janabanana
      SirGreenDragonToo Level 1 Level 1 (0 points)

        I'd like to detect the difference between close window and close tab so that I can diaplay an alert for command window to make sure the user wants to closee the wndow containing all of the tabs. This is a document based app.

         

        I need to do this from the menu as well as from the window and tab close buttons.

         

        I have tried using performClose but that isn't called from the window and tab close buttons and using windowShouldClose means I'd have to write some hacky code to tell if that method was being called on all the documents represented in tabs in my windows so I think that is too late.

         

        Any pointers?

        • Re: Detect Close Window vs Close Tab
          Claude31 Level 8 Level 8 (5,735 points)

          Could the discussion in this other thread help ?

           

          https://forums.developer.apple.com/message/236563#236563

            • Re: Detect Close Window vs Close Tab
              janabanana Level 1 Level 1 (0 points)

              I have read the thread you linked.  I have fiddled a little bit with this but haven't spent the time to totally figure it out.  But, what I have found is this:  depending on the state of the check box in the System Preferences, In the General Pane, "Close windows when quitting an app," pressing the option key in your app will/should reveal an option for quitting the app (Option Command Q).  From what I can determine, pressing the option key gives the opposite of the selection in the System Preferences.  So, given that, if one could figure out where/how to hook into that, there might be a way to always save all the tabs regardless of the state of that checkbox.  At one point in the past I had a user defaults preference setting configured in my app to override that global system preference. I think it was this one:  [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSQuitAlwaysKeepsWindows"];  But, I think Apple frowns upon this as it tampers with the behavior that the users would expect when they try to set it in the System Preferences.