diff --git a/src/apps/terminal/AppearPrefView.cpp b/src/apps/terminal/AppearPrefView.cpp index 591dfaa63d..bad6929ace 100644 --- a/src/apps/terminal/AppearPrefView.cpp +++ b/src/apps/terminal/AppearPrefView.cpp @@ -13,6 +13,8 @@ #include #include +#include +#include #include #include #include @@ -27,6 +29,7 @@ #include "Colors.h" #include "PrefHandler.h" #include "TermConst.h" +#include "TermWindow.h" #undef B_TRANSLATION_CONTEXT @@ -99,6 +102,14 @@ AppearancePrefView::AppearancePrefView(const char* name, PrefHandler::Default()->getString(PREF_HALF_FONT_STYLE)); fFontField = new BMenuField(B_TRANSLATE("Font:"), fontMenu); + BMenu* sizeMenu = TermWindow::MakeWindowSizeMenu(); + sizeMenu->SetLabelFromMarked(true); + fWindowSizeField = new BMenuField(B_TRANSLATE("Window size:"), sizeMenu); + + BMenu* encodingMenu = TermWindow::MakeEncodingMenu(); + encodingMenu->SetLabelFromMarked(true); + fEncodingField = new BMenuField(B_TRANSLATE("Encoding:"), encodingMenu); + BPopUpMenu* schemesPopUp = _MakeColorSchemeMenu(MSG_COLOR_SCHEME_CHANGED, gPredefinedColorSchemes, gPredefinedColorSchemes[0]); fColorSchemeField = new BMenuField(B_TRANSLATE("Color scheme:"), @@ -132,12 +143,16 @@ AppearancePrefView::AppearancePrefView(const char* name, .Add(fTabTitle->CreateTextViewLayoutItem(), 1, 0) .Add(fWindowTitle->CreateLabelLayoutItem(), 0, 1) .Add(fWindowTitle->CreateTextViewLayoutItem(), 1, 1) - .Add(fFontField->CreateLabelLayoutItem(), 0, 2) - .Add(fFontField->CreateMenuBarLayoutItem(), 1, 2) - .Add(fColorSchemeField->CreateLabelLayoutItem(), 0, 3) - .Add(fColorSchemeField->CreateMenuBarLayoutItem(), 1, 3) - .Add(fColorField->CreateLabelLayoutItem(), 0, 4) - .Add(fColorField->CreateMenuBarLayoutItem(), 1, 4) + .Add(fWindowSizeField->CreateLabelLayoutItem(), 0, 2) + .Add(fWindowSizeField->CreateMenuBarLayoutItem(), 1, 2) + .Add(fFontField->CreateLabelLayoutItem(), 0, 3) + .Add(fFontField->CreateMenuBarLayoutItem(), 1, 3) + .Add(fEncodingField->CreateLabelLayoutItem(), 0, 4) + .Add(fEncodingField->CreateMenuBarLayoutItem(), 1, 4) + .Add(fColorSchemeField->CreateLabelLayoutItem(), 0, 5) + .Add(fColorSchemeField->CreateMenuBarLayoutItem(), 1, 5) + .Add(fColorField->CreateLabelLayoutItem(), 0, 6) + .Add(fColorField->CreateMenuBarLayoutItem(), 1, 6) .End() .AddGlue() .Add(fColorControl = new BColorControl(BPoint(10, 10), @@ -149,6 +164,8 @@ AppearancePrefView::AppearancePrefView(const char* name, fTabTitle->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fWindowTitle->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fFontField->SetAlignment(B_ALIGN_RIGHT); + fWindowSizeField->SetAlignment(B_ALIGN_RIGHT); + fEncodingField->SetAlignment(B_ALIGN_RIGHT); fColorField->SetAlignment(B_ALIGN_RIGHT); fColorSchemeField->SetAlignment(B_ALIGN_RIGHT); @@ -164,17 +181,6 @@ AppearancePrefView::AppearancePrefView(const char* name, } -void -AppearancePrefView::GetPreferredSize(float* _width, float* _height) -{ - if (_width) - *_width = Bounds().Width(); - - if (*_height) - *_height = fColorControl->Frame().bottom; -} - - void AppearancePrefView::Revert() { @@ -188,6 +194,8 @@ AppearancePrefView::Revert() fWarnOnExit->SetValue(pref->getBool(PREF_WARN_ON_EXIT)); _SetCurrentColorScheme(); + _SetEncoding(pref->getString(PREF_TEXT_ENCODING)); + _SetWindowSize(pref->getInt32(PREF_ROWS), pref->getInt32(PREF_COLS)); fColorControl->SetValue(pref->getRGB(PREF_TEXT_FORE_COLOR)); const char* family = pref->getString(PREF_HALF_FONT_FAMILY); @@ -219,6 +227,8 @@ AppearancePrefView::AttachedToWindow() fColorControl->SetTarget(this); fColorField->Menu()->SetTargetForItems(this); fColorSchemeField->Menu()->SetTargetForItems(this); + fWindowSizeField->Menu()->SetTargetForItems(this); + fEncodingField->Menu()->SetTargetForItems(this); _SetCurrentColorScheme(); } @@ -311,6 +321,24 @@ AppearancePrefView::MessageReceived(BMessage* msg) break; } + case MSG_COLS_CHANGED: + { + int rows = msg->FindInt32("rows"); + int columns = msg->FindInt32("columns"); + _SetWindowSize(rows, columns); + PrefHandler* handler = PrefHandler::Default(); + if (handler->getInt32(PREF_ROWS) != rows) { + PrefHandler::Default()->setInt32(PREF_ROWS, rows); + modified = true; + } + if (handler->getInt32(PREF_COLS) != columns) { + PrefHandler::Default()->setInt32(PREF_COLS, columns); + modified = true; + } + + break; + } + case MSG_BLINK_CURSOR_CHANGED: if (PrefHandler::Default()->getBool(PREF_BLINK_CURSOR) != fBlinkCursor->Value()) { @@ -425,6 +453,39 @@ AppearancePrefView::_SetCurrentColorScheme() } +void +AppearancePrefView::_SetEncoding(const char* name) +{ + const BPrivate::BCharacterSet* charset + = BPrivate::BCharacterSetRoster::FindCharacterSetByName(name); + if (charset == NULL) + return; + int code = charset->GetConversionID(); + for (int32 i = 0; i < fEncodingField->Menu()->CountItems(); i++) { + BMenuItem* item = fEncodingField->Menu()->ItemAt(i); + BMessage* msg = item->Message(); + if (msg->FindInt32("op") == code) { + item->SetMarked(true); + break; + } + } +} + + +void +AppearancePrefView::_SetWindowSize(int rows, int cols) +{ + for (int32 i = 0; i < fWindowSizeField->Menu()->CountItems(); i++) { + BMenuItem* item = fWindowSizeField->Menu()->ItemAt(i); + BMessage* msg = item->Message(); + if (msg->FindInt32("rows") == rows && msg->FindInt32("columns") == cols) { + item->SetMarked(true); + break; + } + } +} + + /*static*/ BMenu* AppearancePrefView::_MakeFontMenu(uint32 command, const char* defaultFamily, const char* defaultStyle) diff --git a/src/apps/terminal/AppearPrefView.h b/src/apps/terminal/AppearPrefView.h index ed059feb16..7d6de490fe 100644 --- a/src/apps/terminal/AppearPrefView.h +++ b/src/apps/terminal/AppearPrefView.h @@ -27,8 +27,8 @@ static const uint32 MSG_BLINK_CURSOR_CHANGED = 'mbcc'; static const uint32 MSG_BRIGHT_INSTEAD_OF_BOLD_CHANGED = 'bibc'; static const uint32 MSG_WARN_ON_EXIT_CHANGED = 'mwec'; static const uint32 MSG_COLS_CHANGED = 'mccl'; -static const uint32 MSG_ROWS_CHANGED = 'mcrw'; static const uint32 MSG_HISTORY_CHANGED = 'mhst'; +// TODO MSG_ENCODING_CHANGED? static const uint32 MSG_PREF_MODIFIED = 'mpmo'; @@ -51,12 +51,11 @@ public: virtual void MessageReceived(BMessage* message); virtual void AttachedToWindow(); - virtual void GetPreferredSize(float* _width, - float* _height); - private: void _ChangeColorScheme(color_scheme* scheme); void _SetCurrentColorScheme(); + void _SetEncoding(const char* encoding); + void _SetWindowSize(int rows, int cols); static BMenu* _MakeFontMenu(uint32 command, const char* defaultFamily, @@ -82,6 +81,9 @@ private: BCheckBox* fWarnOnExit; BMenuField* fFontField; + BMenuField* fWindowSizeField; + BMenuField* fEncodingField; + BMenuField* fColorSchemeField; BMenuField* fColorField; BColorControl* fColorControl; diff --git a/src/apps/terminal/TermConst.h b/src/apps/terminal/TermConst.h index e01d91cbf7..681c915fc6 100644 --- a/src/apps/terminal/TermConst.h +++ b/src/apps/terminal/TermConst.h @@ -65,15 +65,12 @@ static const ulong PSET_BACK_COLOR = 'pbcl'; static const ulong PSET__CODING = 'pcod'; // Terminal Size Messages -static const uint32 EIGHTYTWENTYFOUR = 'etfo'; static const uint32 EIGHTYTWENTYFIVE = 'etfv'; static const uint32 EIGHTYFORTY = 'efor'; -static const uint32 ONETHREETWOTWENTYFOUR = 'hunf'; static const uint32 ONETHREETWOTWENTYFIVE = 'hunv'; static const uint32 FULLSCREEN = 'fscr'; static const uint32 MSG_FONT_CHANGED = 'fntc'; -static const uint32 SAVE_AS_DEFAULT = 'sadf'; static const uint32 MSG_CHECK_CHILDREN = 'ckch'; static const uint32 MSG_REMOVE_RESIZE_VIEW_IF_NEEDED = 'rmrv'; static const uint32 MSG_TERMINAL_BUFFER_CHANGED = 'bufc'; diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index 481d463818..461058d3b5 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -422,7 +422,7 @@ TermWindow::MenusBeginning() /* static */ BMenu* -TermWindow::_MakeEncodingMenu() +TermWindow::MakeEncodingMenu() { BMenu* menu = new (std::nothrow) BMenu(B_TRANSLATE("Text encoding")); if (menu == NULL) @@ -470,6 +470,11 @@ TermWindow::_SetupMenu() fFontSizeMenu->AddItem(fIncreaseFontSizeMenuItem); fFontSizeMenu->AddItem(fDecreaseFontSizeMenuItem); + BMenu* windowSize = MakeWindowSizeMenu(); + windowSize->AddSeparatorItem(); + windowSize->AddItem(new BMenuItem(B_TRANSLATE("Full screen"), + new BMessage(FULLSCREEN), B_ENTER)); + BLayoutBuilder::Menu<>(fMenuBar = new BMenuBar(Bounds(), "mbar")) // Terminal .AddMenu(B_TRANSLATE_COMMENT("Terminal", "The title for the main window" @@ -511,13 +516,11 @@ TermWindow::_SetupMenu() // Settings .AddMenu(B_TRANSLATE("Settings")) - .AddItem(_MakeWindowSizeMenu()) - .AddItem(fEncodingMenu = _MakeEncodingMenu()) + .AddItem(windowSize) + .AddItem(fEncodingMenu = MakeEncodingMenu()) .AddItem(fFontSizeMenu) .AddSeparator() .AddItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS), MENU_PREF_OPEN) - .AddSeparator() - .AddItem(B_TRANSLATE("Save as default"), SAVE_AS_DEFAULT) .End() ; @@ -929,14 +932,6 @@ TermWindow::MessageReceived(BMessage *message) break; } - case SAVE_AS_DEFAULT: - { - BPath path; - if (PrefHandler::GetDefaultPath(path) == B_OK) - PrefHandler::Default()->SaveAsText(path.Path(), - PREFFILE_MIMETYPE); - break; - } case MENU_PAGE_SETUP: _DoPageSetup(); break; @@ -1660,7 +1655,7 @@ TermWindow::_ResizeView(TermView *view) /* static */ BMenu* -TermWindow::_MakeWindowSizeMenu() +TermWindow::MakeWindowSizeMenu() { BMenu* menu = new (std::nothrow) BMenu(B_TRANSLATE("Window size")); if (menu == NULL) @@ -1678,17 +1673,14 @@ TermWindow::_MakeWindowSizeMenu() char label[32]; int32 columns = windowSizes[i][0]; int32 rows = windowSizes[i][1]; - snprintf(label, sizeof(label), "%" B_PRId32 "x%" B_PRId32, columns, rows); + snprintf(label, sizeof(label), "%" B_PRId32 "x%" B_PRId32, columns, + rows); BMessage* message = new BMessage(MSG_COLS_CHANGED); message->AddInt32("columns", columns); message->AddInt32("rows", rows); menu->AddItem(new BMenuItem(label, message)); } - menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem(B_TRANSLATE("Full screen"), - new BMessage(FULLSCREEN), B_ENTER)); - return menu; } diff --git a/src/apps/terminal/TermWindow.h b/src/apps/terminal/TermWindow.h index 5740595445..7bae44f953 100644 --- a/src/apps/terminal/TermWindow.h +++ b/src/apps/terminal/TermWindow.h @@ -62,6 +62,9 @@ public: void SessionChanged(); + static BMenu* MakeEncodingMenu(); + static BMenu* MakeWindowSizeMenu(); + protected: virtual bool QuitRequested(); virtual void MessageReceived(BMessage* message); @@ -134,8 +137,6 @@ private: void _SetTermColors(TermViewContainerView* termView); void _InitWindow(); void _SetupMenu(); - static BMenu* _MakeEncodingMenu(); - static BMenu* _MakeWindowSizeMenu(); static BMenu* _MakeFontSizeMenu(uint32 command, uint8 defaultSize); void _UpdateSwitchTerminalsMenuItem();