1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 16:49:41 +02:00

Use names not numbers in MacroIdOfName()

Previously the ID for a macro was, e.g. Macro003.  However this would
not work if macros were added or deleted, since chains containing the old
macro references would now refer to a different macro.  So changed to using
names.
This commit is contained in:
James Crook 2018-03-04 19:02:22 +00:00
parent 585a4c6170
commit 70b1f69bbe
3 changed files with 32 additions and 1 deletions

View File

@ -192,6 +192,27 @@ void ApplyMacroDialog::OnApplyToProject(wxCommandEvent & WXUNUSED(event))
ApplyMacroToProject( item );
}
wxString ApplyMacroDialog::MacroIdOfName( const wxString & MacroName )
{
wxString Temp = MacroName;
Temp.Replace(" ","");
Temp = wxString( "Macro_" ) + Temp;
return Temp;
}
// Does nothing if not found, rather than returning an error.
void ApplyMacroDialog::ApplyMacroToProject( const wxString & MacroID, bool bHasGui )
{
for( size_t i=0;i<mMacros->GetItemCount();i++){
wxString name = mMacros->GetItemText(i);
if( MacroIdOfName( name ) == MacroID ){
ApplyMacroToProject( i, bHasGui );
return;
}
}
}
void ApplyMacroDialog::ApplyMacroToProject( int iMacro, bool bHasGui )
{
wxString name = mMacros->GetItemText(iMacro);

View File

@ -56,7 +56,9 @@ class ApplyMacroDialog : public wxDialogWrapper {
virtual wxString GetHelpPageName() {return "Tools_Menu#macros_compact_dialog";};
void PopulateMacros();
static wxString MacroIdOfName( const wxString & MacroName );
void ApplyMacroToProject( int iMacro, bool bHasGui=true );
void ApplyMacroToProject( const wxString & MacroID, bool bHasGui=true );
// These will be reused in the derived class...

View File

@ -1713,7 +1713,8 @@ void AudacityProject::PopulateMacrosMenu( CommandManager* c, CommandFlag flags
int i;
for (i = 0; i < (int)names.GetCount(); i++) {
c->AddItem(wxString::Format("Macro%03i", i ), names[i], FN(OnApplyMacroDirectly),
wxString MacroID = ApplyMacroDialog::MacroIdOfName( names[i] );
c->AddItem(MacroID, names[i], FN(OnApplyMacroDirectly),
flags,
flags);
}
@ -6860,10 +6861,17 @@ void AudacityProject::OnApplyMacroDirectly(const CommandContext &context )
//wxLogDebug( "Macro was: %s", context.parameter);
ApplyMacroDialog dlg(this);
wxString Name = context.parameter;
// We used numbers previously, but macros could get renumbered, making
// macros containing macros unpredictable.
#ifdef MACROS_BY_NUMBERS
long item=0;
// Take last three letters (of e.g. Macro007) and convert to a number.
Name.Mid( Name.Length() - 3 ).ToLong( &item, 10 );
dlg.ApplyMacroToProject( item, false );
#else
dlg.ApplyMacroToProject( Name, false );
#endif
ModifyUndoMenuItems();
}