1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-23 17:30:17 +01:00

Bug 2296 - There is no Import or Export for Macros

This commit is contained in:
Leland Lucius
2020-08-08 21:17:14 -05:00
parent c13a074cb2
commit 52b15ce03f
4 changed files with 113 additions and 20 deletions

View File

@@ -164,7 +164,7 @@ int MacroCommands::GetCount()
return (int)mCommandMacro.size();
}
bool MacroCommands::ReadMacro(const wxString & macro)
wxString MacroCommands::ReadMacro(const wxString & macro, wxWindow *parent)
{
// Clear any previous macro
ResetMacro();
@@ -172,6 +172,38 @@ bool MacroCommands::ReadMacro(const wxString & macro)
// Build the filename
wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
// But, ask the user for the real name if we're importing
if (parent) {
FilePath fn = FileNames::SelectFile(FileNames::Operation::_None,
XO("Import Macro"),
wxEmptyString,
name.GetName(),
wxT("txt"),
{ FileNames::TextFiles },
wxFD_OPEN | wxRESIZE_BORDER,
parent);
// User canceled...
if (fn.empty()) {
return wxEmptyString;
}
wxFileName check(fn);
check.SetPath(name.GetPath());
if (check.FileExists())
{
int id = AudacityMessageBox(
XO("Macro %s already exists. Would you like to replace it?").Format(check.GetName()),
XO("Import Macro"),
wxYES_NO);
if (id == wxNO) {
return wxEmptyString;
}
}
name.Assign(fn);
}
// Set the file name
wxTextFile tf(name.GetFullPath());
@@ -179,7 +211,7 @@ bool MacroCommands::ReadMacro(const wxString & macro)
tf.Open();
if (!tf.IsOpened()) {
// wxTextFile will display any errors
return false;
return wxEmptyString;
}
// Load commands from the file
@@ -206,15 +238,38 @@ bool MacroCommands::ReadMacro(const wxString & macro)
// Done with the file
tf.Close();
return true;
// Write to macro directory if importing
if (parent) {
return WriteMacro(name.GetName());
}
return name.GetName();
}
bool MacroCommands::WriteMacro(const wxString & macro)
wxString MacroCommands::WriteMacro(const wxString & macro, wxWindow *parent)
{
// Build the filename
// Build the default filename
wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
// But, ask the user for the real name if we're exporting
if (parent) {
FilePath fn = FileNames::SelectFile(FileNames::Operation::_None,
XO("Export Macro"),
wxEmptyString,
name.GetName(),
wxT("txt"),
{ FileNames::TextFiles },
wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
parent);
// User canceled...
if (fn.empty()) {
return wxEmptyString;
}
name.Assign(fn);
}
// Set the file name
wxTextFile tf(name.GetFullPath());
@@ -228,7 +283,7 @@ bool MacroCommands::WriteMacro(const wxString & macro)
if (!tf.IsOpened()) {
// wxTextFile will display any errors
return false;
return wxEmptyString;
}
// Start with a clean slate
@@ -247,7 +302,7 @@ bool MacroCommands::WriteMacro(const wxString & macro)
// Done with the file
tf.Close();
return true;
return name.GetName();
}
bool MacroCommands::AddMacro(const wxString & macro)