From 7b09225bf7a0f93205a0fbfc5d75e6c05c9ab991 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 10 Jun 2019 19:10:07 -0400 Subject: [PATCH] Use a hook to implement the shift-click shortcut to keyboard prefs... This frees EIGHTEEN files from the big strongly connected component!! They are: Dependencies Export ExportCL ExportFFmpeg ExportFFmpegDialogs ExportFLAC EportMP2 ExportMP3 ExportOGG ExportPCM ExtImportPrefs Import ImportRaw KeyConfigPrefs KeyView LibraryPrefs PrefsDialog SpectrumPrefs ... and that includes all of the remaining *Prefs files. It does still leave the nine Export* files in a smaller s.c.c, which could be broken with a registration system, as was done for import at commit e2cf1d9 --- src/AudacityApp.cpp | 21 +++++++++++++++++++++ src/commands/CommandManager.cpp | 29 ++++++++++++++++------------- src/commands/CommandManager.h | 7 +++++++ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index 191d44ce8..1ebe5e758 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -108,6 +108,10 @@ It handles initialization and termination by subclassing wxApp. #include "tracks/ui/Scrubbing.h" #include "widgets/FileHistory.h" +#ifdef EXPERIMENTAL_EASY_CHANGE_KEY_BINDINGS +#include "../prefs/KeyConfigPrefs.h" +#endif + //temporarily commented out till it is added to all projects //#include "Profiler.h" @@ -1593,6 +1597,23 @@ bool AudacityApp::OnInit() mTimer.SetOwner(this, kAudacityAppTimerID); mTimer.Start(200); +#ifdef EXPERIMENTAL_EASY_CHANGE_KEY_BINDINGS + CommandManager::SetMenuHook( [](const CommandID &id){ + if (::wxGetMouseState().ShiftDown()) { + // Only want one page of the preferences + PrefsDialog::Factories factories; + factories.push_back(KeyConfigPrefsFactory( id )); + auto pWindow = FindProjectFrame( GetActiveProject() ); + GlobalPrefsDialog dialog( pWindow, factories ); + dialog.ShowModal(); + MenuCreator::RebuildAllMenuBars(); + return true; + } + else + return false; + } ); +#endif + return TRUE; } diff --git a/src/commands/CommandManager.cpp b/src/commands/CommandManager.cpp index 597647247..82f373ecb 100644 --- a/src/commands/CommandManager.cpp +++ b/src/commands/CommandManager.cpp @@ -170,6 +170,20 @@ const CommandManager &CommandManager::Get( const AudacityProject &project ) return Get( const_cast< AudacityProject & >( project ) ); } +static CommandManager::MenuHook &sMenuHook() +{ + static CommandManager::MenuHook theHook; + return theHook; +} + +auto CommandManager::SetMenuHook( const MenuHook &hook ) -> MenuHook +{ + auto &theHook = sMenuHook(); + auto result = theHook; + theHook = hook; + return result; +} + /// /// Standard Constructor /// @@ -1272,24 +1286,13 @@ bool CommandManager::HandleCommandEntry(const CommandListEntry * entry, ///CommandManagerListener function. If you pass any flags, ///the command won't be executed unless the flags are compatible ///with the command's flags. -#include "../prefs/PrefsDialog.h" -#include "../prefs/KeyConfigPrefs.h" bool CommandManager::HandleMenuID(int id, CommandFlag flags, CommandMask mask) { CommandListEntry *entry = mCommandNumericIDHash[id]; -#ifdef EXPERIMENTAL_EASY_CHANGE_KEY_BINDINGS - if (::wxGetMouseState().ShiftDown()) { - // Only want one page of the preferences - PrefsDialog::Factories factories; - factories.push_back(KeyConfigPrefsFactory( entry->name )); - auto pWindow = FindProjectFrame( GetActiveProject() ); - GlobalPrefsDialog dialog( pWindow, factories ); - dialog.ShowModal(); - MenuCreator::RebuildAllMenuBars(); + auto hook = sMenuHook(); + if (hook && hook(entry->name)) return true; - } -#endif return HandleCommandEntry( entry, flags, mask ); } diff --git a/src/commands/CommandManager.h b/src/commands/CommandManager.h index fdaaf0aa3..792d0b020 100644 --- a/src/commands/CommandManager.h +++ b/src/commands/CommandManager.h @@ -108,6 +108,13 @@ class AUDACITY_DLL_API CommandManager final static CommandManager &Get( AudacityProject &project ); static const CommandManager &Get( const AudacityProject &project ); + // Type of a function that can intercept menu item handling. + // If it returns true, bypass the usual dipatch of commands. + using MenuHook = std::function< bool(const CommandID&) >; + + // install a menu hook, returning the previously installed one + static MenuHook SetMenuHook( const MenuHook &hook ); + // // Constructor / Destructor //