mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-31 16:09:28 +02:00
Rewrite insertion of menu items by null and Nyquist modules...
... using the new registration system, and without the fragile hacks making assumptions about the positions of menus within the menu bar.
This commit is contained in:
parent
baada94567
commit
56cd24a062
@ -146,33 +146,6 @@ int ModuleDispatch(ModuleDispatchTypes type)
|
|||||||
break;
|
break;
|
||||||
case AppQuiting:
|
case AppQuiting:
|
||||||
break;
|
break;
|
||||||
case ProjectInitialized:
|
|
||||||
case MenusRebuilt:
|
|
||||||
{
|
|
||||||
AudacityProject *p = GetActiveProject();
|
|
||||||
if( p== NULL )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
wxMenuBar * pBar = GetProjectFrame( *p ).GetMenuBar();
|
|
||||||
wxMenu * pMenu = pBar->GetMenu( 8 ); // Menu 8 is the Analyze Menu.
|
|
||||||
CommandManager * c = &CommandManager::Get( *p );
|
|
||||||
|
|
||||||
c->SetCurrentMenu( pMenu );
|
|
||||||
c->AddSeparator();
|
|
||||||
// We add two new commands into the Analyze menu.
|
|
||||||
c->AddItem( *p,
|
|
||||||
_T("A New Command"), // internal name
|
|
||||||
XO("1st Experimental Command..."), //displayed name
|
|
||||||
ident, ModNullFN( OnFuncFirst ),
|
|
||||||
AudioIONotBusyFlag() );
|
|
||||||
c->AddItem( *p,
|
|
||||||
_T("Another New Command"),
|
|
||||||
XO("2nd Experimental Command"),
|
|
||||||
ident, ModNullFN( OnFuncSecond ),
|
|
||||||
AudioIONotBusyFlag() );
|
|
||||||
c->ClearCurrentMenu();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -180,6 +153,26 @@ int ModuleDispatch(ModuleDispatchTypes type)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register our extra menu items
|
||||||
|
namespace {
|
||||||
|
using namespace MenuTable;
|
||||||
|
// We add two new commands into the Analyze menu.
|
||||||
|
AttachedItem sAttachment{ wxT("Analyze"),
|
||||||
|
( FinderScope( ident ), Section( wxT("NullModule"),
|
||||||
|
Command(
|
||||||
|
_T("A New Command"), // internal name
|
||||||
|
XO("1st Experimental Command..."), //displayed name
|
||||||
|
ModNullFN( OnFuncFirst ),
|
||||||
|
AudioIONotBusyFlag() ),
|
||||||
|
Command(
|
||||||
|
_T("Another New Command"),
|
||||||
|
XO("2nd Experimental Command"),
|
||||||
|
ModNullFN( OnFuncSecond ),
|
||||||
|
AudioIONotBusyFlag() )
|
||||||
|
) )
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
//Example code commented out.
|
//Example code commented out.
|
||||||
#if 0
|
#if 0
|
||||||
// This is an example function to hijack the main panel
|
// This is an example function to hijack the main panel
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "effects/nyquist/Nyquist.h"
|
#include "effects/nyquist/Nyquist.h"
|
||||||
#include "../images/AudacityLogo.xpm"
|
#include "../images/AudacityLogo.xpm"
|
||||||
#include "../../src/commands/CommandContext.h"
|
#include "../../src/commands/CommandContext.h"
|
||||||
|
#include "../../src/commands/CommandManager.h"
|
||||||
#include "widgets/AudacityMessageBox.h"
|
#include "widgets/AudacityMessageBox.h"
|
||||||
|
|
||||||
#include "NyqBench.h"
|
#include "NyqBench.h"
|
||||||
@ -167,8 +168,7 @@ extern "C"
|
|||||||
|
|
||||||
extern int DLL_API ModuleDispatch(ModuleDispatchTypes type);
|
extern int DLL_API ModuleDispatch(ModuleDispatchTypes type);
|
||||||
// ModuleDispatch
|
// ModuleDispatch
|
||||||
// is called by Audacity to initialize/terminmate the module,
|
// is called by Audacity to initialize/terminate the module
|
||||||
// and ask if it has anything for the menus.
|
|
||||||
int ModuleDispatch(ModuleDispatchTypes type){
|
int ModuleDispatch(ModuleDispatchTypes type){
|
||||||
switch (type){
|
switch (type){
|
||||||
case AppQuiting: {
|
case AppQuiting: {
|
||||||
@ -181,29 +181,6 @@ extern "C"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ProjectInitialized:
|
|
||||||
case MenusRebuilt: {
|
|
||||||
AudacityProject *p = GetActiveProject();
|
|
||||||
wxASSERT(p != NULL);
|
|
||||||
CommandManager *c = &CommandManager::Get( *p );
|
|
||||||
wxASSERT(c != NULL);
|
|
||||||
|
|
||||||
wxMenuBar * pBar = GetProjectFrame( *p ).GetMenuBar();
|
|
||||||
wxASSERT(pBar != NULL );
|
|
||||||
wxMenu * pMenu = pBar->GetMenu( 9 ); // Menu 9 is the Tools Menu.
|
|
||||||
wxASSERT( pMenu != NULL );
|
|
||||||
|
|
||||||
c->SetCurrentMenu(pMenu);
|
|
||||||
c->AddSeparator();
|
|
||||||
c->AddItem( *p, wxT("NyqBench"),
|
|
||||||
XO("&Nyquist Workbench..."),
|
|
||||||
findme,
|
|
||||||
static_cast<CommandFunctorPointer>(&NyqBench::ShowNyqBench),
|
|
||||||
AudioIONotBusyFlag());
|
|
||||||
|
|
||||||
c->ClearCurrentMenu();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -211,6 +188,18 @@ extern "C"
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Register our extra menu item
|
||||||
|
namespace {
|
||||||
|
using namespace MenuTable;
|
||||||
|
AttachedItem sAttachment{ wxT("Tools"),
|
||||||
|
( FinderScope( findme ), Section( wxT("NyquistWorkBench"),
|
||||||
|
Command( wxT("NyqBench"), XO("&Nyquist Workbench..."),
|
||||||
|
static_cast<CommandFunctorPointer>(&NyqBench::ShowNyqBench),
|
||||||
|
AudioIONotBusyFlag())
|
||||||
|
) )
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// NyqTextCtrl
|
// NyqTextCtrl
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@ -84,8 +84,7 @@ typedef enum
|
|||||||
AppInitialized,
|
AppInitialized,
|
||||||
AppQuiting,
|
AppQuiting,
|
||||||
ProjectInitialized,
|
ProjectInitialized,
|
||||||
ProjectClosing,
|
ProjectClosing
|
||||||
MenusRebuilt
|
|
||||||
} ModuleDispatchTypes;
|
} ModuleDispatchTypes;
|
||||||
|
|
||||||
|
|
||||||
@ -108,8 +107,7 @@ DLL_API const wxChar * GetVersionString()
|
|||||||
|
|
||||||
extern int DLL_API ModuleDispatch(ModuleDispatchTypes type);
|
extern int DLL_API ModuleDispatch(ModuleDispatchTypes type);
|
||||||
// ModuleDispatch
|
// ModuleDispatch
|
||||||
// is called by Audacity to initialize/terminmate the module,
|
// is called by Audacity to initialize/terminate the module
|
||||||
// and ask if it has anything for the menus.
|
|
||||||
// We don't (yet) do anything in this, since we have a special function for the scripter
|
// We don't (yet) do anything in this, since we have a special function for the scripter
|
||||||
// all we need to do is return 1.
|
// all we need to do is return 1.
|
||||||
int ModuleDispatch(ModuleDispatchTypes type){
|
int ModuleDispatch(ModuleDispatchTypes type){
|
||||||
@ -120,8 +118,7 @@ int ModuleDispatch(ModuleDispatchTypes type){
|
|||||||
case AppQuiting: {
|
case AppQuiting: {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ProjectInitialized:
|
case ProjectInitialized: {
|
||||||
case MenusRebuilt: {
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
#include <wx/frame.h>
|
#include <wx/frame.h>
|
||||||
|
|
||||||
#include "ModuleManager.h"
|
|
||||||
#include "Project.h"
|
#include "Project.h"
|
||||||
#include "ProjectHistory.h"
|
#include "ProjectHistory.h"
|
||||||
#include "ProjectSettings.h"
|
#include "ProjectSettings.h"
|
||||||
@ -1046,8 +1045,6 @@ void MenuCreator::RebuildMenuBar(AudacityProject &project)
|
|||||||
CommandManager::Get( project ).PurgeData();
|
CommandManager::Get( project ).PurgeData();
|
||||||
|
|
||||||
CreateMenusAndCommands(project);
|
CreateMenusAndCommands(project);
|
||||||
|
|
||||||
ModuleManager::Get().Dispatch(MenusRebuilt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuManager::OnUndoRedo( wxCommandEvent &evt )
|
void MenuManager::OnUndoRedo( wxCommandEvent &evt )
|
||||||
|
@ -38,8 +38,7 @@ typedef enum
|
|||||||
AppInitialized,
|
AppInitialized,
|
||||||
AppQuiting,
|
AppQuiting,
|
||||||
ProjectInitialized,
|
ProjectInitialized,
|
||||||
ProjectClosing,
|
ProjectClosing
|
||||||
MenusRebuilt
|
|
||||||
} ModuleDispatchTypes;
|
} ModuleDispatchTypes;
|
||||||
|
|
||||||
typedef int (*fnModuleDispatch)(ModuleDispatchTypes type);
|
typedef int (*fnModuleDispatch)(ModuleDispatchTypes type);
|
||||||
|
@ -477,26 +477,6 @@ wxMenu * CommandManager::CurrentMenu() const
|
|||||||
return tmpCurrentSubMenu;
|
return tmpCurrentSubMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandManager::SetCurrentMenu(wxMenu * menu)
|
|
||||||
{
|
|
||||||
// uCurrentMenu ought to be null in correct usage
|
|
||||||
wxASSERT(!uCurrentMenu);
|
|
||||||
// Make sure of it anyway
|
|
||||||
uCurrentMenu.reset();
|
|
||||||
|
|
||||||
mCurrentMenu = menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandManager::ClearCurrentMenu()
|
|
||||||
{
|
|
||||||
// uCurrentMenu ought to be null in correct usage
|
|
||||||
wxASSERT(!uCurrentMenu);
|
|
||||||
// Make sure of it anyway
|
|
||||||
uCurrentMenu.reset();
|
|
||||||
|
|
||||||
mCurrentMenu = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CommandManager::AddItem(AudacityProject &project,
|
void CommandManager::AddItem(AudacityProject &project,
|
||||||
|
@ -133,8 +133,6 @@ class AUDACITY_DLL_API CommandManager final
|
|||||||
|
|
||||||
std::unique_ptr<wxMenuBar> AddMenuBar(const wxString & sMenu);
|
std::unique_ptr<wxMenuBar> AddMenuBar(const wxString & sMenu);
|
||||||
|
|
||||||
// You may either called SetCurrentMenu later followed by ClearCurrentMenu,
|
|
||||||
// or else BeginMenu followed by EndMenu. Don't mix them.
|
|
||||||
wxMenu *BeginMenu(const TranslatableString & tName);
|
wxMenu *BeginMenu(const TranslatableString & tName);
|
||||||
void EndMenu();
|
void EndMenu();
|
||||||
|
|
||||||
@ -235,11 +233,6 @@ class AUDACITY_DLL_API CommandManager final
|
|||||||
void Check(const CommandID &name, bool checked);
|
void Check(const CommandID &name, bool checked);
|
||||||
void Modify(const wxString &name, const TranslatableString &newLabel);
|
void Modify(const wxString &name, const TranslatableString &newLabel);
|
||||||
|
|
||||||
// You may either called SetCurrentMenu later followed by ClearCurrentMenu,
|
|
||||||
// or else BeginMenu followed by EndMenu. Don't mix them.
|
|
||||||
void SetCurrentMenu(wxMenu * menu);
|
|
||||||
void ClearCurrentMenu();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Modifying accelerators
|
// Modifying accelerators
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user