From 53c32667f76b0d92770db06ba7f26c7979608ce8 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 21 Nov 2010 21:00:10 +0000 Subject: [PATCH] TermWindow::_CanClose(): Collect the names of the running processes and display them in the alert. Fixes #6862. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39564 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TermWindow.cpp | 60 ++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index b410f5596e..e397733c17 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -293,34 +293,56 @@ TermWindow::_CanClose(int32 index) if (!warnOnExit) return true; - bool isBusy = false; - if (index != -1) - isBusy = _TermViewAt(index)->IsShellBusy(); - else { + uint32 busyProcessCount = 0; + BString busyProcessNames; + // all names, separated by "\n\t" + + if (index != -1) { + ActiveProcessInfo info; + if (_TermViewAt(index)->GetActiveProcessInfo(info) + && info.ID() != info.ShellProcessID()) { + busyProcessCount++; + busyProcessNames = info.Name(); + } + } else { for (int32 i = 0; i < fSessions.CountItems(); i++) { - if (_TermViewAt(i)->IsShellBusy()) { - isBusy = true; - break; + ActiveProcessInfo info; + if (_TermViewAt(i)->GetActiveProcessInfo(info) + && info.ID() != info.ShellProcessID()) { + if (++busyProcessCount > 1) + busyProcessNames << "\n\t"; + busyProcessNames << info.Name(); } } } - if (isBusy) { - const char* alertMessage = index == -1 || fSessions.CountItems() == 1 - ? B_TRANSLATE("A process is still running.\n" + 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("A process is still running.\n" + : B_TRANSLATE("The process \"%1\" is still running.\n" "If you close the tab, the process will be killed."); - 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); - int32 result = alert->Go(); - if (result == 1) - return false; + } else { + // multiple pending processes + alertMessage = B_TRANSLATE( + "The following processes are still running:\n\n" + "\t%1\n\n" + "If you close the tab, the processes will be killed."); } - return true; + 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; }