Style cleanups

Usability fixes for preferences window


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13507 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2005-07-06 19:31:17 +00:00
parent dd80de6b0d
commit ec87043e1a
6 changed files with 421 additions and 547 deletions

View File

@ -33,23 +33,19 @@
#include <Menu.h> #include <Menu.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <TextControl.h>
#include <Beep.h>
#include <stdlib.h> #include <stdlib.h>
#include "AppearPrefView.h" #include "AppearPrefView.h"
#include "MenuUtil.h"
#include "PrefHandler.h" #include "PrefHandler.h"
#include "TermWindow.h" #include "TermWindow.h"
#include "TermConst.h" #include "TermConst.h"
#include "MenuUtil.h"
#include "TTextControl.h"
#define MAX_FONT_SIZE 32 BPopUpMenu *MakeFontMenu(ulong msg, const char *defaultFontName);
#define MIN_FONT_SIZE 6 BPopUpMenu *MakeSizeMenu(ulong msg, uint8 defaultSize);
AppearancePrefView::AppearancePrefView (BRect frame, const char *name, AppearancePrefView::AppearancePrefView (BRect frame, const char *name, TermWindow *window)
TermWindow *window)
:PrefView (frame, name) :PrefView (frame, name)
{ {
const char *color_tbl[]= const char *color_tbl[]=
@ -64,139 +60,181 @@ AppearancePrefView::AppearancePrefView (BRect frame, const char *name,
}; };
fTermWindow = window; fTermWindow = window;
mHalfFont = new BMenuField(BRect(0,0,220,20), "halffont", "Half Size Font", MakeFontMenu(MSG_HALF_FONT_CHANGED, gTermPref->getString(PREF_HALF_FONT_FAMILY)), B_WILL_DRAW);
AddChild(mHalfFont);
mHalfFont->SetDivider (120);
mHalfSize = new TTextControl(BRect(220, 0, 300, 20), "halfsize", "Size", "", new BMessage(MSG_HALF_SIZE_CHANGED)); float fontDividerSize = StringWidth("Half Size Font") + 15.0;
AddChild(mHalfSize); float sizeDividerSize = StringWidth("Size") + 15.0;
mHalfSize->SetText(gTermPref->getString(PREF_HALF_FONT_SIZE));
mHalfSize->SetDivider (50); BRect r(5,5,225,25);
mFullFont = new BMenuField(BRect(0,30,220,50), "fullfont", "Full Size Font", MakeFontMenu(MSG_FULL_FONT_CHANGED, gTermPref->getString(PREF_FULL_FONT_FAMILY)), B_WILL_DRAW); BMenu *menu = MakeFontMenu(MSG_HALF_FONT_CHANGED, gTermPref->getString(PREF_HALF_FONT_FAMILY));
AddChild(mFullFont); fHalfFont = new BMenuField(r, "halffont", "Half Width Font", menu, B_WILL_DRAW);
mFullFont->SetDivider (120); AddChild(fHalfFont);
fHalfFont->SetDivider(fontDividerSize);
r.OffsetBy(r.Width() + 10, 0);
menu = MakeSizeMenu(MSG_HALF_SIZE_CHANGED, 12);
fHalfFontSize = new BMenuField(r, "halfsize", "Size", menu, B_WILL_DRAW);
fHalfFontSize->SetDivider(sizeDividerSize);
AddChild(fHalfFontSize);
r.OffsetBy(-r.Width() - 10,r.Height() + 5);
menu = MakeFontMenu(MSG_FULL_FONT_CHANGED, gTermPref->getString(PREF_FULL_FONT_FAMILY));
fFullFont = new BMenuField(r, "fullfont", "Full Width Font", menu, B_WILL_DRAW);
AddChild(fFullFont);
fFullFont->SetDivider(fontDividerSize);
mFullSize = new TTextControl(BRect(220, 30, 300, 50), "fullsize", "Size", "", new BMessage(MSG_FULL_SIZE_CHANGED)); r.OffsetBy(r.Width() + 10, 0);
AddChild(mFullSize); menu = MakeSizeMenu(MSG_FULL_SIZE_CHANGED, 12);
mFullSize->SetText(gTermPref->getString(PREF_FULL_FONT_SIZE)); fFullFontSize = new BMenuField(r, "fullsize", "Size", menu, B_WILL_DRAW);
mFullSize->SetDivider (50); fFullFontSize->SetDivider(sizeDividerSize);
AddChild(fFullFontSize);
mColorField = new BMenuField(BRect(0,60,200,80), NULL, NULL, MakeMenu (MSG_COLOR_FIELD_CHANGED, color_tbl, color_tbl[0]), B_WILL_DRAW);
AddChild(mColorField); r.OffsetBy(-r.Width() - 10,r.Height() + 25);
fColorField = new BMenuField(r, NULL, NULL, MakeMenu (MSG_COLOR_FIELD_CHANGED, color_tbl, color_tbl[0]), B_WILL_DRAW);
mColorCtl = SetupBColorControl(BPoint(20, 85), B_CELLS_32x8, 6, MSG_COLOR_CHANGED); AddChild(fColorField);
mColorCtl->SetValue(gTermPref->getRGB(PREF_TEXT_FORE_COLOR));
fColorCtl = SetupBColorControl(BPoint(r.left, r.bottom + 10), B_CELLS_32x8, 6,
MSG_COLOR_CHANGED);
fColorCtl->SetValue(gTermPref->getRGB(PREF_TEXT_FORE_COLOR));
} }
void void
AppearancePrefView::Revert (void) AppearancePrefView::Revert (void)
{ {
fColorField->Menu()->ItemAt(0)->SetMarked (true);
mHalfSize->SetText (gTermPref->getString (PREF_HALF_FONT_SIZE)); fColorCtl->SetValue (gTermPref->getRGB(PREF_TEXT_FORE_COLOR));
mFullSize->SetText (gTermPref->getString (PREF_FULL_FONT_SIZE));
mColorField->Menu()->ItemAt(0)->SetMarked (true);
mColorCtl->SetValue (gTermPref->getRGB(PREF_TEXT_FORE_COLOR));
mHalfFont->Menu()->FindItem (gTermPref->getString(PREF_HALF_FONT_FAMILY))->SetMarked(true); fHalfFont->Menu()->FindItem (gTermPref->getString(PREF_HALF_FONT_FAMILY))->SetMarked(true);
mFullFont->Menu()->FindItem (gTermPref->getString(PREF_FULL_FONT_FAMILY))->SetMarked(true); fFullFont->Menu()->FindItem (gTermPref->getString(PREF_FULL_FONT_FAMILY))->SetMarked(true);
fHalfFontSize->Menu()->FindItem (gTermPref->getString(PREF_HALF_FONT_FAMILY))->SetMarked(true);
return; fFullFontSize->Menu()->FindItem (gTermPref->getString(PREF_FULL_FONT_FAMILY))->SetMarked(true);
}
////////////////////////////////////////////////////////////////////////////
// SaveIfModified (void)
//
////////////////////////////////////////////////////////////////////////////
void
AppearancePrefView::SaveIfModified (void)
{
BMessenger messenger (fTermWindow);
if (mHalfSize->IsModified()) {
gTermPref->setString (PREF_HALF_FONT_SIZE, mHalfSize->Text());
messenger.SendMessage (MSG_HALF_SIZE_CHANGED);
mHalfSize->ModifiedText (false);
}
if (mFullSize->IsModified()) {
gTermPref->setString (PREF_FULL_FONT_SIZE, mFullSize->Text());
messenger.SendMessage (MSG_FULL_SIZE_CHANGED);
mFullSize->ModifiedText (false);
}
return;
} }
void void
AppearancePrefView::AttachedToWindow (void) AppearancePrefView::AttachedToWindow (void)
{ {
mHalfSize->SetTarget (this); fHalfFontSize->Menu()->SetTargetForItems(this);
mFullSize->SetTarget (this); fFullFontSize->Menu()->SetTargetForItems(this);
mHalfFont->Menu()->SetTargetForItems(this);
mFullFont->Menu()->SetTargetForItems(this); fHalfFont->Menu()->SetTargetForItems(this);
fFullFont->Menu()->SetTargetForItems(this);
mColorCtl->SetTarget (this);
mColorField->Menu()->SetTargetForItems(this);
fColorCtl->SetTarget (this);
fColorField->Menu()->SetTargetForItems(this);
} }
void void
AppearancePrefView::MessageReceived (BMessage *msg) AppearancePrefView::MessageReceived (BMessage *msg)
{ {
bool modified = false; bool modified = false;
int size;
switch (msg->what) { switch (msg->what)
case MSG_HALF_FONT_CHANGED: {
gTermPref->setString (PREF_HALF_FONT_FAMILY, mHalfFont->Menu()->FindMarked()->Label()); case MSG_HALF_FONT_CHANGED:
modified = true; {
break; gTermPref->setString (PREF_HALF_FONT_FAMILY, fHalfFont->Menu()->FindMarked()->Label());
modified = true;
case MSG_HALF_SIZE_CHANGED: break;
size = atoi (mHalfSize->Text()); }
if (size > MAX_FONT_SIZE || size < MIN_FONT_SIZE) { case MSG_HALF_SIZE_CHANGED:
mHalfSize->SetText (gTermPref->getString (PREF_HALF_FONT_SIZE)); {
beep (); gTermPref->setString (PREF_HALF_FONT_SIZE, fHalfFontSize->Menu()->FindMarked()->Label());
} else { modified = true;
gTermPref->setString (PREF_HALF_FONT_SIZE, mHalfSize->Text()); break;
modified = true; }
} case MSG_FULL_FONT_CHANGED:
break; {
gTermPref->setString (PREF_FULL_FONT_FAMILY, fFullFont->Menu()->FindMarked()->Label());
case MSG_FULL_FONT_CHANGED: modified = true;
gTermPref->setString (PREF_FULL_FONT_FAMILY, mFullFont->Menu()->FindMarked()->Label()); break;
modified = true; }
break; case MSG_FULL_SIZE_CHANGED:
{
case MSG_FULL_SIZE_CHANGED: gTermPref->setString (PREF_FULL_FONT_SIZE, fFullFontSize->Menu()->FindMarked()->Label());
size = atoi (mHalfSize->Text()); modified = true;
if (size > MAX_FONT_SIZE || size < MIN_FONT_SIZE) { break;
mFullSize->SetText (gTermPref->getString (PREF_FULL_FONT_SIZE)); }
beep (); case MSG_COLOR_CHANGED:
} else { {
gTermPref->setString (PREF_FULL_FONT_SIZE, mFullSize->Text()); gTermPref->setRGB(fColorField->Menu()->FindMarked()->Label(), fColorCtl->ValueAsColor());
} modified = true;
modified = true; break;
break; }
case MSG_COLOR_FIELD_CHANGED:
case MSG_COLOR_CHANGED: {
gTermPref->setRGB(mColorField->Menu()->FindMarked()->Label(), mColorCtl->ValueAsColor()); fColorCtl->SetValue(gTermPref->getRGB (fColorField->Menu()->FindMarked()->Label()));
modified = true; break;
break; }
default:
case MSG_COLOR_FIELD_CHANGED: {
mColorCtl->SetValue(gTermPref->getRGB (mColorField->Menu()->FindMarked()->Label())); PrefView::MessageReceived(msg);
break; return; // Oh !
}
default: }
PrefView::MessageReceived(msg);
return; // Oh ! if(modified)
} {
fTermWindow->PostMessage(msg);
if(modified){ Window()->PostMessage(MSG_PREF_MODIFIED);
fTermWindow->PostMessage (msg); }
(this->Window())->PostMessage(MSG_PREF_MODIFIED); }
}
BPopUpMenu *
MakeFontMenu(ulong msg, const char *defaultFontName)
{
BPopUpMenu *menu = new BPopUpMenu("");
int32 numFamilies = count_font_families();
for ( int32 i = 0; i < numFamilies; i++ )
{
font_family family;
uint32 flags;
if ( get_font_family(i, &family, &flags) == B_OK )
{
menu->AddItem(new BMenuItem(family, new BMessage(msg)));
if(!strcmp(defaultFontName, family))
{
BMenuItem *item=menu->ItemAt(i);
item->SetMarked(true);
}
}
}
return menu;
}
BPopUpMenu *
MakeSizeMenu(ulong msg, uint8 defaultSize)
{
BPopUpMenu *menu = new BPopUpMenu("size");
BMenuItem *item;
for(uint8 i=9; i<13; i++)
{
BString string;
string << i;
item = new BMenuItem(string.String(), new BMessage(msg));
menu->AddItem(item);
if(i == defaultSize)
item->SetMarked(true);
}
item = new BMenuItem("14", new BMessage(msg));
menu->AddItem(item);
if(defaultSize == 14)
item->SetMarked(true);
item = new BMenuItem("16", new BMessage(msg));
menu->AddItem(item);
if(defaultSize == 16)
item->SetMarked(true);
return menu;
} }

