mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-14 17:14:07 +01:00
Revert changes for Bug 1119 made by Paul.
These changes were made too close to release and are considered too dangerous for 2.4.0. We will use the changes Leland provided. We can review these proposed changes by Paul after 2.4.0 is released.
This commit is contained in:
@@ -7,14 +7,16 @@
|
||||
|
||||
#ifdef __WXMAC__
|
||||
|
||||
#include "WindowMenus.h"
|
||||
|
||||
#include "../CommonCommandFlags.h"
|
||||
#include "../Menus.h"
|
||||
#include "../Project.h"
|
||||
#include "../ProjectFileIO.h"
|
||||
#include "../commands/CommandContext.h"
|
||||
|
||||
#include <wx/frame.h>
|
||||
#include <wx/menu.h>
|
||||
#include <wx/menuitem.h>
|
||||
|
||||
#undef USE_COCOA
|
||||
|
||||
@@ -53,69 +55,74 @@ void DoMacMinimize(AudacityProject *project)
|
||||
}
|
||||
}
|
||||
|
||||
std::vector< wxWindowID > sReservedIds;
|
||||
std::vector< std::weak_ptr< AudacityProject > > sProjects;
|
||||
|
||||
void RebuildMenu(wxCommandEvent &evt)
|
||||
{
|
||||
// Let other listeners hear it too
|
||||
evt.Skip();
|
||||
|
||||
// This is a big hammer.
|
||||
// Really we just need to recreate just the Window menu.
|
||||
// This causes the checkmark to be put in the right place for the
|
||||
// currently active project
|
||||
MenuCreator::RebuildAllMenuBars();
|
||||
}
|
||||
|
||||
wxWindowID ReservedID(
|
||||
size_t index, const std::shared_ptr< AudacityProject > &pProject )
|
||||
{
|
||||
if ( sReservedIds.empty() ) {
|
||||
// Do this once only per session, and don't worry about unbinding
|
||||
wxTheApp->Bind( EVT_PROJECT_ACTIVATION, RebuildMenu );
|
||||
wxTheApp->Bind( EVT_PROJECT_TITLE_CHANGE, RebuildMenu );
|
||||
}
|
||||
|
||||
while ( sReservedIds.size() <= index )
|
||||
sReservedIds.emplace_back( wxIdManager::ReserveId() );
|
||||
|
||||
if ( sProjects.size() < sReservedIds.size() )
|
||||
sProjects.resize( sReservedIds.size() );
|
||||
sProjects[ index ] = pProject;
|
||||
|
||||
return sReservedIds[ index ];
|
||||
}
|
||||
|
||||
void OnWindow( wxCommandEvent &evt )
|
||||
{
|
||||
const auto begin = sReservedIds.begin(), end = sReservedIds.end(),
|
||||
iter = std::find( begin, end, evt.GetId() );
|
||||
size_t index = iter - begin;
|
||||
if ( index < sProjects.size() ) {
|
||||
auto pProject = sProjects[ index ].lock();
|
||||
if ( pProject ) {
|
||||
// Make it the active project
|
||||
SetActiveProject(pProject.get());
|
||||
|
||||
// And ensure it's visible
|
||||
wxFrame *frame = pProject->GetFrame();
|
||||
if (frame->IsIconized())
|
||||
{
|
||||
frame->Restore();
|
||||
}
|
||||
frame->Raise();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/// Namespace for functions for window management (mac only?)
|
||||
namespace WindowActions {
|
||||
|
||||
// exported helper functions
|
||||
// none
|
||||
|
||||
// Refreshes the Window menu in all projects
|
||||
void Refresh()
|
||||
{
|
||||
// Must do it in all projects
|
||||
for (auto thisProject : AllProjects{})
|
||||
{
|
||||
// Need the projects frame, but this should always be successful
|
||||
wxFrame *frame = thisProject->GetFrame();
|
||||
wxASSERT(frame != NULL);
|
||||
if (!frame)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// This can happen if we are called before the menubar is set in the frame
|
||||
wxMenuBar *bar = frame->GetMenuBar();
|
||||
if (!bar)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Should always find the Window menu
|
||||
int pos = bar->FindMenu(wxT("Window"));
|
||||
wxASSERT(pos != wxNOT_FOUND);
|
||||
if (pos == wxNOT_FOUND)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// We can not get the menu proper
|
||||
wxMenu *menu = bar->GetMenu(pos);
|
||||
|
||||
// Remove all existing window items
|
||||
for (auto item : menu->GetMenuItems())
|
||||
{
|
||||
if (item->GetId() >= WindowActions::ID_BASE)
|
||||
{
|
||||
menu->Destroy(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Add all projects to this project's Window menu
|
||||
for (auto project : AllProjects{})
|
||||
{
|
||||
int itemId = WindowActions::ID_BASE + project->GetProjectNumber();
|
||||
wxString itemName = project->GetFrame()->GetTitle();
|
||||
bool isActive = (GetActiveProject() == project.get());
|
||||
|
||||
// This should never really happen, but a menu item must have a name
|
||||
if (itemName.empty())
|
||||
{
|
||||
itemName = _("<untitled>");
|
||||
}
|
||||
|
||||
// Add it to the menu and check it if it's the active project
|
||||
wxMenuItem *item = menu->Append(itemId, itemName);
|
||||
item->SetCheckable(true);
|
||||
item->Check(isActive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Menu handler functions
|
||||
|
||||
@@ -180,9 +187,9 @@ namespace {
|
||||
using namespace MenuTable;
|
||||
BaseItemSharedPtr WindowMenu()
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// poor imitation of the Mac Windows Menu
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// poor imitation of the Mac Windows Menu
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static BaseItemSharedPtr menu{
|
||||
( FinderScope{ findCommandHandler },
|
||||
Menu( wxT("Window"), XO("&Window"),
|
||||
@@ -208,34 +215,10 @@ BaseItemSharedPtr WindowMenu()
|
||||
Special( wxT("PopulateWindowsStep"),
|
||||
[](AudacityProject &, wxMenu &theMenu)
|
||||
{
|
||||
// Undo previous bindings
|
||||
for ( auto id : sReservedIds )
|
||||
wxTheApp->Unbind( wxEVT_MENU, OnWindow, id );
|
||||
|
||||
// Add all projects to this project's Window menu
|
||||
size_t ii = 0;
|
||||
for (auto project : AllProjects{})
|
||||
{
|
||||
int itemId = ReservedID( ii++, project );
|
||||
wxString itemName = project->GetFrame()->GetTitle();
|
||||
bool isActive = (GetActiveProject() == project.get());
|
||||
|
||||
// This should never really happen, but a menu item must have a name
|
||||
if (itemName.empty())
|
||||
{
|
||||
itemName = _("<untitled>");
|
||||
}
|
||||
|
||||
// Add it to the menu and check it if it's the active project
|
||||
wxMenuItem *item = theMenu.Append(itemId, itemName);
|
||||
item->SetCheckable(true);
|
||||
item->Check(isActive);
|
||||
|
||||
// Bind the callback
|
||||
wxTheApp->Bind( wxEVT_MENU, OnWindow, itemId );
|
||||
}
|
||||
// Should something be done here???
|
||||
} )
|
||||
)
|
||||
|
||||
) ) };
|
||||
return menu;
|
||||
}
|
||||
|
||||
22
src/menus/WindowMenus.h
Normal file
22
src/menus/WindowMenus.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "../Audacity.h"
|
||||
|
||||
#include "../commands/CommandManager.h"
|
||||
|
||||
#ifdef __WXMAC__
|
||||
|
||||
/// Namespace for functions for window management (mac only?)
|
||||
namespace WindowActions {
|
||||
|
||||
// Range of assigned menu IDs
|
||||
static const wxWindowID ID_BASE = 30000;
|
||||
static const wxWindowID ID_LAST = 30999;
|
||||
|
||||
// Exported helper functions
|
||||
void Refresh();
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
// Not WXMAC.
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user