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 6188267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:12:11+00:00 2026-05-24T02:12:11+00:00

I’m writing a super cool app with a preferences panel. If a user opens

  • 0

I’m writing a super cool app with a preferences panel. If a user opens the preferences panel, makes a change to her preferences, and then closes the panel without saving those changes, she will be greeted by an NSAlert informing her of the dire consequences. The NSAlert sheet has two buttons, “OK” and “Cancel”. If the user presses “OK”, then the sheet and the prefs panel should close. If the user presses “Cancel”, then the sheet should close, but not the prefs panel.

Here’s a simplified version of the code in question:

def windowShouldClose
  window_will_close = true

  unless self.user_is_aware_of_unsaved_changes
    window_will_close = false
    alert = make_appropriate_NSAlert # this method returns an NSAlert

    alert.beginSheetModalForWindow(self.window,
      modalDelegate: self,
      didEndSelector: :'userShouldBeAware:returnCode:contextInfo:',
      contextInfo: nil)
  end

  window_will_close
end

def userShouldBeAware(alert, returnCode:returnCode, contextInfo:contextInfo)
  if returnCode == NSAlertFirstButtonReturn
    self.user_is_aware_of_unsaved_changes = true
  end
end

def windowDidEndSheet(notification)
  self.window.performClose(self) if self.user_is_aware_of_unsaved_changes
end

I believe that I have made my super cool app perform the necessary duties, but I am concerned that this is not the way Apple intended or would recommend for me to implement this feature. It feels like a hack, and I was nowhere told explicitly that this is the way to do it. I tried a number of things before stumbling upon this solution.

I would like to make model mac apps. Is there some patten or document that goes into more detail about this? I have read Apple’s documentation for the NSAlert class and their article on Sheet Programming Topics.

Thanks!

  • 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-05-24T02:12:13+00:00Added an answer on May 24, 2026 at 2:12 am

    First off, according to the HIG, preference panes should not ask to cancel or confirm. Just auto-save whenever the user changes something. For reference, see how iTunes handles its preferences.

    If you do want a save dialog, here’s what I do. It can come in handy for when the user closes the app window and there’s things to save. I use a drawer. That’s a panel that I store in my MainMenu .nib file. Then I make it available as instance variable doneWindow, all using InterfaceBuilder and some clicking. Some more clicking in InterfaceBuilder registers the following two methods to be invoked at the appropriate events.

    def showSaveDialog
        NSApp.beginSheet( doneWindow,
            modalForWindow: mainWindow,
            modalDelegate: self,
            didEndSelector: "didEndSheet:returnCode:contextInfo:".to_sym,
            contextInfo: nil)
    end
    
    def save(bla)
        NSApp.endSheet doneWindow
        Pomodoro.new(:text => doneText).save
        notifyLabelUpdate
    end
    
    def didEndSheet(bla, returnCode: aCode, contextInfo: bla3)
        doneWindow.orderOut self
    end
    

    Note that the guide on sheets that you point to is the most confusing guide I’ve seen anywhere on the Apple documentation.

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

Sidebar

Related Questions

I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.