mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-14 17:14:07 +01:00
Move code for common track menu items
This commit is contained in:
committed by
Paul Licameli
parent
bd0603b66a
commit
0e5e7b1c05
@@ -13,8 +13,12 @@ Paul Licameli split from TrackPanel.cpp
|
||||
#include "TrackButtonHandles.h"
|
||||
#include "../../HitTestResult.h"
|
||||
#include "../../RefreshCode.h"
|
||||
#include "../../MixerBoard.h"
|
||||
#include "../../Project.h"
|
||||
#include "../../TrackPanel.h"
|
||||
#include "../../TrackPanelMouseEvent.h"
|
||||
#include "../../WaveTrack.h"
|
||||
#include <wx/textdlg.h>
|
||||
|
||||
int TrackControls::gCaptureState;
|
||||
|
||||
@@ -47,6 +51,15 @@ Track *TrackControls::FindTrack()
|
||||
return GetTrack();
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
OnSetNameID = 2000,
|
||||
OnMoveUpID,
|
||||
OnMoveDownID,
|
||||
OnMoveTopID,
|
||||
OnMoveBottomID,
|
||||
};
|
||||
|
||||
class TrackMenuTable : public PopupMenuTable
|
||||
{
|
||||
TrackMenuTable() : mpData(NULL) {}
|
||||
@@ -56,11 +69,10 @@ public:
|
||||
static TrackMenuTable &Instance();
|
||||
|
||||
private:
|
||||
void OnSetName(wxCommandEvent &);
|
||||
void OnMoveTrack(wxCommandEvent &event);
|
||||
|
||||
void InitMenu(Menu*, void *pUserData) override
|
||||
{
|
||||
mpData = static_cast<TrackControls::InitMenuData*>(pUserData);
|
||||
}
|
||||
void InitMenu(Menu *pMenu, void *pUserData) override;
|
||||
|
||||
void DestroyMenu() override
|
||||
{
|
||||
@@ -76,9 +88,107 @@ TrackMenuTable &TrackMenuTable::Instance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
void TrackMenuTable::InitMenu(Menu *pMenu, void *pUserData)
|
||||
{
|
||||
mpData = static_cast<TrackControls::InitMenuData*>(pUserData);
|
||||
Track *const pTrack = mpData->pTrack;
|
||||
|
||||
TrackList *const tracks = GetActiveProject()->GetTracks();
|
||||
|
||||
pMenu->Enable(OnMoveUpID, tracks->CanMoveUp(pTrack));
|
||||
pMenu->Enable(OnMoveDownID, tracks->CanMoveDown(pTrack));
|
||||
pMenu->Enable(OnMoveTopID, tracks->CanMoveUp(pTrack));
|
||||
pMenu->Enable(OnMoveBottomID, tracks->CanMoveDown(pTrack));
|
||||
}
|
||||
|
||||
BEGIN_POPUP_MENU(TrackMenuTable)
|
||||
POPUP_MENU_ITEM(OnSetNameID, _("&Name..."), OnSetName)
|
||||
POPUP_MENU_SEPARATOR()
|
||||
POPUP_MENU_ITEM(
|
||||
// It is not correct to use KeyStringDisplay here -- wxWidgets will apply
|
||||
// its equivalent to the key names passed to menu functions.
|
||||
OnMoveUpID,
|
||||
_("Move Track &Up") + wxT("\t") +
|
||||
(GetActiveProject()->GetCommandManager()->
|
||||
GetKeyFromName(wxT("TrackMoveUp"))),
|
||||
OnMoveTrack)
|
||||
POPUP_MENU_ITEM(
|
||||
OnMoveDownID,
|
||||
_("Move Track &Down") + wxT("\t") +
|
||||
(GetActiveProject()->GetCommandManager()->
|
||||
GetKeyFromName(wxT("TrackMoveDown"))),
|
||||
OnMoveTrack)
|
||||
POPUP_MENU_ITEM(
|
||||
OnMoveTopID,
|
||||
_("Move Track to &Top") + wxT("\t") +
|
||||
(GetActiveProject()->GetCommandManager()->
|
||||
GetKeyFromName(wxT("TrackMoveTop"))),
|
||||
OnMoveTrack)
|
||||
POPUP_MENU_ITEM(
|
||||
OnMoveBottomID,
|
||||
_("Move Track to &Bottom") + wxT("\t") +
|
||||
(GetActiveProject()->GetCommandManager()->
|
||||
GetKeyFromName(wxT("TrackMoveBottom"))),
|
||||
OnMoveTrack)
|
||||
END_POPUP_MENU()
|
||||
|
||||
void TrackMenuTable::OnSetName(wxCommandEvent &)
|
||||
{
|
||||
Track *const pTrack = mpData->pTrack;
|
||||
if (pTrack)
|
||||
{
|
||||
AudacityProject *const proj = ::GetActiveProject();
|
||||
const wxString oldName = pTrack->GetName();
|
||||
const wxString newName =
|
||||
wxGetTextFromUser(_("Change track name to:"),
|
||||
_("Track Name"), oldName);
|
||||
if (newName != wxT("")) // wxGetTextFromUser returns empty string on Cancel.
|
||||
{
|
||||
pTrack->SetName(newName);
|
||||
// if we have a linked channel this name should change as well
|
||||
// (otherwise sort by name and time will crash).
|
||||
if (pTrack->GetLinked())
|
||||
pTrack->GetLink()->SetName(newName);
|
||||
|
||||
MixerBoard *const pMixerBoard = proj->GetMixerBoard();
|
||||
auto pt = dynamic_cast<PlayableTrack*>(pTrack);
|
||||
if (pt && pMixerBoard)
|
||||
pMixerBoard->UpdateName(pt);
|
||||
|
||||
proj->PushState(wxString::Format(_("Renamed '%s' to '%s'"),
|
||||
oldName.c_str(),
|
||||
newName.c_str()),
|
||||
_("Name Change"));
|
||||
|
||||
mpData->result = RefreshCode::RefreshAll;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TrackMenuTable::OnMoveTrack(wxCommandEvent &event)
|
||||
{
|
||||
AudacityProject *const project = GetActiveProject();
|
||||
AudacityProject::MoveChoice choice;
|
||||
switch (event.GetId()) {
|
||||
default:
|
||||
wxASSERT(false);
|
||||
case OnMoveUpID:
|
||||
choice = AudacityProject::OnMoveUpID; break;
|
||||
case OnMoveDownID:
|
||||
choice = AudacityProject::OnMoveDownID; break;
|
||||
case OnMoveTopID:
|
||||
choice = AudacityProject::OnMoveTopID; break;
|
||||
case OnMoveBottomID:
|
||||
choice = AudacityProject::OnMoveBottomID; break;
|
||||
}
|
||||
|
||||
project->MoveTrack(mpData->pTrack, choice);
|
||||
|
||||
// MoveTrack already refreshed TrackPanel, which means repaint will happen.
|
||||
// This is a harmless redundancy:
|
||||
mpData->result = RefreshCode::RefreshAll;
|
||||
}
|
||||
|
||||
unsigned TrackControls::DoContextMenu
|
||||
(const wxRect &rect, wxWindow *pParent, wxPoint *)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user