From 5dda419aebf40cc6cc5c7e0a89b6c8f22b760fea Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Wed, 16 Jan 2008 11:33:47 +0000 Subject: [PATCH] If spawning a shell in a tab failed, the tab wouldn't be removed by the cleanup thread, since, not being attached to the window, Window() returned NULL. Now CustomTermView::NotifyQuit() accounts for this, and sends the message to the first window in the BApplication. Moreover, RemoveTab() would always remove the currently selected tab, and not the requested one. Changed a printf() to fprintf(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23558 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/Shell.cpp | 3 ++- src/apps/terminal/TermWindow.cpp | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/apps/terminal/Shell.cpp b/src/apps/terminal/Shell.cpp index 2bad0b959a..03fdbe81ba 100644 --- a/src/apps/terminal/Shell.cpp +++ b/src/apps/terminal/Shell.cpp @@ -311,7 +311,7 @@ Shell::_Spawn(int row, int col, const char *encoding, int argc, const char **arg } if (master < 0) { - printf("didn't find any available pseudo ttys."); + fprintf(stderr, "didn't find any available pseudo ttys."); return B_ERROR; } @@ -490,6 +490,7 @@ Shell::_Spawn(int row, int col, const char *encoding, int argc, const char **arg /* * Exec failed. */ + sleep(1); const char *spawnAlertMessage = "alert --stop " "'Cannot execute \"%s\":\n" diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index 894de28926..2ae568a70b 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -269,7 +269,7 @@ TermWindow::MessageReceived(BMessage *message) be_app->GetAppInfo(&info); // try launching two different ways to work around possible problems - if (be_roster->Launch(&info.ref)!=B_OK) + if (be_roster->Launch(&info.ref) != B_OK) be_roster->Launch(TERM_SIGNATURE); break; } @@ -664,7 +664,7 @@ void TermWindow::_RemoveTab(int32 index) { if (fTabView->CountTabs() > 1) - delete fTabView->RemoveTab(fTabView->Selection()); + delete fTabView->RemoveTab(index); else PostMessage(B_QUIT_REQUESTED); } @@ -735,11 +735,20 @@ CustomTermView::CustomTermView(int32 rows, int32 columns, int32 argc, const char void CustomTermView::NotifyQuit(int32 reason) { - if (Window()) { + BWindow *window = Window(); + if (window == NULL) + window = be_app->WindowAt(0); + + // TODO: If we got this from a view in a tab not currently selected, + // Window() will be NULL, as the view is detached. + // So we send the message to the first application window + // This isn't so cool, but for now, a Terminal app has only one + // window. + if (window != NULL) { BMessage message(kCloseView); message.AddPointer("termView", this); - message.AddInt32("reason", reason); - Window()->PostMessage(&message); + message.AddInt32("reason", reason); + window->PostMessage(&message); } }