Audacity  3.0.3
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 "LoadCommands.h"
21 #include "AudacityLogger.h"
22 #include "Project.h"
23 #include "../ProjectFileIO.h"
24 #include "../ProjectFileManager.h"
25 #include "../ProjectManager.h"
26 #include "../export/Export.h"
27 #include "../Shuttle.h"
28 #include "../ShuttleGui.h"
29 #include "CommandContext.h"
30 
31 
33 { XO("Open Project2") };
34 
36 
38  S.Define( mFileName, wxT("Filename"), "test.aup3" );
39  S.OptionalN(bHasAddToHistory).Define( mbAddToHistory, wxT("AddToHistory"), false );
40  return true;
41 }
42 
44 {
45  S.AddSpace(0, 5);
46 
47  S.StartMultiColumn(2, wxALIGN_CENTER);
48  {
49  S.TieTextBox(XXO("File Name:"),mFileName);
50  S.TieCheckBox(XXO("Add to History"), mbAddToHistory );
51  }
52  S.EndMultiColumn();
53 }
54 
56 
57  auto &projectFileIO = ProjectFileIO::Get(context.project);
58 
59  auto oldFileName = projectFileIO.GetFileName();
60  if(mFileName.empty())
61  {
62  // This path queries the user for files to open
63  auto project = &context.project;
65  }
66  else
67  {
68  ProjectManager::ProjectChooser chooser{ &context.project, true };
70  std::ref(chooser), mFileName, mbAddToHistory))
71  chooser.Commit();
72  }
73  const auto &newFileName = projectFileIO.GetFileName();
74 
75  // Because Open does not return a success or failure, we have to guess
76  // at this point, based on whether the project file name has
77  // changed and what to...
78  return !newFileName.empty() && newFileName != oldFileName;
79 }
80 
82 { XO("Save Project2") };
83 
85 
87  S.Define( mFileName, wxT("Filename"), "name.aup3" );
88  S.Define( mbAddToHistory, wxT("AddToHistory"), false );
89  return true;
90 }
91 
93 {
94  S.AddSpace(0, 5);
95 
96  S.StartMultiColumn(2, wxALIGN_CENTER);
97  {
98  S.TieTextBox(XXO("File Name:"),mFileName);
99  S.TieCheckBox(XXO("Add to History"), mbAddToHistory );
100  }
101  S.EndMultiColumn();
102 }
103 
105 {
106  auto &projectFileManager = ProjectFileManager::Get( context.project );
107  if ( mFileName.empty() )
108  return projectFileManager.SaveAs();
109  else
110  return projectFileManager.SaveAs(mFileName, mbAddToHistory);
111 }
112 
114 { XO("Save Copy") };
115 
117 
119  S.Define( mFileName, wxT("Filename"), "name.aup3" );
120  return true;
121 }
122 
124 {
125  S.AddSpace(0, 5);
126 
127  S.StartMultiColumn(2, wxALIGN_CENTER);
128  {
129  S.TieTextBox(XXO("File Name:"),mFileName);
130  }
131  S.EndMultiColumn();
132 }
133 
135 {
136  auto &projectFileManager = ProjectFileManager::Get( context.project );
137  return projectFileManager.SaveCopy(mFileName);
138 }
139 
141 { XO("Save Log") };
142 
144 
146 {
147  S.Define( mFileName, wxT("Filename"), "log.txt" );
148  return true;
149 }
150 
152 {
153  S.AddSpace(0, 5);
154 
155  S.StartMultiColumn(2, wxALIGN_CENTER);
156  {
157  S.TieTextBox(XXO("File Name:"),mFileName);
158  }
159  S.EndMultiColumn();
160 }
161 
163 {
164  auto logger = AudacityLogger::Get();
165  return logger->SaveLog(mFileName);
166 }
167 
169 { XO("Clear Log") };
170 
172 
174 {
175  return true;
176 }
177 
178 bool ClearLogCommand::PromptUser(wxWindow *parent)
179 {
180  return true;
181 }
182 
184 {
185  auto logger = AudacityLogger::Get();
186  return logger->ClearLog();
187 }
SaveProjectCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: OpenSaveCommands.cpp:86
anonymous_namespace{OpenSaveCommands.cpp}::reg2
BuiltinCommandsModule::Registration< SaveProjectCommand > reg2
Definition: OpenSaveCommands.cpp:84
anonymous_namespace{OpenSaveCommands.cpp}::reg5
BuiltinCommandsModule::Registration< ClearLogCommand > reg5
Definition: OpenSaveCommands.cpp:171
LoadCommands.h
Project.h
OpenProjectCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: OpenSaveCommands.h:33
OpenProjectCommand::bHasAddToHistory
bool bHasAddToHistory
Definition: OpenSaveCommands.h:47
SaveProjectCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: OpenSaveCommands.h:53
ShuttleGuiBase::TieCheckBox
wxCheckBox * TieCheckBox(const TranslatableString &Prompt, bool &Var)
Definition: ShuttleGui.cpp:1629
ProjectFileManager::OpenFile
static AudacityProject * OpenFile(const ProjectChooserFn &chooser, const FilePath &fileName, bool addtohistory=true)
Definition: ProjectFileManager.cpp:869
ProjectManager::ProjectChooser
Callable object that supplies the chooser argument of ProjectFileManager::OpenFile.
Definition: ProjectManager.h:63
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2459
OpenProjectCommand::mFileName
wxString mFileName
Definition: OpenSaveCommands.h:45
XO
#define XO(s)
Definition: Internat.h:31
ProjectFileIO::Get
static ProjectFileIO & Get(AudacityProject &project)
Definition: ProjectFileIO.cpp:266
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:62
OpenProjectCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: OpenSaveCommands.cpp:43
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
ClearLogCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: OpenSaveCommands.cpp:173
OpenProjectCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: OpenSaveCommands.cpp:37
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
SaveCopyCommand::mFileName
wxString mFileName
Definition: OpenSaveCommands.h:85
ShuttleParams::OptionalN
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:72
ShuttleGuiBase::TieTextBox
wxTextCtrl * TieTextBox(const TranslatableString &Caption, wxString &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1652
ClearLogCommand::Apply
bool Apply(const CommandContext &context) override
Definition: OpenSaveCommands.cpp:183
BuiltinCommandsModule::Registration
Definition: LoadCommands.h:41
anonymous_namespace{OpenSaveCommands.cpp}::reg3
BuiltinCommandsModule::Registration< SaveCopyCommand > reg3
Definition: OpenSaveCommands.cpp:116
CommandContext.h
XXO
#define XXO(s)
Definition: Internat.h:44
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:34
ProjectFileManager::Get
static ProjectFileManager & Get(AudacityProject &project)
Definition: ProjectFileManager.cpp:66
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
SaveCopyCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: OpenSaveCommands.cpp:118
SaveLogCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: OpenSaveCommands.h:91
AudacityLogger::Get
static AudacityLogger * Get()
Definition: AudacityLogger.cpp:35
SaveLogCommand::Apply
bool Apply(const CommandContext &context) override
Definition: OpenSaveCommands.cpp:162
SaveCopyCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: OpenSaveCommands.cpp:123
OpenProjectCommand::Apply
bool Apply(const CommandContext &context) override
Definition: OpenSaveCommands.cpp:55
AudacityLogger.h
SaveCopyCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: OpenSaveCommands.h:73
SaveProjectCommand::mbAddToHistory
bool mbAddToHistory
Definition: OpenSaveCommands.h:66
SaveProjectCommand::Apply
bool Apply(const CommandContext &context) override
Definition: OpenSaveCommands.cpp:104
ClearLogCommand::PromptUser
bool PromptUser(wxWindow *parent) override
Definition: OpenSaveCommands.cpp:178
anonymous_namespace{OpenSaveCommands.cpp}::reg4
BuiltinCommandsModule::Registration< SaveLogCommand > reg4
Definition: OpenSaveCommands.cpp:143
SaveProjectCommand::mFileName
wxString mFileName
Definition: OpenSaveCommands.h:65
ProjectManager::OpenFiles
static void OpenFiles(AudacityProject *proj)
Definition: ProjectManager.cpp:866
ClearLogCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: OpenSaveCommands.h:109
SaveProjectCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: OpenSaveCommands.cpp:92
SaveLogCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: OpenSaveCommands.cpp:145
SaveCopyCommand::Apply
bool Apply(const CommandContext &context) override
Definition: OpenSaveCommands.cpp:134
ShuttleParams::Define
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:332
OpenSaveCommands.h
OpenProjectCommand::mbAddToHistory
bool mbAddToHistory
Definition: OpenSaveCommands.h:46
anonymous_namespace{OpenSaveCommands.cpp}::reg
BuiltinCommandsModule::Registration< OpenProjectCommand > reg
Definition: OpenSaveCommands.cpp:35
SaveLogCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: OpenSaveCommands.cpp:151
CommandContext::project
AudacityProject & project
Definition: CommandContext.h:64
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
SaveLogCommand::mFileName
wxString mFileName
Definition: OpenSaveCommands.h:103