Audacity 3.2.0
Functions | Variables
anonymous_namespace{EditMenus.cpp} Namespace Reference

Functions

void FinishCopy (const Track *n, const Track::Holder &dest, TrackList &list)
 
bool DoPasteText (AudacityProject &project)
 
bool DoPasteNothingSelected (AudacityProject &project)
 
BaseItemSharedPtr EditMenu ()
 
BaseItemSharedPtr ExtraEditMenu ()
 

Variables

AttachedItem sAttachment1
 
auto canSelectAll
 
auto selectAll
 
RegisteredMenuItemEnabler selectTracks
 
RegisteredMenuItemEnabler selectAnyTracks
 
RegisteredMenuItemEnabler selectWaveTracks
 
RegisteredMenuItemEnabler selectWaveTracks2
 
AttachedItem sAttachment2
 

Function Documentation

◆ DoPasteNothingSelected()

bool anonymous_namespace{EditMenus.cpp}::DoPasteNothingSelected ( AudacityProject project)

Definition at line 79 of file EditMenus.cpp.

80{
81 auto &tracks = TrackList::Get( project );
82 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
83 auto &viewInfo = ViewInfo::Get( project );
84 auto &window = ProjectWindow::Get( project );
85
86 // First check whether anything's selected.
87 if (tracks.Selected())
88 return false;
89 else
90 {
91 const auto &clipboard = Clipboard::Get();
92 auto clipTrackRange = clipboard.GetTracks().Any< const Track >();
93 if (clipTrackRange.empty())
94 return true; // nothing to paste
95
96 Track* pFirstNewTrack = NULL;
97 for (auto pClip : clipTrackRange) {
98 auto pNewTrack = pClip->PasteInto( project );
99 bool newTrack = (pNewTrack.use_count() == 1);
100 wxASSERT(pClip);
101
102 if (!pFirstNewTrack)
103 pFirstNewTrack = pNewTrack.get();
104
105 pNewTrack->SetSelected(true);
106 if (newTrack)
107 FinishCopy(pClip, pNewTrack, tracks);
108 else
109 Track::FinishCopy(pClip, pNewTrack.get());
110 }
111
112 // Select some pasted samples, which is probably impossible to get right
113 // with various project and track sample rates.
114 // So do it at the sample rate of the project
115 double projRate = ProjectRate::Get( project ).GetRate();
116 double quantT0 = QUANTIZED_TIME(clipboard.T0(), projRate);
117 double quantT1 = QUANTIZED_TIME(clipboard.T1(), projRate);
118 selectedRegion.setTimes(
119 0.0, // anywhere else and this should be
120 // half a sample earlier
121 quantT1 - quantT0);
122
123 ProjectHistory::Get( project )
124 .PushState(XO("Pasted from the clipboard"), XO("Paste"));
125
126 if (pFirstNewTrack) {
127 TrackFocus::Get(project).Set(pFirstNewTrack);
128 pFirstNewTrack->EnsureVisible();
129 }
130
131 return true;
132 }
133}
#define XO(s)
Definition: Internat.h:31
#define QUANTIZED_TIME(time, rate)
Definition: MemoryX.h:533
static Clipboard & Get()
Definition: Clipboard.cpp:29
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53
static ProjectWindow & Get(AudacityProject &project)
Track * Get()
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
void EnsureVisible(bool modifyState=false)
Definition: Track.cpp:97
virtual void SetSelected(bool s)
Definition: Track.cpp:87
virtual Holder PasteInto(AudacityProject &) const =0
Find or create the destination track for a paste, maybe in a different project.
static void FinishCopy(const Track *n, Track *dest)
Definition: Track.cpp:414
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
void FinishCopy(const Track *n, const Track::Holder &dest, TrackList &list)
Definition: EditMenus.cpp:35

References Track::EnsureVisible(), FinishCopy(), Track::FinishCopy(), Clipboard::Get(), TrackFocus::Get(), ProjectHistory::Get(), ProjectRate::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), ProjectRate::GetRate(), Track::PasteInto(), ProjectHistory::PushState(), QUANTIZED_TIME, ViewInfo::selectedRegion, Track::SetSelected(), and XO.

Referenced by EditActions::Handler::OnPaste().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoPasteText()

bool anonymous_namespace{EditMenus.cpp}::DoPasteText ( AudacityProject project)

Definition at line 44 of file EditMenus.cpp.

