1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-19 17:40:15 +02:00

Long message target

This allows interactive display of the results of new commands that generate
lots of text.
This commit is contained in:
James Crook 2018-02-07 21:22:05 +00:00 committed by Paul Licameli
parent 037df23d3c
commit 4c65a74c03
7 changed files with 185 additions and 5 deletions

View File

@ -284,3 +284,12 @@ bool CommandImplementation::Apply(const CommandContext & WXUNUSED(context))
{ {
return true; return true;
} }
// Hackery so that we dont have to update the makefiles on linux (yet)
#ifndef __WIN32__
#include "CommandTargets.cpp"
#endif

View File

@ -45,7 +45,8 @@ CommandContext::CommandContext(
, const CommandParameter &param , const CommandParameter &param
) )
: project{ p } : project{ p }
, pOutput( nullptr ) // No target specified? Use the special interactive one that pops up a dialog.
, pOutput( std::move( std::make_unique<InteractiveOutputTarget>()) )
, pEvt{ e } , pEvt{ e }
, index{ ii } , index{ ii }
, parameter{ param } , parameter{ param }

View File

@ -0,0 +1,158 @@
/**********************************************************************
Audacity - A Digital Audio Editor
Copyright 1999-2009 Audacity Team
License: wxwidgets
Dan Horgan
******************************************************************//**
\file CommandTargets.cpp
\brief Contains definitions for CommandType class
\class InteractiveOutputTarget
\brief InteractiveOutputTarget is an output target that pops up a
dialog, if necessary.
*//*******************************************************************/
#include "../Audacity.h"
#include "CommandTargets.h"
#include <wx/string.h>
#include "../ShuttleGui.h"
#include "../Project.h"
/// Dialog for long messages.
class AUDACITY_DLL_API LongMessageDialog /* not final */ : public wxDialogWrapper
{
public:
// constructors and destructors
LongMessageDialog(wxWindow * parent,
const wxString & title,
int type = 0,
int flags = wxDEFAULT_DIALOG_STYLE,
int additionalButtons = 0);
~LongMessageDialog();
bool Init();
virtual void OnOk(wxCommandEvent & evt);
virtual void OnCancel(wxCommandEvent & evt);
static void AcceptText( const wxString & Text );
wxTextCtrl * mText;
static LongMessageDialog * pDlg;
private:
int mType;
int mAdditionalButtons;
DECLARE_EVENT_TABLE()
wxDECLARE_NO_COPY_CLASS(LongMessageDialog);
};
LongMessageDialog * LongMessageDialog::pDlg = NULL;
BEGIN_EVENT_TABLE(LongMessageDialog, wxDialogWrapper)
EVT_BUTTON(wxID_OK, LongMessageDialog::OnOk)
END_EVENT_TABLE()
LongMessageDialog::LongMessageDialog(wxWindow * parent,
const wxString & title,
int type,
int flags,
int additionalButtons)
: wxDialogWrapper(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, flags | wxRESIZE_BORDER)
{
mType = type;
mAdditionalButtons = additionalButtons;
}
LongMessageDialog::~LongMessageDialog(){
pDlg = NULL;
}
bool LongMessageDialog::Init()
{
ShuttleGui S(this, eIsCreating);
S.SetBorder(5);
S.StartVerticalLay(true);
{
mText = S.AddTextWindow( "" );
long buttons = eOkButton;
S.AddStandardButtons(buttons|mAdditionalButtons);
}
S.EndVerticalLay();
Layout();
Fit();
SetMinSize(wxSize(600,700));
Center();
return true;
}
void LongMessageDialog::OnOk(wxCommandEvent & WXUNUSED(evt)){
//Close(true);
Destroy();
}
void LongMessageDialog::OnCancel(wxCommandEvent & WXUNUSED(evt)){
//Close(true);
Destroy();
}
void LongMessageDialog::AcceptText( const wxString & Text )
{
if( pDlg == NULL ){
pDlg = new LongMessageDialog( GetActiveProject(), "Long Message" );
pDlg->Init();
pDlg->Show();
}
pDlg->mText->SetValue( pDlg->mText->GetValue( ) + "\n" + Text );
}
/// Displays messages from a command in an AudacityMessageBox
class MessageDialogTarget final : public CommandMessageTarget
{
public:
virtual ~MessageDialogTarget() {}
void Update(const wxString &message) override
{
LongMessageDialog::AcceptText(message);
}
};
/// Extended Target Factory with more options.
class ExtTargetFactory : public TargetFactory
{
public:
static std::unique_ptr<CommandMessageTarget> LongMessages()
{
return std::make_unique<MessageDialogTarget>();
}
};
InteractiveOutputTarget::InteractiveOutputTarget() :
CommandOutputTarget(
ExtTargetFactory::ProgressDefault(),
ExtTargetFactory::LongMessages(),
ExtTargetFactory::MessageDefault()
)
{
}

