Audacity 3.2.0
wxCommandTargets.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity - A Digital Audio Editor
4 Copyright 1999-2009 Audacity Team
5 License: wxwidgets
6
7 Dan Horgan
8
9 Paul Licameli split from CommandTargets.cpp
10
11******************************************************************//*******************************************************************/
25#include "wxCommandTargets.h"
26
27#include <wx/app.h>
28#include <wx/statusbr.h>
29#include <wx/textctrl.h>
30#include "ShuttleGui.h"
31#include "CommandContext.h"
32#include "BasicUI.h"
33#include "wxPanelWrapper.h"
34
35#include <locale>
36#include <sstream>
37
38#if 0
39GUIProgressTarget::~GUIProgressTarget() = default;
40#endif
41
42class AUDACITY_DLL_API LongMessageDialog /* not final */ : public wxDialogWrapper
43{
44public:
45 // constructors and destructors
46 LongMessageDialog(wxWindow * parent,
48 int type = 0,
49 int flags = wxDEFAULT_DIALOG_STYLE,
50 int additionalButtons = 0);
52
53 bool Init();
54 virtual void OnOk(wxCommandEvent & evt);
55 virtual void OnCancel(wxCommandEvent & evt);
56
57 static void AcceptText( const wxString & Text );
58 static void Flush();
59
60 wxTextCtrl * mTextCtrl;
61 wxString mText;
63private:
64 int mType;
66
67 DECLARE_EVENT_TABLE()
68 wxDECLARE_NO_COPY_CLASS(LongMessageDialog);
69};
70
72
73BEGIN_EVENT_TABLE(LongMessageDialog, wxDialogWrapper)
74 EVT_BUTTON(wxID_OK, LongMessageDialog::OnOk)
76
79 int type,
80 int flags,
81 int additionalButtons)
82: wxDialogWrapper(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, flags | wxRESIZE_BORDER)
83{
84 mType = type;
85 mAdditionalButtons = additionalButtons;
86 SetName(XO("Long Message"));
87 // The long message adds lots of short strings onto this one.
88 // So preallocate to make it faster.
89 // Needs 37Kb for all commands.
90 mText.Alloc(40000);
91}
92
94 pDlg = NULL;
95}
96
98{
100
101 S.SetBorder(5);
102 S.StartVerticalLay(true);
103 {
104 mTextCtrl = S.AddTextWindow( "" );
105 long buttons = eOkButton;
106 S.AddStandardButtons(buttons|mAdditionalButtons);
107 }
108 S.EndVerticalLay();
109
110 Layout();
111 Fit();
112 SetMinSize(wxSize(600,350));
113 Center();
114 return true;
115}
116
117void LongMessageDialog::OnOk(wxCommandEvent & WXUNUSED(evt)){
118 //Close(true);
119 Destroy();
120}
121
122void LongMessageDialog::OnCancel(wxCommandEvent & WXUNUSED(evt)){
123 //Close(true);
124 Destroy();
125}
126
127void LongMessageDialog::AcceptText( const wxString & Text )
128{
129 if( pDlg == NULL ){
130 pDlg = new LongMessageDialog(
131 wxTheApp->GetTopWindow(), XO( "Long Message" ) );
132 pDlg->Init();
133 pDlg->Show();
134 }
135 pDlg->mText = pDlg->mText + Text;
136}
137
139{
140 if( pDlg ){
141 if( !pDlg->mText.EndsWith( "\n\n" ))
142 {
143 pDlg->mText += "\n\n";
144 pDlg->mTextCtrl->SetValue( pDlg->mText );
145 pDlg->mTextCtrl->ShowPosition( pDlg->mTextCtrl->GetLastPosition() );
146 }
147 }
148}
149
155{
156public:
157 virtual ~MessageDialogTarget() {Flush();}
158 void Update(const wxString &message) override
159 {
161 }
162 void Flush() override
163 {
165 }
166};
167
169class ExtTargetFactory final : public TargetFactory
170{
171public:
172 static std::shared_ptr<CommandMessageTarget> LongMessages()
173 {
174 return std::make_shared<MessageDialogTarget>();
175 }
176};
177
178namespace {
181 ExtTargetFactory::ProgressDefault(),
182 ExtTargetFactory::LongMessages(),
183 ExtTargetFactory::MessageDefault()
184 } {}
185};
186
187// Inject a substitute factory
188static CommandContext::TargetFactory::SubstituteInUnique<
191}
192
194
195void StatusBarTarget::Update(const wxString &message)
196{
197 mStatus.SetStatusText(message, 0);
198}
Toolkit-neutral facade for basic user interface services.
END_EVENT_TABLE()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
XO("Cut/Copy/Paste")
static const auto title
@ eIsCreating
Definition: ShuttleGui.h:37
@ eOkButton
Definition: ShuttleGui.h:609
#define S(N)
Definition: ToChars.cpp:64
Interface for objects that can receive (string) messages from a command.
CommandOutputTargets a mix of three output classes to output progress indication, status messages and...
Extended Target Factory with more options.
static std::shared_ptr< CommandMessageTarget > LongMessages()
InteractiveOutputTargets is an output target that pops up a dialog, if necessary.
LongMessageDialog is a dialog with a Text Window in it to capture the more lengthy output from some c...
static LongMessageDialog * pDlg
wxTextCtrl * mTextCtrl
static void AcceptText(const wxString &Text)
virtual void OnOk(wxCommandEvent &evt)
virtual void OnCancel(wxCommandEvent &evt)
MessageDialogTarget is a CommandOutputTarget that sends its status to the LongMessageDialog.
void Update(const wxString &message) override
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
~StatusBarTarget() override
void Update(const wxString &message) override
TargetFactory makes Command output targets. By default, we ignore progress updates but display all ot...
Holds a msgid for the translation catalog; may also bind format arguments.
static CommandContext::TargetFactory::SubstituteInUnique< InteractiveOutputTargets > scope