Patch from Justin O'Dell for bug #254, fixing the Defaults button behavior

for the Appearance and Menu prefs, and Tracker's settings.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22049 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ryan Leavengood 2007-08-24 01:17:18 +00:00
parent 8be13cd585
commit 6eb0129659
10 changed files with 195 additions and 44 deletions

View File

@ -92,6 +92,19 @@ SettingsView::SetDefaults()
} }
/*!
This function is used by the window to tell whether
it can ghost the defaults button or not. It doesn't
shows the default settings, this function should
return true.
*/
bool
SettingsView::IsDefaultable() const
{
return true;
}
/*! /*!
The inherited functions should set the values that was The inherited functions should set the values that was
active when the settings window opened. It should also active when the settings window opened. It should also
@ -317,6 +330,19 @@ DesktopSettingsView::SetDefaults()
} }
bool
DesktopSettingsView::IsDefaultable() const
{
TrackerSettings settings;
return settings.ShowDisksIcon() != false
|| settings.MountVolumesOntoDesktop() != true
|| settings.MountSharedVolumesOntoDesktop() != true
|| settings.IntegrateNonBootBeOSDesktops() != false
|| settings.EjectWhenUnmounting() != true;
}
void void
DesktopSettingsView::Revert() DesktopSettingsView::Revert()
{ {
@ -570,6 +596,19 @@ WindowsSettingsView::SetDefaults()
} }
bool
WindowsSettingsView::IsDefaultable() const
{
TrackerSettings settings;
return settings.ShowFullPathInTitleBar() != false
|| settings.SingleWindowBrowse() != false
|| settings.ShowNavigator() != false
|| settings.TransparentSelection() != true
|| settings.SortFolderNamesFirst() != true;
}
void void
WindowsSettingsView::Revert() WindowsSettingsView::Revert()
{ {
@ -843,6 +882,17 @@ TimeFormatSettingsView::SetDefaults()
} }
bool
TimeFormatSettingsView::IsDefaultable() const
{
TrackerSettings settings;
return settings.TimeFormatSeparator() != kSlashSeparator
|| settings.DateOrderFormat() != kMDYFormat
|| settings.ClockIs24Hr() != false;
}
void void
TimeFormatSettingsView::Revert() TimeFormatSettingsView::Revert()
{ {
@ -1146,6 +1196,18 @@ SpaceBarSettingsView::SetDefaults()
} }
bool
SpaceBarSettingsView::IsDefaultable() const
{
TrackerSettings settings;
return settings.ShowVolumeSpaceBar() != false
|| settings.UsedSpaceColor() != Color(0, 203, 0, 192)
|| settings.FreeSpaceColor() != Color(255, 255, 255, 192)
|| settings.WarningSpaceColor() != Color(203, 0, 0, 192);
}
void void
SpaceBarSettingsView::Revert() SpaceBarSettingsView::Revert()
{ {
@ -1307,6 +1369,16 @@ TrashSettingsView::SetDefaults()
} }
bool
TrashSettingsView::IsDefaultable() const
{
TrackerSettings settings;
return settings.DontMoveFilesToTrash() != false
|| settings.AskBeforeDeleteFile() != true;
}
void void
TrashSettingsView::Revert() TrashSettingsView::Revert()
{ {

View File

@ -57,6 +57,7 @@ class SettingsView : public BView {
virtual ~SettingsView(); virtual ~SettingsView();
virtual void SetDefaults(); virtual void SetDefaults();
virtual bool IsDefaultable() const;
virtual void Revert(); virtual void Revert();
virtual void ShowCurrentSettings(); virtual void ShowCurrentSettings();
virtual void RecordRevertSettings(); virtual void RecordRevertSettings();
@ -75,6 +76,7 @@ class DesktopSettingsView : public SettingsView {
virtual void GetPreferredSize(float *_width, float *_height); virtual void GetPreferredSize(float *_width, float *_height);
virtual void SetDefaults(); virtual void SetDefaults();
virtual bool IsDefaultable() const;
virtual void Revert(); virtual void Revert();
virtual void ShowCurrentSettings(); virtual void ShowCurrentSettings();
virtual void RecordRevertSettings(); virtual void RecordRevertSettings();
@ -108,6 +110,7 @@ class WindowsSettingsView : public SettingsView {
virtual void GetPreferredSize(float *_width, float *_height); virtual void GetPreferredSize(float *_width, float *_height);
virtual void SetDefaults(); virtual void SetDefaults();
virtual bool IsDefaultable() const;
virtual void Revert(); virtual void Revert();
virtual void ShowCurrentSettings(); virtual void ShowCurrentSettings();
virtual void RecordRevertSettings(); virtual void RecordRevertSettings();
@ -139,6 +142,7 @@ class TimeFormatSettingsView : public SettingsView {
virtual void GetPreferredSize(float *_width, float *_height); virtual void GetPreferredSize(float *_width, float *_height);
virtual void SetDefaults(); virtual void SetDefaults();
virtual bool IsDefaultable() const;
virtual void Revert(); virtual void Revert();
virtual void ShowCurrentSettings(); virtual void ShowCurrentSettings();
virtual void RecordRevertSettings(); virtual void RecordRevertSettings();
@ -178,6 +182,7 @@ class SpaceBarSettingsView : public SettingsView {
virtual void GetPreferredSize(float *_width, float *_height); virtual void GetPreferredSize(float *_width, float *_height);
virtual void SetDefaults(); virtual void SetDefaults();
virtual bool IsDefaultable() const;
virtual void Revert(); virtual void Revert();
virtual void ShowCurrentSettings(); virtual void ShowCurrentSettings();
virtual void RecordRevertSettings(); virtual void RecordRevertSettings();
@ -206,6 +211,7 @@ class TrashSettingsView : public SettingsView {
virtual void GetPreferredSize(float *_width, float *_height); virtual void GetPreferredSize(float *_width, float *_height);
virtual void SetDefaults(); virtual void SetDefaults();
virtual bool IsDefaultable() const;
virtual void Revert(); virtual void Revert();
virtual void ShowCurrentSettings(); virtual void ShowCurrentSettings();
virtual void RecordRevertSettings(); virtual void RecordRevertSettings();

View File

@ -88,6 +88,7 @@ TrackerSettingsWindow::TrackerSettingsWindow()
fDefaultsButton = new BButton(rect, "Defaults", "Defaults", fDefaultsButton = new BButton(rect, "Defaults", "Defaults",
new BMessage(kDefaultsButtonPressed), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); new BMessage(kDefaultsButtonPressed), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
fDefaultsButton->ResizeToPreferred(); fDefaultsButton->ResizeToPreferred();
fDefaultsButton->SetEnabled(false);
fDefaultsButton->MoveBy(0, -fDefaultsButton->Bounds().Height()); fDefaultsButton->MoveBy(0, -fDefaultsButton->Bounds().Height());
topView->AddChild(fDefaultsButton); topView->AddChild(fDefaultsButton);
@ -240,13 +241,16 @@ TrackerSettingsWindow::_HandleChangedContents()
{ {
int32 itemCount = fSettingsTypeListView->CountItems(); int32 itemCount = fSettingsTypeListView->CountItems();
bool defaultable = false;
bool revertable = false; bool revertable = false;
for (int32 i = 0; i < itemCount; i++) { for (int32 i = 0; i < itemCount; i++) {
defaultable |= _ViewAt(i)->IsDefaultable();
revertable |= _ViewAt(i)->IsRevertable(); revertable |= _ViewAt(i)->IsRevertable();
} }
fSettingsTypeListView->Invalidate(); fSettingsTypeListView->Invalidate();
fDefaultsButton->SetEnabled(defaultable);
fRevertButton->SetEnabled(revertable); fRevertButton->SetEnabled(revertable);
TrackerSettings().SaveSettings(false); TrackerSettings().SaveSettings(false);
@ -258,8 +262,10 @@ TrackerSettingsWindow::_HandlePressedDefaultsButton()
{ {
int32 itemCount = fSettingsTypeListView->CountItems(); int32 itemCount = fSettingsTypeListView->CountItems();
for (int32 i = 0; i < itemCount; i++) for (int32 i = 0; i < itemCount; i++) {
_ViewAt(i)->SetDefaults(); if (_ViewAt(i)->IsDefaultable())
_ViewAt(i)->SetDefaults();
}
_HandleChangedContents(); _HandleChangedContents();
} }

View File

@ -146,7 +146,8 @@ APRView::APRView(const BRect &frame, const char *name, int32 resize, int32 flags
fDefaults = new BButton(BRect(0,0,1,1),"DefaultsButton","Defaults", fDefaults = new BButton(BRect(0,0,1,1),"DefaultsButton","Defaults",
new BMessage(DEFAULT_SETTINGS), new BMessage(DEFAULT_SETTINGS),
B_FOLLOW_LEFT |B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); B_FOLLOW_LEFT |B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE);
fDefaults->ResizeToPreferred(); fDefaults->ResizeToPreferred();
fDefaults->SetEnabled(false);
fDefaults->MoveTo((fPicker->Frame().right-(fDefaults->Frame().Width()*2)-20)/2,fPicker->Frame().bottom+20); fDefaults->MoveTo((fPicker->Frame().right-(fDefaults->Frame().Width()*2)-20)/2,fPicker->Frame().bottom+20);
AddChild(fDefaults); AddChild(fDefaults);
@ -157,8 +158,8 @@ APRView::APRView(const BRect &frame, const char *name, int32 resize, int32 flags
fRevert = new BButton(cvrect,"RevertButton","Revert", fRevert = new BButton(cvrect,"RevertButton","Revert",
new BMessage(REVERT_SETTINGS), new BMessage(REVERT_SETTINGS),
B_FOLLOW_LEFT |B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); B_FOLLOW_LEFT |B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE);
AddChild(fRevert);
fRevert->SetEnabled(false); fRevert->SetEnabled(false);
AddChild(fRevert);
} }
@ -185,6 +186,8 @@ APRView::AttachedToWindow(void)
fDefaults->Frame().bottom + 10); fDefaults->Frame().bottom + 10);
LoadSettings(); LoadSettings();
fAttrList->Select(0); fAttrList->Select(0);
fDefaults->SetEnabled(fCurrentSet.IsDefaultable());
} }
void void
@ -221,6 +224,7 @@ APRView::MessageReceived(BMessage *msg)
// Update current fAttribute in the settings // Update current fAttribute in the settings
fCurrentSet.SetColor(fAttrString.String(),col); fCurrentSet.SetColor(fAttrString.String(),col);
fDefaults->SetEnabled(fCurrentSet.IsDefaultable());
fRevert->SetEnabled(true); fRevert->SetEnabled(true);
break; break;
@ -236,6 +240,8 @@ APRView::MessageReceived(BMessage *msg)
fAttrString=whichitem->Text(); fAttrString=whichitem->Text();
UpdateControlsFromAttr(whichitem->Text()); UpdateControlsFromAttr(whichitem->Text());
fDefaults->SetEnabled(fCurrentSet.IsDefaultable());
break; break;
} }
case REVERT_SETTINGS: { case REVERT_SETTINGS: {
@ -248,6 +254,7 @@ APRView::MessageReceived(BMessage *msg)
} }
case DEFAULT_SETTINGS: { case DEFAULT_SETTINGS: {
fCurrentSet.SetToDefaults(); fCurrentSet.SetToDefaults();
fDefaults->SetEnabled(false);
UpdateControlsFromAttr(fAttrString.String()); UpdateControlsFromAttr(fAttrString.String());
BMenuItem *item = fDecorMenu->FindItem("Default"); BMenuItem *item = fDecorMenu->FindItem("Default");

View File

@ -26,6 +26,15 @@ set_rgb_color(rgb_color& color, uint8 red, uint8 green, uint8 blue)
} }
static bool
match_rgb_color(rgb_color& color, uint8 red, uint8 green, uint8 blue)
{
return color.red == red
&& color.green == green
&& color.blue == blue;
}
// #pragma mark - // #pragma mark -
@ -172,6 +181,40 @@ printf("Initializing color settings to defaults\n");
set_rgb_color(inactive_window_tab_text, 80, 80, 80); set_rgb_color(inactive_window_tab_text, 80, 80, 80);
} }
/*!
\brief Checks if the ColorSet can be set to defaults.
*/
bool
ColorSet::IsDefaultable()
{
// TODO: Move all the default color values into constants
return !match_rgb_color(panel_background, 216, 216, 216)
|| !match_rgb_color(panel_text, 0, 0, 0)
|| !match_rgb_color(document_background, 255, 255, 255)
|| !match_rgb_color(document_text, 0, 0, 0)
|| !match_rgb_color(control_background, 245, 245, 245)
|| !match_rgb_color(control_text, 0, 0, 0)
|| !match_rgb_color(control_border, 0, 0, 0)
|| !match_rgb_color(control_highlight, 102, 152, 203)
|| !match_rgb_color(keyboard_navigation_base, 0, 0, 229)
|| !match_rgb_color(keyboard_navigation_pulse, 0, 0, 0)
|| !match_rgb_color(shine, 255, 255, 255)
|| !match_rgb_color(shadow, 0, 0, 0)
|| !match_rgb_color(menu_background, 216, 216, 216)
|| !match_rgb_color(menu_selected_background, 115, 120, 184)
|| !match_rgb_color(menu_text, 0, 0, 0)
|| !match_rgb_color(menu_selected_text, 255, 255, 255)
|| !match_rgb_color(menu_selected_border, 0, 0, 0)
|| !match_rgb_color(tooltip_background, 255, 255, 0)
|| !match_rgb_color(tooltip_text, 0, 0, 0)
|| !match_rgb_color(success, 0, 255, 0)
|| !match_rgb_color(failure, 255, 0, 0)
|| !match_rgb_color(window_tab, 255, 203, 0)
|| !match_rgb_color(window_tab_text, 0, 0, 0)
|| !match_rgb_color(inactive_window_tab, 232, 232, 232)
|| !match_rgb_color(inactive_window_tab_text, 80, 80, 80);
}
/*! /*!
\brief Attaches the color set's members as data to the given BMessage \brief Attaches the color set's members as data to the given BMessage
\param msg The message to receive the attributes \param msg The message to receive the attributes

View File

@ -32,6 +32,7 @@ class ColorSet : public BLocker {
bool ConvertFromMessage(const BMessage *msg); bool ConvertFromMessage(const BMessage *msg);
void SetToDefaults(void); void SetToDefaults(void);
bool IsDefaultable(void);
rgb_color StringToColor(const char *string); rgb_color StringToColor(const char *string);
rgb_color AttributeToColor(int32 which); rgb_color AttributeToColor(int32 which);

View File

@ -74,3 +74,17 @@ MenuSettings::ResetToDefaults()
set_menu_info(&fDefaultSettings); set_menu_info(&fDefaultSettings);
} }
bool
MenuSettings::IsDefaultable()
{
menu_info info;
get_menu_info(&info);
return info.font_size != fDefaultSettings.font_size
|| info.background_color != fDefaultSettings.background_color
|| info.separator != fDefaultSettings.separator
|| info.click_to_open != fDefaultSettings.click_to_open
|| info.triggers_always_shown != fDefaultSettings.triggers_always_shown;
}

View File

@ -21,6 +21,7 @@ class MenuSettings {
void Revert(); void Revert();
void ResetToDefaults(); void ResetToDefaults();
bool IsDefaultable();
private: private:
MenuSettings(); MenuSettings();

View File

@ -31,7 +31,6 @@ MenuWindow::MenuWindow(BRect rect)
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
{ {
fColorWindow = NULL; fColorWindow = NULL;
fRevert = false;
BView* topView = new BView(Bounds(), "menuView", B_FOLLOW_ALL_SIDES, BView* topView = new BView(Bounds(), "menuView", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW); B_WILL_DRAW);
@ -48,10 +47,11 @@ MenuWindow::MenuWindow(BRect rect)
BRect buttonFrame(menuBarFrame.left, menuBarFrame.bottom + 10, BRect buttonFrame(menuBarFrame.left, menuBarFrame.bottom + 10,
menuBarFrame.left + 75, menuBarFrame.bottom + 30); menuBarFrame.left + 75, menuBarFrame.bottom + 30);
BButton* defaultButton = new BButton(buttonFrame, "Default", "Defaults", fDefaultsButton = new BButton(buttonFrame, "Default", "Defaults",
new BMessage(MENU_DEFAULT), B_FOLLOW_H_CENTER | B_FOLLOW_BOTTOM, new BMessage(MENU_DEFAULT), B_FOLLOW_H_CENTER | B_FOLLOW_BOTTOM,
B_WILL_DRAW | B_NAVIGABLE); B_WILL_DRAW | B_NAVIGABLE);
topView->AddChild(defaultButton); fDefaultsButton->SetEnabled(false);
topView->AddChild(fDefaultsButton);
buttonFrame.OffsetBy(buttonFrame.Width() + 20, 0); buttonFrame.OffsetBy(buttonFrame.Width() + 20, 0);
fRevertButton = new BButton(buttonFrame, "Revert", "Revert", new BMessage(MENU_REVERT), fRevertButton = new BButton(buttonFrame, "Revert", "Revert", new BMessage(MENU_REVERT),
@ -60,8 +60,7 @@ MenuWindow::MenuWindow(BRect rect)
topView->AddChild(fRevertButton); topView->AddChild(fRevertButton);
topView->MakeFocus(); topView->MakeFocus();
fMenuBar->Update();
Update();
} }
@ -73,25 +72,27 @@ MenuWindow::MessageReceived(BMessage *msg)
switch (msg->what) { switch (msg->what) {
case MENU_REVERT: case MENU_REVERT:
fRevert = false;
settings->Revert(); settings->Revert();
Update();
fRevertButton->SetEnabled(false);
fDefaultsButton->SetEnabled(settings->IsDefaultable());
fMenuBar->Update();
break; break;
case MENU_DEFAULT: case MENU_DEFAULT:
fRevert = true;
settings->ResetToDefaults(); settings->ResetToDefaults();
Update();
fDefaultsButton->SetEnabled(false);
fMenuBar->Update();
break; break;
case UPDATE_WINDOW: case UPDATE_WINDOW:
Update(); fMenuBar->Update();
break; break;
case MENU_FONT_FAMILY: case MENU_FONT_FAMILY:
case MENU_FONT_STYLE: case MENU_FONT_STYLE:
{ {
fRevert = true;
const font_family *family; const font_family *family;
msg->FindString("family", (const char **)&family); msg->FindString("family", (const char **)&family);
const font_style *style; const font_style *style;
@ -101,40 +102,49 @@ MenuWindow::MessageReceived(BMessage *msg)
strlcpy(info.f_family, (const char *)family, B_FONT_FAMILY_LENGTH); strlcpy(info.f_family, (const char *)family, B_FONT_FAMILY_LENGTH);
strlcpy(info.f_style, (const char *)style, B_FONT_STYLE_LENGTH); strlcpy(info.f_style, (const char *)style, B_FONT_STYLE_LENGTH);
settings->Set(info); settings->Set(info);
Update();
fRevertButton->SetEnabled(true);
fDefaultsButton->SetEnabled(settings->IsDefaultable());
fMenuBar->Update();
break; break;
} }
case MENU_FONT_SIZE: case MENU_FONT_SIZE:
fRevert = true;
settings->Get(info); settings->Get(info);
msg->FindFloat("size", &info.font_size); msg->FindFloat("size", &info.font_size);
settings->Set(info); settings->Set(info);
Update();
fRevertButton->SetEnabled(true);
fDefaultsButton->SetEnabled(settings->IsDefaultable());
fMenuBar->Update();
break; break;
case ALLWAYS_TRIGGERS_MSG: case ALLWAYS_TRIGGERS_MSG:
fRevert = true;
settings->Get(info); settings->Get(info);
info.triggers_always_shown = !info.triggers_always_shown; info.triggers_always_shown = !info.triggers_always_shown;
settings->Set(info); settings->Set(info);
fRevertButton->SetEnabled(true);
fDefaultsButton->SetEnabled(settings->IsDefaultable());
fMenuBar->UpdateMenu(); fMenuBar->UpdateMenu();
Update(); fMenuBar->Update();
break; break;
case CTL_MARKED_MSG: case CTL_MARKED_MSG:
fRevert = true;
// This might not be the same for all keyboards // This might not be the same for all keyboards
set_modifier_key(B_LEFT_COMMAND_KEY, 0x5c); set_modifier_key(B_LEFT_COMMAND_KEY, 0x5c);
set_modifier_key(B_RIGHT_COMMAND_KEY, 0x60); set_modifier_key(B_RIGHT_COMMAND_KEY, 0x60);
set_modifier_key(B_LEFT_CONTROL_KEY, 0x5d); set_modifier_key(B_LEFT_CONTROL_KEY, 0x5d);
set_modifier_key(B_RIGHT_OPTION_KEY, 0x5f); set_modifier_key(B_RIGHT_OPTION_KEY, 0x5f);
be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED));
Update();
fRevertButton->SetEnabled(true);
fDefaultsButton->SetEnabled(settings->IsDefaultable());
fMenuBar->Update();
break; break;
case ALT_MARKED_MSG: case ALT_MARKED_MSG:
fRevert = true;
// This might not be the same for all keyboards // This might not be the same for all keyboards
set_modifier_key(B_LEFT_COMMAND_KEY, 0x5d); set_modifier_key(B_LEFT_COMMAND_KEY, 0x5d);
set_modifier_key(B_RIGHT_COMMAND_KEY, 0x5f); set_modifier_key(B_RIGHT_COMMAND_KEY, 0x5f);
@ -142,7 +152,10 @@ MenuWindow::MessageReceived(BMessage *msg)
set_modifier_key(B_RIGHT_OPTION_KEY, 0x60); set_modifier_key(B_RIGHT_OPTION_KEY, 0x60);
be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED));
Update();
fRevertButton->SetEnabled(true);
fDefaultsButton->SetEnabled(settings->IsDefaultable());
fMenuBar->Update();
break; break;
case COLOR_SCHEME_OPEN_MSG: case COLOR_SCHEME_OPEN_MSG:
@ -158,8 +171,9 @@ MenuWindow::MessageReceived(BMessage *msg)
break; break;
case MENU_COLOR: case MENU_COLOR:
fRevert = true; fRevertButton->SetEnabled(true);
Update(); fDefaultsButton->SetEnabled(settings->IsDefaultable());
fMenuBar->Update();
break; break;
default: default:
@ -180,13 +194,3 @@ MenuWindow::QuitRequested()
return true; return true;
} }
void
MenuWindow::Update()
{
fRevertButton->SetEnabled(fRevert);
// alert the rest of the application to update
fMenuBar->Update();
}

View File

@ -25,14 +25,11 @@ class MenuWindow : public BWindow {
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested(); virtual bool QuitRequested();
void Update();
void Defaults();
private: private:
bool fRevert; ColorWindow* fColorWindow;
ColorWindow* fColorWindow; MenuBar* fMenuBar;
MenuBar* fMenuBar; BButton* fDefaultsButton;
BButton* fRevertButton; BButton* fRevertButton;
}; };
#endif // MENU_WINDOW_H #endif // MENU_WINDOW_H