Skip to content

Commit

Permalink
Break dependency of PluginMenus on ProjectWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Licameli committed Nov 8, 2023
1 parent a933dc2 commit c3a41c0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
6 changes: 6 additions & 0 deletions libraries/lib-viewport/Viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,12 @@ void Viewport::Redraw()
});
}

void Viewport::SetToDefaultSize()
{
if (mpCallbacks)
mpCallbacks->SetToDefaultSize();
}

void Viewport::OnUndoPushedModified()
{
Redraw();
Expand Down
4 changes: 4 additions & 0 deletions libraries/lib-viewport/Viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class VIEWPORT_API ViewportCallbacks {
virtual void SetVerticalScrollbar(int position, int thumbSize,
int range, int pageSize, bool refresh) = 0;
virtual void ShowVerticalScrollbar(bool shown) = 0;

virtual void SetToDefaultSize() = 0;
};

struct ViewportMessage {
Expand Down Expand Up @@ -175,6 +177,8 @@ class VIEWPORT_API Viewport final

void Redraw();

void SetToDefaultSize();

private:
// How many pixels are covered by the period from lowermost scrollable time, to the given time:
// PRL: Bug1197: we seem to need to compute all in double, to avoid differing results on Mac
Expand Down
16 changes: 6 additions & 10 deletions src/ProjectWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Paul Licameli split from AudacityProject.cpp
#include "ViewInfo.h"
#include "WaveClip.h"
#include "WaveTrack.h"
#include "commands/CommandContext.h"
#include "prefs/ThemePrefs.h"
#include "prefs/TracksPrefs.h"
#include "toolbars/ToolManager.h"
Expand Down Expand Up @@ -430,14 +429,6 @@ const ProjectWindow *ProjectWindow::Find( const AudacityProject *pProject )
return Find( const_cast< AudacityProject * >( pProject ) );
}

void ProjectWindow::OnResetWindow(const CommandContext& context)
{
auto& project = context.project;
auto& window = ProjectWindow::Get(project);

window.Reset();
}

int ProjectWindow::NextWindowID()
{
return mNextWindowID++;
Expand Down Expand Up @@ -524,6 +515,11 @@ struct Adapter final : ViewportCallbacks {
if (mwWindow)
mwWindow->ShowVerticalScrollbar(shown);
}
void SetToDefaultSize() override
{
if (mwWindow)
mwWindow->SetToDefaultSize();
}

wxWeakRef<ProjectWindow> mwWindow;
};
Expand Down Expand Up @@ -919,7 +915,7 @@ wxPanel* ProjectWindow::GetTopPanel() noexcept
return mTopPanel;
}

void ProjectWindow::Reset()
void ProjectWindow::SetToDefaultSize()
{
wxRect defaultRect;
GetDefaultWindowRect(&defaultRect);
Expand Down
8 changes: 2 additions & 6 deletions src/ProjectWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Paul Licameli split from AudacityProject.h
#include "Prefs.h"
#include "Viewport.h"

class CommandContext;

class wxScrollBar;
class wxPanel;
class wxSplitterWindow;
Expand All @@ -44,8 +42,6 @@ class AUDACITY_DLL_API ProjectWindow final : public ProjectWindowBase
static ProjectWindow *Find( AudacityProject *pProject );
static const ProjectWindow *Find( const AudacityProject *pProject );

static void OnResetWindow(const CommandContext& context);

explicit ProjectWindow(
wxWindow * parent, wxWindowID id,
const wxPoint & pos, const wxSize &size,
Expand All @@ -61,8 +57,6 @@ class AUDACITY_DLL_API ProjectWindow final : public ProjectWindowBase
bool IsBeingDeleted() const { return mIsDeleting; }
void SetIsBeingDeleted() { mIsDeleting = true; }

void Reset();

/**
* \brief Track list window is the parent container for TrackPanel
* \return Pointer to a track list window (not null)
Expand Down Expand Up @@ -155,6 +149,8 @@ class AUDACITY_DLL_API ProjectWindow final : public ProjectWindowBase
int range, int pageSize, bool refresh) override;
void ShowVerticalScrollbar(bool shown) override;

void SetToDefaultSize() override;

// PRL: old and incorrect comment below, these functions are used elsewhere than TrackPanel
// TrackPanel access
wxSize GetTPTracksUsableArea() /* not override */;
Expand Down
4 changes: 2 additions & 2 deletions src/menus/PluginMenus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "ProjectRate.h"
#include "ProjectSnap.h"
#include "../ProjectSettings.h"
#include "../ProjectWindow.h"
#include "../ProjectWindows.h"
#include "../ProjectSelectionManager.h"
#include "RealtimeEffectPanel.h"
Expand All @@ -22,6 +21,7 @@
#include "TrackFocus.h"
#include "TempDirectory.h"
#include "UndoManager.h"
#include "Viewport.h"
#include "../commands/CommandContext.h"
#include "../commands/CommandManager.h"
#include "../effects/EffectManager.h"
Expand Down Expand Up @@ -99,7 +99,7 @@ void OnResetConfig(const CommandContext &context)
gPrefs->Flush();
DoReloadPreferences(project);

ProjectWindow::OnResetWindow(context);
Viewport::Get(project).SetToDefaultSize();
ToolManager::OnResetToolBars(context);

// These are necessary to preserve the newly correctly laid out toolbars.
Expand Down

0 comments on commit c3a41c0

Please sign in to comment.