Use a try { } catch block in TermWindow::_AddTab(). Note that this
doesn't fix bug #1392, since TermView::_InitObject() use std::nothrow for allocations. Added TermWindow::_GetPreferredFonts() and moved some code in there. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21984 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
a2e2784cf3
commit
e7f9f277ef
@ -199,6 +199,28 @@ TermWindow::_SetupMenu()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TermWindow::_GetPreferredFonts(BFont &fullFont, BFont &halfFont)
|
||||||
|
{
|
||||||
|
const char *family = PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY);
|
||||||
|
|
||||||
|
halfFont.SetFamilyAndStyle(family, NULL);
|
||||||
|
float size = PrefHandler::Default()->getFloat(PREF_HALF_FONT_SIZE);
|
||||||
|
if (size < 6.0f)
|
||||||
|
size = 6.0f;
|
||||||
|
halfFont.SetSize(size);
|
||||||
|
|
||||||
|
family = PrefHandler::Default()->getString(PREF_FULL_FONT_FAMILY);
|
||||||
|
|
||||||
|
fullFont.SetFamilyAndStyle(family, NULL);
|
||||||
|
size = PrefHandler::Default()->getFloat(PREF_FULL_FONT_SIZE);
|
||||||
|
if (size < 6.0f)
|
||||||
|
size = 6.0f;
|
||||||
|
fullFont.SetSize(size);
|
||||||
|
fullFont.SetSpacing(B_FIXED_SPACING);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermWindow::MessageReceived(BMessage *message)
|
TermWindow::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
@ -565,79 +587,66 @@ TermWindow::_DoPrint()
|
|||||||
void
|
void
|
||||||
TermWindow::_AddTab(Arguments *args)
|
TermWindow::_AddTab(Arguments *args)
|
||||||
{
|
{
|
||||||
// Setup font.
|
|
||||||
|
|
||||||
const char *family = PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY);
|
|
||||||
|
|
||||||
BFont halfFont;
|
|
||||||
halfFont.SetFamilyAndStyle(family, NULL);
|
|
||||||
float size = PrefHandler::Default()->getFloat(PREF_HALF_FONT_SIZE);
|
|
||||||
if (size < 6.0f)
|
|
||||||
size = 6.0f;
|
|
||||||
halfFont.SetSize(size);
|
|
||||||
|
|
||||||
family = PrefHandler::Default()->getString(PREF_FULL_FONT_FAMILY);
|
|
||||||
|
|
||||||
BFont fullFont;
|
|
||||||
fullFont.SetFamilyAndStyle(family, NULL);
|
|
||||||
size = PrefHandler::Default()->getFloat(PREF_FULL_FONT_SIZE);
|
|
||||||
if (size < 6.0f)
|
|
||||||
size = 6.0f;
|
|
||||||
fullFont.SetSize(size);
|
|
||||||
fullFont.SetSpacing(B_FIXED_SPACING);
|
|
||||||
|
|
||||||
// Make Terminal text view.
|
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
const char *const *argv = NULL;
|
const char *const *argv = NULL;
|
||||||
if (args != NULL)
|
if (args != NULL)
|
||||||
args->GetShellArguments(argc, argv);
|
args->GetShellArguments(argc, argv);
|
||||||
|
|
||||||
// Note: I don't pass the Arguments class directly to the termview,
|
try {
|
||||||
// only to avoid adding it as a dependency: in other words, to keep
|
// Note: I don't pass the Arguments class directly to the termview,
|
||||||
// the TermView class as agnostic as possible about the surrounding world.
|
// only to avoid adding it as a dependency: in other words, to keep
|
||||||
CustomTermView *view = new CustomTermView(PrefHandler::Default()->getInt32(PREF_ROWS),
|
// the TermView class as agnostic as possible about the surrounding world.
|
||||||
PrefHandler::Default()->getInt32(PREF_COLS),
|
CustomTermView *view =
|
||||||
argc, (const char **)argv);
|
new CustomTermView(PrefHandler::Default()->getInt32(PREF_ROWS),
|
||||||
|
PrefHandler::Default()->getInt32(PREF_COLS),
|
||||||
BScrollView *scrollView = new BScrollView("scrollView", view, B_FOLLOW_ALL,
|
argc, (const char **)argv);
|
||||||
B_WILL_DRAW|B_FRAME_EVENTS, false, true);
|
|
||||||
|
|
||||||
BTab *tab = new BTab;
|
|
||||||
// TODO: Use a better name. For example, do like MacOsX's Terminal
|
|
||||||
// and update the title using the last executed command ?
|
|
||||||
// Or like Gnome's Terminal and use the current path ?
|
|
||||||
fTabView->AddTab(scrollView, tab);
|
|
||||||
tab->SetLabel("Terminal");
|
|
||||||
view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL));
|
|
||||||
|
|
||||||
// TODO: Resize the vertical scrollbar to take the window gripping handle into account
|
|
||||||
// (shouldn't this be done in BScrollView itself ? At least BScrollBar does that).
|
|
||||||
scrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, -13);
|
|
||||||
view->SetEncoding(longname2id(PrefHandler::Default()->getString(PREF_TEXT_ENCODING)));
|
|
||||||
view->SetTermFont(&halfFont, &fullFont);
|
|
||||||
|
|
||||||
_SetTermColors(view);
|
|
||||||
|
|
||||||
// If it's the first time we're called, setup the window
|
|
||||||
if (fTabView->CountTabs() == 1) {
|
|
||||||
int width, height;
|
|
||||||
view->GetFontSize(&width, &height);
|
|
||||||
SetSizeLimits(MIN_COLS * width, MAX_COLS * width,
|
|
||||||
MIN_COLS * height, MAX_COLS * height);
|
|
||||||
|
|
||||||
float fWidth, fHeight;
|
|
||||||
view->GetPreferredSize(&fWidth, &fHeight);
|
|
||||||
|
|
||||||
// Resize Window
|
BScrollView *scrollView = new BScrollView("scrollView", view, B_FOLLOW_ALL,
|
||||||
ResizeTo(fWidth + B_V_SCROLL_BAR_WIDTH, fHeight + fMenubar->Bounds().Height());
|
B_WILL_DRAW|B_FRAME_EVENTS, false, true);
|
||||||
|
|
||||||
// TODO: If I don't do this, the view won't show up.
|
BTab *tab = new BTab;
|
||||||
// Bug in BTabView or in my code ?
|
// TODO: Use a better name. For example, do like MacOsX's Terminal
|
||||||
fTabView->Select(0);
|
// and update the title using the last executed command ?
|
||||||
|
// Or like Gnome's Terminal and use the current path ?
|
||||||
|
fTabView->AddTab(scrollView, tab);
|
||||||
|
tab->SetLabel("Terminal");
|
||||||
|
view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL));
|
||||||
|
|
||||||
|
// Resize the vertical scrollbar to take the window gripping handle into account
|
||||||
|
// TODO: shouldn't this be done in BScrollView itself ? At least BScrollBar does that.
|
||||||
|
scrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, -13);
|
||||||
|
|
||||||
|
view->SetEncoding(longname2id(PrefHandler::Default()->getString(PREF_TEXT_ENCODING)));
|
||||||
|
|
||||||
|
BFont fullFont, halfFont;
|
||||||
|
_GetPreferredFonts(fullFont, halfFont);
|
||||||
|
view->SetTermFont(&halfFont, &fullFont);
|
||||||
|
|
||||||
|
_SetTermColors(view);
|
||||||
|
|
||||||
|
// If it's the first time we're called, setup the window
|
||||||
|
if (fTabView->CountTabs() == 1) {
|
||||||
|
int width, height;
|
||||||
|
view->GetFontSize(&width, &height);
|
||||||
|
SetSizeLimits(MIN_COLS * width, MAX_COLS * width,
|
||||||
|
MIN_COLS * height, MAX_COLS * height);
|
||||||
|
|
||||||
|
float fWidth, fHeight;
|
||||||
|
view->GetPreferredSize(&fWidth, &fHeight);
|
||||||
|
|
||||||
|
// Resize Window
|
||||||
|
ResizeTo(fWidth + B_V_SCROLL_BAR_WIDTH, fHeight + fMenubar->Bounds().Height());
|
||||||
|
|
||||||
|
// TODO: If I don't do this, the view won't show up.
|
||||||
|
// Bug in BTabView or in my code ?
|
||||||
|
fTabView->Select(0);
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
// most probably out of memory. That's bad.
|
||||||
|
// TODO: Should cleanup, I guess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermWindow::_RemoveTab(int32 index)
|
TermWindow::_RemoveTab(int32 index)
|
||||||
{
|
{
|
||||||
|
@ -58,6 +58,7 @@ private:
|
|||||||
void _SetTermColors(TermView *termView);
|
void _SetTermColors(TermView *termView);
|
||||||
void _InitWindow();
|
void _InitWindow();
|
||||||
void _SetupMenu();
|
void _SetupMenu();
|
||||||
|
void _GetPreferredFonts(BFont &full, BFont &half);
|
||||||
status_t _DoPageSetup();
|
status_t _DoPageSetup();
|
||||||
void _DoPrint();
|
void _DoPrint();
|
||||||
void _AddTab(Arguments *args);
|
void _AddTab(Arguments *args);
|
||||||
|
Loading…
Reference in New Issue
Block a user