1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-03-08 23:45:37 +01:00

Reusable preference-populating code for other registries than Menus

This commit is contained in:
Paul Licameli
2020-02-01 06:30:04 -05:00
parent 98e6a0e339
commit a729dfec3b
2 changed files with 62 additions and 42 deletions

View File

@@ -42,7 +42,6 @@
#include "widgets/AudacityMessageBox.h"
#include "widgets/ErrorDialog.h"
#include <mutex>
#include <unordered_set>
#include <wx/menu.h>
@@ -941,6 +940,22 @@ void Visit( Visitor &visitor, BaseItem *pTopItem, GroupItem *pRegistry )
gPrefs->Flush();
}
OrderingPreferenceInitializer::OrderingPreferenceInitializer(
Literal root, const Pairs &pairs )
{
bool doFlush = false;
for (const auto &pair : pairs) {
const auto key = wxString{'/'} + root + pair.first;
if ( gPrefs->Read(key).empty() ) {
gPrefs->Write( key, pair.second );
doFlush = true;
}
}
if (doFlush)
gPrefs->Flush();
}
}
/// CreateMenusAndCommands builds the menus, and also rebuilds them after
@@ -963,45 +978,6 @@ MenuTable::AttachedItem::AttachedItem(
namespace {
// Once only, cause initial population of preferences for the ordering
// of some menu items that used to be given in tables but are now separately
// registered in several .cpp files; the sequence of registration depends
// on unspecified accidents of static initialization order across
// compilation units, so we need something specific here to preserve old
// default appearance of menus.
// But this needs only to mention some strings -- there is no compilation or
// link dependency of this source file on those other implementation files.
void InitializeMenuOrdering()
{
using Pair = std::pair<const wxChar *, const wxChar *>;
static const Pair pairs [] = {
{wxT(""), wxT(
"File,Edit,Select,View,Transport,Tracks,Generate,Effect,Analyze,Tools,Window,Optional,Help"
)},
{wxT("/Optional/Extra/Part1"), wxT(
"Transport,Tools,Mixer,Edit,PlayAtSpeed,Seek,Device,Select"
)},
{wxT("/Optional/Extra/Part2"), wxT(
"Navigation,Focus,Cursor,Track,Scriptables1,Scriptables2"
)},
{wxT("/View/Windows"), wxT("UndoHistory,Karaoke,MixerBoard")},
{wxT("/Analyze/Analyzers/Windows"), wxT("ContrastAnalyser,PlotSpectrum")},
{wxT("/Transport/Basic"),wxT("Play,Record,Scrubbing,Cursor")},
};
bool doFlush = false;
for (auto pair : pairs) {
const auto key = wxString{'/'} + MenuPathStart + pair.first;
if ( gPrefs->Read(key).empty() ) {
gPrefs->Write( key, pair.second );
doFlush = true;
}
}
if (doFlush)
gPrefs->Flush();
}
using namespace MenuTable;
struct MenuItemVisitor : MenuVisitor
@@ -1105,8 +1081,31 @@ struct MenuItemVisitor : MenuVisitor
void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
{
static std::once_flag flag;
std::call_once( flag, InitializeMenuOrdering );
// Once only, cause initial population of preferences for the ordering
// of some menu items that used to be given in tables but are now separately
// registered in several .cpp files; the sequence of registration depends
// on unspecified accidents of static initialization order across
// compilation units, so we need something specific here to preserve old
// default appearance of menus.
// But this needs only to mention some strings -- there is no compilation or
// link dependency of this source file on those other implementation files.
static Registry::OrderingPreferenceInitializer init{
MenuPathStart,
{
{wxT(""), wxT(
"File,Edit,Select,View,Transport,Tracks,Generate,Effect,Analyze,Tools,Window,Optional,Help"
)},
{wxT("/Optional/Extra/Part1"), wxT(
"Transport,Tools,Mixer,Edit,PlayAtSpeed,Seek,Device,Select"
)},
{wxT("/Optional/Extra/Part2"), wxT(
"Navigation,Focus,Cursor,Track,Scriptables1,Scriptables2"
)},
{wxT("/View/Windows"), wxT("UndoHistory,Karaoke,MixerBoard")},
{wxT("/Analyze/Analyzers/Windows"), wxT("ContrastAnalyser,PlotSpectrum")},
{wxT("/Transport/Basic"),wxT("Play,Record,Scrubbing,Cursor")},
}
};
auto &commandManager = CommandManager::Get( project );