More work towards a tabbed terminal. Actually it already somewhat works

(code not enabled, though). Moved scripting from TermWindow to 
TermView. Added a SmartTabView which (for now) only resizes the 
child views to fit their size. Usual cleanups.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21723 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-07-27 21:23:32 +00:00
parent 619c170539
commit 258e949475
12 changed files with 189 additions and 140 deletions
+1
View File
@@ -16,6 +16,7 @@ Application Terminal :
PrefView.cpp
PrefWindow.cpp
Shell.cpp
SmartTabView.cpp
TermApp.cpp
TermBuffer.cpp
TermParse.cpp
+4 -4
View File
@@ -172,12 +172,12 @@ Shell::~Shell()
status_t
Shell::Open(int row, int col, const char *command, const char *coding)
Shell::Open(int row, int col, const char *command, const char *encoding)
{
if (fFd >= 0)
return B_ERROR;
status_t status = _Spawn(row, col, command, coding);
status_t status = _Spawn(row, col, command, encoding);
if (status < B_OK)
return status;
@@ -314,7 +314,7 @@ receive_handshake_message(handshake_t& handshake)
status_t
Shell::_Spawn(int row, int col, const char *command, const char *coding)
Shell::_Spawn(int row, int col, const char *command, const char *encoding)
{
signal(SIGTTOU, SIG_IGN);
@@ -536,7 +536,7 @@ Shell::_Spawn(int row, int col, const char *command, const char *coding)
*/
setenv("TERM", "beterm", true);
setenv("TTY", ttyName, true);
setenv("TTYPE", coding, true);
setenv("TTYPE", encoding, true);
/*
* If don't set command args, exec SHELL_COMMAND.
+6 -26
View File
@@ -3,33 +3,13 @@
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
* Copyright (c) 2004 Daniel Furrer <[email protected]>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files or portions
* thereof (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice
* in the binary, as well as this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Distributed under the terms of the MIT License.
* Authors:
* Stefano Ceccherini <[email protected]>
* Kian Duffy <[email protected]>
* Kazuho Okui
* Takashi Murai
*/
#ifndef _SHELL_H
#define _SHELL_H
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright 2007, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stefano Ceccherini ([email protected])
*/
#include "SmartTabView.h"
SmartTabView::SmartTabView(BRect frame, const char *name, button_width width,
uint32 resizingMode, uint32 flags)
:
BTabView(frame, name, width, resizingMode, flags)
{
}
SmartTabView::~SmartTabView()
{
}
void
SmartTabView::Select(int32 index)
{
BTabView::Select(index);
BTab *tab = TabAt(Selection());
if (tab != NULL) {
BView *view = tab->View();
if (view != NULL)
view->ResizeTo(Bounds().Width(), Bounds().Height());
}
}
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright 2007, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stefano Ceccherini ([email protected])
*/
#ifndef __SMARTTABVIEW_H
#define __SMARTTABVIEW_H
#include <TabView.h>
class SmartTabView : public BTabView {
public:
SmartTabView(BRect frame, const char *name,
button_width width = B_WIDTH_AS_USUAL,
uint32 resizingMode = B_FOLLOW_ALL,
uint32 flags = B_FULL_UPDATE_ON_RESIZE |
B_WILL_DRAW | B_NAVIGABLE_JUMP |
B_FRAME_EVENTS | B_NAVIGABLE);
virtual ~SmartTabView();
virtual void Select(int32 tab);
};
#endif // __SMARTTABVIEW_H
+2 -3
View File
@@ -87,11 +87,10 @@ but it font is full width font on preference panel.
#include <string.h>
#define ARRAY_SIZE 512
#define ROW(x) (((x) + fRowOffset) % fBufferSize)
TermBuffer::TermBuffer(int rows, int cols)
TermBuffer::TermBuffer(int rows, int cols, int bufferSize)
{
if (rows < 1)
rows = 1;
@@ -109,7 +108,7 @@ TermBuffer::TermBuffer(int rows, int cols)
fSelStart.Set(-1,-1);
fSelEnd.Set(-1,-1);
fBufferSize = PrefHandler::Default()->getInt32(PREF_HISTORY_SIZE);
fBufferSize = bufferSize;
if (fBufferSize < 1000)
fBufferSize = 1000;
+3 -3
View File
@@ -30,10 +30,10 @@
#ifndef _TERMBUFFER_H
#define _TERMBUFFER_H
#include <SupportDefs.h>
#include "TermConst.h"
#include "CurPos.h"
#include "TermConst.h"
#include <SupportDefs.h>
struct term_buffer
@@ -49,7 +49,7 @@ class BString;
class TermBuffer {
public:
TermBuffer(int row, int col);
TermBuffer(int row, int col, int bufferSize = 1000);
~TermBuffer();
//
+1
View File
@@ -20,6 +20,7 @@
#include <Application.h>
#include <Beep.h>
#include <Message.h>
#include <Window.h>
//////////////////////////////////////////////////////////////////////////////
+81 -5
View File
@@ -31,9 +31,11 @@
#include <MessageRunner.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <PropertyInfo.h>
#include <Roster.h>
#include <ScrollBar.h>
#include <String.h>
#include <Window.h>
#include <ctype.h>
#include <signal.h>
@@ -134,7 +136,7 @@ TermView::TermView(BRect frame, const char *command)
fTermColumns(PrefHandler::Default()->getInt32(PREF_COLS)),
fEncoding(M_UTF8),
fTop(0),
fTextBuffer(new (nothrow) TermBuffer(fTermRows, fTermColumns)),
fTextBuffer(NULL),
fScrollBar(NULL),
fScrTop(0),
fScrBot(fTermRows - 1),
@@ -156,17 +158,17 @@ TermView::TermView(BRect frame, const char *command)
void
TermView::_InitObject(const char *command)
{
fTextBuffer = new TermBuffer(fTermRows, fTermColumns, fScrBufSize);
SetMouseCursor();
SetTermFont(be_fixed_font, be_fixed_font);
SetTermColor();
//SetIMAware(PrefHandler::Default()->getInt32(PREF_IM_AWARE));
const char *encoding = PrefHandler::Default()->getString(PREF_TEXT_ENCODING);
SetEncoding(longname2id(encoding));
fShell = new Shell();
status_t status = fShell->Open(fTermRows, fTermColumns, command, longname2shortname(encoding));
status_t status = fShell->Open(fTermRows, fTermColumns,
command, longname2shortname(id2longname(fEncoding)));
if (status < B_OK)
throw status;
@@ -1531,7 +1533,41 @@ TermView::MessageReceived(BMessage *msg)
case B_SELECT_ALL:
DoSelectAll();
break;
case B_SET_PROPERTY: {
int32 i;
int32 encodingID;
BMessage spe;
msg->GetCurrentSpecifier(&i, &spe);
if (!strcmp("encoding", spe.FindString("property", i))){
msg->FindInt32 ("data", &encodingID);
SetEncoding(encodingID);
msg->SendReply(B_REPLY);
} else {
BView::MessageReceived(msg);
}
break;
}
case B_GET_PROPERTY: {
int32 i;
BMessage spe;
msg->GetCurrentSpecifier(&i, &spe);
if (!strcmp("encoding", spe.FindString("property", i))){
BMessage reply(B_REPLY);
reply.AddInt32("result", Encoding());
msg->SendReply(&reply);
}
else if (!strcmp("tty", spe.FindString("property", i))) {
BMessage reply(B_REPLY);
reply.AddString("result", TerminalName());
msg->SendReply(&reply);
} else {
BView::MessageReceived(msg);
}
break;
}
case MENU_CLEAR_ALL:
DoClearAll();
fShell->Write(ctrl_l, 1);
@@ -1570,6 +1606,46 @@ TermView::MessageReceived(BMessage *msg)
}
status_t
TermView::GetSupportedSuites(BMessage *message)
{
static property_info propList[] = {
{ "encoding",
{B_GET_PROPERTY, 0},
{B_DIRECT_SPECIFIER, 0},
"get muterminal encoding"},
{ "encoding",
{B_SET_PROPERTY, 0},
{B_DIRECT_SPECIFIER, 0},
"set muterminal encoding"},
{ "tty",
{B_GET_PROPERTY, 0},
{B_DIRECT_SPECIFIER, 0},
"get tty_name."},
{ 0 }
};
message->AddString("suites", "suite/vnd.naan-termview");
BPropertyInfo propInfo(propList);
message->AddFlat("messages", &propInfo);
return BView::GetSupportedSuites(message);
}
BHandler*
TermView::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
int32 form, const char *property)
{
if (((strcmp(property, "encode") == 0)
&& ((msg->what == B_SET_PROPERTY) || (msg->what == B_GET_PROPERTY)))
|| ((strcmp(property, "tty") == 0) && (msg->what == B_GET_PROPERTY)))
return this;
return BView::ResolveSpecifier(msg, index, specifier, form, property);
}
//! Gets dropped file full path and display it at cursor position.
void
TermView::DoFileDrop(entry_ref &ref)
+6 -3
View File
@@ -33,8 +33,6 @@
#include "CurPos.h"
#include "TermConst.h"
#include "TermWindow.h"
#include <Messenger.h>
#include <String.h>
@@ -52,7 +50,7 @@ class Shell;
class TermBuffer;
class TermView : public BView {
public:
TermView(BRect frame, const char *command);
TermView(BRect frame, const char *command = NULL);
~TermView();
virtual void GetPreferredSize(float *width, float *height);
@@ -142,6 +140,11 @@ protected:
virtual void FrameResized(float width, float height);
virtual void MessageReceived(BMessage* message);
virtual status_t GetSupportedSuites(BMessage *msg);
virtual BHandler* ResolveSpecifier(BMessage *msg, int32 index,
BMessage *specifier, int32 form,
const char *property);
private:
void _InitObject(const char *command);
+18 -90
View File
@@ -16,6 +16,7 @@
#include "PrefWindow.h"
#include "PrefView.h"
#include "PrefHandler.h"
#include "SmartTabView.h"
#include "TermConst.h"
#include "TermView.h"
@@ -26,7 +27,6 @@
#include <MenuItem.h>
#include <Path.h>
#include <PrintJob.h>
#include <PropertyInfo.h>
#include <Roster.h>
#include <Screen.h>
#include <ScrollBar.h>
@@ -52,14 +52,14 @@ const static float kViewOffset = 3;
#if 0
TermWindow::TermWindow(BRect frame, const char* title, const char *command)
:
BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE|B_QUIT_ON_WINDOW_CLOSE)
BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE|B_QUIT_ON_WINDOW_CLOSE),
fTabView(NULL)
{
fTermView = new TermView(Bounds(), command);
AddChild(fTermView);
float width, height;
fTermView->GetPreferredSize(&width, &height);
ResizeTo(width, height);
fTabView = new SmartTabView(Bounds(), "Tab view");
AddChild(fTabView);
_NewTab(command);
_NewTab(NULL);
}
#else
@@ -386,43 +386,7 @@ TermWindow::MessageReceived(BMessage *message)
fTermView->SetEncoding(coding_id);
break;
}
// Extended B_SET_PROPERTY. Dispatch this message,
// Set coding ID.
case B_SET_PROPERTY: {
int32 i;
BMessage spe;
message->GetCurrentSpecifier(&i, &spe);
if (!strcmp("encode", spe.FindString("property", i))){
message->FindInt32 ("data", &coding_id);
fTermView->SetEncoding (coding_id);
message->SendReply(B_REPLY);
} else {
BWindow::MessageReceived(message);
}
break;
}
// Extended B_GET_PROPERTY. Dispatch this message, reply now coding ID.
case B_GET_PROPERTY: {
int32 i;
BMessage spe;
message->GetCurrentSpecifier(&i, &spe);
if (!strcmp("encode", spe.FindString("property", i))){
BMessage reply(B_REPLY);
reply.AddInt32("result", fTermView->Encoding());
message->SendReply(&reply);
}
else if (!strcmp("tty", spe.FindString("property", i))) {
BMessage reply(B_REPLY);
reply.AddString("result", fTermView->TerminalName());
message->SendReply(&reply);
} else {
BWindow::MessageReceived(message);
}
break;
}
// Message from Preference panel.
case MSG_ROWS_CHANGED:
case MSG_COLS_CHANGED: {
@@ -579,51 +543,6 @@ TermWindow::QuitRequested()
}
status_t
TermWindow::GetSupportedSuites(BMessage *msg)
{
static property_info propList[] = {
{ "encode",
{B_GET_PROPERTY, 0},
{B_DIRECT_SPECIFIER, 0},
"get muterminal encode"},
{ "encode",
{B_SET_PROPERTY, 0},
{B_DIRECT_SPECIFIER, 0},
"set muterminal encode"},
{ "tty",
{B_GET_PROPERTY, 0},
{B_DIRECT_SPECIFIER, 0},
"get tty_name."},
{ 0 }
};
msg->AddString("suites", "suite/vnd.naan-termwindow");
BPropertyInfo propInfo(propList);
msg->AddFlat("messages", &propInfo);
return BWindow::GetSupportedSuites(msg);
}
////////////////////////////////////////////////////////////////////////////
// ResolveSpecifier
//
////////////////////////////////////////////////////////////////////////////
BHandler*
TermWindow::ResolveSpecifier(BMessage *msg, int32 index,
BMessage *specifier, int32 form,
const char *property)
{
if (((strcmp(property, "encode") == 0)
&& ((msg->what == B_SET_PROPERTY) || (msg->what == B_GET_PROPERTY)))
|| ((strcmp(property, "tty") == 0) && (msg->what == B_GET_PROPERTY)))
return this;
return BWindow::ResolveSpecifier(msg, index, specifier, form, property);
}
status_t
TermWindow::_DoPageSetup()
{
@@ -684,3 +603,12 @@ TermWindow::_DoPrint()
}
#endif
void
TermWindow::_NewTab(const char *command)
{
TermView *view = new TermView(Bounds(), command);
fTabView->AddTab(view);
}
+4 -6
View File
@@ -40,7 +40,7 @@ class BMenuBar;
class FindWindow;
class PrefWindow;
class TermView;
class SmartTabView;
class TermWindow : public BWindow {
public:
TermWindow(BRect frame, const char* title, const char *command);
@@ -52,17 +52,15 @@ protected:
virtual void MenusBeginning();
virtual bool QuitRequested();
status_t GetSupportedSuites(BMessage *msg);
BHandler* ResolveSpecifier(BMessage *msg, int32 index,
BMessage *specifier, int32 form,
const char *property);
private:
void _InitWindow(const char *command);
void _SetupMenu();
status_t _DoPageSetup();
void _DoPrint();
void _NewTab(const char *command);
SmartTabView *fTabView;
TermView *fTermView;
BMenuBar *fMenubar;
BMenu *fFilemenu,