mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-02 08:59:28 +02:00
Removed duplicated code to tidy up ProgressDialog confirmations.
This commit is contained in:
parent
6686d0e314
commit
3add43b931
@ -1199,14 +1199,12 @@ bool ProgressDialog::Create(const wxString & title,
|
|||||||
{
|
{
|
||||||
w = safenew wxButton(this, wxID_OK, _("Stop"));
|
w = safenew wxButton(this, wxID_OK, _("Stop"));
|
||||||
h->Add(w, 0, wxRIGHT, 10);
|
h->Add(w, 0, wxRIGHT, 10);
|
||||||
m_btnStop = w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(flags & pdlgHideCancelButton))
|
if (!(flags & pdlgHideCancelButton))
|
||||||
{
|
{
|
||||||
w = safenew wxButton(this, wxID_CANCEL, _("Cancel"));
|
w = safenew wxButton(this, wxID_CANCEL, _("Cancel"));
|
||||||
h->Add(w, 0, wxRIGHT, 10);
|
h->Add(w, 0, wxRIGHT, 10);
|
||||||
m_btnCancel = w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v->Add(uh.release(), 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10);
|
v->Add(uh.release(), 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10);
|
||||||
@ -1504,17 +1502,8 @@ bool ProgressDialog::SearchForWindow(const wxWindowList & list, const wxWindow *
|
|||||||
|
|
||||||
void ProgressDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
|
void ProgressDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
|
||||||
{
|
{
|
||||||
if (m_bConfirmAction) {
|
if (!ConfirmAction(_("Are you sure you wish to cancel?"), _("Confirm Cancel"), wxID_CANCEL)) {
|
||||||
wxString sPrompt = _("Are you sure you wish to cancel?");
|
return;
|
||||||
wxMessageDialog dlgMessage(this,
|
|
||||||
sPrompt,
|
|
||||||
_("Confirm Cancel"),
|
|
||||||
wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT | wxSTAY_ON_TOP);
|
|
||||||
int iAction = dlgMessage.ShowModal();
|
|
||||||
if (iAction != wxID_YES) {
|
|
||||||
m_btnCancel->SetFocus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
FindWindowById(wxID_CANCEL, this)->Disable();
|
FindWindowById(wxID_CANCEL, this)->Disable();
|
||||||
mCancel = true;
|
mCancel = true;
|
||||||
@ -1522,17 +1511,8 @@ void ProgressDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
|
|||||||
|
|
||||||
void ProgressDialog::OnStop(wxCommandEvent & WXUNUSED(event))
|
void ProgressDialog::OnStop(wxCommandEvent & WXUNUSED(event))
|
||||||
{
|
{
|
||||||
if (m_bConfirmAction) {
|
if (!ConfirmAction(_("Are you sure you wish to stop?"), _("Confirm Stop"), wxID_OK)) {
|
||||||
wxString sPrompt = _("Are you sure you wish to stop?");
|
return;
|
||||||
wxMessageDialog dlgMessage(this,
|
|
||||||
sPrompt,
|
|
||||||
_("Confirm Stop"),
|
|
||||||
wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT | wxSTAY_ON_TOP);
|
|
||||||
int iAction = dlgMessage.ShowModal();
|
|
||||||
if (iAction != wxID_YES) {
|
|
||||||
m_btnStop->SetFocus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
FindWindowById(wxID_OK, this)->Disable();
|
FindWindowById(wxID_OK, this)->Disable();
|
||||||
mCancel = false;
|
mCancel = false;
|
||||||
@ -1541,16 +1521,8 @@ void ProgressDialog::OnStop(wxCommandEvent & WXUNUSED(event))
|
|||||||
|
|
||||||
void ProgressDialog::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
|
void ProgressDialog::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
|
||||||
{
|
{
|
||||||
if (m_bConfirmAction) {
|
if (!ConfirmAction(_("Are you sure you wish to close?"), _("Confirm Close"))) {
|
||||||
wxString sPrompt = _("Are you sure you wish to close?");
|
return;
|
||||||
wxMessageDialog dlgMessage(this,
|
|
||||||
sPrompt,
|
|
||||||
_("Confirm Close"),
|
|
||||||
wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT | wxSTAY_ON_TOP);
|
|
||||||
int iAction = dlgMessage.ShowModal();
|
|
||||||
if (iAction != wxID_YES) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mCancel = true;
|
mCancel = true;
|
||||||
}
|
}
|
||||||
@ -1586,6 +1558,33 @@ void ProgressDialog::Beep() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MY: Confirm action taken by user.
|
||||||
|
// Returns TRUE if the user confirms Yes
|
||||||
|
bool ProgressDialog::ConfirmAction(const wxString & sPrompt,
|
||||||
|
const wxString & sTitle,
|
||||||
|
int iButtonID /* = -1 */) {
|
||||||
|
|
||||||
|
// Check if confirmations are enabled?
|
||||||
|
// If not then return TRUE
|
||||||
|
if (m_bConfirmAction == false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxMessageDialog dlgMessage(this,
|
||||||
|
sPrompt,
|
||||||
|
sTitle,
|
||||||
|
wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT | wxSTAY_ON_TOP);
|
||||||
|
int iAction = dlgMessage.ShowModal();
|
||||||
|
|
||||||
|
bool bReturn = (iAction == wxID_YES);
|
||||||
|
if ((bReturn == false) && (iButtonID > -1)) {
|
||||||
|
// Set the focus back to the relevant button
|
||||||
|
FindWindowById(iButtonID, this)->SetFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
return bReturn;
|
||||||
|
}
|
||||||
|
|
||||||
TimerProgressDialog::TimerProgressDialog(const wxLongLong_t duration,
|
TimerProgressDialog::TimerProgressDialog(const wxLongLong_t duration,
|
||||||
const wxString & title,
|
const wxString & title,
|
||||||
const wxString & message /* = wxEmptyString */,
|
const wxString & message /* = wxEmptyString */,
|
||||||
|
@ -96,10 +96,6 @@ protected:
|
|||||||
bool m_bShowElapsedTime = true;
|
bool m_bShowElapsedTime = true;
|
||||||
bool m_bConfirmAction = false;
|
bool m_bConfirmAction = false;
|
||||||
|
|
||||||
// MY: Declare the buttons so we can se the focus on them later
|
|
||||||
wxWindow *m_btnStop;
|
|
||||||
wxWindow *m_btnCancel;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Init();
|
void Init();
|
||||||
bool SearchForWindow(const wxWindowList & list, const wxWindow *searchfor) const;
|
bool SearchForWindow(const wxWindowList & list, const wxWindow *searchfor) const;
|
||||||
@ -107,6 +103,10 @@ private:
|
|||||||
void OnStop(wxCommandEvent & e);
|
void OnStop(wxCommandEvent & e);
|
||||||
void OnCloseWindow(wxCloseEvent & e);
|
void OnCloseWindow(wxCloseEvent & e);
|
||||||
void Beep() const;
|
void Beep() const;
|
||||||
|
|
||||||
|
bool ConfirmAction(const wxString & sPrompt,
|
||||||
|
const wxString & sTitle,
|
||||||
|
int iButtonID = -1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// This guarantees we have an active event loop...possible during OnInit()
|
// This guarantees we have an active event loop...possible during OnInit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user