From 5501ac0fc29c20e0ab2b41ec81b252ee079f5b36 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 14 Feb 2020 12:38:28 -0500 Subject: [PATCH] Move defs of menu items for changing tools, to be with the toolbar --- src/menus/ToolbarMenus.cpp | 107 --------------------------- src/toolbars/ToolsToolBar.cpp | 133 ++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 107 deletions(-) diff --git a/src/menus/ToolbarMenus.cpp b/src/menus/ToolbarMenus.cpp index 2d4996364..51c23931a 100644 --- a/src/menus/ToolbarMenus.cpp +++ b/src/menus/ToolbarMenus.cpp @@ -1,27 +1,10 @@ #include "../Audacity.h" #include "../Menus.h" -#include "../TrackPanel.h" #include "../ProjectSettings.h" #include "../commands/CommandContext.h" #include "../commands/CommandManager.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 ToolbarActions { @@ -42,66 +25,6 @@ void OnResetToolBars(const CommandContext &context) 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 } // namespace @@ -152,36 +75,6 @@ AttachedItem sAttachment1{ Placement{ wxT("View/Other"), { OrderingHint::Begin } }, 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 diff --git a/src/toolbars/ToolsToolBar.cpp b/src/toolbars/ToolsToolBar.cpp index f8f91bd38..ac4ed1ca5 100644 --- a/src/toolbars/ToolsToolBar.cpp +++ b/src/toolbars/ToolsToolBar.cpp @@ -305,3 +305,136 @@ AttachedToolBarMenuItem sAttachment{ 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() ) +}; +}