View File

@ -38,30 +38,24 @@ class TTextControl;
class AppearancePrefView : public PrefView class AppearancePrefView : public PrefView
{ {
public: public:
AppearancePrefView(BRect r, AppearancePrefView(BRect r, const char *name,
const char *name, TermWindow *window);
TermWindow *window);
virtual void Revert (void); virtual void Revert (void);
virtual void SaveIfModified (void); virtual void MessageReceived (BMessage *);
virtual void MessageReceived (BMessage *); virtual void AttachedToWindow (void);
virtual void AttachedToWindow (void);
private: private:
TTextControl *mHalfSize; BMenuField *fHalfFont,
TTextControl *mFullSize; *fHalfFontSize,
BMenuField *mHalfFont; *fFullFont,
BMenuField *mFullFont; *fFullFontSize;
BMenuField *mColorField; BMenuField *fColorField;
BColorControl *mColorCtl; BColorControl *fColorCtl;
int mSubMenu_button; TermWindow *fTermWindow;
int mPaste_button;
TermWindow *fTermWindow;
}; };
#endif //AppearancePrefView_H_INCLUDED #endif //AppearancePrefView_H_INCLUDED

View File

@ -44,132 +44,83 @@ extern PrefHandler *gTermPref;
#define LOCALE_FILE_DIR PREF_FOLDER"menu/" #define LOCALE_FILE_DIR PREF_FOLDER"menu/"
//////////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////////
BPopUpMenu *
MakeFontMenu(ulong msg, const char *defaultFontName)
{
BPopUpMenu *menu = new BPopUpMenu("font");
int32 numFamilies = count_font_families();
for ( int32 i = 0; i < numFamilies; i++ ) {
font_family family;
uint32 flags;
if ( get_font_family(i, &family, &flags) == B_OK ) {
menu->AddItem(new BMenuItem(family, new BMessage(msg)));
if(!strcmp(defaultFontName, family)){
(menu->ItemAt(i))->SetMarked(true);
}
}
}
return menu;
}
//////////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////////
BPopUpMenu * BPopUpMenu *
MakeMenu(ulong msg, const char **items, const char *defaultItemName) MakeMenu(ulong msg, const char **items, const char *defaultItemName)
{ {
BPopUpMenu *menu = new BPopUpMenu(""); BPopUpMenu *menu = new BPopUpMenu("");
int32 i = 0; int32 i = 0;
while(*items) { while(*items)
menu->AddItem(new BMenuItem(*items, new BMessage(msg))); {
if(!strcmp(*items, defaultItemName)){ menu->AddItem(new BMenuItem(*items, new BMessage(msg)));
(menu->ItemAt(i))->SetMarked(true); if(!strcmp(*items, defaultItemName))
} {
items++; (menu->ItemAt(i))->SetMarked(true);
i++; }
} items++;
i++;
return menu; }
return menu;
} }
////////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////////
int int
longname2op(const char *longname) longname2op(const char *longname)
{ {
int op = M_UTF8; int op = M_UTF8;
const etable *s = encoding_table; const etable *s = encoding_table;
for (int i = 0; s->name; s++, i++){ for (int i = 0; s->name; s++, i++)
if(!strcmp(s->name, longname)) { {
op = s->op; if(!strcmp(s->name, longname))
break; {
} op = s->op;
} break;
}
return op; }
return op;
} }
//////////////////////////////////////////////////////////////////////////// const char *
//
//
////////////////////////////////////////////////////////////////////////////
const char*
op2longname(int op) op2longname(int op)
{ {
return encoding_table[op].name; return encoding_table[op].name;
} }
//////////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////////
void void
MakeEncodingMenu(BMenu *eMenu, int coding, bool flag) MakeEncodingMenu(BMenu *eMenu, int coding, bool flag)
{ {
const etable *e = encoding_table; const etable *e = encoding_table;
int i = 0; int i = 0;
while(e->name){ while(e->name)
BMessage *msg = new BMessage(MENU_ENCODING); {
msg->AddInt32("op", (int32)e->op); BMessage *msg = new BMessage(MENU_ENCODING);
if (flag) { msg->AddInt32("op", (int32)e->op);
eMenu->AddItem(new BMenuItem(e->name, msg, e->shortcut)); if (flag)
} eMenu->AddItem(new BMenuItem(e->name, msg, e->shortcut));
else { else
eMenu->AddItem(new BMenuItem(e->name, msg)); eMenu->AddItem(new BMenuItem(e->name, msg));
}
if ( i == coding)
if ( i == coding) { {
(eMenu->ItemAt(i))->SetMarked(true); (eMenu->ItemAt(i))->SetMarked(true);
} }
e++; e++;
i++; i++;
} }
} }
//////////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////////
void void
LoadLocaleFile (PrefHandler *pref) LoadLocaleFile(PrefHandler *pref)
{ {
const char *locale;
const char *locale; char buf[B_PATH_NAME_LENGTH];
char buf[B_PATH_NAME_LENGTH]; status_t sts;
status_t sts;
locale = gTermPref->getString (PREF_GUI_LANGUAGE);
/* sprintf (buf, "%s%s", LOCALE_FILE_DIR, locale);
* Open menu localize file.
*/ sts = pref->OpenText (buf);
locale = gTermPref->getString (PREF_GUI_LANGUAGE);
sprintf (buf, "%s%s", LOCALE_FILE_DIR, locale); if (sts == B_ERROR)
pref->OpenText (LOCALE_FILE_DEFAULT);
sts = pref->OpenText (buf);
if (sts == B_ERROR)
pref->OpenText (LOCALE_FILE_DEFAULT);
return;
} }

