Fix #6919. Enable / disable revert and default button at the right time.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39698 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
01c2a7f38f
commit
8ce987787a
@ -32,6 +32,14 @@ enum stepping_mode {
|
||||
|
||||
struct freq_preferences
|
||||
{
|
||||
bool IsEqual(const freq_preferences& prefs) {
|
||||
if (mode == prefs.mode && custom_stepping == prefs.custom_stepping
|
||||
&& stepping_threshold == prefs.stepping_threshold
|
||||
&& integration_time == prefs.integration_time)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// stepping mode
|
||||
stepping_mode mode;
|
||||
int16 custom_stepping;
|
||||
|
@ -63,6 +63,9 @@ public:
|
||||
BString& PreferencesFile() { return fPreferencesFile; }
|
||||
status_t GetPreferencesPath(BPath &path);
|
||||
|
||||
bool DefaultsSet();
|
||||
bool StartPrefsSet();
|
||||
|
||||
private:
|
||||
BString fPreferencesFile;
|
||||
|
||||
@ -107,6 +110,7 @@ public:
|
||||
|
||||
private:
|
||||
void _MoveToPosition();
|
||||
void _UpdateButtons();
|
||||
|
||||
BView* fPreferencesView;
|
||||
BButton* fRevertButton;
|
||||
@ -234,6 +238,22 @@ PreferencesStorage<Preferences>::SavePreferences()
|
||||
}
|
||||
|
||||
|
||||
template<typename Preferences>
|
||||
bool
|
||||
PreferencesStorage<Preferences>::DefaultsSet()
|
||||
{
|
||||
return fPreferences.IsEqual(fDefaultPreferences);
|
||||
}
|
||||
|
||||
|
||||
template<typename Preferences>
|
||||
bool
|
||||
PreferencesStorage<Preferences>::StartPrefsSet()
|
||||
{
|
||||
return fPreferences.IsEqual(fStartPreferences);
|
||||
}
|
||||
|
||||
|
||||
template<typename Preferences>
|
||||
PrefFileWatcher<Preferences>::PrefFileWatcher(
|
||||
PreferencesStorage<Preferences>* storage, BHandler* target)
|
||||
@ -343,10 +363,11 @@ PreferencesWindow<Preferences>::PreferencesWindow(const char* title,
|
||||
fRevertButton = new BButton(B_TRANSLATE("Revert"),
|
||||
new BMessage(kRevertMsg));
|
||||
|
||||
fRevertButton->SetEnabled(false);
|
||||
buttonView->AddChild(fRevertButton);
|
||||
buttonView->GetLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
|
||||
|
||||
_UpdateButtons();
|
||||
|
||||
SetLayout(new BGroupLayout(B_VERTICAL));
|
||||
fRootLayout = new BGroupLayout(B_VERTICAL);
|
||||
fRootLayout->SetInsets(10, 10, 10, 10);
|
||||
@ -377,19 +398,19 @@ PreferencesWindow<Preferences>::MessageReceived(BMessage *msg)
|
||||
switch(msg->what)
|
||||
{
|
||||
case kConfigChangedMsg:
|
||||
fRevertButton->SetEnabled(true);
|
||||
_UpdateButtons();
|
||||
break;
|
||||
|
||||
case kDefaultMsg:
|
||||
PreferencesStorage<Preferences>::Defaults();
|
||||
fRevertButton->SetEnabled(true);
|
||||
_UpdateButtons();
|
||||
if (fPreferencesView)
|
||||
PostMessage(kDefaultMsg, fPreferencesView);
|
||||
break;
|
||||
|
||||
case kRevertMsg:
|
||||
PreferencesStorage<Preferences>::Revert();
|
||||
fRevertButton->SetEnabled(false);
|
||||
_UpdateButtons();
|
||||
if (fPreferencesView)
|
||||
PostMessage(kRevertMsg, fPreferencesView);
|
||||
break;
|
||||
@ -442,6 +463,22 @@ PreferencesWindow<Preferences>::_MoveToPosition()
|
||||
MoveTo(position);
|
||||
}
|
||||
|
||||
|
||||
template<typename Preferences>
|
||||
void
|
||||
PreferencesWindow<Preferences>::_UpdateButtons()
|
||||
{
|
||||
if (!PreferencesStorage<Preferences>::DefaultsSet())
|
||||
fDefaultButton->SetEnabled(true);
|
||||
else
|
||||
fDefaultButton->SetEnabled(false);
|
||||
if (!PreferencesStorage<Preferences>::StartPrefsSet())
|
||||
fRevertButton->SetEnabled(true);
|
||||
else
|
||||
fRevertButton->SetEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
#undef B_TRANSLATE_CONTEXT
|
||||
|
||||
#endif // PREFERENCES_WINDOW_h
|
||||
|
Loading…
Reference in New Issue
Block a user