1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-01 15:43:44 +02:00

Enh 66 again: do not make duplicate About dialogs on Mac

This commit is contained in:
Paul Licameli 2016-06-20 19:12:03 -04:00
parent 41f9f506c0
commit 5e95491bfc
4 changed files with 31 additions and 14 deletions

View File

@ -223,11 +223,23 @@ END_EVENT_TABLE()
IMPLEMENT_CLASS(AboutDialog, wxDialog)
namespace {
AboutDialog *sActiveInstance{};
}
AboutDialog *AboutDialog::ActiveIntance()
{
return sActiveInstance;
}
AboutDialog::AboutDialog(wxWindow * parent)
: wxDialog(parent, -1, _("About Audacity"),
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
wxASSERT(!sActiveInstance);
sActiveInstance = this;
SetName(GetTitle());
this->SetBackgroundColour(theTheme.Colour( clrAboutBoxBackground ));
icon = NULL;
@ -964,12 +976,16 @@ void AboutDialog::AddBuildinfoRow( wxString* htmlstring, const wxChar * libname,
*htmlstring += wxT("</td></tr>");
}
AboutDialog::~AboutDialog()
{
sActiveInstance = {};
}
void AboutDialog::OnOK(wxCommandEvent & WXUNUSED(event))
{
#ifdef __WXMAC__
Destroy();
#else
EndModal(wxID_OK);
#endif
}

View File

@ -56,11 +56,13 @@ class AboutDialog final : public wxDialog {
AboutDialog(wxWindow * parent);
virtual ~ AboutDialog();
static AboutDialog *ActiveIntance();
void OnOK(wxCommandEvent & event);
wxStaticBitmap *icon;
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
private:
enum Role {

View File

@ -2030,21 +2030,19 @@ int AudacityApp::OnExit()
void AudacityApp::OnMenuAbout(wxCommandEvent & event)
{
// This function shadows a similar function
// in Menus.cpp, but should only be used on the Mac platform
// when no project windows are open. This check assures that
// this happens, and enable the same code to be present on
// all platforms.
if(gAudacityProjects.GetCount() == 0) {
// in Menus.cpp, but should only be used on the Mac platform.
#ifdef __WXMAC__
// Modeless dialog, consistent with other Mac applications
// Modeless dialog, consistent with other Mac applications
// Not more than one at once!
const auto instance = AboutDialog::ActiveIntance();
if (instance)
instance->Raise();
else
// This dialog deletes itself when dismissed
(safenew AboutDialog{ nullptr })->Show(true);
#else
AboutDialog dlog(NULL);
dlog.ShowModal();
wxASSERT(false);
#endif
}
else
event.Skip();
}
void AudacityApp::OnMenuNew(wxCommandEvent & event)

View File

@ -6604,7 +6604,8 @@ void AudacityProject::OnAbout()
{
#ifdef __WXMAC__
// Modeless dialog, consistent with other Mac applications
(safenew AboutDialog{ nullptr })->Show(true);
wxCommandEvent dummy;
wxGetApp().OnMenuAbout(dummy);
#else
// Windows and Linux still modal.
AboutDialog dlog(this);