diff --git a/src/kits/tracker/SettingsViews.cpp b/src/kits/tracker/SettingsViews.cpp index 1f4a730c30..24e1810123 100644 --- a/src/kits/tracker/SettingsViews.cpp +++ b/src/kits/tracker/SettingsViews.cpp @@ -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 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 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 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 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 SpaceBarSettingsView::Revert() { @@ -1307,6 +1369,16 @@ TrashSettingsView::SetDefaults() } +bool +TrashSettingsView::IsDefaultable() const +{ + TrackerSettings settings; + + return settings.DontMoveFilesToTrash() != false + || settings.AskBeforeDeleteFile() != true; +} + + void TrashSettingsView::Revert() { diff --git a/src/kits/tracker/SettingsViews.h b/src/kits/tracker/SettingsViews.h index 639e419d53..82355714e2 100644 --- a/src/kits/tracker/SettingsViews.h +++ b/src/kits/tracker/SettingsViews.h @@ -57,6 +57,7 @@ class SettingsView : public BView { virtual ~SettingsView(); virtual void SetDefaults(); + virtual bool IsDefaultable() const; virtual void Revert(); virtual void ShowCurrentSettings(); virtual void RecordRevertSettings(); @@ -75,6 +76,7 @@ class DesktopSettingsView : public SettingsView { virtual void GetPreferredSize(float *_width, float *_height); virtual void SetDefaults(); + virtual bool IsDefaultable() const; virtual void Revert(); virtual void ShowCurrentSettings(); virtual void RecordRevertSettings(); @@ -108,6 +110,7 @@ class WindowsSettingsView : public SettingsView { virtual void GetPreferredSize(float *_width, float *_height); virtual void SetDefaults(); + virtual bool IsDefaultable() const; virtual void Revert(); virtual void ShowCurrentSettings(); virtual void RecordRevertSettings(); @@ -139,6 +142,7 @@ class TimeFormatSettingsView : public SettingsView { virtual void GetPreferredSize(float *_width, float *_height); virtual void SetDefaults(); + virtual bool IsDefaultable() const; virtual void Revert(); virtual void ShowCurrentSettings(); virtual void RecordRevertSettings(); @@ -178,6 +182,7 @@ class SpaceBarSettingsView : public SettingsView { virtual void GetPreferredSize(float *_width, float *_height); virtual void SetDefaults(); + virtual bool IsDefaultable() const; virtual void Revert(); virtual void ShowCurrentSettings(); virtual void RecordRevertSettings(); @@ -206,6 +211,7 @@ class TrashSettingsView : public SettingsView { virtual void GetPreferredSize(float *_width, float *_height); virtual void SetDefaults(); + virtual bool IsDefaultable() const; virtual void Revert(); virtual void ShowCurrentSettings(); virtual void RecordRevertSettings(); diff --git a/src/kits/tracker/TrackerSettingsWindow.cpp b/src/kits/tracker/TrackerSettingsWindow.cpp index 104d90175c..cf741b0b16 100644 --- a/src/kits/tracker/TrackerSettingsWindow.cpp +++ b/src/kits/tracker/TrackerSettingsWindow.cpp @@ -88,6 +88,7 @@ TrackerSettingsWindow::TrackerSettingsWindow() fDefaultsButton = new BButton(rect, "Defaults", "Defaults", new BMessage(kDefaultsButtonPressed), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); fDefaultsButton->ResizeToPreferred(); + fDefaultsButton->SetEnabled(false); fDefaultsButton->MoveBy(0, -fDefaultsButton->Bounds().Height()); topView->AddChild(fDefaultsButton); @@ -240,13 +241,16 @@ TrackerSettingsWindow::_HandleChangedContents() { int32 itemCount = fSettingsTypeListView->CountItems(); + bool defaultable = false; bool revertable = false; for (int32 i = 0; i < itemCount; i++) { + defaultable |= _ViewAt(i)->IsDefaultable(); revertable |= _ViewAt(i)->IsRevertable(); } - fSettingsTypeListView->Invalidate(); + fSettingsTypeListView->Invalidate(); + fDefaultsButton->SetEnabled(defaultable); fRevertButton->SetEnabled(revertable); TrackerSettings().SaveSettings(false); @@ -258,8 +262,10 @@ TrackerSettingsWindow::_HandlePressedDefaultsButton() { int32 itemCount = fSettingsTypeListView->CountItems(); - for (int32 i = 0; i < itemCount; i++) - _ViewAt(i)->SetDefaults(); + for (int32 i = 0; i < itemCount; i++) { + if (_ViewAt(i)->IsDefaultable()) + _ViewAt(i)->SetDefaults(); + } _HandleChangedContents(); } diff --git a/src/preferences/appearance/APRView.cpp b/src/preferences/appearance/APRView.cpp index f54b124f57..90519b3ee8 100644 --- a/src/preferences/appearance/APRView.cpp +++ b/src/preferences/appearance/APRView.cpp @@ -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", new BMessage(DEFAULT_SETTINGS), 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); AddChild(fDefaults); @@ -157,8 +158,8 @@ APRView::APRView(const BRect &frame, const char *name, int32 resize, int32 flags fRevert = new BButton(cvrect,"RevertButton","Revert", new BMessage(REVERT_SETTINGS), B_FOLLOW_LEFT |B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); - AddChild(fRevert); fRevert->SetEnabled(false); + AddChild(fRevert); } @@ -185,6 +186,8 @@ APRView::AttachedToWindow(void) fDefaults->Frame().bottom + 10); LoadSettings(); fAttrList->Select(0); + + fDefaults->SetEnabled(fCurrentSet.IsDefaultable()); } void @@ -221,6 +224,7 @@ APRView::MessageReceived(BMessage *msg) // Update current fAttribute in the settings fCurrentSet.SetColor(fAttrString.String(),col); + fDefaults->SetEnabled(fCurrentSet.IsDefaultable()); fRevert->SetEnabled(true); break; @@ -236,6 +240,8 @@ APRView::MessageReceived(BMessage *msg) fAttrString=whichitem->Text(); UpdateControlsFromAttr(whichitem->Text()); + + fDefaults->SetEnabled(fCurrentSet.IsDefaultable()); break; } case REVERT_SETTINGS: { @@ -248,6 +254,7 @@ APRView::MessageReceived(BMessage *msg) } case DEFAULT_SETTINGS: { fCurrentSet.SetToDefaults(); + fDefaults->SetEnabled(false); UpdateControlsFromAttr(fAttrString.String()); BMenuItem *item = fDecorMenu->FindItem("Default"); diff --git a/src/preferences/appearance/ColorSet.cpp b/src/preferences/appearance/ColorSet.cpp index ac14253fea..b59dc37f0f 100644 --- a/src/preferences/appearance/ColorSet.cpp +++ b/src/preferences/appearance/ColorSet.cpp @@ -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 - @@ -172,6 +181,40 @@ printf("Initializing color settings to defaults\n"); 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 \param msg The message to receive the attributes diff --git a/src/preferences/appearance/ColorSet.h b/src/preferences/appearance/ColorSet.h index 8fe8a72fdd..e5d49094cb 100644 --- a/src/preferences/appearance/ColorSet.h +++ b/src/preferences/appearance/ColorSet.h @@ -32,6 +32,7 @@ class ColorSet : public BLocker { bool ConvertFromMessage(const BMessage *msg); void SetToDefaults(void); + bool IsDefaultable(void); rgb_color StringToColor(const char *string); rgb_color AttributeToColor(int32 which); diff --git a/src/preferences/menu/MenuSettings.cpp b/src/preferences/menu/MenuSettings.cpp index 046f5c2737..52f0787021 100644 --- a/src/preferences/menu/MenuSettings.cpp +++ b/src/preferences/menu/MenuSettings.cpp @@ -74,3 +74,17 @@ MenuSettings::ResetToDefaults() 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; +} + diff --git a/src/preferences/menu/MenuSettings.h b/src/preferences/menu/MenuSettings.h index 99721d24af..0da789f8f7 100644 --- a/src/preferences/menu/MenuSettings.h +++ b/src/preferences/menu/MenuSettings.h @@ -21,6 +21,7 @@ class MenuSettings { void Revert(); void ResetToDefaults(); + bool IsDefaultable(); private: MenuSettings(); diff --git a/src/preferences/menu/MenuWindow.cpp b/src/preferences/menu/MenuWindow.cpp index 3b5c0c8653..ddeea1ea6d 100644 --- a/src/preferences/menu/MenuWindow.cpp +++ b/src/preferences/menu/MenuWindow.cpp @@ -31,7 +31,6 @@ MenuWindow::MenuWindow(BRect rect) B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) { fColorWindow = NULL; - fRevert = false; BView* topView = new BView(Bounds(), "menuView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW); @@ -48,10 +47,11 @@ MenuWindow::MenuWindow(BRect rect) BRect buttonFrame(menuBarFrame.left, menuBarFrame.bottom + 10, 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, B_WILL_DRAW | B_NAVIGABLE); - topView->AddChild(defaultButton); + fDefaultsButton->SetEnabled(false); + topView->AddChild(fDefaultsButton); buttonFrame.OffsetBy(buttonFrame.Width() + 20, 0); fRevertButton = new BButton(buttonFrame, "Revert", "Revert", new BMessage(MENU_REVERT), @@ -60,8 +60,7 @@ MenuWindow::MenuWindow(BRect rect) topView->AddChild(fRevertButton); topView->MakeFocus(); - - Update(); + fMenuBar->Update(); } @@ -73,25 +72,27 @@ MenuWindow::MessageReceived(BMessage *msg) switch (msg->what) { case MENU_REVERT: - fRevert = false; settings->Revert(); - Update(); + + fRevertButton->SetEnabled(false); + fDefaultsButton->SetEnabled(settings->IsDefaultable()); + fMenuBar->Update(); break; case MENU_DEFAULT: - fRevert = true; settings->ResetToDefaults(); - Update(); + + fDefaultsButton->SetEnabled(false); + fMenuBar->Update(); break; case UPDATE_WINDOW: - Update(); + fMenuBar->Update(); break; case MENU_FONT_FAMILY: case MENU_FONT_STYLE: { - fRevert = true; const font_family *family; msg->FindString("family", (const char **)&family); 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_style, (const char *)style, B_FONT_STYLE_LENGTH); settings->Set(info); - Update(); + + fRevertButton->SetEnabled(true); + fDefaultsButton->SetEnabled(settings->IsDefaultable()); + fMenuBar->Update(); break; } case MENU_FONT_SIZE: - fRevert = true; settings->Get(info); msg->FindFloat("size", &info.font_size); settings->Set(info); - Update(); + + fRevertButton->SetEnabled(true); + fDefaultsButton->SetEnabled(settings->IsDefaultable()); + fMenuBar->Update(); break; case ALLWAYS_TRIGGERS_MSG: - fRevert = true; settings->Get(info); info.triggers_always_shown = !info.triggers_always_shown; settings->Set(info); + + fRevertButton->SetEnabled(true); + fDefaultsButton->SetEnabled(settings->IsDefaultable()); fMenuBar->UpdateMenu(); - Update(); + fMenuBar->Update(); break; case CTL_MARKED_MSG: - fRevert = true; // This might not be the same for all keyboards set_modifier_key(B_LEFT_COMMAND_KEY, 0x5c); set_modifier_key(B_RIGHT_COMMAND_KEY, 0x60); set_modifier_key(B_LEFT_CONTROL_KEY, 0x5d); set_modifier_key(B_RIGHT_OPTION_KEY, 0x5f); be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); - Update(); + + fRevertButton->SetEnabled(true); + fDefaultsButton->SetEnabled(settings->IsDefaultable()); + fMenuBar->Update(); break; case ALT_MARKED_MSG: - fRevert = true; + // This might not be the same for all keyboards set_modifier_key(B_LEFT_COMMAND_KEY, 0x5d); set_modifier_key(B_RIGHT_COMMAND_KEY, 0x5f); @@ -142,7 +152,10 @@ MenuWindow::MessageReceived(BMessage *msg) set_modifier_key(B_RIGHT_OPTION_KEY, 0x60); be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); - Update(); + + fRevertButton->SetEnabled(true); + fDefaultsButton->SetEnabled(settings->IsDefaultable()); + fMenuBar->Update(); break; case COLOR_SCHEME_OPEN_MSG: @@ -158,8 +171,9 @@ MenuWindow::MessageReceived(BMessage *msg) break; case MENU_COLOR: - fRevert = true; - Update(); + fRevertButton->SetEnabled(true); + fDefaultsButton->SetEnabled(settings->IsDefaultable()); + fMenuBar->Update(); break; default: @@ -180,13 +194,3 @@ MenuWindow::QuitRequested() return true; } - -void -MenuWindow::Update() -{ - fRevertButton->SetEnabled(fRevert); - - // alert the rest of the application to update - fMenuBar->Update(); -} - diff --git a/src/preferences/menu/MenuWindow.h b/src/preferences/menu/MenuWindow.h index c87bcd91e4..3179dddc0d 100644 --- a/src/preferences/menu/MenuWindow.h +++ b/src/preferences/menu/MenuWindow.h @@ -25,14 +25,11 @@ class MenuWindow : public BWindow { virtual void MessageReceived(BMessage *message); virtual bool QuitRequested(); - void Update(); - void Defaults(); - private: - bool fRevert; - ColorWindow* fColorWindow; - MenuBar* fMenuBar; - BButton* fRevertButton; + ColorWindow* fColorWindow; + MenuBar* fMenuBar; + BButton* fDefaultsButton; + BButton* fRevertButton; }; #endif // MENU_WINDOW_H