Refactor a little bit in order to better handle the button states as suggested by Axel. Should resolve #7073.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40193 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent 2011-01-10 18:09:13 +00:00
parent ed32e8efbb
commit 0baa186bfb
2 changed files with 27 additions and 23 deletions

View File

@ -195,7 +195,8 @@ DrivesPage::DrivesPage(WizardView* wizardView, const BootMenuList& menus,
BMessage* settings, const char* name) BMessage* settings, const char* name)
: :
WizardPageView(settings, name), WizardPageView(settings, name),
fWizardView(wizardView) fWizardView(wizardView),
fHasInstallableItems(false)
{ {
BString text; BString text;
text << B_TRANSLATE_COMMENT("Drives", "Title") << "\n" text << B_TRANSLATE_COMMENT("Drives", "Title") << "\n"
@ -207,8 +208,6 @@ DrivesPage::DrivesPage(WizardView* wizardView, const BootMenuList& menus,
fDrivesView = new BListView("drives"); fDrivesView = new BListView("drives");
fDrivesView->SetSelectionMessage(new BMessage(kMsgSelectionChanged)); fDrivesView->SetSelectionMessage(new BMessage(kMsgSelectionChanged));
bool any = _FillDrivesView(menus);
BScrollView* scrollView = new BScrollView("scrollView", fDrivesView, 0, BScrollView* scrollView = new BScrollView("scrollView", fDrivesView, 0,
false, true); false, true);
@ -218,18 +217,8 @@ DrivesPage::DrivesPage(WizardView* wizardView, const BootMenuList& menus,
.Add(description, 0.5) .Add(description, 0.5)
.Add(scrollView, 1); .Add(scrollView, 1);
fWizardView->SetPreviousButtonHidden(!any); _UpdateWizardButtons(NULL);
if (any) { _FillDrivesView(menus);
fWizardView->SetPreviousButtonLabel(
B_TRANSLATE_COMMENT("Uninstall", "Button"));
if (fDrivesView->CurrentSelection() == -1) {
fWizardView->SetPreviousButtonEnabled(false);
fWizardView->SetNextButtonEnabled(false);
}
} else {
fWizardView->SetNextButtonLabel(
B_TRANSLATE_COMMENT("Quit", "Button"));
}
} }
@ -273,14 +262,14 @@ DrivesPage::MessageReceived(BMessage* message)
/*! Builds the list view items, and adds them to fDriveView. /*! Builds the list view items, and adds them to fDriveView.
Returns whether there were any possible install targets. Automatically Sets the fHasInstallableItems member to indicate if there
are any possible install targets. Automatically
selects the boot drive. selects the boot drive.
*/ */
bool void
DrivesPage::_FillDrivesView(const BootMenuList& menus) DrivesPage::_FillDrivesView(const BootMenuList& menus)
{ {
const char* selected = fSettings->FindString("disk"); const char* selected = fSettings->FindString("disk");
bool any = false;
BDiskDeviceRoster roster; BDiskDeviceRoster roster;
BDiskDevice device; BDiskDevice device;
@ -288,7 +277,7 @@ DrivesPage::_FillDrivesView(const BootMenuList& menus)
if (device.HasMedia() && !device.IsReadOnly()) { if (device.HasMedia() && !device.IsReadOnly()) {
DriveItem* item = new DriveItem(device, menus); DriveItem* item = new DriveItem(device, menus);
if (item->CanBeInstalled()) if (item->CanBeInstalled())
any = true; fHasInstallableItems = true;
fDrivesView->AddItem(item); fDrivesView->AddItem(item);
if ((selected == NULL && item->IsBootDrive()) if ((selected == NULL && item->IsBootDrive())
@ -298,8 +287,6 @@ DrivesPage::_FillDrivesView(const BootMenuList& menus)
} }
} }
} }
return any;
} }
@ -313,8 +300,24 @@ DrivesPage::_SelectedDriveItem()
void void
DrivesPage::_UpdateWizardButtons(DriveItem* item) DrivesPage::_UpdateWizardButtons(DriveItem* item)
{ {
if (item == NULL) fWizardView->SetPreviousButtonHidden(!fHasInstallableItems);
if (fHasInstallableItems) {
fWizardView->SetPreviousButtonLabel(
B_TRANSLATE_COMMENT("Uninstall", "Button"));
if (fDrivesView->CurrentSelection() == -1) {
fWizardView->SetPreviousButtonEnabled(false);
fWizardView->SetNextButtonEnabled(false);
}
} else {
fWizardView->SetNextButtonLabel(
B_TRANSLATE_COMMENT("Quit", "Button"));
}
if (item == NULL) {
fWizardView->SetPreviousButtonEnabled(false);
fWizardView->SetNextButtonEnabled(false);
return; return;
}
fWizardView->SetPreviousButtonEnabled( fWizardView->SetPreviousButtonEnabled(
item->CanBeInstalled() && item->IsInstalled()); item->CanBeInstalled() && item->IsInstalled());

View File

@ -31,13 +31,14 @@ protected:
void MessageReceived(BMessage* message); void MessageReceived(BMessage* message);
private: private:
bool _FillDrivesView(const BootMenuList& menus); void _FillDrivesView(const BootMenuList& menus);
DriveItem* _SelectedDriveItem(); DriveItem* _SelectedDriveItem();
void _UpdateWizardButtons(DriveItem* item); void _UpdateWizardButtons(DriveItem* item);
private: private:
WizardView* fWizardView; WizardView* fWizardView;
BListView* fDrivesView; BListView* fDrivesView;
bool fHasInstallableItems;
}; };