1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-10 09:27:43 +02:00

ProjectHistory does not depend on ViewMenus ...

... Remove the last dependency by making the special vertical zoom fit on undo
push an event callback
This commit is contained in:
Paul Licameli 2019-06-08 12:01:48 -04:00
parent e2c6720436
commit d1a1b112ba
3 changed files with 41 additions and 12 deletions

View File

@ -134,7 +134,6 @@ void DoSelectSomething( AudacityProject &project );
namespace ViewActions {
double GetZoomOfToFit( const AudacityProject &project );
void DoZoomFit( AudacityProject &project );
void DoZoomFitV( AudacityProject &project );
}
/// Namespace for functions for Transport menu

View File

@ -11,10 +11,8 @@ Paul Licameli split from ProjectManager.cpp
#include "ProjectHistory.h"
#include "DirManager.h"
#include "Menus.h"
#include "Project.h"
#include "ProjectFileIO.h"
#include "ProjectSettings.h"
#include "Tags.h"
#include "Track.h"
#include "TrackPanel.h"
@ -91,7 +89,6 @@ void ProjectHistory::PushState(const wxString &desc,
{
auto &project = mProject;
auto &projectFileIO = ProjectFileIO::Get( project );
const auto &settings = ProjectSettings::Get( project );
auto &tracks = TrackList::Get( project );
auto &viewInfo = ViewInfo::Get( project );
auto &undoManager = UndoManager::Get( project );
@ -102,8 +99,6 @@ void ProjectHistory::PushState(const wxString &desc,
mDirty = true;
if (settings.GetTracksFitVerticallyZoomed())
ViewActions::DoZoomFitV( project );
if((flags & UndoPush::AUTOSAVE) != UndoPush::MINIMAL)
projectFileIO.AutoSave();
}

View File

@ -8,6 +8,7 @@
#include "../Prefs.h"
#include "../Project.h"
#include "../ProjectHistory.h"
#include "../ProjectSettings.h"
#include "../ProjectWindow.h"
#include "../TrackPanel.h"
#include "../UndoManager.h"
@ -178,6 +179,9 @@ void DoZoomFit(AudacityProject &project)
window.TP_ScrollWindow(start);
}
}
namespace {
void DoZoomFitV(AudacityProject &project)
{
auto &trackPanel = TrackPanel::Get( project );
@ -205,10 +209,16 @@ void DoZoomFitV(AudacityProject &project)
for (auto t : range)
t->SetHeight(height);
}
}
namespace ViewActions {
// Menu handler functions
struct Handler : CommandHandlerObject {
struct Handler final
: CommandHandlerObject // MUST be the first base class!
, ClientData::Base
{
void OnZoomIn(const CommandContext &context)
{
@ -417,15 +427,40 @@ void OnShowEffectsRack(const CommandContext &WXUNUSED(context) )
}
#endif
// Not a menu item, but a listener for events
void OnUndoPushed( wxCommandEvent &evt )
{
evt.Skip();
const auto &settings = ProjectSettings::Get( mProject );
if (settings.GetTracksFitVerticallyZoomed())
DoZoomFitV( mProject );
}
Handler( AudacityProject &project )
: mProject{ project }
{
mProject.Bind( EVT_UNDO_PUSHED, &Handler::OnUndoPushed, this );
}
~Handler()
{
mProject.Unbind( EVT_UNDO_PUSHED, &Handler::OnUndoPushed, this );
}
AudacityProject &mProject;
}; // struct Handler
} // namespace
static CommandHandlerObject &findCommandHandler(AudacityProject &) {
// Handler is not stateful. Doesn't need a factory registered with
// AudacityProject.
static ViewActions::Handler instance;
return instance;
// Handler needs a back-reference to the project, so needs a factory registered
// with AudacityProject.
static const AudacityProject::AttachedObjects::RegisteredFactory key{
[]( AudacityProject &project ) {
return std::make_unique< ViewActions::Handler >( project ); } };
static CommandHandlerObject &findCommandHandler(AudacityProject &project) {
return project.AttachedObjects::Get< ViewActions::Handler >( key );
};
// Menu definitions