45{
46 auto &tracks = TrackList::Get( project );
47 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
48 auto &window = ProjectWindow::Get( project );
49
50 for (auto pLabelTrack : tracks.Any<LabelTrack>())
51 {
52 // Does this track have an active label?
53 if (LabelTrackView::Get( *pLabelTrack ).GetTextEditIndex(project) != -1) {
54
55 // Yes, so try pasting into it
56 auto &view = LabelTrackView::Get( *pLabelTrack );
57 if (view.PasteSelectedText( project, selectedRegion.t0(),
58 selectedRegion.t1() ))
59 {
60 ProjectHistory::Get( project )
61 .PushState(XO("Pasted text from the clipboard"), XO("Paste"));
62
63 // Make sure caret is in view
64 int x;
65 if (view.CalcCursorX( project, &x )) {
66 window.ScrollIntoView(x);
67 }
68
69 return true;
70 }
71 }
72 }
73 return false;
74}
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:89
static LabelTrackView & Get(LabelTrack &)
int GetTextEditIndex(AudacityProject &project) const

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), LabelTrackView::Get(), LabelTrackView::GetTextEditIndex(), ProjectHistory::PushState(), ViewInfo::selectedRegion, and XO.

Referenced by EditActions::Handler::OnPaste().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EditMenu()

BaseItemSharedPtr anonymous_namespace{EditMenus.cpp}::EditMenu ( )

Definition at line 1066 of file EditMenus.cpp.

