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 ******************************************************************//**
11
12 \file OpenSaveCommands.cpp
13 \brief Contains definitions for the OpenProjectCommand and SaveProjectCommand classes
14
15 *//*******************************************************************/
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
32 const ComponentInterfaceSymbol OpenProjectCommand::Symbol
33 { XO("Open Project2") };
34
35 namespace{ BuiltinCommandsModule::Registration< OpenProjectCommand > reg; }
36
DefineParams(ShuttleParams & S)37 bool OpenProjectCommand::DefineParams( ShuttleParams & S ){
38 S.Define( mFileName, wxT("Filename"), "test.aup3" );
39 S.OptionalN(bHasAddToHistory).Define( mbAddToHistory, wxT("AddToHistory"), false );
40 return true;
41 }
42
PopulateOrExchange(ShuttleGui & S)43 void OpenProjectCommand::PopulateOrExchange(ShuttleGui & S)
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
Apply(const CommandContext & context)55 bool OpenProjectCommand::Apply(const CommandContext & context){
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;
64 ProjectManager::OpenFiles(project);
65 }
66 else
67 {
68 ProjectManager::ProjectChooser chooser{ &context.project, true };
69 if(ProjectFileManager::OpenFile(
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
81 const ComponentInterfaceSymbol SaveProjectCommand::Symbol
82 { XO("Save Project2") };
83
84 namespace{ BuiltinCommandsModule::Registration< SaveProjectCommand > reg2; }
85
DefineParams(ShuttleParams & S)86 bool SaveProjectCommand::DefineParams( ShuttleParams & S ){
87 S.Define( mFileName, wxT("Filename"), "name.aup3" );
88 S.Define( mbAddToHistory, wxT("AddToHistory"), false );
89 return true;
90 }
91
PopulateOrExchange(ShuttleGui & S)92 void SaveProjectCommand::PopulateOrExchange(ShuttleGui & S)
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
Apply(const CommandContext & context)104 bool SaveProjectCommand::Apply(const CommandContext &context)
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
113 const ComponentInterfaceSymbol SaveCopyCommand::Symbol
114 { XO("Save Copy") };
115
116 namespace{ BuiltinCommandsModule::Registration< SaveCopyCommand > reg3; }
117
DefineParams(ShuttleParams & S)118 bool SaveCopyCommand::DefineParams( ShuttleParams & S ){
119 S.Define( mFileName, wxT("Filename"), "name.aup3" );
120 return true;
121 }
122
PopulateOrExchange(ShuttleGui & S)123 void SaveCopyCommand::PopulateOrExchange(ShuttleGui & S)
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
Apply(const CommandContext & context)134 bool SaveCopyCommand::Apply(const CommandContext &context)
135 {
136 auto &projectFileManager = ProjectFileManager::Get( context.project );
137 return projectFileManager.SaveCopy(mFileName);
138 }
139
140 const ComponentInterfaceSymbol SaveLogCommand::Symbol
141 { XO("Save Log") };
142
143 namespace{ BuiltinCommandsModule::Registration< SaveLogCommand > reg4; }
144
DefineParams(ShuttleParams & S)145 bool SaveLogCommand::DefineParams(ShuttleParams & S)
146 {
147 S.Define( mFileName, wxT("Filename"), "log.txt" );
148 return true;
149 }
150
PopulateOrExchange(ShuttleGui & S)151 void SaveLogCommand::PopulateOrExchange(ShuttleGui & S)
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
Apply(const CommandContext & context)162 bool SaveLogCommand::Apply(const CommandContext &context)
163 {
164 auto logger = AudacityLogger::Get();
165 return logger->SaveLog(mFileName);
166 }
167
168 const ComponentInterfaceSymbol ClearLogCommand::Symbol
169 { XO("Clear Log") };
170
171 namespace{ BuiltinCommandsModule::Registration< ClearLogCommand > reg5; }
172
DefineParams(ShuttleParams & S)173 bool ClearLogCommand::DefineParams(ShuttleParams & S)
174 {
175 return true;
176 }
177
PromptUser(wxWindow * parent)178 bool ClearLogCommand::PromptUser(wxWindow *parent)
179 {
180 return true;
181 }
182
Apply(const CommandContext & context)183 bool ClearLogCommand::Apply(const CommandContext &context)
184 {
185 auto logger = AudacityLogger::Get();
186 return logger->ClearLog();
187 }
188