From b5161317281a4c32b6a8d332389ee8178f244ce0 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 16 Sep 2021 20:45:06 -0400 Subject: handle lut mode exceptions on apply --- grapher/Models/AccelGUI.cs | 33 +++++++++++++++++++++------ grapher/Models/Options/LUT/LUTPanelOptions.cs | 14 ++++++------ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index e694dd4..4ce6ed8 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -112,7 +112,7 @@ namespace grapher } } - public void UpdateActiveSettingsFromFields() + public DriverSettings MakeSettingsFromFields() { var settings = new DriverSettings(); @@ -130,19 +130,38 @@ namespace grapher Settings.SetHiddenOptions(settings); - ButtonDelay(WriteButton); + return settings; + } - SettingsErrors errors = Settings.TryActivate(settings); - if (errors.Empty()) + public void UpdateActiveSettingsFromFields() + { + string error_message; + + try { - RefreshActive(); + ButtonDelay(WriteButton); + + var settings = MakeSettingsFromFields(); + SettingsErrors errors = Settings.TryActivate(settings); + if (errors.Empty()) + { + RefreshActive(); + return; + } + else + { + error_message = errors.ToString(); + } } - else + catch (ApplicationException e) { - new MessageDialog(errors.ToString(), "bad input").ShowDialog(); + error_message = e.Message; } + + new MessageDialog(error_message, "bad input").ShowDialog(); } + public void UpdateInputManagers() { MouseWatcher.UpdateHandles(Settings.ActiveSettings.baseSettings.deviceID); diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs index 0d244b4..4357619 100644 --- a/grapher/Models/Options/LUT/LUTPanelOptions.cs +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -137,7 +137,7 @@ namespace grapher.Models.Options.LUT { if (string.IsNullOrWhiteSpace(userText)) { - throw new Exception("Text must be entered in text box to fill Look Up Table."); + throw new ApplicationException("Text must be entered in text box to fill Look Up Table."); } Vec2[] points = new Vec2[256]; @@ -152,7 +152,7 @@ namespace grapher.Models.Options.LUT if (pointSplit.Length != 2) { - throw new Exception($"Point at index {index} is malformed. Expected format: x,y; Given: {pointEntry.Trim()}"); + throw new ApplicationException($"Point at index {index} is malformed. Expected format: x,y; Given: {pointEntry.Trim()}"); } float x; @@ -164,17 +164,17 @@ namespace grapher.Models.Options.LUT } catch (Exception ex) { - throw new Exception($"X-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[0]}", ex); + throw new ApplicationException($"X-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[0]}", ex); } if (x <= 0) { - throw new Exception($"X-value for point at index {index} is less than or equal to 0. Point (0,0) is implied and should not be specified in points text."); + throw new ApplicationException($"X-value for point at index {index} is less than or equal to 0. Point (0,0) is implied and should not be specified in points text."); } if (x <= lastX) { - throw new Exception($"X-value for point at index {index} is less than or equal to previous x-value. Value: {x} Previous: {lastX}"); + throw new ApplicationException($"X-value for point at index {index} is less than or equal to previous x-value. Value: {x} Previous: {lastX}"); } lastX = x; @@ -185,12 +185,12 @@ namespace grapher.Models.Options.LUT } catch (Exception ex) { - throw new Exception($"Y-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[1]}", ex); + throw new ApplicationException($"Y-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[1]}", ex); } if (y <= 0) { - throw new Exception($"Y-value for point at index {index} is less than or equal to 0. Value: {y}"); + throw new ApplicationException($"Y-value for point at index {index} is less than or equal to 0. Value: {y}"); } points[index] = new Vec2 { x = x, y = y }; -- cgit v1.2.3