mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-25 08:38:39 +02:00
More preliminaries for making menus table-driven
This commit is contained in:
commit
4cc92a26fa
@ -390,7 +390,6 @@ void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
|
||||
{
|
||||
auto menubar = c->AddMenuBar(wxT("appmenu"));
|
||||
wxASSERT(menubar);
|
||||
c->SetOccultCommands( false );
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// File menu
|
||||
@ -1394,11 +1393,9 @@ void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
|
||||
|
||||
bool bShowExtraMenus;
|
||||
gPrefs->Read(wxT("/GUI/ShowExtraMenus"), &bShowExtraMenus, false);
|
||||
std::unique_ptr<wxMenuBar> menubar2;
|
||||
if( !bShowExtraMenus )
|
||||
{
|
||||
menubar2 = c->AddMenuBar(wxT("ext-menu"));
|
||||
c->SetOccultCommands(true);
|
||||
c->BeginOccultCommands();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -1594,8 +1591,13 @@ void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
|
||||
|
||||
c->AddSeparator();
|
||||
|
||||
c->AddGlobalCommand(wxT("PrevWindow"), XXO("Move Backward Through Active Windows"), FN(OnPrevWindow), wxT("Alt+Shift+F6"));
|
||||
c->AddGlobalCommand(wxT("NextWindow"), XXO("Move Forward Through Active Windows"), FN(OnNextWindow), wxT("Alt+F6"));
|
||||
// Global commands
|
||||
c->AddItem( wxT("PrevWindow"), XXO("Move Backward Through Active Windows"),
|
||||
FN(OnPrevWindow), AlwaysEnabledFlag,
|
||||
Options{ wxT("Alt+Shift+F6") }.IsGlobal() );
|
||||
c->AddItem( wxT("NextWindow"), XXO("Move Forward Through Active Windows"),
|
||||
FN(OnNextWindow), AlwaysEnabledFlag,
|
||||
Options{ wxT("Alt+F6") }.IsGlobal() );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -1786,8 +1788,7 @@ void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
|
||||
|
||||
if (!bShowExtraMenus)
|
||||
{
|
||||
c->SwapMenuBars();
|
||||
c->SetOccultCommands(false);
|
||||
c->EndOccultCommands();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -597,17 +597,17 @@ wxMenuBar * CommandManager::CurrentMenuBar() const
|
||||
}
|
||||
|
||||
///
|
||||
/// Swap the last two menu bars in the list,
|
||||
/// to make the previous menu bar 'current' again.
|
||||
/// Typically used to switch back and forth
|
||||
/// between adding to a hidden menu bar and
|
||||
/// adding to one that is visible,
|
||||
/// adding to one that is visible
|
||||
///
|
||||
void CommandManager::SwapMenuBars()
|
||||
void CommandManager::PopMenuBar()
|
||||
{
|
||||
int l = mMenuBarList.size();
|
||||
wxASSERT(l >= 2);
|
||||
std::swap(mMenuBarList[l - 2], mMenuBarList[l - 1]);
|
||||
auto iter = mMenuBarList.end();
|
||||
if ( iter != mMenuBarList.begin() )
|
||||
mMenuBarList.erase( --iter );
|
||||
else
|
||||
wxASSERT( false );
|
||||
}
|
||||
|
||||
|
||||
@ -754,6 +754,13 @@ void CommandManager::AddItem(const wxChar *name,
|
||||
CommandFlag flags,
|
||||
const Options &options)
|
||||
{
|
||||
if (options.global) {
|
||||
wxASSERT( flags == AlwaysEnabledFlag );
|
||||
AddGlobalCommand(
|
||||
name, label_in, hasDialog, finder, callback, options.accel );
|
||||
return;
|
||||
}
|
||||
|
||||
wxASSERT( flags != NoFlagsSpecified );
|
||||
|
||||
auto mask = options.mask;
|
||||
@ -1824,9 +1831,24 @@ void CommandManager::WriteXML(XMLWriter &xmlFile) const
|
||||
xmlFile.EndTag(wxT("audacitykeyboard"));
|
||||
}
|
||||
|
||||
void CommandManager::SetOccultCommands( bool bOccult)
|
||||
void CommandManager::BeginOccultCommands()
|
||||
{
|
||||
bMakingOccultCommands = bOccult;
|
||||
// To do: perhaps allow occult item switching at lower levels of the
|
||||
// menu tree.
|
||||
wxASSERT( !CurrentMenu() );
|
||||
|
||||
// Make a temporary menu bar collecting items added after.
|
||||
// This bar will be discarded but other side effects on the command
|
||||
// manager persist.
|
||||
mTempMenuBar = AddMenuBar(wxT("ext-menu"));
|
||||
bMakingOccultCommands = true;
|
||||
}
|
||||
|
||||
void CommandManager::EndOccultCommands()
|
||||
{
|
||||
PopMenuBar();
|
||||
bMakingOccultCommands = false;
|
||||
mTempMenuBar.reset();
|
||||
}
|
||||
|
||||
void CommandManager::SetCommandFlags(const wxString &name,
|
||||
|
@ -40,7 +40,7 @@ struct MenuBarListEntry
|
||||
{}
|
||||
|
||||
wxString name;
|
||||
wxMenuBar *menubar; // This structure does not assume memory ownership!
|
||||
wxWeakRef<wxMenuBar> menubar; // This structure does not assume memory ownership!
|
||||
};
|
||||
|
||||
struct SubMenuListEntry
|
||||
@ -166,6 +166,8 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
||||
{ mask = value; return std::move(*this); }
|
||||
Options &&LongName (const wxString &value) &&
|
||||
{ longName = value; return std::move(*this); }
|
||||
Options &&IsGlobal () &&
|
||||
{ global = true; return std::move(*this); }
|
||||
|
||||
const wxChar *accel{ wxT("") };
|
||||
int check{ -1 }; // default value means it's not a check item
|
||||
@ -173,6 +175,7 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
||||
CommandParameter parameter{};
|
||||
CommandMask mask{ NoFlagsSpecified };
|
||||
wxString longName{}; // translated
|
||||
bool global{ false };
|
||||
};
|
||||
|
||||
void AddItemList(const wxString & name,
|
||||
@ -208,15 +211,9 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
||||
const wxChar *accel,
|
||||
CommandFlag flags);
|
||||
|
||||
void AddGlobalCommand(const wxChar *name,
|
||||
const wxChar *label,
|
||||
bool hasDialog,
|
||||
CommandHandlerFinder finder,
|
||||
CommandFunctorPointer callback,
|
||||
const wxChar *accel);
|
||||
|
||||
void SwapMenuBars();
|
||||
void SetOccultCommands( bool bOccult);
|
||||
void PopMenuBar();
|
||||
void BeginOccultCommands();
|
||||
void EndOccultCommands();
|
||||
|
||||
|
||||
void SetCommandFlags(const wxString &name, CommandFlag flags, CommandMask mask);
|
||||
@ -303,7 +300,7 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
||||
// Sorted list of the shortcut keys to be exluded from the standard defaults
|
||||
static const std::vector<NormalizedKeyString> &ExcludedList();
|
||||
|
||||
protected:
|
||||
private:
|
||||
|
||||
//
|
||||
// Creating menus and adding commands
|
||||
@ -334,6 +331,13 @@ protected:
|
||||
int count,
|
||||
bool bIsEffect,
|
||||
const CommandParameter ¶meter);
|
||||
|
||||
void AddGlobalCommand(const wxChar *name,
|
||||
const wxChar *label,
|
||||
bool hasDialog,
|
||||
CommandHandlerFinder finder,
|
||||
CommandFunctorPointer callback,
|
||||
const wxChar *accel);
|
||||
|
||||
//
|
||||
// Executing commands
|
||||
@ -391,6 +395,7 @@ private:
|
||||
wxMenu *mCurrentMenu {};
|
||||
|
||||
bool bMakingOccultCommands;
|
||||
std::unique_ptr< wxMenuBar > mTempMenuBar;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user