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:
Stefano Ceccherini 2007-08-16 15:32:09 +00:00
parent a2e2784cf3
commit e7f9f277ef
2 changed files with 76 additions and 66 deletions

View File

@ -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,37 +587,17 @@ 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);
try {
// Note: I don't pass the Arguments class directly to the termview, // Note: I don't pass the Arguments class directly to the termview,
// only to avoid adding it as a dependency: in other words, to keep // only to avoid adding it as a dependency: in other words, to keep
// the TermView class as agnostic as possible about the surrounding world. // the TermView class as agnostic as possible about the surrounding world.
CustomTermView *view = new CustomTermView(PrefHandler::Default()->getInt32(PREF_ROWS), CustomTermView *view =
new CustomTermView(PrefHandler::Default()->getInt32(PREF_ROWS),
PrefHandler::Default()->getInt32(PREF_COLS), PrefHandler::Default()->getInt32(PREF_COLS),
argc, (const char **)argv); argc, (const char **)argv);
@ -610,10 +612,14 @@ TermWindow::_AddTab(Arguments *args)
tab->SetLabel("Terminal"); tab->SetLabel("Terminal");
view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL)); view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL));
// TODO: Resize the vertical scrollbar to take the window gripping handle into account // 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). // TODO: shouldn't this be done in BScrollView itself ? At least BScrollBar does that.
scrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, -13); scrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, -13);
view->SetEncoding(longname2id(PrefHandler::Default()->getString(PREF_TEXT_ENCODING))); view->SetEncoding(longname2id(PrefHandler::Default()->getString(PREF_TEXT_ENCODING)));
BFont fullFont, halfFont;
_GetPreferredFonts(fullFont, halfFont);
view->SetTermFont(&halfFont, &fullFont); view->SetTermFont(&halfFont, &fullFont);
_SetTermColors(view); _SetTermColors(view);
@ -635,9 +641,12 @@ TermWindow::_AddTab(Arguments *args)
// Bug in BTabView or in my code ? // Bug in BTabView or in my code ?
fTabView->Select(0); 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)
{ {

View File

@ -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);