Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7817401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:13:12+00:00 2026-06-02T06:13:12+00:00

So, here’s my case : I’m developing a NON-standard document-based application and I want

  • 0

So, here’s my case :

I’m developing a NON-standard document-based application and I want to handle the scenario of aborting the termination when there still are unsaved changes in any of the documents.

My initial idea is :

  • User tries to quit the application (either through the "Quit XXXXX" menu item or by clicking the "X" button)
  • Are there any modified documents?
  • if NO : quit
  • if YES : notify user that there are unmodified documents. if he wants to proceed, then quit. Else cancel termination.

So, I decided to do it the delegate-way.

In my Application delegate, I’ve implemented :

  • -windowToClose: (triggered on NSWindowWillCloseNotification)
  • applicationShouldTerminate:
  • applicationShouldTerminateAfterLastWindowClosed:

Now, that’s what I’m thinking. In the applicationShouldTerminate: method :

  • Return NSTerminateNow if no modified documents exist
  • Return NSTerminateCancel if there ARE modified documents. In that case, pop up an alert sheet or something like that and if user confirms he wants to quit, then call a [NSApp terminate:nil];

Is that the right way to go about it?

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:13:14+00:00Added an answer on June 2, 2026 at 6:13 am

    That’s indeed how to do it. But in your applicationShouldTerminate implementation, you should just pop up the alert right there, and return NSTerminateNow if the user didn’t click Cancel; NSTerminateCancel otherwise. No need to manually terminate the application later.

    Edit: to show an alert as a sheet but run it as a modal dialog, call beginSheetModalForWindow on the alert, then call [NSApp runModalForWindow:alert]. In addition, in the end selector that you pass for beginSheetModalForWindow, you need to call [NSApp stopModal] to get out of the modal loop.

    However, it is better in this case to run the alert as a sheet for the window, and return NSTerminateLater in your applicationShouldTerminate implementation. Then, in the end selector for the alert, call [NSApp replyToApplicationShouldTerminate:]. This is how Apple recommends you implement this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a complete example. I want to forbid using A::set from objects casted
Here's the deal: I'm in the process of planning a mid-sized business application that
Here's what I want to do: Given a table PeopleOutfit (id int primary key,
Here's the method. I want to know if I am violating any best practices
Here's my scenario: <!-- Normal Control --> <div class=required> <label for=address1>Address line 1</label> <input
Here is my code...I have two dimensional matrices A,B. I want to develop the
here i want to understand the architecture of bluez (Bluetooth Stack Protocol). I understood
Here's what I'm trying to do... It's quite simple and obviously there must be
Here's my scenario - I have an SSIS job that depends on another prior
Here is the scenario: I'm writing an app that will watch for any changes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.