audacia/src/widgets/MultiDialog.cpp

221 lines
6.3 KiB
C++
Raw Normal View History

/**********************************************************************
Audacity: A Digital Audio Editor
Audacity(R) is copyright (c) 1999-2010 Audacity Team.
License: GPL v2. See License.txt.
MultiDialog.h
Monty
Vaughan Johnson
*******************************************************************//**
\class MultiDialog
\brief A multi purpose dialog, mainly used to show lists of orphaned or
damaged block files. It is a good alternative to having a dialog pop up
for each problem encountered, since there can be many orphans.
*//*******************************************************************/
#include "MultiDialog.h"
#include "../ShuttleGui.h"
2016-11-22 18:16:03 +00:00
#include <wx/app.h>
#include <wx/button.h>
#include <wx/dialog.h>
#include <wx/intl.h>
#include <wx/icon.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/statbmp.h>
#include <wx/artprov.h>
#include <wx/radiobox.h>
2020-02-09 20:46:16 +00:00
#include <wx/bmpbuttn.h>
#include "../AudacityLogger.h"
#include "wxPanelWrapper.h"
#include "../Theme.h"
#include "../AllThemeResources.h"
#include "../widgets/HelpSystem.h"
Automation: AudacityCommand This is a squash of 50 commits. This merges the capabilities of BatchCommands and Effects using a new AudacityCommand class. AudacityCommand provides one function to specify the parameters, and then we leverage that one function in automation, whether by chains, mod-script-pipe or (future) Nyquist. - Now have AudacityCommand which is using the same mechanism as Effect - Has configurable parameters - Has data-entry GUI (built using shuttle GUI) - Registers with PluginManager. - Menu commands now provided in chains, and to python batch. - Tested with Zoom Toggle. - ShuttleParams now can set, get, set defaults, validate and specify the parameters. - Bugfix: Don't overwrite values with defaults first time out. - Add DefineParams function for all built-in effects. - Extend CommandContext to carry output channels for results. We abuse EffectsManager. It handles both Effects and AudacityCommands now. In time an Effect should become a special case of AudacityCommand and we'll split and rename the EffectManager class. - Don't use 'default' as a parameter name. - Massive renaming for CommandDefinitionInterface - EffectIdentInterface becomes EffectDefinitionInterface - EffectAutomationParameters becomes CommandAutomationParameters - PluginType is now a bit field. This way we can search for related types at the same time. - Most old batch commands made into AudacityCommands. The ones that weren't are for a reason. They are used by mod-script-pipe to carry commands and responses across from a non-GUI thread to the GUI thread. - Major tidy up of ScreenshotCommand - Reworking of SelectCommand - GetPreferenceCommand and SetPreferenceCommand - GetTrackInfo and SetTrackInfo - GetInfoCommand - Help, Open, Save, Import and Export commands. - Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo which are now better handled by other commands. - JSONify "GetInfo: Commands" output, i.e. commas in the right places. - General work on better Doxygen. - Lyrics -> LyricsPanel - Meter -> MeterPanel - Updated Linux makefile. - Scripting commands added into Extra menu. - Distinct names for previously duplicated find-clipping parameters. - Fixed longstanding error with erroneous status field number which previously caused an ASSERT in debug. - Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-01-14 18:51:41 +00:00
class MultiDialog final : public wxDialogWrapper
{
public:
MultiDialog(wxWindow * pParent,
const TranslatableString &message,
const TranslatableString &title,
const TranslatableStrings &buttons,
const wxString &helpPage,
const TranslatableString &boxMsg, bool log);
~MultiDialog() {};
2014-06-03 20:30:19 +00:00
private:
void OnOK( wxCommandEvent &event );
void OnShowLog(wxCommandEvent& event);
void OnHelp(wxCommandEvent& event);
wxRadioBox* mRadioBox;
ManualPageID mHelpPage;
DECLARE_EVENT_TABLE()
};
#define ID_SHOW_LOG_BUTTON 3333
BEGIN_EVENT_TABLE(MultiDialog, wxDialogWrapper)
EVT_BUTTON( wxID_OK, MultiDialog::OnOK )
EVT_BUTTON(ID_SHOW_LOG_BUTTON, MultiDialog::OnShowLog)
EVT_BUTTON(wxID_HELP, MultiDialog::OnHelp)
END_EVENT_TABLE()
2014-06-03 20:30:19 +00:00
MultiDialog::MultiDialog(wxWindow * pParent,
const TranslatableString &message,
const TranslatableString &title,
const TranslatableStrings &buttons,
const wxString &helpPage,
const TranslatableString &boxMsg,
bool log
)
: wxDialogWrapper(pParent, wxID_ANY, title,
2014-06-03 20:30:19 +00:00
wxDefaultPosition, wxDefaultSize,
wxCAPTION), // not wxDEFAULT_DIALOG_STYLE because we don't want wxCLOSE_BOX and wxSYSTEM_MENU
mHelpPage( helpPage)
{
SetName();
ShuttleGui S{ this, eIsCreating };
{
S.SetBorder( 5 );
S.StartVerticalLay( 0 );
{
S.StartHorizontalLay(wxALIGN_LEFT | wxALL, 0);
{
S.SetBorder( 0 );
wxBitmap bitmap = wxArtProvider::GetIcon(wxART_WARNING,
wxART_MESSAGE_BOX);
auto icon = safenew wxStaticBitmap(S.GetParent(), -1, bitmap);
S
.Position( wxCENTER )
.AddWindow( icon );
S.SetBorder( 15 );
S.Prop(1).AddVariableText( message, false, wxCENTER | wxLEFT );
}
S.EndHorizontalLay();
const auto buttonLabels = transform_container<wxArrayStringEx>(
buttons, std::mem_fn( &TranslatableString::Translation ) );
const auto count = buttons.size();
const auto boxStr = boxMsg.Translation();
S.SetBorder( 5 );
mRadioBox = safenew wxRadioBox(S.GetParent(), -1,
boxStr,
wxDefaultPosition, wxDefaultSize,
count, count ? &buttonLabels[0] : nullptr,
1, wxRA_SPECIFY_COLS);
mRadioBox->SetSelection(0);
S.Prop( 1 )
.Name( boxMsg )
.Position(wxEXPAND | wxALL)
.AddWindow( mRadioBox );
S.StartHorizontalLay(wxALIGN_CENTER | wxALL, 0);
{
if (log)
{
S
.Id(ID_SHOW_LOG_BUTTON)
.AddButton(
XXO("Show Log for Details"), wxALIGN_LEFT | wxALL,
// set default to encourage user to look at files.
true);
S.AddSpace(40, 0);
}
2016-02-18 07:54:50 +00:00
auto pButton = S.Id(wxID_OK)
.AddButton(XXO("OK"), wxALIGN_CENTER, !log);
if (!mHelpPage.empty()) {
auto pHelpBtn = S.Id(wxID_HELP)
.AddBitmapButton(theTheme.Bitmap(bmpHelpIcon), wxALIGN_CENTER, false);
pHelpBtn->SetToolTip(XO("Help").Translation());
pHelpBtn->SetLabel(XO("Help").Translation()); // for screen readers
}
}
S.EndHorizontalLay();
}
S.EndVerticalLay();
}
SetAutoLayout(true);
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
}
void MultiDialog::OnOK(wxCommandEvent & WXUNUSED(event))
{
EndModal(mRadioBox->GetSelection());
}
void MultiDialog::OnShowLog(wxCommandEvent & WXUNUSED(event))
{
auto logger = AudacityLogger::Get();
if (logger) {
logger->Show();
}
}
void MultiDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
{
HelpSystem::ShowHelp(FindWindow(wxID_HELP), mHelpPage, true);
}
int ShowMultiDialog(const TranslatableString &message,
const TranslatableString &title,
const TranslatableStrings &buttons,
const wxString &helpPage,
const TranslatableString &boxMsg, bool log)
{
2016-11-22 18:16:03 +00:00
wxWindow * pParent = wxTheApp->GetTopWindow();
// We want a parent we can display over, so don't make it a parent if top
// window is a STAY_ON_TOP.
if (pParent) {
if ((pParent->GetWindowStyle() & wxSTAY_ON_TOP) == wxSTAY_ON_TOP)
pParent = NULL;
}
MultiDialog dlog(pParent,
message, title, buttons, helpPage, boxMsg, log);
// If dialog does not have a parent, cannot be centred on it.
if (pParent != NULL)
dlog.CentreOnParent();
else {
dlog.CenterOnScreen();
// and after centring move the dialog left by the size of the dialog.
// Likely to help if we have the splash screen visible, or if
// we're spanning two equally sized monitors.
// Unlikely to make things worse.
wxSize Size = dlog.GetSize();
Size.SetHeight( 10 );
wxPoint Pos = dlog.GetPosition() -Size;
dlog.Move(Pos);
}
return dlog.ShowModal();
}
const TranslatableString &DefaultMultiDialogMessage()
{
static auto result = XO("Please select an action");
return result;
}