58 lines
2.3 KiB
Rust
58 lines
2.3 KiB
Rust
use egui::{Color32, RichText};
|
|
use crate::{manifest::song::Song, ui::gui::windows::{song_edit::GuiSongEditor, WindowIndex}};
|
|
|
|
pub struct ContextMenu;
|
|
|
|
// NOTE: This should be a component but theres no easy way to do that, so we just make it folow the
|
|
// trait manually, ish, more like a convention
|
|
impl /* ComponentUi for */ ContextMenu {
|
|
pub fn ui(gui: &mut crate::ui::gui::Gui, ui: &mut egui::Ui, pname: &String, sname: &String, song: &Song) {
|
|
if ui.button("Edit").clicked() {
|
|
let w = gui.windows.get_window::<GuiSongEditor>(WindowIndex::SongEdit);
|
|
w.set_active_song(pname, sname, song.get_url_str());
|
|
gui.windows.open(WindowIndex::SongEdit, true);
|
|
ui.close_menu();
|
|
}
|
|
|
|
if ui.button("Download").clicked() {
|
|
if let Err(e) = gui.downloader.download_song_nb(&gui.cfg, pname, sname, song, gui.manifest.get_format()) {
|
|
log::error!("{e}");
|
|
gui.throw_error(format!("Failed to download song {sname}: {e}"));
|
|
}
|
|
ui.close_menu();
|
|
}
|
|
|
|
if ui.button("Open Source").clicked() {
|
|
if let Err(e) = open::that(song.get_url_str()) {
|
|
log::error!("{e}");
|
|
gui.throw_error(format!("Failed to open song source: {e}"));
|
|
}
|
|
ui.close_menu();
|
|
}
|
|
if ui.button("Play").clicked() {
|
|
let p = crate::util::get_song_path(pname, sname, gui.manifest.get_format());
|
|
|
|
if !p.exists() {
|
|
gui.throw_error("Song does not exist on disk".to_string());
|
|
} else if let Err(e) = open::that(p) {
|
|
log::error!("{e}");
|
|
gui.throw_error(format!("Failed to play song: {e}"));
|
|
}
|
|
ui.close_menu();
|
|
}
|
|
if ui.button("Delete from disk").clicked() {
|
|
let p = crate::util::get_song_path(pname, sname, gui.manifest.get_format());
|
|
if p.exists() {
|
|
if let Err(e) = std::fs::remove_file(p) {
|
|
gui.throw_error(format!("Failed to delete file: {e}"));
|
|
}
|
|
}
|
|
ui.close_menu();
|
|
}
|
|
if ui.button(RichText::new("Delete").color(Color32::RED)).clicked() {
|
|
gui.throw_error("TODO");
|
|
ui.close_menu();
|
|
}
|
|
}
|
|
}
|