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, 1, 1));
170
171 /* Buttons */
172 // Tooltips match menu entries.
173 // We previously had longer tooltips which were not more clear.
174 AddButton(bmpZoomIn, bmpZoomIn, bmpZoomInDisabled, ETBZoomInID,
175 XO("Zoom In"));
176 AddButton(bmpZoomOut, bmpZoomOut, bmpZoomOutDisabled, ETBZoomOutID,
177 XO("Zoom Out"));
178 AddButton(bmpZoomSel, bmpZoomSel, bmpZoomSelDisabled, ETBZoomSelID,
179 XO("Zoom to Selection"));
180 AddButton(bmpZoomFit, bmpZoomFit, bmpZoomFitDisabled, ETBZoomFitID,
181 XO("Fit to Width"));
182 AddButton(bmpZoomToggle, bmpZoomToggle, bmpZoomToggleDisabled, ETBZoomToggleID,
183 XO("Zoom Toggle"));
184
185 // Tooltips slightly more verbose than the menu entries are.
186 AddButton(bmpTrim, bmpTrim, bmpTrimDisabled, ETBTrimID,
187 XO("Trim audio outside selection"));
188 AddButton(bmpSilence, bmpSilence, bmpSilenceDisabled, ETBSilenceID,
189 XO("Silence audio selection"));
190
191#ifdef OPTION_SYNC_LOCK_BUTTON
192 AddButton(bmpSyncLockTracksUp, bmpSyncLockTracksDown, bmpSyncLockTracksUp, ETBSyncLockID,
193 XO("Sync-Lock Tracks"), true);
194#else
195 AddSeparator();
196#endif
197
198 AddButton(bmpUndo, bmpUndo, bmpUndoDisabled, ETBUndoID,
199 XO("Undo"));
200 AddButton(bmpRedo, bmpRedo, bmpRedoDisabled, ETBRedoID,
201 XO("Redo"));
202
206
209
210#ifdef OPTION_SYNC_LOCK_BUTTON
211 mButtons.PushDown(ETBSyncLockID);
212#endif
213
215}
216
218{
220
221 // Set label to pull in language change
222 SetLabel(XO("Edit"));
223
224 // Give base class a chance
226}
227
229{
231}
232
234{
236}
237
238void EditToolBar::OnButton(wxCommandEvent &event)
239{
240 mButtons.OnButton(event);
241}
242
246};
247
248#include "ToolManager.h"
249
250namespace {
252 /* i18n-hint: Clicking this menu item shows the toolbar for editing */
253 EditToolBar::ID(), wxT("ShowEditTB"), XXO("&Edit Toolbar")
254};
255}
256
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.
static const ToolBarButtons::ButtonList EditToolbarButtonList
Definition: EditToolBar.cpp:88
@ 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 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
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:74
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:837
void UpdatePrefs() override
Definition: ToolBar.cpp:622
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:78
Holds a msgid for the translation catalog; may also bind format arguments.
AttachedToolBarMenuItem sAttachment