Sounds preflet: small UX improvements.

* Disable BMenuField unless a sound event is selected.
* Changes in the MenuItem enable/disable the play button as necessary.
  (previously only changes in the EventList did that).
* Enable the play button when BFilePanel is closed (after selecting valid file).

Fixes the (still reproducible) UI/UX portion of #17150.

Change-Id: I5b5d00cc7fce00a0d0f908bbaff883169f38f855
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5613
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Oscar Lesta 2022-09-03 07:37:13 +00:00 committed by waddlesplash
parent 3e06d97bc8
commit e4d44d82aa
2 changed files with 19 additions and 10 deletions

View File

@ -48,6 +48,7 @@ HWindow::HWindow(BRect rect, const char* name)
:
BWindow(rect, name, B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS),
fFilePanel(NULL),
fPlayButton(NULL),
fPlayer(NULL)
{
_InitGUI();
@ -173,6 +174,8 @@ HWindow::MessageReceived(BMessage* message)
// check file menu
if (menuitem != NULL)
menuitem->SetMarked(true);
fPlayButton->SetEnabled(true);
}
break;
}
@ -212,6 +215,9 @@ HWindow::MessageReceived(BMessage* message)
= dynamic_cast<BMenuField*>(FindView("filemenu"));
if (menufield == NULL)
return;
menufield->SetEnabled(true);
BMenu* menu = menufield->Menu();
if (message->FindString("path", &path) == B_OK) {
@ -227,18 +233,14 @@ HWindow::MessageReceived(BMessage* message)
}
HEventRow* row = (HEventRow*)fEventList->CurrentSelection();
BButton* button = dynamic_cast<BButton*>(FindView("play"));
if (row != NULL) {
menufield->SetEnabled(true);
const char* path = row->Path();
if (path != NULL && strcmp(path, ""))
button->SetEnabled(true);
else
button->SetEnabled(false);
fPlayButton->SetEnabled(path != NULL && strcmp(path, "") != 0);
} else {
menufield->SetEnabled(false);
button->SetEnabled(false);
fPlayButton->SetEnabled(false);
}
}
break;
@ -250,12 +252,16 @@ HWindow::MessageReceived(BMessage* message)
if (message->FindRef("refs", &ref) == B_OK) {
fEventList->SetPath(BPath(&ref).Path());
_UpdateZoomLimits();
HEventRow* row = (HEventRow*)fEventList->CurrentSelection();
fPlayButton->SetEnabled(row != NULL && row->Path() != NULL);
}
break;
}
case M_NONE_MESSAGE:
{
fPlayButton->SetEnabled(false);
fEventList->SetPath(NULL);
break;
}
@ -308,10 +314,10 @@ HWindow::_InitGUI()
// intercept in DispatchMessage to trigger the buttons enabling or disabling.
stopbutton->SetFlags(stopbutton->Flags() | B_PULSE_NEEDED);
BButton* playbutton = new BButton("play", "\xE2\x96\xB6",
fPlayButton = new BButton("play", "\xE2\x96\xB6",
new BMessage(M_PLAY_MESSAGE));
playbutton->SetEnabled(false);
playbutton->SetExplicitSize(buttonsSize);
fPlayButton->SetEnabled(false);
fPlayButton->SetExplicitSize(buttonsSize);
BLayoutBuilder::Group<>(this, B_VERTICAL)
.SetInsets(B_USE_WINDOW_SPACING)
@ -319,7 +325,7 @@ HWindow::_InitGUI()
.AddGroup(B_HORIZONTAL)
.Add(menuField)
.AddGroup(B_HORIZONTAL, 0)
.Add(playbutton)
.Add(fPlayButton)
.Add(stopbutton)
.End()
.End();
@ -330,6 +336,8 @@ HWindow::_InitGUI()
if (noneItem != NULL)
noneItem->SetMarked(true);
menuField->SetEnabled(false);
_UpdateZoomLimits();
}

View File

@ -52,6 +52,7 @@ private:
private:
HEventList* fEventList;
BFilePanel* fFilePanel;
BButton* fPlayButton;
BFileGameSound* fPlayer;
BRect fFrame;
};