Exemplo n.º 1
0
bool
ZipOMatic::QuitRequested(void)
{
	if (CountWindows() <= 0)
		return true;
	
	BWindow* window;
	ZippoWindow* zippo;
	ZippoWindow* lastFoundZippo = NULL;
	int32 zippoCount = 0;
	
	for (int32 i = 0;; i++) {
		window = WindowAt(i);
		if (window == NULL)
			break;
		
		zippo = dynamic_cast<ZippoWindow*>(window);
		if (zippo == NULL)
			continue;
		
		lastFoundZippo = zippo;
		
		if (zippo->Lock()) {
			if (zippo->IsZipping())
				zippoCount++;
			else
				zippo->PostMessage(B_QUIT_REQUESTED);
				
			zippo->Unlock();
		}
	}
	
	if (zippoCount == 1) {
		// This is likely the most frequent case - a single zipper.
		// We post a message to the window so it can put up its own
		// BAlert instead of the app-wide BAlert. This avoids making
		// a difference between having pressed Commmand-W or Command-Q.
		// Closing or quitting, it doesn't matter for a single window.

		if (lastFoundZippo->Lock()) {
			lastFoundZippo->Activate();
			lastFoundZippo->PostMessage(B_QUIT_REQUESTED);
			lastFoundZippo->Unlock();
		}
		return false;
	}

	if (zippoCount > 0) {
		// The multi-zipper case differs from the single-zipper case
		// in that zippers are not paused while the BAlert is up.

		BString question;
		question << TR("You have %ld Zip-O-Matic running.\n\n");
		question << TR("Do you want to stop them?");
		
		BString temp;
		temp << zippoCount;
		question.ReplaceFirst("%ld", temp.String());

		BAlert* alert = new BAlert(NULL, question.String(),
			TR("Stop them"), TR("Let them continue"), NULL, B_WIDTH_AS_USUAL,
			B_WARNING_ALERT);
		alert->Go(fInvoker);
		alert->Activate();
			// BAlert, being modal, does not show on the current workspace
			// if the application has no window there. Activate() triggers
			// a switch to a workspace where it does have a window.
			
			// TODO: See if AS_ACTIVATE_WINDOW should be handled differently
			// in src/servers/app/Desktop.cpp Desktop::ActivateWindow()
			// or if maybe BAlert should (and does not?) activate itself.
			
		return false;
	}

	if (CountWindows() <= 0)
		return true;
	
	return false;
}