1067{
1069
1070 static const auto NotBusyTimeAndTracksFlags =
1072
1073 // The default shortcut key for Redo is different on different platforms.
1074 static constexpr auto redoKey =
1075#ifdef __WXMSW__
1076 wxT("Ctrl+Y")
1077#else
1078 wxT("Ctrl+Shift+Z")
1079#endif
1080 ;
1081
1082 // The default shortcut key for Preferences is different on different
1083 // platforms.
1084 static constexpr auto prefKey =
1085#ifdef __WXMAC__
1086 wxT("Ctrl+,")
1087#else
1088 wxT("Ctrl+P")
1089#endif
1090 ;
1091
1092 static BaseItemSharedPtr menu{
1094 Menu( wxT("Edit"), XXO("&Edit"),
1095 Section( "UndoRedo",
1096 Command( wxT("Undo"), XXO("&Undo"), FN(OnUndo),
1097 AudioIONotBusyFlag() | UndoAvailableFlag(), wxT("Ctrl+Z") ),
1098
1099 Command( wxT("Redo"), XXO("&Redo"), FN(OnRedo),
1100 AudioIONotBusyFlag() | RedoAvailableFlag(), redoKey ),
1101
1102 Special( wxT("UndoItemsUpdateStep"),
1103 [](AudacityProject &project, wxMenu&) {
1104 // Change names in the CommandManager as a side-effect
1106 })
1107 ),
1108
1109 Section( "Basic",
1110 // Basic Edit commands
1111 /* i18n-hint: (verb)*/
1112 Command( wxT("Cut"), XXO("Cu&t"), FN(OnCut),
1114 wxT("Ctrl+X") ),
1115 Command( wxT("Delete"), XXO("&Delete"), FN(OnDelete),
1117 wxT("Ctrl+K") ),
1118 /* i18n-hint: (verb)*/
1119 Command( wxT("Copy"), XXO("&Copy"), FN(OnCopy),
1120 AudioIONotBusyFlag() | CutCopyAvailableFlag(), wxT("Ctrl+C") ),
1121 /* i18n-hint: (verb)*/
1122 Command( wxT("Paste"), XXO("&Paste"), FN(OnPaste),
1123 AudioIONotBusyFlag(), wxT("Ctrl+V") ),
1124 /* i18n-hint: (verb)*/
1125 Command( wxT("Duplicate"), XXO("Duplic&ate"), FN(OnDuplicate),
1126 NotBusyTimeAndTracksFlags, wxT("Ctrl+D") ),
1127
1128 Section( "",
1129 Menu( wxT("RemoveSpecial"), XXO("R&emove Special"),
1130 Section( "",
1131 /* i18n-hint: (verb) Do a special kind of cut*/
1132 Command( wxT("SplitCut"), XXO("Spl&it Cut"), FN(OnSplitCut),
1133 NotBusyTimeAndTracksFlags,
1134 Options{ wxT("Ctrl+Alt+X") } ),
1135 /* i18n-hint: (verb) Do a special kind of DELETE*/
1136 Command( wxT("SplitDelete"), XXO("Split D&elete"), FN(OnSplitDelete),
1137 NotBusyTimeAndTracksFlags,
1138 Options{ wxT("Ctrl+Alt+K") } )
1139 ),
1140
1141 Section( "",
1142 /* i18n-hint: (verb)*/
1143 Command( wxT("Silence"), XXO("Silence Audi&o"), FN(OnSilence),
1145 wxT("Ctrl+L") ),
1146 /* i18n-hint: (verb)*/
1147 Command( wxT("Trim"), XXO("Tri&m Audio"), FN(OnTrim),
1149 Options{ wxT("Ctrl+T") } )
1150 )
1151 )
1152 )
1153 ),
1154
1155
1156 Section( "Other",
1158
1159 Menu( wxT("Clip"), XXO("Audi&o Clips"),
1160 Section( "",
1161 /* i18n-hint: (verb) It's an item on a menu. */
1162 Command( wxT("Split"), XXO("Sp&lit"), FN(OnSplit),
1164 Options{ wxT("Ctrl+I") } ),
1165 Command( wxT("SplitNew"), XXO("Split Ne&w"), FN(OnSplitNew),
1167 Options{ wxT("Ctrl+Alt+I") } )
1168 ),
1169
1170 Section( "",
1171 /* i18n-hint: (verb)*/
1172 Command( wxT("Join"), XXO("&Join"), FN(OnJoin),
1173 NotBusyTimeAndTracksFlags, wxT("Ctrl+J") ),
1174 Command( wxT("Disjoin"), XXO("Detac&h at Silences"), FN(OnDisjoin),
1175 NotBusyTimeAndTracksFlags, wxT("Ctrl+Alt+J") )
1176 )
1177 ),
1178
1180
1181 Command( wxT("EditMetaData"), XXO("&Metadata..."), FN(OnEditMetadata),
1183
1185
1186 ),
1187
1188 // Note that on Mac, the Preferences menu item is specially handled in
1189 // CommandManager (assigned a special wxWidgets id) so that it does
1190 // not appear in the Edit menu but instead under Audacity, consistent with
1191 // MacOS conventions.
1192 Section( "Preferences",
1193 Command( wxT("Preferences"), XXO("Pre&ferences..."), FN(OnPreferences),
1194 AudioIONotBusyFlag(), prefKey )
1195 )
1196
1197 ) ) };
1198 return menu;
1199}
const ReservedCommandFlag & NoAutoSelect()
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & UndoAvailableFlag()
const ReservedCommandFlag & RedoAvailableFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & EditableTracksSelectedFlag()
const ReservedCommandFlag & WaveTracksSelectedFlag()
static CommandHandlerObject & findCommandHandler(AudacityProject &)
Definition: EditMenus.cpp:1028
static const ReservedCommandFlag & CutCopyAvailableFlag()
Definition: EditMenus.cpp:1040
#define FN(X)
Definition: EditMenus.cpp:1037
#define XXO(s)
Definition: Internat.h:44
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
static void ModifyUndoMenuItems(AudacityProject &project)
Definition: Menus.cpp:444
std::unique_ptr< MenuItem > Menu(const Identifier &internalName, const TranslatableString &title, Args &&... args)
std::unique_ptr< MenuPart > Section(const Identifier &internalName, Args &&... args)
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
std::unique_ptr< SpecialItem > Special(const Identifier &name, const SpecialItem::Appender &fn)
std::shared_ptr< BaseItem > BaseItemSharedPtr
Definition: Registry.h:72
std::vector< CommandFlagOptions > & Options()
Definition: Menus.cpp:535

References AudioIONotBusyFlag(), MenuTable::Command(), CutCopyAvailableFlag(), EditableTracksSelectedFlag(), findCommandHandler(), FN, MenuTable::Menu(), MenuManager::ModifyUndoMenuItems(), NoAutoSelect(), anonymous_namespace{Menus.cpp}::Options(), RedoAvailableFlag(), MenuTable::Section(), MenuTable::Special(), TimeSelectedFlag(), UndoAvailableFlag(), WaveTracksSelectedFlag(), and XXO.

Here is the call graph for this function:

◆ ExtraEditMenu()

BaseItemSharedPtr anonymous_namespace{EditMenus.cpp}::ExtraEditMenu ( )

Definition at line 1206 of file EditMenus.cpp.

