?? about closing of apps

Discussion in 'Mac Programming' started by Fajhetti, Feb 11, 2010.

  1. Fajhetti macrumors newbie

    Joined:
    Jul 20, 2008
    #1
    I am having some trouble and would appreciate any and all suggestions on how to solve this problem. Also, if you see any glaring issues with what I am doing feel free to point them out. All help would be appreciated.

    So what I am trying to do is close the application gracefully. I have read through that documentation, but either it didn't sink in or it isn't there. When they select Quit Application the applicationShouldTerminate fires and checks current activity like a champ. When they click the red x I get the same check for activity, but no matter what I do in windowWillClose it closes. I have a feeling that there is a method that I should be listening to prior to windowWillClose, but I can not find it. Please help.


    Code:
    - 
    - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app 
    {
    	bool testActivity = [[ActivityMonitorViewController sharedActivityMonitorController] IsThereActivity];
        if (testActivity) 
    	{
            int choice = NSAlertDefaultReturn; 
    		if (testActivity)
    		{ 
    			
                NSString *title = @"You currently have an order that is in the process of uploading.  Would you like to wait until that upload is finished?";
    			choice = NSRunAlertPanel(title,
    									 @"If you do not finish the upload we can not begin your order.", 
    									 @"Wait for Upload.", @"Close", nil);
                
    			if (choice == NSAlertOtherReturn) return NSTerminateCancel;  
    		}
    	}
       	
    	[MyApplicationController SaveOrders];
    	return NSTerminateNow;
    }
    
    
    That seems to be working just fine. Allowing me to ask the user a question in certain scenarios. However, I need to do the same type of thing if they click the little red X. I can not figure out how to make them work the same.

    Currently I have this
    Code:
    - (void)windowWillClose:(NSNotification *)aNotification
    {
    	bool testActivity = [[ActivityMonitorViewController sharedActivityMonitorController] IsThereActivity];
    	if (testActivity)
    		[[MainWindowController sharedMainWindowController] setShouldCloseDocument:NO];
    	else
    		[NSApp terminate:self];
    }
    
    

    Please help.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Look at the NSWindow delegate method windowShouldClose:
     

Share This Page