PackageInstaller: Unbreak selecting custom install folders.

BFilePanel always sends B_CANCEL when it hides (as documented in the BeBook),
not just when the user cancels the file panel. Track what message we expect
and only react to B_CANCEL when it means the user really canceled selecting
the target folder.
This commit is contained in:
Stephan Aßmus 2014-02-25 22:31:58 +01:00
parent 91e3737dd8
commit 792a46db79
2 changed files with 23 additions and 0 deletions

View File

@ -73,6 +73,7 @@ PackageView::PackageView(const entry_ref* ref)
BView("package_view", 0), BView("package_view", 0),
fOpenPanel(new BFilePanel(B_OPEN_PANEL, NULL, NULL, B_DIRECTORY_NODE, fOpenPanel(new BFilePanel(B_OPEN_PANEL, NULL, NULL, B_DIRECTORY_NODE,
false)), false)),
fExpectingOpenPanelResult(false),
fInfo(ref), fInfo(ref),
fInstallProcess(this) fInstallProcess(this)
{ {
@ -180,6 +181,7 @@ PackageView::MessageReceived(BMessage* message)
} }
case P_MSG_OPEN_PANEL: case P_MSG_OPEN_PANEL:
fExpectingOpenPanelResult = true;
fOpenPanel->Show(); fOpenPanel->Show();
break; break;
@ -266,6 +268,9 @@ PackageView::MessageReceived(BMessage* message)
case B_REFS_RECEIVED: case B_REFS_RECEIVED:
{ {
if (!_ValidateFilePanelMessage(message))
break;
entry_ref ref; entry_ref ref;
if (message->FindRef("refs", &ref) == B_OK) { if (message->FindRef("refs", &ref) == B_OK) {
BPath path(&ref); BPath path(&ref);
@ -290,6 +295,9 @@ PackageView::MessageReceived(BMessage* message)
case B_CANCEL: case B_CANCEL:
{ {
if (!_ValidateFilePanelMessage(message))
break;
// file panel aborted, select first suitable item // file panel aborted, select first suitable item
for (int32 i = 0; i < fDestination->CountItems(); i++) { for (int32 i = 0; i < fDestination->CountItems(); i++) {
BMenuItem* item = fDestination->ItemAt(i); BMenuItem* item = fDestination->ItemAt(i);
@ -723,3 +731,14 @@ PackageView::_AddMenuItem(const char* name, BMessage* message,
menu->AddItem(item); menu->AddItem(item);
return item; return item;
} }
bool
PackageView::_ValidateFilePanelMessage(BMessage* message)
{
if (!fExpectingOpenPanelResult)
return false;
fExpectingOpenPanelResult = false;
return true;
}

View File

@ -66,6 +66,8 @@ private:
BMenuItem* _AddMenuItem(const char* name, BMenuItem* _AddMenuItem(const char* name,
BMessage* message, BMenu* menu) const; BMessage* message, BMenu* menu) const;
bool _ValidateFilePanelMessage(BMessage* message);
private: private:
BPopUpMenu* fInstallTypes; BPopUpMenu* fInstallTypes;
BTextView* fInstallTypeDescriptionView; BTextView* fInstallTypeDescriptionView;
@ -74,6 +76,8 @@ private:
BButton* fBeginButton; BButton* fBeginButton;
BFilePanel* fOpenPanel; BFilePanel* fOpenPanel;
bool fExpectingOpenPanelResult;
BPath fCurrentPath; BPath fCurrentPath;
uint32 fCurrentType; uint32 fCurrentType;