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 "MenuRegistry.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;
74 // Error check?
76 }
77 else
78 {
79 ProjectManager::ProjectChooser chooser{ &context.project, true };
81 std::ref(chooser), mFileName, mbAddToHistory))
82 chooser.Commit();
83 }
84 const auto &newFileName = projectFileIO.GetFileName();
85
86 // Because Open does not return a success or failure, we have to guess
87 // at this point, based on whether the project file name has
88 // changed and what to...
89 return !newFileName.empty() && newFileName != oldFileName;
90}
91
93{ XO("Save Project2") };
94
96
97template<bool Const>
99 S.Define( mFileName, wxT("Filename"), wxString{"name.aup3"} );
100 S.Define( mbAddToHistory, wxT("AddToHistory"), false );
101 return true;
102}
103
105 { return VisitSettings<false>(S); }
106
108 { return VisitSettings<true>(S); }
109
111{
112 S.AddSpace(0, 5);
113
114 S.StartMultiColumn(2, wxALIGN_CENTER);
115 {
116 S.TieTextBox(XXO("File Name:"),mFileName);
117 S.TieCheckBox(XXO("Add to History"), mbAddToHistory );
118 }
119 S.EndMultiColumn();
120}
121
123{
124 auto &projectFileManager = ProjectFileManager::Get( context.project );
125 if ( mFileName.empty() )
126 return projectFileManager.SaveAs();
127 else
128 return projectFileManager.SaveAs(mFileName, mbAddToHistory);
129}
130
132{ XO("Save Copy") };
133
135
136template<bool Const>
138 S.Define( mFileName, wxT("Filename"), wxString{"name.aup3"} );
139 return true;
140}
141
143 { return VisitSettings<false>(S); }
144
146 { return VisitSettings<true>(S); }
147
149{
150 S.AddSpace(0, 5);
151
152 S.StartMultiColumn(2, wxALIGN_CENTER);
153 {
154 S.TieTextBox(XXO("File Name:"),mFileName);
155 }
156 S.EndMultiColumn();
157}
158
160{
161 auto &projectFileManager = ProjectFileManager::Get( context.project );
162 return projectFileManager.SaveCopy(mFileName);
163}
164
166{ XO("Save Log") };
167
169
170template<bool Const>
172{
173 S.Define( mFileName, wxT("Filename"), wxString{"log.txt"} );
174 return true;
175}
176
178 { return VisitSettings<false>(S); }
179
181 { return VisitSettings<true>(S); }
182
184{
185 S.AddSpace(0, 5);
186
187 S.StartMultiColumn(2, wxALIGN_CENTER);
188 {
189 S.TieTextBox(XXO("File Name:"),mFileName);
190 }
191 S.EndMultiColumn();
192}
193
195{
196 auto logger = AudacityLogger::Get();
197 return logger->SaveLog(mFileName);
198}
199
201{ XO("Clear Log") };
202
204
205template<bool Const>
207{
208 return true;
209}
210
212 { return VisitSettings<false>(S); }
213
215 { return VisitSettings<true>(S); }
216
217bool ClearLogCommand::PromptUser(wxWindow *parent)
218{
219 return true;
220}
221
223{
224 auto logger = AudacityLogger::Get();
225 return logger->ClearLog();
226}
227
228namespace {
229using namespace MenuRegistry;
230
231// Register menu items
232
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 wxT("Optional/Extra/Part2/Scriptables2")
245};
246}
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)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
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:640
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
constexpr auto Items
Definition: MenuRegistry.h:427
constexpr auto Command
Definition: MenuRegistry.h:456
BuiltinCommandsModule::Registration< OpenProjectCommand > reg
BuiltinCommandsModule::Registration< SaveLogCommand > reg4
BuiltinCommandsModule::Registration< ClearLogCommand > reg5
BuiltinCommandsModule::Registration< SaveCopyCommand > reg3
BuiltinCommandsModule::Registration< SaveProjectCommand > reg2