73 lines
2.5 KiB
Rust
73 lines
2.5 KiB
Rust
use crate::manifest::song::{Song, SongType};
|
|
use super::{State, Window};
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct GuiNewSong {
|
|
typ: SongType,
|
|
name: String,
|
|
playlist: Option<String>,
|
|
url: String,
|
|
}
|
|
|
|
impl Window for GuiNewSong {
|
|
fn ui(&mut self, state: &mut State, ctx: &egui::Context, open: &mut bool) -> anyhow::Result<()> {
|
|
let mut save = false;
|
|
egui::Window::new("New song")
|
|
.open(open)
|
|
.show(ctx, |ui| {
|
|
ui.horizontal(|ui| {
|
|
ui.label("Type: ");
|
|
egui::ComboBox::from_id_source("new_song_window_type")
|
|
.selected_text(format!("{:?}", self.typ))
|
|
.show_ui(ui, |ui| {
|
|
ui.selectable_value(&mut self.typ, SongType::Youtube, "Youtube");
|
|
ui.selectable_value(&mut self.typ, SongType::Spotify, "Spotify");
|
|
ui.selectable_value(&mut self.typ, SongType::Soundcloud, "Soundcloud");
|
|
}
|
|
);
|
|
});
|
|
|
|
ui.horizontal(|ui| {
|
|
ui.label("Name: ");
|
|
ui.text_edit_singleline(&mut self.name);
|
|
});
|
|
ui.horizontal(|ui| {
|
|
ui.label("Playlist: ");
|
|
egui::ComboBox::from_id_source("new_song_window_playlist")
|
|
.selected_text(self.playlist.clone().unwrap_or_default())
|
|
.show_ui(ui, |ui| {
|
|
for p in state.manifest.get_playlists().keys() {
|
|
ui.selectable_value(&mut self.playlist, Option::Some(p.clone()), p.as_str());
|
|
}
|
|
}
|
|
);
|
|
});
|
|
ui.horizontal(|ui| {
|
|
ui.label("Url: ");
|
|
ui.text_edit_singleline(&mut self.url);
|
|
});
|
|
|
|
if ui.button("Save").clicked() {
|
|
save = true;
|
|
}
|
|
});
|
|
|
|
if save {
|
|
let Some(playlist) = state.manifest.get_playlist_mut(&self.playlist.clone().unwrap()) else {
|
|
panic!("couldnt find playlist from a preset playlist list????????????");
|
|
};
|
|
|
|
playlist.add_song(
|
|
self.name.clone(),
|
|
Song::from_url_str(self.url.clone()).unwrap().set_type(self.typ.clone()).clone()
|
|
);
|
|
|
|
|
|
let _ = state.manifest.save(None);
|
|
*open = false;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|