add window size and encoding to terminal prefs

* The menu items now only set the values for the current window without
saving,
* The settings in the preference window are persistent,
* The "save as defaults" menu item is removed.

Fixes #5030.
This commit is contained in:
Adrien Destugues 2014-11-10 11:43:18 +01:00
parent defb82922a
commit 482f0eeb01
5 changed files with 98 additions and 45 deletions

View File

@ -13,6 +13,8 @@
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <CharacterSet.h>
#include <CharacterSetRoster.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <ColorControl.h> #include <ColorControl.h>
#include <LayoutBuilder.h> #include <LayoutBuilder.h>
@ -27,6 +29,7 @@
#include "Colors.h" #include "Colors.h"
#include "PrefHandler.h" #include "PrefHandler.h"
#include "TermConst.h" #include "TermConst.h"
#include "TermWindow.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
@ -99,6 +102,14 @@ AppearancePrefView::AppearancePrefView(const char* name,
PrefHandler::Default()->getString(PREF_HALF_FONT_STYLE)); PrefHandler::Default()->getString(PREF_HALF_FONT_STYLE));
fFontField = new BMenuField(B_TRANSLATE("Font:"), fontMenu); 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, BPopUpMenu* schemesPopUp = _MakeColorSchemeMenu(MSG_COLOR_SCHEME_CHANGED,
gPredefinedColorSchemes, gPredefinedColorSchemes[0]); gPredefinedColorSchemes, gPredefinedColorSchemes[0]);
fColorSchemeField = new BMenuField(B_TRANSLATE("Color scheme:"), fColorSchemeField = new BMenuField(B_TRANSLATE("Color scheme:"),
@ -132,12 +143,16 @@ AppearancePrefView::AppearancePrefView(const char* name,
.Add(fTabTitle->CreateTextViewLayoutItem(), 1, 0) .Add(fTabTitle->CreateTextViewLayoutItem(), 1, 0)
.Add(fWindowTitle->CreateLabelLayoutItem(), 0, 1) .Add(fWindowTitle->CreateLabelLayoutItem(), 0, 1)
.Add(fWindowTitle->CreateTextViewLayoutItem(), 1, 1) .Add(fWindowTitle->CreateTextViewLayoutItem(), 1, 1)
.Add(fFontField->CreateLabelLayoutItem(), 0, 2) .Add(fWindowSizeField->CreateLabelLayoutItem(), 0, 2)
.Add(fFontField->CreateMenuBarLayoutItem(), 1, 2) .Add(fWindowSizeField->CreateMenuBarLayoutItem(), 1, 2)
.Add(fColorSchemeField->CreateLabelLayoutItem(), 0, 3) .Add(fFontField->CreateLabelLayoutItem(), 0, 3)
.Add(fColorSchemeField->CreateMenuBarLayoutItem(), 1, 3) .Add(fFontField->CreateMenuBarLayoutItem(), 1, 3)
.Add(fColorField->CreateLabelLayoutItem(), 0, 4) .Add(fEncodingField->CreateLabelLayoutItem(), 0, 4)
.Add(fColorField->CreateMenuBarLayoutItem(), 1, 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() .End()
.AddGlue() .AddGlue()
.Add(fColorControl = new BColorControl(BPoint(10, 10), .Add(fColorControl = new BColorControl(BPoint(10, 10),
@ -149,6 +164,8 @@ AppearancePrefView::AppearancePrefView(const char* name,
fTabTitle->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fTabTitle->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
fWindowTitle->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fWindowTitle->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
fFontField->SetAlignment(B_ALIGN_RIGHT); fFontField->SetAlignment(B_ALIGN_RIGHT);
fWindowSizeField->SetAlignment(B_ALIGN_RIGHT);
fEncodingField->SetAlignment(B_ALIGN_RIGHT);
fColorField->SetAlignment(B_ALIGN_RIGHT); fColorField->SetAlignment(B_ALIGN_RIGHT);
fColorSchemeField->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 void
AppearancePrefView::Revert() AppearancePrefView::Revert()
{ {
@ -188,6 +194,8 @@ AppearancePrefView::Revert()
fWarnOnExit->SetValue(pref->getBool(PREF_WARN_ON_EXIT)); fWarnOnExit->SetValue(pref->getBool(PREF_WARN_ON_EXIT));
_SetCurrentColorScheme(); _SetCurrentColorScheme();
_SetEncoding(pref->getString(PREF_TEXT_ENCODING));
_SetWindowSize(pref->getInt32(PREF_ROWS), pref->getInt32(PREF_COLS));
fColorControl->SetValue(pref->getRGB(PREF_TEXT_FORE_COLOR)); fColorControl->SetValue(pref->getRGB(PREF_TEXT_FORE_COLOR));
const char* family = pref->getString(PREF_HALF_FONT_FAMILY); const char* family = pref->getString(PREF_HALF_FONT_FAMILY);
@ -219,6 +227,8 @@ AppearancePrefView::AttachedToWindow()
fColorControl->SetTarget(this); fColorControl->SetTarget(this);
fColorField->Menu()->SetTargetForItems(this); fColorField->Menu()->SetTargetForItems(this);
fColorSchemeField->Menu()->SetTargetForItems(this); fColorSchemeField->Menu()->SetTargetForItems(this);
fWindowSizeField->Menu()->SetTargetForItems(this);
fEncodingField->Menu()->SetTargetForItems(this);
_SetCurrentColorScheme(); _SetCurrentColorScheme();
} }
@ -311,6 +321,24 @@ AppearancePrefView::MessageReceived(BMessage* msg)
break; 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: case MSG_BLINK_CURSOR_CHANGED:
if (PrefHandler::Default()->getBool(PREF_BLINK_CURSOR) if (PrefHandler::Default()->getBool(PREF_BLINK_CURSOR)
!= fBlinkCursor->Value()) { != 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* /*static*/ BMenu*
AppearancePrefView::_MakeFontMenu(uint32 command, AppearancePrefView::_MakeFontMenu(uint32 command,
const char* defaultFamily, const char* defaultStyle) const char* defaultFamily, const char* defaultStyle)

View File

@ -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_BRIGHT_INSTEAD_OF_BOLD_CHANGED = 'bibc';
static const uint32 MSG_WARN_ON_EXIT_CHANGED = 'mwec'; static const uint32 MSG_WARN_ON_EXIT_CHANGED = 'mwec';
static const uint32 MSG_COLS_CHANGED = 'mccl'; static const uint32 MSG_COLS_CHANGED = 'mccl';
static const uint32 MSG_ROWS_CHANGED = 'mcrw';
static const uint32 MSG_HISTORY_CHANGED = 'mhst'; static const uint32 MSG_HISTORY_CHANGED = 'mhst';
// TODO MSG_ENCODING_CHANGED?
static const uint32 MSG_PREF_MODIFIED = 'mpmo'; static const uint32 MSG_PREF_MODIFIED = 'mpmo';
@ -51,12 +51,11 @@ public:
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void GetPreferredSize(float* _width,
float* _height);
private: private:
void _ChangeColorScheme(color_scheme* scheme); void _ChangeColorScheme(color_scheme* scheme);
void _SetCurrentColorScheme(); void _SetCurrentColorScheme();
void _SetEncoding(const char* encoding);
void _SetWindowSize(int rows, int cols);
static BMenu* _MakeFontMenu(uint32 command, static BMenu* _MakeFontMenu(uint32 command,
const char* defaultFamily, const char* defaultFamily,
@ -82,6 +81,9 @@ private:
BCheckBox* fWarnOnExit; BCheckBox* fWarnOnExit;
BMenuField* fFontField; BMenuField* fFontField;
BMenuField* fWindowSizeField;
BMenuField* fEncodingField;
BMenuField* fColorSchemeField; BMenuField* fColorSchemeField;
BMenuField* fColorField; BMenuField* fColorField;
BColorControl* fColorControl; BColorControl* fColorControl;

View File

@ -65,15 +65,12 @@ static const ulong PSET_BACK_COLOR = 'pbcl';
static const ulong PSET__CODING = 'pcod'; static const ulong PSET__CODING = 'pcod';
// Terminal Size Messages // Terminal Size Messages
static const uint32 EIGHTYTWENTYFOUR = 'etfo';
static const uint32 EIGHTYTWENTYFIVE = 'etfv'; static const uint32 EIGHTYTWENTYFIVE = 'etfv';
static const uint32 EIGHTYFORTY = 'efor'; static const uint32 EIGHTYFORTY = 'efor';
static const uint32 ONETHREETWOTWENTYFOUR = 'hunf';
static const uint32 ONETHREETWOTWENTYFIVE = 'hunv'; static const uint32 ONETHREETWOTWENTYFIVE = 'hunv';
static const uint32 FULLSCREEN = 'fscr'; static const uint32 FULLSCREEN = 'fscr';
static const uint32 MSG_FONT_CHANGED = 'fntc'; 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_CHECK_CHILDREN = 'ckch';
static const uint32 MSG_REMOVE_RESIZE_VIEW_IF_NEEDED = 'rmrv'; static const uint32 MSG_REMOVE_RESIZE_VIEW_IF_NEEDED = 'rmrv';
static const uint32 MSG_TERMINAL_BUFFER_CHANGED = 'bufc'; static const uint32 MSG_TERMINAL_BUFFER_CHANGED = 'bufc';

View File

@ -422,7 +422,7 @@ TermWindow::MenusBeginning()
/* static */ /* static */
BMenu* BMenu*
TermWindow::_MakeEncodingMenu() TermWindow::MakeEncodingMenu()
{ {
BMenu* menu = new (std::nothrow) BMenu(B_TRANSLATE("Text encoding")); BMenu* menu = new (std::nothrow) BMenu(B_TRANSLATE("Text encoding"));
if (menu == NULL) if (menu == NULL)
@ -470,6 +470,11 @@ TermWindow::_SetupMenu()
fFontSizeMenu->AddItem(fIncreaseFontSizeMenuItem); fFontSizeMenu->AddItem(fIncreaseFontSizeMenuItem);
fFontSizeMenu->AddItem(fDecreaseFontSizeMenuItem); 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")) BLayoutBuilder::Menu<>(fMenuBar = new BMenuBar(Bounds(), "mbar"))
// Terminal // Terminal
.AddMenu(B_TRANSLATE_COMMENT("Terminal", "The title for the main window" .AddMenu(B_TRANSLATE_COMMENT("Terminal", "The title for the main window"
@ -511,13 +516,11 @@ TermWindow::_SetupMenu()
// Settings // Settings
.AddMenu(B_TRANSLATE("Settings")) .AddMenu(B_TRANSLATE("Settings"))
.AddItem(_MakeWindowSizeMenu()) .AddItem(windowSize)
.AddItem(fEncodingMenu = _MakeEncodingMenu()) .AddItem(fEncodingMenu = MakeEncodingMenu())
.AddItem(fFontSizeMenu) .AddItem(fFontSizeMenu)
.AddSeparator() .AddSeparator()
.AddItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS), MENU_PREF_OPEN) .AddItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS), MENU_PREF_OPEN)
.AddSeparator()
.AddItem(B_TRANSLATE("Save as default"), SAVE_AS_DEFAULT)
.End() .End()
; ;
@ -929,14 +932,6 @@ TermWindow::MessageReceived(BMessage *message)
break; 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: case MENU_PAGE_SETUP:
_DoPageSetup(); _DoPageSetup();
break; break;
@ -1660,7 +1655,7 @@ TermWindow::_ResizeView(TermView *view)
/* static */ BMenu* /* static */ BMenu*
TermWindow::_MakeWindowSizeMenu() TermWindow::MakeWindowSizeMenu()
{ {
BMenu* menu = new (std::nothrow) BMenu(B_TRANSLATE("Window size")); BMenu* menu = new (std::nothrow) BMenu(B_TRANSLATE("Window size"));
if (menu == NULL) if (menu == NULL)
@ -1678,17 +1673,14 @@ TermWindow::_MakeWindowSizeMenu()
char label[32]; char label[32];
int32 columns = windowSizes[i][0]; int32 columns = windowSizes[i][0];
int32 rows = windowSizes[i][1]; 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); BMessage* message = new BMessage(MSG_COLS_CHANGED);
message->AddInt32("columns", columns); message->AddInt32("columns", columns);
message->AddInt32("rows", rows); message->AddInt32("rows", rows);
menu->AddItem(new BMenuItem(label, message)); menu->AddItem(new BMenuItem(label, message));
} }
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem(B_TRANSLATE("Full screen"),
new BMessage(FULLSCREEN), B_ENTER));
return menu; return menu;
} }

View File

@ -62,6 +62,9 @@ public:
void SessionChanged(); void SessionChanged();
static BMenu* MakeEncodingMenu();
static BMenu* MakeWindowSizeMenu();
protected: protected:
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
@ -134,8 +137,6 @@ private:
void _SetTermColors(TermViewContainerView* termView); void _SetTermColors(TermViewContainerView* termView);
void _InitWindow(); void _InitWindow();
void _SetupMenu(); void _SetupMenu();
static BMenu* _MakeEncodingMenu();
static BMenu* _MakeWindowSizeMenu();
static BMenu* _MakeFontSizeMenu(uint32 command, static BMenu* _MakeFontSizeMenu(uint32 command,
uint8 defaultSize); uint8 defaultSize);
void _UpdateSwitchTerminalsMenuItem(); void _UpdateSwitchTerminalsMenuItem();