diff --git a/src/apps/terminal/Shell.cpp b/src/apps/terminal/Shell.cpp index 1323e6da81..9c0bf2e979 100644 --- a/src/apps/terminal/Shell.cpp +++ b/src/apps/terminal/Shell.cpp @@ -312,8 +312,10 @@ Shell::AttachBuffer(TerminalBuffer *buffer) void Shell::DetachBuffer() { - if (fAttached) + if (fAttached) { fTermParse->StopThreads(); + fAttached = false; + } } diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index 6e97c72cf0..b9caedcb36 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -18,15 +18,12 @@ #include "TermView.h" -#include #include #include #include #include #include -#include - #include #include #include @@ -87,7 +84,11 @@ static property_info sPropList[] = { {B_GET_PROPERTY, 0}, {B_DIRECT_SPECIFIER, 0}, "get tty name."}, - { 0 } + { "command", + {B_EXECUTE_PROPERTY, 0}, + {B_DIRECT_SPECIFIER, 0}, + "execute command"}, + { 0 }, }; @@ -245,13 +246,8 @@ TermView::TermView(BMessage* archive) fRows = ROWS_DEFAULT; int32 argc = 0; - if (archive->HasInt32("argc")) - archive->FindInt32("argc", &argc); - - const char **argv = new const char*[argc]; - for (int32 i = 0; i < argc; i++) { - archive->FindString("argv", i, (const char**)&argv[i]); - } + const char** argv = NULL; + _GetArgumentsFromMessage(archive, argv, argc); // TODO: Retrieve colors, history size, etc. from archive status_t status = _InitObject(ShellParameters(argc, argv)); @@ -365,12 +361,7 @@ TermView::_InitObject(const ShellParameters& shellParameters) ShellParameters modifiedShellParameters(shellParameters); modifiedShellParameters.SetEncoding(fEncoding); - error = fShell->Open(fRows, fColumns, modifiedShellParameters); - - if (error < B_OK) - return error; - - error = _AttachShell(fShell); + error = _AttachShell(fShell, modifiedShellParameters); if (error < B_OK) return error; @@ -992,12 +983,30 @@ TermView::_InvalidateTextRange(TermPos start, TermPos end) } +void +TermView::_GetArgumentsFromMessage(const BMessage* message, const char**& argv, int32& argc) +{ + type_code type; + if (message->GetInfo("argv", &type, &argc) == B_OK) { + argv = new const char*[argc + 1]; + int32 i = 0; + while (message->FindString("argv", i, &argv[i]) == B_OK) + i++; + argv[i] = NULL; + } +} + + status_t -TermView::_AttachShell(Shell *shell) +TermView::_AttachShell(Shell *shell, const ShellParameters& shellParameters) { if (shell == NULL) return B_BAD_VALUE; + status_t status = shell->Open(fRows, fColumns, shellParameters); + if (status != B_OK) + return status; + fShell = shell; return fShell->AttachBuffer(TextBuffer()); @@ -1745,6 +1754,37 @@ TermView::MessageReceived(BMessage *message) break; } + case B_EXECUTE_PROPERTY: + { + int32 i; + BMessage specifier; + if (message->GetCurrentSpecifier(&i, &specifier) == B_OK + && strcmp("command", + specifier.FindString("property", i)) == 0) { + + Shell* shell = _DetachShell(); + shell->Close(); + + int32 argc = 0; + const char** argv = NULL; + _GetArgumentsFromMessage(message, argv, argc); + + if (message->GetBool("clear", false)) + Clear(); + + ShellParameters shellParameters(argc, argv); + shellParameters.SetEncoding(fEncoding); + _AttachShell(shell, shellParameters); + + delete[] argv; + + message->SendReply(B_REPLY); + } else { + BView::MessageReceived(message); + } + break; + } + case B_MODIFIERS_CHANGED: { _UpdateModifiers(); diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index 4f9d129245..b28da78a76 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -197,7 +197,10 @@ private: status_t _InitObject( const ShellParameters& shellParameters); - status_t _AttachShell(Shell* shell); + void _GetArgumentsFromMessage(const BMessage* message, + const char**& argv, int32& argc); + + status_t _AttachShell(Shell* shell, const ShellParameters& shellParameters); Shell* _DetachShell(); void _Activate();