1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-03-06 14:35:32 +01:00

Move defs of menu items for changing tools, to be with the toolbar

This commit is contained in:
Paul Licameli
2020-02-14 12:38:28 -05:00
parent d0a99d5ae5
commit 5501ac0fc2
2 changed files with 133 additions and 107 deletions

View File

@@ -1,27 +1,10 @@
#include "../Audacity.h" #include "../Audacity.h"
#include "../Menus.h" #include "../Menus.h"
#include "../TrackPanel.h"
#include "../ProjectSettings.h" #include "../ProjectSettings.h"
#include "../commands/CommandContext.h" #include "../commands/CommandContext.h"
#include "../commands/CommandManager.h" #include "../commands/CommandManager.h"
#include "../toolbars/ToolManager.h" #include "../toolbars/ToolManager.h"
#include "../toolbars/ToolsToolBar.h"
// private helper classes and functions
namespace {
/// Called by handlers that set tools.
void SetTool(AudacityProject &project, int tool)
{
auto toolbar = &ToolsToolBar::Get( project );
if (toolbar) {
toolbar->SetCurrentTool(tool);
TrackPanel::Get( project ).Refresh(false);
}
}
}
/// Namespace for functions for View Toolbar menu /// Namespace for functions for View Toolbar menu
namespace ToolbarActions { namespace ToolbarActions {
@@ -42,66 +25,6 @@ void OnResetToolBars(const CommandContext &context)
MenuManager::Get(project).ModifyToolbarMenus(project); MenuManager::Get(project).ModifyToolbarMenus(project);
} }
/// Handler to set the select tool active
void OnSelectTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::selectTool);
}
/// Handler to set the Envelope tool active
void OnEnvelopeTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::envelopeTool);
}
void OnDrawTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::drawTool);
}
/// Handler to set the Zoom tool active
void OnZoomTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::zoomTool);
}
/// Handler to set the Time shift tool active
void OnTimeShiftTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::slideTool);
}
void OnMultiTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::multiTool);
}
void OnPrevTool(const CommandContext &context)
{
auto &project = context.project;
auto &toolbar = ToolsToolBar::Get( project );
auto &trackPanel = TrackPanel::Get( project );
using namespace ToolCodes;
// Use GetDownTool() here since GetCurrentTool() can return a value that
// doesn't represent the real tool if the Multi-tool is being used.
toolbar.SetCurrentTool((toolbar.GetDownTool()+(numTools-1))%numTools);
trackPanel.Refresh(false);
}
void OnNextTool(const CommandContext &context)
{
auto &project = context.project;
auto &toolbar = ToolsToolBar::Get( project );
auto &trackPanel = TrackPanel::Get( project );
using namespace ToolCodes;
// Use GetDownTool() here since GetCurrentTool() can return a value that
// doesn't represent the real tool if the Multi-tool is being used.
toolbar.SetCurrentTool((toolbar.GetDownTool()+1)%numTools);
trackPanel.Refresh(false);
}
}; // struct Handler }; // struct Handler
} // namespace } // namespace
@@ -152,36 +75,6 @@ AttachedItem sAttachment1{
Placement{ wxT("View/Other"), { OrderingHint::Begin } }, Placement{ wxT("View/Other"), { OrderingHint::Begin } },
Shared( ToolbarsMenu() ) Shared( ToolbarsMenu() )
}; };
BaseItemSharedPtr ExtraToolsMenu()
{
static BaseItemSharedPtr menu{
( FinderScope{ findCommandHandler },
Menu( wxT("Tools"), XO("T&ools"),
Command( wxT("SelectTool"), XXO("&Selection Tool"), FN(OnSelectTool),
AlwaysEnabledFlag, wxT("F1") ),
Command( wxT("EnvelopeTool"), XXO("&Envelope Tool"),
FN(OnEnvelopeTool), AlwaysEnabledFlag, wxT("F2") ),
Command( wxT("DrawTool"), XXO("&Draw Tool"), FN(OnDrawTool),
AlwaysEnabledFlag, wxT("F3") ),
Command( wxT("ZoomTool"), XXO("&Zoom Tool"), FN(OnZoomTool),
AlwaysEnabledFlag, wxT("F4") ),
Command( wxT("TimeShiftTool"), XXO("&Time Shift Tool"),
FN(OnTimeShiftTool), AlwaysEnabledFlag, wxT("F5") ),
Command( wxT("MultiTool"), XXO("&Multi Tool"), FN(OnMultiTool),
AlwaysEnabledFlag, wxT("F6") ),
Command( wxT("PrevTool"), XXO("&Previous Tool"), FN(OnPrevTool),
AlwaysEnabledFlag, wxT("A") ),
Command( wxT("NextTool"), XXO("&Next Tool"), FN(OnNextTool),
AlwaysEnabledFlag, wxT("D") )
) ) };
return menu;
}
AttachedItem sAttachment2{
wxT("Optional/Extra/Part1"),
Shared( ExtraToolsMenu() )
};
} }
#undef FN #undef FN

