Rewrite the structure of the gui and cli interfaces
Added a more modular way to add windows
This commit is contained in:
72
src/ui/gui/windows/song_new.rs
Normal file
72
src/ui/gui/windows/song_new.rs
Normal file
@@ -0,0 +1,72 @@
|
||||
use crate::manifest::song::{Song, SongType};
|
||||
use super::{State, Window};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct GuiNewSong {
|
||||
ed_type: SongType,
|
||||
ed_name: String,
|
||||
ed_playlist: Option<String>,
|
||||
ed_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.ed_type))
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut self.ed_type, SongType::Youtube, "Youtube");
|
||||
ui.selectable_value(&mut self.ed_type, SongType::Spotify, "Spotify");
|
||||
ui.selectable_value(&mut self.ed_type, SongType::Soundcloud, "Soundcloud");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Name: ");
|
||||
ui.text_edit_singleline(&mut self.ed_name);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Playlist: ");
|
||||
egui::ComboBox::from_id_source("new_song_window_playlist")
|
||||
.selected_text(format!("{}", self.ed_playlist.clone().unwrap_or("".to_string())))
|
||||
.show_ui(ui, |ui| {
|
||||
for p in state.manifest.get_playlists().keys() {
|
||||
ui.selectable_value(&mut self.ed_playlist, Option::Some(p.clone()), p.as_str());
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Url: ");
|
||||
ui.text_edit_singleline(&mut self.ed_url);
|
||||
});
|
||||
|
||||
if ui.button("Save").clicked() {
|
||||
save = true;
|
||||
}
|
||||
});
|
||||
|
||||
if save {
|
||||
let Some(playlist) = state.manifest.get_playlist_mut(&self.ed_playlist.clone().unwrap()) else {
|
||||
panic!("couldnt find playlist from a preset playlist list????????????");
|
||||
};
|
||||
|
||||
playlist.add_song(
|
||||
self.ed_name.clone(),
|
||||
Song::from_url_str(self.ed_url.clone()).unwrap().set_type(self.ed_type.clone()).clone()
|
||||
);
|
||||
|
||||
|
||||
let _ = state.manifest.save(None);
|
||||
*open = false;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user