mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-23 15:50:05 +02:00
Bug 2296 - There is no Import or Export for Macros
This commit is contained in:
parent
c13a074cb2
commit
52b15ce03f
@ -164,7 +164,7 @@ int MacroCommands::GetCount()
|
|||||||
return (int)mCommandMacro.size();
|
return (int)mCommandMacro.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MacroCommands::ReadMacro(const wxString & macro)
|
wxString MacroCommands::ReadMacro(const wxString & macro, wxWindow *parent)
|
||||||
{
|
{
|
||||||
// Clear any previous macro
|
// Clear any previous macro
|
||||||
ResetMacro();
|
ResetMacro();
|
||||||
@ -172,6 +172,38 @@ bool MacroCommands::ReadMacro(const wxString & macro)
|
|||||||
// Build the filename
|
// Build the filename
|
||||||
wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
|
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
|
// Set the file name
|
||||||
wxTextFile tf(name.GetFullPath());
|
wxTextFile tf(name.GetFullPath());
|
||||||
|
|
||||||
@ -179,7 +211,7 @@ bool MacroCommands::ReadMacro(const wxString & macro)
|
|||||||
tf.Open();
|
tf.Open();
|
||||||
if (!tf.IsOpened()) {
|
if (!tf.IsOpened()) {
|
||||||
// wxTextFile will display any errors
|
// wxTextFile will display any errors
|
||||||
return false;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load commands from the file
|
// Load commands from the file
|
||||||
@ -206,15 +238,38 @@ bool MacroCommands::ReadMacro(const wxString & macro)
|
|||||||
// Done with the file
|
// Done with the file
|
||||||
tf.Close();
|
tf.Close();
|
||||||
|
|
||||||
return true;
|
// Write to macro directory if importing
|
||||||
|
if (parent) {
|
||||||
|
return WriteMacro(name.GetName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return name.GetName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString MacroCommands::WriteMacro(const wxString & macro, wxWindow *parent)
|
||||||
bool MacroCommands::WriteMacro(const wxString & macro)
|
|
||||||
{
|
{
|
||||||
// Build the filename
|
// Build the default filename
|
||||||
wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
|
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
|
// Set the file name
|
||||||
wxTextFile tf(name.GetFullPath());
|
wxTextFile tf(name.GetFullPath());
|
||||||
|
|
||||||
@ -228,7 +283,7 @@ bool MacroCommands::WriteMacro(const wxString & macro)
|
|||||||
|
|
||||||
if (!tf.IsOpened()) {
|
if (!tf.IsOpened()) {
|
||||||
// wxTextFile will display any errors
|
// wxTextFile will display any errors
|
||||||
return false;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start with a clean slate
|
// Start with a clean slate
|
||||||
@ -247,7 +302,7 @@ bool MacroCommands::WriteMacro(const wxString & macro)
|
|||||||
// Done with the file
|
// Done with the file
|
||||||
tf.Close();
|
tf.Close();
|
||||||
|
|
||||||
return true;
|
return name.GetName();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MacroCommands::AddMacro(const wxString & macro)
|
bool MacroCommands::AddMacro(const wxString & macro)
|
||||||
|
@ -103,8 +103,8 @@ class MacroCommands final {
|
|||||||
void ResetMacro();
|
void ResetMacro();
|
||||||
|
|
||||||
void RestoreMacro(const wxString & name);
|
void RestoreMacro(const wxString & name);
|
||||||
bool ReadMacro(const wxString & macro);
|
wxString ReadMacro(const wxString & macro, wxWindow *parent = nullptr);
|
||||||
bool WriteMacro(const wxString & macro);
|
wxString WriteMacro(const wxString & macro, wxWindow *parent = nullptr);
|
||||||
bool AddMacro(const wxString & macro);
|
bool AddMacro(const wxString & macro);
|
||||||
bool DeleteMacro(const wxString & name);
|
bool DeleteMacro(const wxString & name);
|
||||||
bool RenameMacro(const wxString & oldmacro, const wxString & newmacro);
|
bool RenameMacro(const wxString & oldmacro, const wxString & newmacro);
|
||||||
|
@ -500,6 +500,8 @@ BEGIN_EVENT_TABLE(MacrosWindow, ApplyMacroDialog)
|
|||||||
EVT_BUTTON(RemoveButtonID, MacrosWindow::OnRemove)
|
EVT_BUTTON(RemoveButtonID, MacrosWindow::OnRemove)
|
||||||
EVT_BUTTON(RenameButtonID, MacrosWindow::OnRename)
|
EVT_BUTTON(RenameButtonID, MacrosWindow::OnRename)
|
||||||
EVT_BUTTON(RestoreButtonID, MacrosWindow::OnRestore)
|
EVT_BUTTON(RestoreButtonID, MacrosWindow::OnRestore)
|
||||||
|
EVT_BUTTON(ImportButtonID, MacrosWindow::OnImport)
|
||||||
|
EVT_BUTTON(ExportButtonID, MacrosWindow::OnExport)
|
||||||
EVT_BUTTON(ExpandID, MacrosWindow::OnExpand)
|
EVT_BUTTON(ExpandID, MacrosWindow::OnExpand)
|
||||||
EVT_BUTTON(ShrinkID, MacrosWindow::OnShrink)
|
EVT_BUTTON(ShrinkID, MacrosWindow::OnShrink)
|
||||||
|
|
||||||
@ -603,15 +605,8 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S)
|
|||||||
mRemove = S.Id(RemoveButtonID).AddButton(XXO("Remo&ve"));
|
mRemove = S.Id(RemoveButtonID).AddButton(XXO("Remo&ve"));
|
||||||
mRename = S.Id(RenameButtonID).AddButton(XXO("&Rename..."));
|
mRename = S.Id(RenameButtonID).AddButton(XXO("&Rename..."));
|
||||||
mRestore = S.Id(RestoreButtonID).AddButton(XXO("Re&store"));
|
mRestore = S.Id(RestoreButtonID).AddButton(XXO("Re&store"));
|
||||||
// Not yet ready for prime time.
|
mImport = S.Id(ImportButtonID).AddButton(XO("I&mport..."));
|
||||||
#if 0
|
mExport = S.Id(ExportButtonID).AddButton(XO("E&xport..."));
|
||||||
S.Id(ImportButtonID)
|
|
||||||
.Disable()
|
|
||||||
.AddButton(XO("I&mport..."));
|
|
||||||
S.Id(ExportButtonID)
|
|
||||||
.Disable()
|
|
||||||
.AddButton(XO("E&xport..."));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
S.EndVerticalLay();
|
S.EndVerticalLay();
|
||||||
}
|
}
|
||||||
@ -623,7 +618,6 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S)
|
|||||||
{
|
{
|
||||||
S.StartHorizontalLay(wxEXPAND,1);
|
S.StartHorizontalLay(wxEXPAND,1);
|
||||||
{
|
{
|
||||||
|
|
||||||
mList = S.Id(CommandsListID)
|
mList = S.Id(CommandsListID)
|
||||||
.Style(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
|
.Style(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
|
||||||
wxLC_SINGLE_SEL)
|
wxLC_SINGLE_SEL)
|
||||||
@ -1052,6 +1046,46 @@ void MacrosWindow::OnRestore(wxCommandEvent & WXUNUSED(event))
|
|||||||
PopulateList();
|
PopulateList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
void MacrosWindow::OnImport(wxCommandEvent & WXUNUSED(event))
|
||||||
|
{
|
||||||
|
if (!ChangeOK()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long item = mMacros->GetNextItem(-1,
|
||||||
|
wxLIST_NEXT_ALL,
|
||||||
|
wxLIST_STATE_SELECTED);
|
||||||
|
if (item == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString name = mMacros->GetItemText(item);
|
||||||
|
|
||||||
|
name = mMacroCommands.ReadMacro({}, this);
|
||||||
|
if (name == wxEmptyString) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mActiveMacro = name;
|
||||||
|
|
||||||
|
PopulateMacros();
|
||||||
|
UpdateMenus();
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
void MacrosWindow::OnExport(wxCommandEvent & WXUNUSED(event))
|
||||||
|
{
|
||||||
|
long item = mMacros->GetNextItem(-1,
|
||||||
|
wxLIST_NEXT_ALL,
|
||||||
|
wxLIST_STATE_SELECTED);
|
||||||
|
if (item == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mMacroCommands.WriteMacro(mMacros->GetItemText(item), this);
|
||||||
|
}
|
||||||
|
|
||||||
/// An item in the list has been selected.
|
/// An item in the list has been selected.
|
||||||
/// Bring up a dialog to allow its parameters to be edited.
|
/// Bring up a dialog to allow its parameters to be edited.
|
||||||
void MacrosWindow::OnCommandActivated(wxListEvent & WXUNUSED(event))
|
void MacrosWindow::OnCommandActivated(wxListEvent & WXUNUSED(event))
|
||||||
|
@ -103,6 +103,8 @@ private:
|
|||||||
void OnRemove(wxCommandEvent &event);
|
void OnRemove(wxCommandEvent &event);
|
||||||
void OnRename(wxCommandEvent &event);
|
void OnRename(wxCommandEvent &event);
|
||||||
void OnRestore(wxCommandEvent &event);
|
void OnRestore(wxCommandEvent &event);
|
||||||
|
void OnImport(wxCommandEvent &event);
|
||||||
|
void OnExport(wxCommandEvent &event);
|
||||||
void OnExpand(wxCommandEvent &event);
|
void OnExpand(wxCommandEvent &event);
|
||||||
void OnShrink(wxCommandEvent &event);
|
void OnShrink(wxCommandEvent &event);
|
||||||
void OnSize(wxSizeEvent &event);
|
void OnSize(wxSizeEvent &event);
|
||||||
@ -127,6 +129,8 @@ private:
|
|||||||
wxButton *mRemove;
|
wxButton *mRemove;
|
||||||
wxButton *mRename;
|
wxButton *mRename;
|
||||||
wxButton *mRestore;
|
wxButton *mRestore;
|
||||||
|
wxButton *mImport;
|
||||||
|
wxButton *mExport;
|
||||||
|
|
||||||
int mSelectedCommand;
|
int mSelectedCommand;
|
||||||
bool mChanged;
|
bool mChanged;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user