Audacity 3.2.0
EditToolBar.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 EditToolBar.cpp
6
7 Dominic Mazzoni
8 Shane T. Mueller
9 Leland Lucius
10
11 See EditToolBar.h for details
12
13*******************************************************************//*******************************************************************/
31
32
33
34#include "EditToolBar.h"
35
36// For compilers that support precompilation, includes "wx/wx.h".
37#include <wx/wxprec.h>
38
39#include <wx/setup.h> // for wxUSE_* macros
40
41#ifndef WX_PRECOMP
42#include <wx/app.h>
43#include <wx/sizer.h>
44#include <wx/tooltip.h>
45#endif
46
47#include "AllThemeResources.h"
48#include "ImageManipulation.h"
49#include "Prefs.h"
50#include "Project.h"
51#include "UndoManager.h"
52#include "../widgets/AButton.h"
53
54#include "CommandContext.h"
55#include "CommandManager.h"
56#include "../commands/CommandDispatch.h"
57
58enum {
62
65
68
69 // no sync-lock on/off button.
70 // #define OPTION_SYNC_LOCK_BUTTON
71
72#ifdef OPTION_SYNC_LOCK_BUTTON
73 ETBSyncLockID,
74#endif
75
78
80};
81
82#ifdef OPTION_SYNC_LOCK_BUTTON
83#include "SyncLock.h"
84#endif
85
86constexpr int first_ETB_ID = 11300;
87
89 { ETBZoomInID, wxT("ZoomIn"), XO("Zoom In") },
90 { ETBZoomOutID, wxT("ZoomOut"), XO("Zoom Out") },
91 { ETBZoomToggleID, wxT("ZoomToggle"), XO("Zoom Toggle") },
92 { ETBZoomSelID, wxT("ZoomSel"), XO("Fit selection to width") },
93 { ETBZoomFitID, wxT("FitInWindow"), XO("Fit project to width") },
94
95 { ETBTrimID, wxT("Trim"), XO("Trim audio outside selection") },
96 { ETBSilenceID, wxT("Silence"), XO("Silence audio selection") },
97#ifdef OPTION_SYNC_LOCK_BUTTON
98 { ETBSyncLockID, wxT("SyncLock"), XO("Sync-Lock Tracks") },
99#endif
100 { ETBUndoID, wxT("Undo"), XO("Undo") },
101 { ETBRedoID, wxT("Redo"), XO("Redo") },
102};
103
105
109
110BEGIN_EVENT_TABLE( EditToolBar, ToolBar )
114 EditToolBar::OnButton )
116
118{
119 return wxT("Edit");
120}
121
122//Standard constructor
124: ToolBar(project, XO("Edit"), ID())
126{
127#ifdef OPTION_SYNC_LOCK_BUTTON
128 auto action = [this]() {
129 bool bSyncLockTracks = SyncLockTracks.Read();
130
131 if (bSyncLockTracks)
132 mButtons.PushDown(ETBSyncLockID);
133 else
134 mButtons.PopUp(ETBSyncLockID);
135 };
136
138#endif
139}
140
142{
143}
144
145void EditToolBar::Create(wxWindow * parent)
146{
147 ToolBar::Create(parent);
148 UpdatePrefs();
149}
150
152{
153 mToolSizer->AddSpacer(0);
154}
155
157 teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
158 int id, const TranslatableString &label, bool toggle)
159{
160 auto r = mButtons.CreateButton(eEnabledUp, eEnabledDown, eDisabled, id, label, toggle);
161 mToolSizer->Add(r);
162}
163
165{
166 SetBackgroundColour( theTheme.Colour( clrMedium ) );
168
169 Add(mToolSizer = safenew wxGridSizer(2, 5, toolbarSpacing, toolbarSpacing),
170 0, wxALIGN_CENTRE | wxALL, toolbarSpacing);
171
172 /* Buttons */
173 // Tooltips match menu entries.
174 // We previously had longer tooltips which were not more clear.
175 AddButton(bmpZoomIn, bmpZoomIn, bmpZoomInDisabled, ETBZoomInID,
176 XO("Zoom In"));
177 AddButton(bmpZoomOut, bmpZoomOut, bmpZoomOutDisabled, ETBZoomOutID,
178 XO("Zoom Out"));
179 AddButton(bmpZoomSel, bmpZoomSel, bmpZoomSelDisabled, ETBZoomSelID,
180 XO("Zoom to Selection"));
181 AddButton(bmpZoomFit, bmpZoomFit, bmpZoomFitDisabled, ETBZoomFitID,
182 XO("Fit to Width"));
183 AddButton(bmpZoomToggle, bmpZoomToggle, bmpZoomToggleDisabled, ETBZoomToggleID,
184 XO("Zoom Toggle"));
185
186 // Tooltips slightly more verbose than the menu entries are.
187 AddButton(bmpTrim, bmpTrim, bmpTrimDisabled, ETBTrimID,
188 XO("Trim audio outside selection"));
189 AddButton(bmpSilence, bmpSilence, bmpSilenceDisabled, ETBSilenceID,
190 XO("Silence audio selection"));
191
192#ifdef OPTION_SYNC_LOCK_BUTTON
193 AddButton(bmpSyncLockTracksUp, bmpSyncLockTracksDown, bmpSyncLockTracksUp, ETBSyncLockID,
194 XO("Sync-Lock Tracks"), true);
195#else
196 AddSeparator();
197#endif
198
199 AddButton(bmpUndo, bmpUndo, bmpUndoDisabled, ETBUndoID,
200 XO("Undo"));
201 AddButton(bmpRedo, bmpRedo, bmpRedoDisabled, ETBRedoID,
202 XO("Redo"));
203
207
210
211#ifdef OPTION_SYNC_LOCK_BUTTON
212 mButtons.PushDown(ETBSyncLockID);
213#endif
214
216}
217
219{
221
222 // Set label to pull in language change
223 SetLabel(XO("Edit"));
224
225 // Give base class a chance
227}
228
230{
232}
233
235{
237}
238
239void EditToolBar::OnButton(wxCommandEvent &event)
240{
241 mButtons.OnButton(event);
242}
243
247};
248
249#include "ToolManager.h"
250
251namespace {
253 /* i18n-hint: Clicking this menu item shows the toolbar for editing */
254 EditToolBar::ID(), wxT("ShowEditTB"), XXO("&Edit Toolbar")
255};
256}
257
wxEVT_COMMAND_BUTTON_CLICKED
wxT("CloseDown"))
END_EVENT_TABLE()
EVT_COMMAND_RANGE(ETBZoomInID+first_ETB_ID, ETBZoomInID+first_ETB_ID+ETBNumButtons - 1, wxEVT_COMMAND_BUTTON_CLICKED, EditToolBar::OnButton) Identifier EditToolBar
Methods for EditToolBar.
@ ETBZoomInID
Definition: EditToolBar.cpp:59
@ ETBRedoID
Definition: EditToolBar.cpp:77
@ ETBNumButtons
Definition: EditToolBar.cpp:79
@ ETBZoomSelID
Definition: EditToolBar.cpp:63
@ ETBUndoID
Definition: EditToolBar.cpp:76
@ ETBZoomOutID
Definition: EditToolBar.cpp:60
@ ETBTrimID
Definition: EditToolBar.cpp:66
@ ETBZoomToggleID
Definition: EditToolBar.cpp:61
@ ETBSilenceID
Definition: EditToolBar.cpp:67
@ ETBZoomFitID
Definition: EditToolBar.cpp:64
static const ToolBarButtons::ButtonList EditToolbarButtonList
Definition: EditToolBar.cpp:88
static RegisteredToolbarFactory factory
constexpr int first_ETB_ID
Definition: EditToolBar.cpp:86
IMPLEMENT_CLASS(EditToolBar, ToolBar)
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
int teBmps
#define safenew
Definition: MemoryX.h:10
BoolSetting SyncLockTracks
Definition: SyncLock.cpp:163
TranslatableString label
Definition: TagsEditor.cpp:165
const auto project
THEME_API Theme theTheme
Definition: Theme.cpp:82
static constexpr auto toolbarSpacing
Preferred spacing between inner toolbar elements.
Definition: ToolBar.h:57
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
A ToolBar that has the edit buttons on it.
Definition: EditToolBar.h:30
void EnableDisableButtons() override
EditToolBar(AudacityProject &project)
void UpdatePrefs() override
void Create(wxWindow *parent) override
ToolBarButtons mButtons
Definition: EditToolBar.h:58
wxGridSizer * mToolSizer
Definition: EditToolBar.h:59
void RegenerateTooltips() override
void Populate() override
void AddButton(teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, const TranslatableString &label, bool toggle=false)
void AddSeparator()
void OnButton(wxCommandEvent &event)
static Identifier ID()
virtual ~EditToolBar()
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:207
wxColour & Colour(int iIndex)
void EnableDisableButtons()
void SetCustomEnableDisableButtonsAction(std::function< void()> action)
void PopUp(int id)
void OnButton(wxCommandEvent &event)
void SetEnabled(int id, bool state)
void PushDown(int id)
std::vector< Entry > ButtonList
AButton * CreateButton(teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, const TranslatableString &label, bool toggle=false)
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:73
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:709
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:408
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:819
void UpdatePrefs() override
Definition: ToolBar.cpp:622
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:77
Holds a msgid for the translation catalog; may also bind format arguments.
AttachedToolBarMenuItem sAttachment