From b4eca493bb93497e1a37ebc5cb2a8ee212cf27ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 24 Apr 2009 15:32:40 +0000 Subject: [PATCH] * Prevent the user from chosing the same disk for source and destination. * Keep the info text and the Begin button in consistent state at all times according to the selection of the disks. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30379 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/installer/InstallerWindow.cpp | 64 ++++++++++++++++---------- src/apps/installer/InstallerWindow.h | 3 -- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/apps/installer/InstallerWindow.cpp b/src/apps/installer/InstallerWindow.cpp index 60bc69cbd0..7cc1217643 100644 --- a/src/apps/installer/InstallerWindow.cpp +++ b/src/apps/installer/InstallerWindow.cpp @@ -196,10 +196,7 @@ InstallerWindow::InstallerWindow() fInstallStatus(kReadyForInstall), fPackagesLayoutItem(NULL), - fSizeViewLayoutItem(NULL), - - fLastSrcItem(NULL), - fLastTargetItem(NULL) + fSizeViewLayoutItem(NULL) { fCopyEngine = new CopyEngine(this); @@ -382,16 +379,10 @@ InstallerWindow::MessageReceived(BMessage *msg) _ShowOptionalPackages(); break; case SRC_PARTITION: - if (fLastSrcItem == fSrcMenu->FindMarked()) - break; - fLastSrcItem = fSrcMenu->FindMarked(); _PublishPackages(); _UpdateMenus(); break; case TARGET_PARTITION: - if (fLastTargetItem == fDestMenu->FindMarked()) - break; - fLastTargetItem = fDestMenu->FindMarked(); _UpdateMenus(); break; case SETUP_MESSAGE: @@ -525,29 +516,41 @@ InstallerWindow::_ScanPartitions() _PublishPackages(); } _UpdateMenus(); - _SetStatusMessage("Choose the disk you want to install onto from the " - "pop-up menu. Then click \"Begin\"."); } void InstallerWindow::_UpdateMenus() { - PartitionMenuItem *item1 = (PartitionMenuItem *)fSrcMenu->FindMarked(); + PartitionMenuItem* srcItem = (PartitionMenuItem*)fSrcMenu->FindMarked(); BString label; - if (item1) { - label = item1->MenuLabel(); + if (srcItem) { + label = srcItem->MenuLabel(); } else { if (fSrcMenu->CountItems() == 0) label = ""; else - label = ((PartitionMenuItem *)fSrcMenu->ItemAt(0))->MenuLabel(); + label = ((PartitionMenuItem*)fSrcMenu->ItemAt(0))->MenuLabel(); } fSrcMenuField->MenuItem()->SetLabel(label.String()); - PartitionMenuItem *item2 = (PartitionMenuItem *)fDestMenu->FindMarked(); - if (item2) { - label = item2->MenuLabel(); + if (srcItem) { + // Prevent the user from having picked the same partition as source + // and destination. + for (int32 i = fDestMenu->CountItems() - 1; i >= 0; i--) { + PartitionMenuItem* dstItem + = (PartitionMenuItem*)fDestMenu->ItemAt(i); + if (dstItem->ID() == srcItem->ID()) { + dstItem->SetEnabled(false); + dstItem->SetMarked(false); + } else + dstItem->SetEnabled(true); + } + } + + PartitionMenuItem* dstItem = (PartitionMenuItem*)fDestMenu->FindMarked(); + if (dstItem) { + label = dstItem->MenuLabel(); } else { if (fDestMenu->CountItems() == 0) label = ""; @@ -555,12 +558,23 @@ InstallerWindow::_UpdateMenus() label = "Please Choose Target"; } fDestMenuField->MenuItem()->SetLabel(label.String()); - char message[255]; - sprintf(message, "Press the Begin button to install from '%s' onto '%s'", - item1 ? item1->Name() : "null", item2 ? item2->Name() : "null"); - _SetStatusMessage(message); - if (item1 && item2) - fBeginButton->SetEnabled(true); + if (srcItem && dstItem) { + char message[255]; + sprintf(message, "Press the Begin button to install from '%s' onto " + "'%s'.", srcItem->Name(), dstItem->Name()); + _SetStatusMessage(message); + } else if (srcItem) { + _SetStatusMessage("Choose the disk you want to install onto from the " + "pop-up menu. Then click \"Begin\"."); + } else if (dstItem) { + _SetStatusMessage("Choose the source disk from the " + "pop-up menu. Then click \"Begin\"."); + } else { + _SetStatusMessage("Choose the source and destination disk from the " + "pop-up menus. Then click \"Begin\"."); + } + + fBeginButton->SetEnabled(srcItem && dstItem); } diff --git a/src/apps/installer/InstallerWindow.h b/src/apps/installer/InstallerWindow.h index 06c3bec19e..4ab550abd4 100644 --- a/src/apps/installer/InstallerWindow.h +++ b/src/apps/installer/InstallerWindow.h @@ -81,9 +81,6 @@ private: CopyEngine* fCopyEngine; BString fLastStatus; - - BMenuItem* fLastSrcItem; - BMenuItem* fLastTargetItem; }; #endif // INSTALLER_WINDOW_H