bool TermWindow::_CanClose(int32 index) { bool warnOnExit = PrefHandler::Default()->getBool(PREF_WARN_ON_EXIT); if (!warnOnExit) return true; uint32 busyProcessCount = 0; BString busyProcessNames; // all names, separated by "\n\t" if (index != -1) { ShellInfo shellInfo; ActiveProcessInfo info; TermView* termView = _TermViewAt(index); if (termView->GetShellInfo(shellInfo) && termView->GetActiveProcessInfo(info) && (info.ID() != shellInfo.ProcessID() || !shellInfo.IsDefaultShell())) { busyProcessCount++; busyProcessNames = info.Name(); } } else { for (int32 i = 0; i < fSessions.CountItems(); i++) { ShellInfo shellInfo; ActiveProcessInfo info; TermView* termView = _TermViewAt(i); if (termView->GetShellInfo(shellInfo) && termView->GetActiveProcessInfo(info) && (info.ID() != shellInfo.ProcessID() || !shellInfo.IsDefaultShell())) { if (++busyProcessCount > 1) busyProcessNames << "\n\t"; busyProcessNames << info.Name(); } } } if (busyProcessCount == 0) return true; BString alertMessage; if (busyProcessCount == 1) { // Only one pending process. Select the alert text depending on whether // the terminal will be closed. alertMessage = index == -1 || fSessions.CountItems() == 1 ? B_TRANSLATE("The process \"%1\" is still running.\n" "If you close the Terminal, the process will be killed.") : B_TRANSLATE("The process \"%1\" is still running.\n" "If you close the tab, the process will be killed."); } else { // multiple pending processes alertMessage = B_TRANSLATE( "The following processes are still running:\n\n" "\t%1\n\n" "If you close the Terminal, the processes will be killed."); } alertMessage.ReplaceFirst("%1", busyProcessNames); BAlert* alert = new BAlert(B_TRANSLATE("Really close?"), alertMessage, B_TRANSLATE("Close"), B_TRANSLATE("Cancel"), NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); alert->SetShortcut(1, B_ESCAPE); return alert->Go() == 0; }