mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-25 16:48:44 +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"));
|
auto menubar = c->AddMenuBar(wxT("appmenu"));
|
||||||
wxASSERT(menubar);
|
wxASSERT(menubar);
|
||||||
c->SetOccultCommands( false );
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// File menu
|
// File menu
|
||||||
@ -1394,11 +1393,9 @@ void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
|
|||||||
|
|
||||||
bool bShowExtraMenus;
|
bool bShowExtraMenus;
|
||||||
gPrefs->Read(wxT("/GUI/ShowExtraMenus"), &bShowExtraMenus, false);
|
gPrefs->Read(wxT("/GUI/ShowExtraMenus"), &bShowExtraMenus, false);
|
||||||
std::unique_ptr<wxMenuBar> menubar2;
|
|
||||||
if( !bShowExtraMenus )
|
if( !bShowExtraMenus )
|
||||||
{
|
{
|
||||||
menubar2 = c->AddMenuBar(wxT("ext-menu"));
|
c->BeginOccultCommands();
|
||||||
c->SetOccultCommands(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
@ -1594,8 +1591,13 @@ void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
|
|||||||
|
|
||||||
c->AddSeparator();
|
c->AddSeparator();
|
||||||
|
|
||||||
c->AddGlobalCommand(wxT("PrevWindow"), XXO("Move Backward Through Active Windows"), FN(OnPrevWindow), wxT("Alt+Shift+F6"));
|
// Global commands
|
||||||
c->AddGlobalCommand(wxT("NextWindow"), XXO("Move Forward Through Active Windows"), FN(OnNextWindow), wxT("Alt+F6"));
|
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)
|
if (!bShowExtraMenus)
|
||||||
{
|
{
|
||||||
c->SwapMenuBars();
|
c->EndOccultCommands();
|
||||||
c->SetOccultCommands(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -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
|
/// Typically used to switch back and forth
|
||||||
/// between adding to a hidden menu bar and
|
/// 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();
|
auto iter = mMenuBarList.end();
|
||||||
wxASSERT(l >= 2);
|
if ( iter != mMenuBarList.begin() )
|
||||||
std::swap(mMenuBarList[l - 2], mMenuBarList[l - 1]);
|
mMenuBarList.erase( --iter );
|
||||||
|
else
|
||||||
|
wxASSERT( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -754,6 +754,13 @@ void CommandManager::AddItem(const wxChar *name,
|
|||||||
CommandFlag flags,
|
CommandFlag flags,
|
||||||
const Options &options)
|
const Options &options)
|
||||||
{
|
{
|
||||||
|
if (options.global) {
|
||||||
|
wxASSERT( flags == AlwaysEnabledFlag );
|
||||||
|
AddGlobalCommand(
|
||||||
|
name, label_in, hasDialog, finder, callback, options.accel );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wxASSERT( flags != NoFlagsSpecified );
|
wxASSERT( flags != NoFlagsSpecified );
|
||||||
|
|
||||||
auto mask = options.mask;
|
auto mask = options.mask;
|
||||||
@ -1824,9 +1831,24 @@ void CommandManager::WriteXML(XMLWriter &xmlFile) const
|
|||||||
xmlFile.EndTag(wxT("audacitykeyboard"));
|
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,
|
void CommandManager::SetCommandFlags(const wxString &name,
|
||||||
|
@ -40,7 +40,7 @@ struct MenuBarListEntry
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
wxString name;
|
wxString name;
|
||||||
wxMenuBar *menubar; // This structure does not assume memory ownership!
|
wxWeakRef<wxMenuBar> menubar; // This structure does not assume memory ownership!
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SubMenuListEntry
|
struct SubMenuListEntry
|
||||||
@ -166,6 +166,8 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
|||||||
{ mask = value; return std::move(*this); }
|
{ mask = value; return std::move(*this); }
|
||||||
Options &&LongName (const wxString &value) &&
|
Options &&LongName (const wxString &value) &&
|
||||||
{ longName = value; return std::move(*this); }
|
{ longName = value; return std::move(*this); }
|
||||||
|
Options &&IsGlobal () &&
|
||||||
|
{ global = true; return std::move(*this); }
|
||||||
|
|
||||||
const wxChar *accel{ wxT("") };
|
const wxChar *accel{ wxT("") };
|
||||||
int check{ -1 }; // default value means it's not a check item
|
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{};
|
CommandParameter parameter{};
|
||||||
CommandMask mask{ NoFlagsSpecified };
|
CommandMask mask{ NoFlagsSpecified };
|
||||||
wxString longName{}; // translated
|
wxString longName{}; // translated
|
||||||
|
bool global{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
void AddItemList(const wxString & name,
|
void AddItemList(const wxString & name,
|
||||||
@ -208,15 +211,9 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
|||||||
const wxChar *accel,
|
const wxChar *accel,
|
||||||
CommandFlag flags);
|
CommandFlag flags);
|
||||||
|
|
||||||
void AddGlobalCommand(const wxChar *name,
|
void PopMenuBar();
|
||||||
const wxChar *label,
|
void BeginOccultCommands();
|
||||||
bool hasDialog,
|
void EndOccultCommands();
|
||||||
CommandHandlerFinder finder,
|
|
||||||
CommandFunctorPointer callback,
|
|
||||||
const wxChar *accel);
|
|
||||||
|
|
||||||
void SwapMenuBars();
|
|
||||||
void SetOccultCommands( bool bOccult);
|
|
||||||
|
|
||||||
|
|
||||||
void SetCommandFlags(const wxString &name, CommandFlag flags, CommandMask mask);
|
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
|
// Sorted list of the shortcut keys to be exluded from the standard defaults
|
||||||
static const std::vector<NormalizedKeyString> &ExcludedList();
|
static const std::vector<NormalizedKeyString> &ExcludedList();
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
|
|
||||||
//
|
//
|
||||||
// Creating menus and adding commands
|
// Creating menus and adding commands
|
||||||
@ -335,6 +332,13 @@ protected:
|
|||||||
bool bIsEffect,
|
bool bIsEffect,
|
||||||
const CommandParameter ¶meter);
|
const CommandParameter ¶meter);
|
||||||
|
|
||||||
|
void AddGlobalCommand(const wxChar *name,
|
||||||
|
const wxChar *label,
|
||||||
|
bool hasDialog,
|
||||||
|
CommandHandlerFinder finder,
|
||||||
|
CommandFunctorPointer callback,
|
||||||
|
const wxChar *accel);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Executing commands
|
// Executing commands
|
||||||
//
|
//
|
||||||
@ -391,6 +395,7 @@ private:
|
|||||||
wxMenu *mCurrentMenu {};
|
wxMenu *mCurrentMenu {};
|
||||||
|
|
||||||
bool bMakingOccultCommands;
|
bool bMakingOccultCommands;
|
||||||
|
std::unique_ptr< wxMenuBar > mTempMenuBar;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user