From c431fbff431bbc2e5f8b0f62047558b0f76e1033 Mon Sep 17 00:00:00 2001 From: Hoang Seidel Date: Tue, 21 Jun 2022 23:04:20 +0200 Subject: [PATCH] nest "More from artist" menu entries in submenu --- .../artist_details/artist_details_model.rs | 26 +++++++++++++++---- src/app/components/details/details_model.rs | 26 +++++++++++++++---- .../now_playing/now_playing_model.rs | 26 +++++++++++++++---- .../playlist_details_model.rs | 26 +++++++++++++++---- .../saved_tracks/saved_tracks_model.rs | 26 +++++++++++++++---- 5 files changed, 105 insertions(+), 25 deletions(-) diff --git a/src/app/components/artist_details/artist_details_model.rs b/src/app/components/artist_details/artist_details_model.rs index c8ccecec..a4f5dfa5 100644 --- a/src/app/components/artist_details/artist_details_model.rs +++ b/src/app/components/artist_details/artist_details_model.rs @@ -123,11 +123,27 @@ impl PlaylistModel for ArtistDetailsModel { let menu = gio::Menu::new(); menu.append(Some(&*labels::VIEW_ALBUM), Some("song.view_album")); - for artist in song.artists.iter().filter(|a| self.id != a.id) { - menu.append( - Some(&labels::more_from_label(&artist.name)), - Some(&format!("song.view_artist_{}", artist.id)), - ); + + let artists_iter = song.artists.iter(); + + if artists_iter.len() > 1 { + let submenu = gio::Menu::new(); + + for artist in artists_iter { + submenu.append( + Some(&artist.name), + Some(&format!("song.view_artist_{}", artist.id)), + ); + } + + menu.append_submenu(Some("More from"), &submenu); + } else { + for artist in artists_iter { + menu.append( + Some(&labels::more_from_label(&artist.name)), + Some(&format!("song.view_artist_{}", artist.id)), + ); + } } menu.append(Some(&*labels::COPY_LINK), Some("song.copy_link")); diff --git a/src/app/components/details/details_model.rs b/src/app/components/details/details_model.rs index 12d98315..e9014d99 100644 --- a/src/app/components/details/details_model.rs +++ b/src/app/components/details/details_model.rs @@ -204,11 +204,27 @@ impl PlaylistModel for DetailsModel { let song = song.description(); let menu = gio::Menu::new(); - for artist in song.artists.iter() { - menu.append( - Some(&labels::more_from_label(&artist.name)), - Some(&format!("song.view_artist_{}", artist.id)), - ); + + let artists_iter = song.artists.iter(); + + if artists_iter.len() > 1 { + let submenu = gio::Menu::new(); + + for artist in artists_iter { + submenu.append( + Some(&artist.name), + Some(&format!("song.view_artist_{}", artist.id)), + ); + } + + menu.append_submenu(Some("More from"), &submenu); + } else { + for artist in artists_iter { + menu.append( + Some(&labels::more_from_label(&artist.name)), + Some(&format!("song.view_artist_{}", artist.id)), + ); + } } menu.append(Some(&*labels::COPY_LINK), Some("song.copy_link")); diff --git a/src/app/components/now_playing/now_playing_model.rs b/src/app/components/now_playing/now_playing_model.rs index 0e32558a..0c91232f 100644 --- a/src/app/components/now_playing/now_playing_model.rs +++ b/src/app/components/now_playing/now_playing_model.rs @@ -90,11 +90,27 @@ impl PlaylistModel for NowPlayingModel { let menu = gio::Menu::new(); menu.append(Some(&*labels::VIEW_ALBUM), Some("song.view_album")); - for artist in song.artists.iter() { - menu.append( - Some(&labels::more_from_label(&artist.name)), - Some(&format!("song.view_artist_{}", artist.id)), - ); + + let artists_iter = song.artists.iter(); + + if artists_iter.len() > 1 { + let submenu = gio::Menu::new(); + + for artist in artists_iter { + submenu.append( + Some(&artist.name), + Some(&format!("song.view_artist_{}", artist.id)), + ); + } + + menu.append_submenu(Some("More from"), &submenu); + } else { + for artist in artists_iter { + menu.append( + Some(&labels::more_from_label(&artist.name)), + Some(&format!("song.view_artist_{}", artist.id)), + ); + } } menu.append(Some(&*labels::COPY_LINK), Some("song.copy_link")); diff --git a/src/app/components/playlist_details/playlist_details_model.rs b/src/app/components/playlist_details/playlist_details_model.rs index 9349f8a1..22168ea0 100644 --- a/src/app/components/playlist_details/playlist_details_model.rs +++ b/src/app/components/playlist_details/playlist_details_model.rs @@ -142,11 +142,27 @@ impl PlaylistModel for PlaylistDetailsModel { let menu = gio::Menu::new(); menu.append(Some(&*labels::VIEW_ALBUM), Some("song.view_album")); - for artist in song.artists.iter() { - menu.append( - Some(&labels::more_from_label(&artist.name)), - Some(&format!("song.view_artist_{}", artist.id)), - ); + + let artists_iter = song.artists.iter(); + + if artists_iter.len() > 1 { + let submenu = gio::Menu::new(); + + for artist in artists_iter { + submenu.append( + Some(&artist.name), + Some(&format!("song.view_artist_{}", artist.id)), + ); + } + + menu.append_submenu(Some("More from"), &submenu); + } else { + for artist in artists_iter { + menu.append( + Some(&labels::more_from_label(&artist.name)), + Some(&format!("song.view_artist_{}", artist.id)), + ); + } } menu.append(Some(&*labels::COPY_LINK), Some("song.copy_link")); diff --git a/src/app/components/saved_tracks/saved_tracks_model.rs b/src/app/components/saved_tracks/saved_tracks_model.rs index 5bc8349a..2038902d 100644 --- a/src/app/components/saved_tracks/saved_tracks_model.rs +++ b/src/app/components/saved_tracks/saved_tracks_model.rs @@ -107,11 +107,27 @@ impl PlaylistModel for SavedTracksModel { let menu = gio::Menu::new(); menu.append(Some(&*labels::VIEW_ALBUM), Some("song.view_album")); - for artist in song.artists.iter() { - menu.append( - Some(&labels::more_from_label(&artist.name)), - Some(&format!("song.view_artist_{}", artist.id)), - ); + + let artists_iter = song.artists.iter(); + + if artists_iter.len() > 1 { + let submenu = gio::Menu::new(); + + for artist in artists_iter { + submenu.append( + Some(&artist.name), + Some(&format!("song.view_artist_{}", artist.id)), + ); + } + + menu.append_submenu(Some("More from"), &submenu); + } else { + for artist in artists_iter { + menu.append( + Some(&labels::more_from_label(&artist.name)), + Some(&format!("song.view_artist_{}", artist.id)), + ); + } } menu.append(Some(&*labels::COPY_LINK), Some("song.copy_link"));