View File

@ -41,15 +41,13 @@ class BPopUpMenu;
class BMenu; class BMenu;
class PrefHandler; class PrefHandler;
BPopUpMenu * MakeMenu(ulong msg, const char **items,
BPopUpMenu * MakeFontMenu(ulong msg, const char *defaultFontName); const char *defaultItemName);
BPopUpMenu * MakeMenu(ulong msg, const char **items,
const char *defaultItemName);
int longname2op(const char *longname); int longname2op(const char *longname);
const char* op2longname(int op); const char * op2longname(int op);
void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag); void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag);
void LoadLocaleFile (PrefHandler *); void LoadLocaleFile (PrefHandler *);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -29,7 +29,6 @@
*/ */
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <TabView.h>
#include <FilePanel.h> #include <FilePanel.h>
#include <Screen.h> #include <Screen.h>
#include <Alert.h> #include <Alert.h>
@ -44,306 +43,209 @@
#include "MenuUtil.h" #include "MenuUtil.h"
#include "AppearPrefView.h" #include "AppearPrefView.h"
//#include "ShellPrefView.h"
#include "PrefView.h" #include "PrefView.h"
#include "spawn.h" #include "spawn.h"
// Gloval Preference Handler // Global Preference Handler
extern PrefHandler *gTermPref; extern PrefHandler *gTermPref;
//////////////////////////////////////////////////////////////////////////////
// PrefDlg
// Constructer
//////////////////////////////////////////////////////////////////////////////
PrefDlg::PrefDlg(TermWindow *inWindow) PrefDlg::PrefDlg(TermWindow *inWindow)
: BWindow(CenteredRect(BRect(0, 0, 350, 250)), "Preference", : BWindow(CenteredRect(BRect(0, 0, 350, 215)), "Preference",
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_NOT_RESIZABLE|B_NOT_ZOOMABLE) B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
{ {
fTermWindow = inWindow;
fTermWindow = inWindow; fPrefTemp = new PrefHandler(gTermPref);
fPrefTemp = new PrefHandler(gTermPref); fDirty = false;
fDirty = false; fSavePanel = NULL;
fSavePanel = NULL;
BRect r;
SetupContent();
Show(); BView *top = new BView(Bounds(), "topview", B_FOLLOW_NONE, B_WILL_DRAW);
top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddShortcut ((ulong)'Q', (ulong)B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); AddChild(top);
AddShortcut ((ulong)'W', (ulong)B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
r=top->Bounds();
r.bottom *= .75;
AppearancePrefView *prefView= new AppearancePrefView(r, "Appearance",
fTermWindow);
top->AddChild(prefView);
fSaveAsFileButton = new BButton(BRect(0,0,1,1), "savebutton",
"Save to File",
new BMessage(MSG_SAVEAS_PRESSED),
B_FOLLOW_TOP, B_WILL_DRAW);
fSaveAsFileButton->ResizeToPreferred();
fSaveAsFileButton->MoveTo(5, top->Bounds().Height() - 5 -
fSaveAsFileButton->Bounds().Height());
top->AddChild(fSaveAsFileButton);
fSaveButton = new BButton(BRect(0,0,1,1), "okbutton", "OK",
new BMessage(MSG_SAVE_PRESSED), B_FOLLOW_TOP,
B_WILL_DRAW);
fSaveButton->ResizeToPreferred();
fSaveButton->MoveTo(top->Bounds().Width() - 5 - fSaveButton->Bounds().Width(),
top->Bounds().Height() - 5 - fSaveButton->Bounds().Height());
fSaveButton->MakeDefault(true);
top->AddChild(fSaveButton);
fRevertButton = new BButton(BRect(0,0,1,1), "revertbutton",
"Cancel", new BMessage(MSG_REVERT_PRESSED),
B_FOLLOW_TOP, B_WILL_DRAW);
fRevertButton->ResizeToPreferred();
fRevertButton->MoveTo(fSaveButton->Frame().left - 10 -
fRevertButton->Bounds().Width(),
top->Bounds().Height() - 5 -
fRevertButton->Bounds().Height());
top->AddChild(fRevertButton);
AddShortcut ((ulong)'Q', (ulong)B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
AddShortcut ((ulong)'W', (ulong)B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
Show();
} }
//////////////////////////////////////////////////////////////////////////////
// PrefDlg
//////////////////////////////////////////////////////////////////////////////
PrefDlg::~PrefDlg (void) PrefDlg::~PrefDlg (void)
{ {
} }
//////////////////////////////////////////////////////////////////////////////
// SetupContent()
// Set up content of window.
//////////////////////////////////////////////////////////////////////////////
void
PrefDlg::SetupContent()
{
BRect r;
Lock();
BView *top = new BView(Bounds(), "topview", B_FOLLOW_NONE, B_WILL_DRAW);
top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild (top);
//
// Tab View
//
r = top->Bounds();
r.bottom -= 40;
r.InsetBy (0, 5);
fTabView = new BTabView(r, "tab_view", B_WIDTH_FROM_WIDEST);
fTabView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
r = fTabView->Bounds();
r.InsetBy(10,10);
r.bottom -= fTabView->TabHeight();
fTabView->AddTab(new AppearancePrefView (r, "Appearance", fTermWindow));
// fTabView->AddTab(new ShellPrefView (r, "Shell", fTermWindow));
//
// OK, Apply and Cancel button.
//
fSaveAsFileButton = new BButton(BRect(50,215,150,20), "savebutton", "Save to File", new BMessage(MSG_SAVEAS_PRESSED), B_FOLLOW_TOP, B_WILL_DRAW);
top->AddChild(fSaveAsFileButton);
fRevertButton = new BButton(BRect(180,215,250,20), "revertbutton", "Cancel", new BMessage(MSG_REVERT_PRESSED), B_FOLLOW_TOP, B_WILL_DRAW);
top->AddChild(fRevertButton);
fSaveButton = new BButton(BRect(260,215,330,20), "okbutton", "OK", new BMessage(MSG_SAVE_PRESSED), B_FOLLOW_TOP, B_WILL_DRAW);
top->AddChild(fSaveButton);
top->AddChild (fTabView);
Unlock();
}
//////////////////////////////////////////////////////////////////////////////
// if OK button pressed
//
//////////////////////////////////////////////////////////////////////////////
void void
PrefDlg::Quit() PrefDlg::Quit()
{ {
fTermWindow->PostMessage(MSG_PREF_CLOSED); fTermWindow->PostMessage(MSG_PREF_CLOSED);
delete fPrefTemp; delete fPrefTemp;
delete fSavePanel; delete fSavePanel;
BWindow::Quit(); BWindow::Quit();
} }
//////////////////////////////////////////////////////////////////////////////
// QuitRequested
// if close box checked and perf is changed..
//////////////////////////////////////////////////////////////////////////////
bool bool
PrefDlg::QuitRequested () PrefDlg::QuitRequested()
{ {
if(!fDirty) return true; if(!fDirty)
return true;
BAlert *alert = new BAlert("",
"Save changes to this preference panel?", BAlert *alert = new BAlert("", "Save changes to this preference panel?",
"Cancel", "Don't Save", "Cancel", "Don't Save", "Save",
"Save", B_WIDTH_AS_USUAL, B_OFFSET_SPACING,
B_WIDTH_AS_USUAL, B_WARNING_ALERT);
B_OFFSET_SPACING, alert->SetShortcut(0, B_ESCAPE);
B_WARNING_ALERT); alert->SetShortcut(1, 'd');
alert->SetShortcut(0, B_ESCAPE); alert->SetShortcut(2, 's');
alert->SetShortcut(1, 'd'); int32 button_index = alert->Go();
alert->SetShortcut(2, 's');
int32 button_index = alert->Go(); if(button_index==0)
return false;
switch (button_index) { else
if(button_index==2)
case 0: // Cancel doSave();
return false;
break; return true;
case 2: // Save
this->doSave();
break;
case 1: // Don't Save
default:
break;
}
return true;
} }
//////////////////////////////////////////////////////////////////////////////
// if SaveAs button pressed
//
//////////////////////////////////////////////////////////////////////////////
void void
PrefDlg::doSaveAs (void) PrefDlg::doSaveAs (void)
{ {
for (int32 i = 0; i < fTabView->CountTabs(); i++) { if(!fSavePanel)
// PrefView *aView = (PrefView *)fTabView->ViewForTab(i); fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this));
// aView->SaveIfModified ();
} fSavePanel->Show();
if(!fSavePanel){
fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this));
}
fSavePanel->Show();
} }
//////////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////////
void void
PrefDlg::SaveRequested(BMessage *msg) PrefDlg::SaveRequested(BMessage *msg)
{ {
entry_ref dirref; entry_ref dirref;
const char *filename; const char *filename;
msg->FindRef("directory", &dirref); msg->FindRef("directory", &dirref);
msg->FindString("name", &filename); msg->FindString("name", &filename);
BDirectory dir(&dirref);
BPath path(&dir, filename); BDirectory dir(&dirref);
BPath path(&dir, filename);
gTermPref->SaveAsText (path.Path(), PREFFILE_MIMETYPE, TERM_SIGNATURE);
gTermPref->SaveAsText (path.Path(), PREFFILE_MIMETYPE, TERM_SIGNATURE);
} }
//////////////////////////////////////////////////////////////////////////////
// if OK button pressed
//
//////////////////////////////////////////////////////////////////////////////
void void
PrefDlg::doSave (void) PrefDlg::doSave (void)
{ {
for (int32 i = 0; i < fTabView->CountTabs(); i++) { delete fPrefTemp;
// PrefView *aView = (PrefView *)fTabView->ViewForTab(i); fPrefTemp = new PrefHandler (gTermPref);
// aView->SaveIfModified ();
} gTermPref->SaveAsText (TERM_PREF, PREFFILE_MIMETYPE);
delete fPrefTemp; fDirty = false;
fPrefTemp = new PrefHandler (gTermPref);
gTermPref->SaveAsText (TERM_PREF, PREFFILE_MIMETYPE);
fDirty = false;
} }
//////////////////////////////////////////////////////////////////////////////
// if cancel button pressed
//
//////////////////////////////////////////////////////////////////////////////
void void
PrefDlg::doRevert (void) PrefDlg::doRevert (void)
{ {
BMessenger messenger (fTermWindow); BMessenger messenger (fTermWindow);
delete gTermPref; delete gTermPref;
gTermPref = new PrefHandler (fPrefTemp); gTermPref = new PrefHandler (fPrefTemp);
messenger.SendMessage (MSG_HALF_FONT_CHANGED); messenger.SendMessage (MSG_HALF_FONT_CHANGED);
messenger.SendMessage (MSG_COLOR_CHANGED); messenger.SendMessage (MSG_COLOR_CHANGED);
messenger.SendMessage (MSG_ROWS_CHANGED); messenger.SendMessage (MSG_ROWS_CHANGED);
messenger.SendMessage (MSG_INPUT_METHOD_CHANGED); messenger.SendMessage (MSG_INPUT_METHOD_CHANGED);
this->DisableUpdates(); fDirty = false;
this->Lock();
for (int32 i = 0; i < fTabView->CountTabs(); i++) {
// PrefView *aView = (PrefView *)fTabView->ViewForTab(i);
// aView->Revert ();
}
this->Unlock();
this->EnableUpdates();
fDirty = false;
} }
//////////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////////
void void
PrefDlg::MessageReceived(BMessage *msg) PrefDlg::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what)
case MSG_SAVE_PRESSED: {
doSave(); case MSG_SAVE_PRESSED:
PostMessage(B_QUIT_REQUESTED); {
break; doSave();
PostMessage(B_QUIT_REQUESTED);
case MSG_SAVEAS_PRESSED: break;
doSaveAs(); }
break; case MSG_SAVEAS_PRESSED:
{
case MSG_REVERT_PRESSED: doSaveAs();
doRevert(); break;
PostMessage(B_QUIT_REQUESTED); }
break; case MSG_REVERT_PRESSED:
{
case MSG_PREF_MODIFIED: doRevert();
fDirty = true; PostMessage(B_QUIT_REQUESTED);
break; break;
}
case B_SAVE_REQUESTED: case MSG_PREF_MODIFIED:
this->SaveRequested(msg); {
break; fDirty = true;
break;
default: }
BWindow::MessageReceived(msg); case B_SAVE_REQUESTED:
break; {
} SaveRequested(msg);
break;
}
default:
{
BWindow::MessageReceived(msg);
break;
}
}
} }
//////////////////////////////////////////////////////////////////////////////
// SetupBox
// make Box
//////////////////////////////////////////////////////////////////////////////
BBox *
PrefDlg::SetupBox(BRect r, const char *label, BView *parent)
{
BBox *b;
b = new BBox(r);
b->SetLabel(label);
parent->AddChild(b);
return b;
}
//////////////////////////////////////////////////////////////////////////////
// SetupButton
// make Button
//////////////////////////////////////////////////////////////////////////////
//BButton *
//PrefDlg::SetupButton(BRect r, const char *label, ulong msg, BView *parent, bool defaultButton)
//{
// BButton *b;
//
// b = new BButton(r, "", label, new BMessage(msg));
// parent->AddChild(b);
//
// if (defaultButton)
// (parent->Window())->SetDefaultButton(b);
//
// return b;
//}
//////////////////////////////////////////////////////////////////////////////
// Ajust Input Rect to locate center of Screen.
// ( static member function. )
//////////////////////////////////////////////////////////////////////////////
BRect BRect
PrefDlg::CenteredRect(BRect r) PrefDlg::CenteredRect(BRect r)
{ {
BRect screenRect = BScreen().Frame(); BRect screenRect = BScreen().Frame();
screenRect.InsetBy(10,10); screenRect.InsetBy(10,10);
float x = screenRect.left + (screenRect.Width() - r.Width()) / 2; float x = screenRect.left + (screenRect.Width() - r.Width()) / 2;
float y = screenRect.top + (screenRect.Height() - r.Height()) / 3; float y = screenRect.top + (screenRect.Height() - r.Height()) / 3;
r.OffsetTo(x, y); r.OffsetTo(x, y);
return r; return r;
} }

