From 4a3ad49fcf2ef7c6ad8b8acfe9948a3e3b987f7f Mon Sep 17 00:00:00 2001 From: Jonas Arnold Date: Fri, 30 Jun 2023 13:55:08 +0200 Subject: [PATCH] fixed issue where app crashes when index is out of range, added message box when an unhandled exception occurred, decreased minimum window size of whole app --- .../MultiFormatDataView/MultiFormatDataView.cs | 7 +++++-- MultiTerm.Wpf/App.xaml.cs | 9 ++++++--- MultiTerm.Wpf/MainWindow.xaml | 2 +- MultiTerm.Wpf/View/ShellView.xaml | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs b/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs index daae6fb..aa62e54 100644 --- a/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs +++ b/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs @@ -323,8 +323,11 @@ public class MultiFormatDataView : Control { // subtracting the counted newline sequences and adding i (length) int elementPositionInCollection = selectionStartIndex - foundManuallyIntroducedNewlineSequenceCharacters + i; - // add element to new selection list - newSelection.Add(this.DataSource.Data.ElementAt(elementPositionInCollection)); + // this item does exist => add it to new selection list + if (this.DataSource.Data.ElementAtOrDefault(elementPositionInCollection) != null) + { + newSelection.Add(this.DataSource.Data.ElementAt(elementPositionInCollection)); + } // next item does not exist => break loop if(this.DataSource.Data.ElementAtOrDefault(elementPositionInCollection + 1) == null) { diff --git a/MultiTerm.Wpf/App.xaml.cs b/MultiTerm.Wpf/App.xaml.cs index 548aff8..dd53c10 100644 --- a/MultiTerm.Wpf/App.xaml.cs +++ b/MultiTerm.Wpf/App.xaml.cs @@ -101,17 +101,20 @@ public partial class App : Application #region Event handlers for hidden exceptions private void AppDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { - logger?.LogException((Exception)e.ExceptionObject, "AppDomain UnhandledException caught", nameof(App)); + logger?.LogException((Exception)e.ExceptionObject, "AppDomain UnhandledException occurred", nameof(App)); + MessageBox.Show("Please check logfile. Exception message: \n" + ((Exception)e.ExceptionObject).Message, "AppDomain UnhandledException occurred", MessageBoxButton.OK, MessageBoxImage.Warning); } private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { - logger?.LogException(e.Exception, "Application DispatcherUnhandledException caught", nameof(App)); + logger?.LogException(e.Exception, "Application DispatcherUnhandledException occurred", nameof(App)); + MessageBox.Show("Please check logfile. Exception message: \n" + e.Exception.Message, "Application DispatcherUnhandledException occurred", MessageBoxButton.OK, MessageBoxImage.Warning); } private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e) { - logger?.LogException(e.Exception, "TaskScheduler UnobservedTaskException caught", nameof(App)); + logger?.LogException(e.Exception, "TaskScheduler UnobservedTaskException occurred", nameof(App)); + MessageBox.Show("Please check logfile. Exception message: \n" + e.Exception.Message, "TaskScheduler UnobservedTaskException occurred", MessageBoxButton.OK, MessageBoxImage.Warning); } #endregion } diff --git a/MultiTerm.Wpf/MainWindow.xaml b/MultiTerm.Wpf/MainWindow.xaml index dd002d5..fdc2630 100644 --- a/MultiTerm.Wpf/MainWindow.xaml +++ b/MultiTerm.Wpf/MainWindow.xaml @@ -8,7 +8,7 @@ xmlns:v="clr-namespace:MultiTerm.Wpf.View" mc:Ignorable="d" Height="900" Width="1600" - MinHeight="900" MinWidth="1600" + MinHeight="800" MinWidth="1300" Title="MultiTerm" Icon="/Assets/mdi-console-white.png" FontSize="14"> diff --git a/MultiTerm.Wpf/View/ShellView.xaml b/MultiTerm.Wpf/View/ShellView.xaml index 3c5f278..3f245d2 100644 --- a/MultiTerm.Wpf/View/ShellView.xaml +++ b/MultiTerm.Wpf/View/ShellView.xaml @@ -107,7 +107,7 @@ - +