From a4d7ab8dc9eeeaa641a3f4ed0e2c1c2beff4b2a3 Mon Sep 17 00:00:00 2001 From: B0ney <40839054+B0ney@users.noreply.github.com> Date: Mon, 22 May 2023 18:48:12 +0100 Subject: [PATCH] GUI: highlight destination bar if it's empty or if the parent directory doesn't exist --- xmodits-gui/src/gui/app.rs | 31 ++++++++++++++++++++++++++----- xmodits-gui/src/gui/mod.rs | 2 +- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/xmodits-gui/src/gui/app.rs b/xmodits-gui/src/gui/app.rs index ba400bff..52ecaaeb 100644 --- a/xmodits-gui/src/gui/app.rs +++ b/xmodits-gui/src/gui/app.rs @@ -12,13 +12,17 @@ use iced::widget::{ }; use iced::window::icon::from_rgba; use iced::window::{Icon, Settings as Window}; -use iced::{Alignment, Application, Element, Length, Renderer, Settings}; +use iced::{Alignment, Application, Command, Element, Length, Renderer, Settings}; use iced_gif::gif; use iced_lazy::lazy; use image::{self, GenericImageView}; -use std::path::PathBuf; +use once_cell::sync::Lazy; +use std::path::{Path, PathBuf}; use style::Theme; +use tracing::warn; + +static DESTINATION_ID: Lazy = Lazy::new(text_input::Id::unique); fn icon() -> Icon { let image = image::load_from_memory(include_bytes!("../../res/img/logo/icon3.png")).unwrap(); @@ -99,17 +103,34 @@ impl App { pub fn destination_bar(&self) -> Element> { let destination = &self.ripping_config.destination; let input: _ = text_input("Output Directory", &format!("{}", destination.display())) + .id(DESTINATION_ID.clone()) .padding(10) .on_input(|s| Message::SetDestination(Some(PathBuf::new().join(s)))); input.into() } - pub fn start_ripping(&mut self) { - if self.entries.len() == 0 { + pub fn start_ripping(&mut self) -> Command { + let focus_destination = || text_input::focus(DESTINATION_ID.clone()); + + match self.ripping_config.destination.parent() { + Some(parent) => { + if parent == Path::new("") || !parent.exists() { + warn!("Destination is either empty or the parent folder doesn't exist."); + return focus_destination(); + } + } + None => return focus_destination(), + }; + + self._start_ripping(); + Command::none() + } + + pub fn _start_ripping(&mut self) { + if self.entries.is_empty() { return; } - let Some(sender) = &self.sender.to_owned() else { return; }; diff --git a/xmodits-gui/src/gui/mod.rs b/xmodits-gui/src/gui/mod.rs index 57a973b6..3c3bed72 100644 --- a/xmodits-gui/src/gui/mod.rs +++ b/xmodits-gui/src/gui/mod.rs @@ -257,7 +257,7 @@ impl Application for App { |_| Message::Ignore, ); } - Message::StartRip => self.start_ripping(), + Message::StartRip => return self.start_ripping(), Message::Subscription(m) => match m { ExtractionMessage::Ready(start_signal) => { self.sender = Some(start_signal);