From f58c120bcc0a84156e5e253be57c1f958ea8576e Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 27 Feb 2022 09:36:14 +0100 Subject: Don’t create an event if repetition is not valid --- src/gui/form/repetition.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/gui/form/repetition.rs') diff --git a/src/gui/form/repetition.rs b/src/gui/form/repetition.rs index 87c8d84..7236016 100644 --- a/src/gui/form/repetition.rs +++ b/src/gui/form/repetition.rs @@ -126,26 +126,23 @@ fn label(text: &str) -> gtk::Label { .build() } -pub fn validate(model: &Model) -> Option { +pub fn validate(model: &Model) -> Result, String> { if model.no_radio.is_active() { - None + Ok(None) } else if model.day_interval_radio.is_active() { - repetition::validate_day(&model.day_interval_entry.buffer().text()) - .map(|d| Repetition::Daily { period: d }) + let period = repetition::validate_period(&model.day_interval_entry.buffer().text())?; + Ok(Some(Repetition::Daily { period })) } else if model.monthly_radio.is_active() { - repetition::validate_day(&model.monthly_entry.buffer().text()).map(|d| { - Repetition::Monthly { - day: DayOfMonth::Day { day: d }, - } - }) + let day = repetition::validate_day(&model.monthly_entry.buffer().text())?; + Ok(Some(Repetition::Monthly { day: DayOfMonth::Day { day } })) } else if model.first_day_radio.is_active() { let weekday = WEEKDAYS[model.first_day_dropdown.selected() as usize]; - Some(Repetition::Monthly { + Ok(Some(Repetition::Monthly { day: DayOfMonth::Weekday { weekday }, - }) + })) } else if model.yearly_radio.is_active() { - Some(Repetition::Yearly) + Ok(Some(Repetition::Yearly)) } else { - None + Err("Aucune option n’a été sélectionnée".to_string()) } } -- cgit v1.2.3