View File

@ -55,38 +55,29 @@ class BFilePanel;
class PrefDlg : public BWindow class PrefDlg : public BWindow
{ {
public: public:
PrefDlg(TermWindow *inWindow); PrefDlg(TermWindow *inWindow);
~PrefDlg (); ~PrefDlg();
void Quit();
void Quit();
private: private:
void doSave (void); void doSave (void);
void doSaveAs (void); void doSaveAs (void);
void doRevert (void); void doRevert (void);
void SaveRequested(BMessage *msg); void SaveRequested(BMessage *msg);
bool QuitRequested (); bool QuitRequested();
void MessageReceived (BMessage *msg); void MessageReceived (BMessage *msg);
void SetupContent(); static BRect CenteredRect(BRect r);
BBox* SetupBox(BRect r, const char *label, BView *parent); TermWindow *fTermWindow;
BButton* SetupButton(BRect r, const char *label, ulong msg, PrefHandler *fPrefTemp;
BView *parent, bool defaultButton=false); BFilePanel *fSavePanel;
static BRect CenteredRect(BRect r); BButton *fSaveAsFileButton,
*fRevertButton,
private: *fSaveButton;
TermWindow *fTermWindow;
BTabView *fTabView; bool fDirty;
PrefHandler *fPrefTemp;
BFilePanel *fSavePanel;
BButton *fSaveAsFileButton;
BButton *fRevertButton;
BButton *fSaveButton;
bool fDirty;
}; };
#endif //PREFDLG_H_INCLUDED #endif //PREFDLG_H_INCLUDED