1207{
1209 static const auto flags =
1211 static BaseItemSharedPtr menu{
1213 Menu( wxT("Edit"), XXO("&Edit"),
1214 Command( wxT("DeleteKey"), XXO("&Delete Key"), FN(OnDelete),
1215 (flags | NoAutoSelect()),
1216 wxT("Backspace") ),
1217 Command( wxT("DeleteKey2"), XXO("Delete Key&2"), FN(OnDelete),
1218 (flags | NoAutoSelect()),
1219 wxT("Delete") )
1220 ) ) };
1221 return menu;
1222}

References AudioIONotBusyFlag(), MenuTable::Command(), EditableTracksSelectedFlag(), findCommandHandler(), FN, MenuTable::Menu(), NoAutoSelect(), anonymous_namespace{Menus.cpp}::Options(), TimeSelectedFlag(), and XXO.

Here is the call graph for this function:

◆ FinishCopy()

void anonymous_namespace{EditMenus.cpp}::FinishCopy ( const Track n,
const Track::Holder dest,
TrackList list 
)

Definition at line 34 of file EditMenus.cpp.

36{
37 Track::FinishCopy( n, dest.get() );
38 if (dest)
39 list.Add( dest );
40}
TrackKind * Add(const std::shared_ptr< TrackKind > &t)
Definition: Track.h:1562

References TrackList::Add(), and Track::FinishCopy().

Referenced by DoPasteNothingSelected(), EditActions::Handler::OnCopy(), EditActions::Handler::OnCut(), EditActions::Handler::OnSplitCut(), and EditActions::Handler::OnSplitNew().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ canSelectAll

auto anonymous_namespace{EditMenus.cpp}::canSelectAll
Initial value:
= [](const AudacityProject &project){
return MenuManager::Get( project ).mWhatIfNoSelection != 0; }
int mWhatIfNoSelection
Definition: Menus.h:124
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:71

Definition at line 1224 of file EditMenus.cpp.

◆ sAttachment1

AttachedItem anonymous_namespace{EditMenus.cpp}::sAttachment1
Initial value:
{
wxT(""),
}

Definition at line 1201 of file EditMenus.cpp.

◆ sAttachment2

AttachedItem anonymous_namespace{EditMenus.cpp}::sAttachment2
Initial value:
{
wxT("Optional/Extra/Part1"),
}
BaseItemSharedPtr ExtraEditMenu()
Definition: EditMenus.cpp:1206

Definition at line 1262 of file EditMenus.cpp.

◆ selectAll

auto anonymous_namespace{EditMenus.cpp}::selectAll
Initial value:
= []( AudacityProject &project, CommandFlag flagsRqd ){
if ( MenuManager::Get( project ).mWhatIfNoSelection == 1 &&
(flagsRqd & NoAutoSelect()).none() )
}
std::bitset< NCommandFlags > CommandFlag
Definition: CommandFlag.h:31
@ none
Definition: Dither.h:20
void DoSelectAllAudio(AudacityProject &project)

Definition at line 1226 of file EditMenus.cpp.

◆ selectAnyTracks

RegisteredMenuItemEnabler anonymous_namespace{EditMenus.cpp}::selectAnyTracks
Initial value:
{{
[]{ return TracksExistFlag(); },
[]{ return AnyTracksSelectedFlag(); },
}}
const ReservedCommandFlag & AnyTracksSelectedFlag()
const ReservedCommandFlag & TracksExistFlag()

Definition at line 1240 of file EditMenus.cpp.

◆ selectTracks

RegisteredMenuItemEnabler anonymous_namespace{EditMenus.cpp}::selectTracks
Initial value:
{{
[]{ return TracksExistFlag(); },
[]{ return EditableTracksSelectedFlag(); },
}}

Definition at line 1232 of file EditMenus.cpp.

◆ selectWaveTracks

RegisteredMenuItemEnabler anonymous_namespace{EditMenus.cpp}::selectWaveTracks
Initial value:
{{
[]{ return WaveTracksExistFlag(); },
}}
const ReservedCommandFlag & WaveTracksExistFlag()

Definition at line 1247 of file EditMenus.cpp.

◆ selectWaveTracks2

RegisteredMenuItemEnabler anonymous_namespace{EditMenus.cpp}::selectWaveTracks2
Initial value:
{{
[]{ return WaveTracksExistFlag(); },
}}
const ReservedCommandFlag & NoiseReductionTimeSelectedFlag()

Definition at line 1255 of file EditMenus.cpp.