private void SubmitMessageButton_Click(object sender, RoutedEventArgs e) { if (UseLanguageAsSourceCheckbox.IsChecked == false && !ShortMessagesSource.Contains(MessageContent.Text)) { ShortMessagesSource.Add(MessageContent.Text); } }
private void DeleteButton_Click(object sender, RoutedEventArgs e) { if (ShortMessagesSource.Count <= 1) { return; } var btn = sender as Button; try { if (ShortMessagesSource.FirstOrDefault(x => x == (string)btn.Tag) is string s) { ShortMessagesSource.Remove(s); } } catch { } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { try { string warning = ""; // sg: Short Gap // sd: Short Duration // lg: Long Gap // ld: Long Duration int sgH, sgM, sgS, sdH, sdM, sdS, lgH, lgM, lgS, ldH, ldM, ldS; sgH = int.Parse(shortGapHours.Text); sgM = int.Parse(shortGapMinutes.Text); sgS = int.Parse(shortGapSeconds.Text); sdH = int.Parse(shortDurationHours.Text); sdM = int.Parse(shortDurationMinutes.Text); sdS = int.Parse(shortDurationSeconds.Text); lgH = int.Parse(longGapHours.Text); lgM = int.Parse(longGapMinutes.Text); lgS = int.Parse(longGapSeconds.Text); ldH = int.Parse(longDurationHours.Text); ldM = int.Parse(longDurationMinutes.Text); ldS = int.Parse(longDurationSeconds.Text); if (sgH > 11 || sdH > 11 || lgH > 11 || ldH > 11) { warning += "» " + App.LocalizedEnvironment.Translation.EyesGuard.TimeManipulation.HoursLimit.FormatWith(new { Hours = 11 }); } if (sgM > 59 || sdM > 59 || lgM > 59 || ldM > 59) { if (warning != "") { warning += "\n"; } warning += "» " + App.LocalizedEnvironment.Translation.EyesGuard.TimeManipulation.MinutesLimit.FormatWith(new{ Minutes = 59 }); } if (sgS > 59 || sdS > 59 || lgS > 59 || ldS > 59) { if (warning != "") { warning += "\n"; } warning += "» " + App.LocalizedEnvironment.Translation.EyesGuard.TimeManipulation.SecondsLimit.FormatWith(new { Seconds = 59 }); } if (new TimeSpan(sgH, sgM, sgS).TotalSeconds >= new TimeSpan(lgH, lgM, lgS).TotalSeconds) { if (warning != "") { warning += "\n"; } warning += "» " + App.LocalizedEnvironment.Translation.EyesGuard.TimeManipulation.SGapMorethanLGap; } if (new TimeSpan(sdH, sdM, sdS).TotalSeconds >= new TimeSpan(ldH, ldM, ldS).TotalSeconds) { if (warning != "") { warning += "\n"; } warning += "» " + App.LocalizedEnvironment.Translation.EyesGuard.TimeManipulation.SDurationMorethanLDuration; } if (new TimeSpan(sdH, sdM, sdS).TotalMinutes > 5) { if (warning != "") { warning += "\n"; } warning += "» " + App.LocalizedEnvironment.Translation.EyesGuard.TimeManipulation.SDurationTooHigh; } if (new TimeSpan(ldH, ldM, ldS).TotalHours > 2) { if (warning != "") { warning += "\n"; } warning += "» " + App.LocalizedEnvironment.Translation.EyesGuard.TimeManipulation.LDurationTooHigh; } if (new TimeSpan(sgH, sgM, sgS).TotalSeconds + new TimeSpan(sdH, sdM, sdS).TotalSeconds >= new TimeSpan(lgH, lgM, lgS).TotalSeconds) { if (warning != "") { warning += "\n"; } warning += "» " + App.LocalizedEnvironment.Translation.EyesGuard.TimeManipulation.NotEnoughGapBetweenLandS; } if (new TimeSpan(sgH, sgM, sgS).TotalSeconds < 60) { if (warning != "") { warning += "\n"; } warning += "» " + App.LocalizedEnvironment.Translation.EyesGuard.TimeManipulation.ShortGapLow; } if (new TimeSpan(lgH, lgM, lgS).TotalMinutes < 5) { if (warning != "") { warning += "\n"; } warning += "» " + App.LocalizedEnvironment.Translation.EyesGuard.TimeManipulation.LongGapLow; } if (warning?.Length == 0) { App.Configuration.ShortBreakGap = new TimeSpan(sgH, sgM, sgS); App.Configuration.ShortBreakDuration = new TimeSpan(sdH, sdM, sdS); App.Configuration.LongBreakGap = new TimeSpan(lgH, lgM, lgS); App.Configuration.LongBreakDuration = new TimeSpan(ldH, ldM, ldS); App.Configuration.ForceUserToBreak = forceUserCheckbox.IsChecked.Value; App.Configuration.SaveStats = storeStatsCheckbox.IsChecked.Value; App.Configuration.OnlyOneShortBreak = onlyOneShortbreakCheckbox.IsChecked.Value; App.Configuration.AlertBeforeLongBreak = alertBeforeLongbreak.IsChecked.Value; App.Configuration.ShortBreakAllowCloseWithRightCLick = shortBreakAllowCloseWithRightCLick.IsChecked.Value; App.Configuration.SystemIdleDetectionEnabled = sytemIdleCheckbox.IsChecked.Value; App.Configuration.ApplicationLocale = (LanguagesCombo.SelectedItem as LanguageHolder)?.Name ?? FsLanguageLoader.DefaultLocale; App.Configuration.UseLanguageProvedidShortMessages = UseLanguageAsSourceCheckbox.IsChecked.Value; if (!App.Configuration.UseLanguageProvedidShortMessages) { App.Configuration.CustomShortMessages = (ShortMessagesSource.Count > 0) ? ShortMessagesSource.ToArray() : new string[] { "Stare far-off" }; } App.Configuration.SaveSettingsToFile(); App.ShowWarning( App.LocalizedEnvironment.Translation.EyesGuard.Settings.SavedSuccessfully, WarningPage.PageStates.Success, new Settings()); } else { App.ShowWarning(warning); } } catch { App.ShowWarning($"{App.LocalizedEnvironment.Translation.EyesGuard.OperationFailed}.\n{App.LocalizedEnvironment.Translation.EyesGuard.CheckInput}."); } }