View File

@ -185,7 +185,7 @@ public:
/// Assumes responsibility for pointers passed into it. /// Assumes responsibility for pointers passed into it.
class CommandOutputTarget class CommandOutputTarget
{ {
private: protected:
std::unique_ptr<CommandProgressTarget> mProgressTarget; std::unique_ptr<CommandProgressTarget> mProgressTarget;
std::shared_ptr<CommandMessageTarget> mStatusTarget; std::shared_ptr<CommandMessageTarget> mStatusTarget;
std::shared_ptr<CommandMessageTarget> mErrorTarget; std::shared_ptr<CommandMessageTarget> mErrorTarget;
@ -215,4 +215,11 @@ public:
} }
}; };
class InteractiveOutputTarget : public CommandOutputTarget
{
public:
InteractiveOutputTarget();
};
#endif /* End of include guard: __COMMANDTARGETS__ */ #endif /* End of include guard: __COMMANDTARGETS__ */

View File

@ -51,10 +51,11 @@ enum {
}; };
const int nFormats =2; const int nFormats =3;
static const wxString kFormats[nFormats] = static const wxString kFormats[nFormats] =
{ {
XO("JSON"), XO("JSON"),
XO("LISP"),
XO("Other") XO("Other")
}; };
@ -80,8 +81,8 @@ void GetInfoCommand::PopulateOrExchange(ShuttleGui & S)
S.StartMultiColumn(2, wxALIGN_CENTER); S.StartMultiColumn(2, wxALIGN_CENTER);
{ {
S.TieChoice( _("Types:"), mInfoType, &types); S.TieChoice( _("Type:"), mInfoType, &types);
S.TieChoice( _("Formats:"), mFormat, &formats); S.TieChoice( _("Format:"), mFormat, &formats);
} }
S.EndMultiColumn(); S.EndMultiColumn();
} }

View File

@ -139,6 +139,7 @@
<ClCompile Include="..\..\..\src\blockfile\NotYetAvailableException.cpp" /> <ClCompile Include="..\..\..\src\blockfile\NotYetAvailableException.cpp" />
<ClCompile Include="..\..\..\src\commands\AudacityCommand.cpp" /> <ClCompile Include="..\..\..\src\commands\AudacityCommand.cpp" />
<ClCompile Include="..\..\..\src\commands\CommandContext.cpp" /> <ClCompile Include="..\..\..\src\commands\CommandContext.cpp" />
<ClCompile Include="..\..\..\src\commands\CommandTargets.cpp" />
<ClCompile Include="..\..\..\src\commands\Demo.cpp" /> <ClCompile Include="..\..\..\src\commands\Demo.cpp" />
<ClCompile Include="..\..\..\src\commands\LoadCommands.cpp" /> <ClCompile Include="..\..\..\src\commands\LoadCommands.cpp" />
<ClCompile Include="..\..\..\src\commands\OpenSaveCommands.cpp" /> <ClCompile Include="..\..\..\src\commands\OpenSaveCommands.cpp" />

View File

@ -1064,6 +1064,9 @@
<ClCompile Include="..\..\..\src\commands\SetTrackInfoCommand.cpp"> <ClCompile Include="..\..\..\src\commands\SetTrackInfoCommand.cpp">
<Filter>src\commands</Filter> <Filter>src\commands</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\src\commands\CommandTargets.cpp">
<Filter>src\commands</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\src\AboutDialog.h"> <ClInclude Include="..\..\..\src\AboutDialog.h">