View File

@@ -305,3 +305,136 @@ AttachedToolBarMenuItem sAttachment{
ToolsBarID, wxT("ShowToolsTB"), XXO("T&ools Toolbar"), ToolsBarID, wxT("ShowToolsTB"), XXO("T&ools Toolbar"),
}; };
} }
// Following code injects menu items for changing the current tool
#include "../TrackPanel.h"
// private helper classes and functions
namespace {
/// Called by handlers that set tools.
void SetTool(AudacityProject &project, int tool)
{
auto toolbar = &ToolsToolBar::Get( project );
if (toolbar) {
toolbar->SetCurrentTool(tool);
TrackPanel::Get( project ).Refresh(false);
}
}
}
/// Namespace for functions for View Toolbar menu
namespace ToolActions {
// exported helper functions
// none
// Menu handler functions
struct Handler : CommandHandlerObject {
/// Handler to set the select tool active
void OnSelectTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::selectTool);
}
/// Handler to set the Envelope tool active
void OnEnvelopeTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::envelopeTool);
}
void OnDrawTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::drawTool);
}
/// Handler to set the Zoom tool active
void OnZoomTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::zoomTool);
}
/// Handler to set the Time shift tool active
void OnTimeShiftTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::slideTool);
}
void OnMultiTool(const CommandContext &context)
{
SetTool(context.project, ToolCodes::multiTool);
}
void OnPrevTool(const CommandContext &context)
{
auto &project = context.project;
auto &toolbar = ToolsToolBar::Get( project );
auto &trackPanel = TrackPanel::Get( project );
using namespace ToolCodes;
// Use GetDownTool() here since GetCurrentTool() can return a value that
// doesn't represent the real tool if the Multi-tool is being used.
toolbar.SetCurrentTool((toolbar.GetDownTool()+(numTools-1))%numTools);
trackPanel.Refresh(false);
}
void OnNextTool(const CommandContext &context)
{
auto &project = context.project;
auto &toolbar = ToolsToolBar::Get( project );
auto &trackPanel = TrackPanel::Get( project );
using namespace ToolCodes;
// Use GetDownTool() here since GetCurrentTool() can return a value that
// doesn't represent the real tool if the Multi-tool is being used.
toolbar.SetCurrentTool((toolbar.GetDownTool()+1)%numTools);
trackPanel.Refresh(false);
}
}; // struct Handler
static CommandHandlerObject &findCommandHandler(AudacityProject &) {
// Handler is not stateful. Doesn't need a factory registered with
// AudacityProject.
static ToolActions::Handler instance;
return instance;
};
#define FN(X) (& ToolActions::Handler :: X)
using namespace MenuTable;
BaseItemSharedPtr ExtraToolsMenu()
{
static BaseItemSharedPtr menu{
( FinderScope{ findCommandHandler },
Menu( wxT("Tools"), XO("T&ools"),
Command( wxT("SelectTool"), XXO("&Selection Tool"), FN(OnSelectTool),
AlwaysEnabledFlag, wxT("F1") ),
Command( wxT("EnvelopeTool"), XXO("&Envelope Tool"),
FN(OnEnvelopeTool), AlwaysEnabledFlag, wxT("F2") ),
Command( wxT("DrawTool"), XXO("&Draw Tool"), FN(OnDrawTool),
AlwaysEnabledFlag, wxT("F3") ),
Command( wxT("ZoomTool"), XXO("&Zoom Tool"), FN(OnZoomTool),
AlwaysEnabledFlag, wxT("F4") ),
Command( wxT("TimeShiftTool"), XXO("&Time Shift Tool"),
FN(OnTimeShiftTool), AlwaysEnabledFlag, wxT("F5") ),
Command( wxT("MultiTool"), XXO("&Multi Tool"), FN(OnMultiTool),
AlwaysEnabledFlag, wxT("F6") ),
Command( wxT("PrevTool"), XXO("&Previous Tool"), FN(OnPrevTool),
AlwaysEnabledFlag, wxT("A") ),
Command( wxT("NextTool"), XXO("&Next Tool"), FN(OnNextTool),
AlwaysEnabledFlag, wxT("D") )
) ) };
return menu;
}
#undef FN
AttachedItem sAttachment2{
wxT("Optional/Extra/Part1"),
Shared( ExtraToolsMenu() )
};
}