Audacity 3.2.0
OpenSaveCommands.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity - A Digital Audio Editor
4 Copyright 1999-2018 Audacity Team
5 File License: wxWidgets
6
7 Stephen Parry
8 James Crook
9
10******************************************************************//*******************************************************************/
16
17
18#include "OpenSaveCommands.h"
19
20#include "CommandDispatch.h"
21#include "CommandManager.h"
22#include "../CommonCommandFlags.h"
23#include "LoadCommands.h"
24#include "AudacityLogger.h"
25#include "Project.h"
26#include "ProjectFileIO.h"
27#include "../ProjectFileManager.h"
28#include "../ProjectManager.h"
29#include "Export.h"
30#include "SettingsVisitor.h"
31#include "ShuttleGui.h"
32#include "CommandContext.h"
33
34
36{ XO("Open Project2") };
37
39
40template<bool Const>
42 S.Define( mFileName, wxT("Filename"), wxString{"test.aup3"} );
43 S.OptionalN(bHasAddToHistory).Define( mbAddToHistory, wxT("AddToHistory"), false );
44 return true;
45}
46
48 { return VisitSettings<false>(S); }
49
51 { return VisitSettings<true>(S); }
52
54{
55 S.AddSpace(0, 5);
56
57 S.StartMultiColumn(2, wxALIGN_CENTER);
58 {
59 S.TieTextBox(XXO("File Name:"),mFileName);
60 S.TieCheckBox(XXO("Add to History"), mbAddToHistory );
61 }
62 S.EndMultiColumn();
63}
64
66
67 auto &projectFileIO = ProjectFileIO::Get(context.project);
68
69 auto oldFileName = projectFileIO.GetFileName();
70 if(mFileName.empty())
71 {
72 // This path queries the user for files to open
73 auto project = &context.project;
75 }
76 else
77 {
78 ProjectManager::ProjectChooser chooser{ &context.project, true };
80 std::ref(chooser), mFileName, mbAddToHistory))
81 chooser.Commit();
82 }
83 const auto &newFileName = projectFileIO.GetFileName();
84
85 // Because Open does not return a success or failure, we have to guess
86 // at this point, based on whether the project file name has
87 // changed and what to...
88 return !newFileName.empty() && newFileName != oldFileName;
89}
90
92{ XO("Save Project2") };
93
95
96template<bool Const>
98 S.Define( mFileName, wxT("Filename"), wxString{"name.aup3"} );
99 S.Define( mbAddToHistory, wxT("AddToHistory"), false );
100 return true;
101}
102
104 { return VisitSettings<false>(S); }
105
107 { return VisitSettings<true>(S); }
108
110{
111 S.AddSpace(0, 5);
112
113 S.StartMultiColumn(2, wxALIGN_CENTER);
114 {
115 S.TieTextBox(XXO("File Name:"),mFileName);
116 S.TieCheckBox(XXO("Add to History"), mbAddToHistory );
117 }
118 S.EndMultiColumn();
119}
120
122{
123 auto &projectFileManager = ProjectFileManager::Get( context.project );
124 if ( mFileName.empty() )
125 return projectFileManager.SaveAs();
126 else
127 return projectFileManager.SaveAs(mFileName, mbAddToHistory);
128}
129
131{ XO("Save Copy") };
132
134
135template<bool Const>
137 S.Define( mFileName, wxT("Filename"), wxString{"name.aup3"} );
138 return true;
139}
140
142 { return VisitSettings<false>(S); }
143
145 { return VisitSettings<true>(S); }
146
148{
149 S.AddSpace(0, 5);
150
151 S.StartMultiColumn(2, wxALIGN_CENTER);
152 {
153 S.TieTextBox(XXO("File Name:"),mFileName);
154 }
155 S.EndMultiColumn();
156}
157
159{
160 auto &projectFileManager = ProjectFileManager::Get( context.project );
161 return projectFileManager.SaveCopy(mFileName);
162}
163
165{ XO("Save Log") };
166
168
169template<bool Const>
171{
172 S.Define( mFileName, wxT("Filename"), wxString{"log.txt"} );
173 return true;
174}
175
177 { return VisitSettings<false>(S); }
178
180 { return VisitSettings<true>(S); }
181
183{
184 S.AddSpace(0, 5);
185
186 S.StartMultiColumn(2, wxALIGN_CENTER);
187 {
188 S.TieTextBox(XXO("File Name:"),mFileName);
189 }
190 S.EndMultiColumn();
191}
192
194{
195 auto logger = AudacityLogger::Get();
196 return logger->SaveLog(mFileName);
197}
198
200{ XO("Clear Log") };
201
203
204template<bool Const>
206{
207 return true;
208}
209
211 { return VisitSettings<false>(S); }
212
214 { return VisitSettings<true>(S); }
215
216bool ClearLogCommand::PromptUser(wxWindow *parent)
217{
218 return true;
219}
220
222{
223 auto logger = AudacityLogger::Get();
224 return logger->ClearLog();
225}
226
227namespace {
228using namespace MenuTable;
229
230// Register menu items
231
233 wxT("Optional/Extra/Part2/Scriptables2"),
234 Items( wxT(""),
235 // Note that the PLUGIN_SYMBOL must have a space between words,
236 // whereas the short-form used here must not.
237 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
238 // you would have to use "CompareAudio" here.)
239 Command( wxT("OpenProject2"), XXO("Open Project..."),
241 Command( wxT("SaveProject2"), XXO("Save Project..."),
243 )
244};
245}
wxT("CloseDown"))
const ReservedCommandFlag & AudioIONotBusyFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
const auto project
#define S(N)
Definition: ToChars.cpp:64
static AudacityLogger * Get()
bool VisitSettings(SettingsVisitorBase< Const > &S)
bool Apply(const CommandContext &context) override
static const ComponentInterfaceSymbol Symbol
bool PromptUser(wxWindow *parent) override
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
bool VisitSettings(SettingsVisitorBase< Const > &S)
bool Apply(const CommandContext &context) override
static const ComponentInterfaceSymbol Symbol
void PopulateOrExchange(ShuttleGui &S) override
static ProjectFileIO & Get(AudacityProject &project)
static AudacityProject * OpenFile(const ProjectChooserFn &chooser, const FilePath &fileName, bool addtohistory=true)
static ProjectFileManager & Get(AudacityProject &project)
Callable object that supplies the chooser argument of ProjectFileManager::OpenFile.
static void OpenFiles(AudacityProject *proj)
static const ComponentInterfaceSymbol Symbol
bool VisitSettings(SettingsVisitorBase< Const > &S)
void PopulateOrExchange(ShuttleGui &S) override
bool Apply(const CommandContext &context) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
bool Apply(const CommandContext &context) override
static const ComponentInterfaceSymbol Symbol
void PopulateOrExchange(ShuttleGui &S) override
void PopulateOrExchange(ShuttleGui &S) override
static const ComponentInterfaceSymbol Symbol
bool VisitSettings(SettingsVisitorBase< Const > &S)
bool Apply(const CommandContext &context) override
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:630
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
constexpr auto Items
constexpr auto Command
BuiltinCommandsModule::Registration< OpenProjectCommand > reg
BuiltinCommandsModule::Registration< SaveLogCommand > reg4
BuiltinCommandsModule::Registration< ClearLogCommand > reg5
BuiltinCommandsModule::Registration< SaveCopyCommand > reg3
BuiltinCommandsModule::Registration< SaveProjectCommand > reg2