MCPcopy Create free account
hub / github.com/Moosync/Moosync / get_menu_items

Method get_menu_items

src/utils/context_menu.rs:203–341  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

201{
202 #[tracing::instrument(level = "debug", skip(self))]
203 fn get_menu_items(&self) -> ReadSignal<ContextMenuItems<Self>> {
204 let i18n = use_i18n();
205
206 let mut artist_items = vec![];
207 if let Some(song) = &self.current_song {
208 if let Some(artists) = &song.artists {
209 for artist in artists.clone() {
210 let artist_name = artist.artist_name.clone().unwrap_or_default();
211 artist_items.push(ContextMenuItemInner::<Self>::new_with_handler(
212 artist_name,
213 move |_, cx| cx.goto_artist(artist.clone()),
214 None,
215 ))
216 }
217 }
218 }
219
220 let mut playlist_items = vec![];
221 for playlist in self.playlists.get().iter() {
222 let playlist_name = playlist.playlist_name.clone();
223 let playlist_id = playlist.playlist_id.clone().unwrap_or_default();
224 playlist_items.push(ContextMenuItemInner::<Self>::new_with_handler(
225 playlist_name,
226 move |_, cx| cx.add_to_playlist(playlist_id.clone()),
227 None,
228 ))
229 }
230
231 let album_title = self
232 .current_song
233 .as_ref()
234 .and_then(|s| s.album.as_ref().map(|a| a.album_name.clone()))
235 .flatten();
236
237 let library_menu_item = if self
238 .current_song
239 .as_ref()
240 .map(|s| s.song.library_item.unwrap_or_default())
241 .unwrap_or_default()
242 {
243 ContextMenuItemInner::<Self>::new_with_handler(
244 t_string!(i18n, contextMenu.song.remove).to_string(),
245 |_, cx| cx.remove_from_library(),
246 None,
247 )
248 } else {
249 ContextMenuItemInner::<Self>::new_with_handler(
250 t_string!(i18n, contextMenu.song.add).to_string(),
251 |_, cx| cx.add_to_library(),
252 None,
253 )
254 };
255
256 let ret: RwSignal<ContextMenuItems<Self>> = RwSignal::new(vec![
257 ContextMenuItemInner::new_with_handler("Play now".into(), |_, cx| cx.play_now(), None),
258 ContextMenuItemInner::new_with_handler(
259 t_string!(i18n, contextMenu.song.playNext).to_string(),
260 |_, cx| cx.play_next(),

Callers

nothing calls this directly

Calls 10

get_sort_cx_itemsFunction · 0.85
cloneMethod · 0.80
goto_artistMethod · 0.80
getMethod · 0.80
remove_from_libraryMethod · 0.80
add_to_libraryMethod · 0.80
current_or_listMethod · 0.80
add_to_playlistMethod · 0.45
remove_from_playlistMethod · 0.45
get_provider_keysMethod · 0.45

Tested by

no test coverage detected