From eac475742786592a2b7f637dcd3ce7af767b8a6c Mon Sep 17 00:00:00 2001 From: Jonas Arnold Date: Sun, 7 May 2023 20:08:43 +0200 Subject: [PATCH] fixed no tab open exception, worked on formatting, added icons for protocol types, worked on status bar messages --- MultiTerm.Core/ViewModel/TerminalViewModel.cs | 4 +- .../MultiFormatDataView.cs | 2 + MultiTerm.Wpf/Assets/mdi-keyboard.png | Bin 0 -> 466 bytes MultiTerm.Wpf/Assets/mdi-network.png | Bin 0 -> 474 bytes MultiTerm.Wpf/Assets/mdi-serial-port.png | Bin 0 -> 392 bytes MultiTerm.Wpf/MultiTerm.Wpf.csproj | 11 ++++- .../MessageImportanceToBrushConverter.cs | 3 +- .../MessageImportanceToFontWeightConverter.cs | 32 ++++++++++++++ .../ProtocolTypeToIconConverter.cs | 40 ++++++++++++++++++ .../View/SettingsView/UsbHidSettingsView.xaml | 15 ++++--- MultiTerm.Wpf/View/ShellView.xaml | 18 +++++--- 11 files changed, 109 insertions(+), 16 deletions(-) create mode 100644 MultiTerm.Wpf/Assets/mdi-keyboard.png create mode 100644 MultiTerm.Wpf/Assets/mdi-network.png create mode 100644 MultiTerm.Wpf/Assets/mdi-serial-port.png create mode 100644 MultiTerm.Wpf/ValueConverters/MessageImportanceToFontWeightConverter.cs create mode 100644 MultiTerm.Wpf/ValueConverters/ProtocolTypeToIconConverter.cs diff --git a/MultiTerm.Core/ViewModel/TerminalViewModel.cs b/MultiTerm.Core/ViewModel/TerminalViewModel.cs index c3045ba..f3a5c69 100644 --- a/MultiTerm.Core/ViewModel/TerminalViewModel.cs +++ b/MultiTerm.Core/ViewModel/TerminalViewModel.cs @@ -48,11 +48,11 @@ public abstract partial class TerminalViewModel : ObservableObject, ITerminalVie { if(this.CommunicationProtocol == null) { - this.Title = $"{ProtocolType}"; + this.Title = $"new"; } else { - this.Title = $"{ProtocolType} {this.CommunicationProtocol?.InstanceIdentifier}"; + this.Title = $"{this.CommunicationProtocol?.InstanceIdentifier}"; } } #endregion diff --git a/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs b/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs index c9be7b0..32b17be 100644 --- a/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs +++ b/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs @@ -155,6 +155,8 @@ public class MultiFormatDataView : Control { // extract instance and guard null if (d is not MultiFormatDataView mfdv) { return; } + // guard DataSource is null + if (mfdv.DataSource == null) { return; } // manually create collection view ICollectionView cv = CollectionViewSource.GetDefaultView(mfdv.DataSource.Data); diff --git a/MultiTerm.Wpf/Assets/mdi-keyboard.png b/MultiTerm.Wpf/Assets/mdi-keyboard.png new file mode 100644 index 0000000000000000000000000000000000000000..c7323cd51ba70fdfda31c9e8762b24b985a7de4d GIT binary patch literal 466 zcmV;@0WJQCP)Px$j7da6R7gveRnb+%KnNTv&<=c7pe0y>c47&3q$Svb9h@Cp2kT2o_)q%3*l0GHn zfoUG>nEXFxP@(Vkv&fnWGk6i;vkC5fV^2yEl8~#Qy*1#wr_qzS0=O%a=EjEPgW&?; zaSO~0RCtLrceNxXKdhithk77wieAJdxQ&JSsG%pcRaeY^{Qd$jzzS_9_R0=N3EhSnQP){Aer0)T^AB9h+AVEdE_{Nm9 zlO>ppJPFRr^xq?uF57{40|Q0We$>M?H@xrq{+*kHa1S(c*L$@U_aic6mki`0Xb*9c zEiSK$1Zru;4+PK49N-ne2Y@H1WOw3x#w;ConJcGO3fW~IaG ztd=J;A)M@joF(@u3XUbPx$lu1NER7gvWRa;dBF$|n4Kmry(!M!*@3Mjw|5|D6l01m(b4$A2>lSj9^AA9z+ z+axoYOcTnJ0Ob1W-*q*3`ai4f#feQI4!Zi*HFCgm;@q<-UbdNuRLO}DJOlX+z{62? z%J~D}6~ITql8_78ll>@0IdFg61q~?yUm1AR2@;a)Z(GQ<;g-xu2ppic!XS`+wJ}18 z$Q&I0f1;@gxH#1V+G^$Neu;{8)dr_Yun>pgN0J>%u7Q&7W}~7r2sWA)iU#@^L2q)W zf@QZ);EiFPi4o}Ot;smCF2c=~k||ZEnk?&Df(wsv>YiO8Dtv;qa##U=4n&Tt6!y1`O*hi|pUSyV&@=*)=MzKz<*7#0R7tRoX9rmu7Z62OZKz zdbB+~%21(|#upcZYjsoGdj3qnH5z%INk0dUqVQrdm&IC#|1lE49hmRs Qr~m)}07*qoM6N<$g3aj4zyJUM literal 0 HcmV?d00001 diff --git a/MultiTerm.Wpf/Assets/mdi-serial-port.png b/MultiTerm.Wpf/Assets/mdi-serial-port.png new file mode 100644 index 0000000000000000000000000000000000000000..78a0523af232e6c37bcc6e7c469cce8d1c392080 GIT binary patch literal 392 zcmV;30eAk1P)Px$LP%x(yY#Zf`A01tb-Esfaw}Nq3IWh*7*fzCIoj z#HFScaL~O!6_v;FU#5KV>q?^;NsOmRopq=P&8%=4?DUb*!>rSd8VdwP8V!uK8^64C zXc#E+bNgtZ=B`cP*=}H1X2(GPmjd1Qs>p>Kg<|d^Y|(lxv={}`MMb;y(bPPhMMd-( z_HBwW7bV+F2z60jC8B{tyo+}<>j)VsX|Sf*V;Q~}`y?{gm+s^e#tO`)yFJ*Zbv;U{ zHQvy`m$3@|#e#g*siO+CS+th?;FddoDj}{true + + + + + + + @@ -21,7 +28,9 @@ - + + + diff --git a/MultiTerm.Wpf/ValueConverters/MessageImportanceToBrushConverter.cs b/MultiTerm.Wpf/ValueConverters/MessageImportanceToBrushConverter.cs index 389d1ea..a3302d4 100644 --- a/MultiTerm.Wpf/ValueConverters/MessageImportanceToBrushConverter.cs +++ b/MultiTerm.Wpf/ValueConverters/MessageImportanceToBrushConverter.cs @@ -1,7 +1,6 @@ using Common.Messaging; using System; using System.Globalization; -using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; @@ -19,7 +18,7 @@ internal class MessageImportanceToBrushConverter : IValueConverter return msgImportance switch { MessageImportance.Normal => Brushes.Black, - MessageImportance.Medium => Brushes.DarkSalmon, + MessageImportance.Medium => Brushes.DarkOrange, MessageImportance.High => Brushes.Red, MessageImportance.HighAndRequiresConfirmation => throw new NotImplementedException(), _ => throw new NotImplementedException(), diff --git a/MultiTerm.Wpf/ValueConverters/MessageImportanceToFontWeightConverter.cs b/MultiTerm.Wpf/ValueConverters/MessageImportanceToFontWeightConverter.cs new file mode 100644 index 0000000..18642dc --- /dev/null +++ b/MultiTerm.Wpf/ValueConverters/MessageImportanceToFontWeightConverter.cs @@ -0,0 +1,32 @@ +using Common.Messaging; +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace MultiTerm.Wpf.ValueConverters; + +[ValueConversion(typeof(MessageImportance), typeof(FontWeight))] + +internal class MessageImportanceToFontWeightConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if(value is not MessageImportance msgImportance) + { throw new ArgumentException($"Wrong object provided, can only convert from type {nameof(MessageImportance)}"); } + + return msgImportance switch + { + MessageImportance.Normal => FontWeights.Normal, + MessageImportance.Medium => FontWeights.Medium, + MessageImportance.High => FontWeights.Bold, + MessageImportance.HighAndRequiresConfirmation => throw new NotImplementedException(), + _ => throw new NotImplementedException(), + }; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} diff --git a/MultiTerm.Wpf/ValueConverters/ProtocolTypeToIconConverter.cs b/MultiTerm.Wpf/ValueConverters/ProtocolTypeToIconConverter.cs new file mode 100644 index 0000000..9450e09 --- /dev/null +++ b/MultiTerm.Wpf/ValueConverters/ProtocolTypeToIconConverter.cs @@ -0,0 +1,40 @@ +using MultiTerm.Protocols.Types; +using System; +using System.Globalization; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Media.Imaging; + +namespace MultiTerm.Wpf.ValueConverters; + +[ValueConversion(typeof(ProtocolType), typeof(Image))] + +internal class ProtocolTypeToIconConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if(value is not ProtocolType protocolType) + { throw new ArgumentException($"Wrong object provided, can only convert from type {nameof(ProtocolType)}"); } + + string resourceFolderPath = "pack://application:,,,/Assets/"; + //string path = $"{typeof(MainWindow).FullName};component/Assets/"; + //string packUri = "pack://application:,,,/Assets/"; + + string fileName = protocolType switch + { + ProtocolType.Serial => "mdi-serial-port.png", + ProtocolType.UsbHid => "mdi-keyboard.png", + ProtocolType.Tcp => "mdi-network.png", + ProtocolType.Udp => "mdi-network.png", + _ => throw new NotImplementedException(), + }; + + var uriSource = new Uri(resourceFolderPath + fileName); + return new BitmapImage(uriSource); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} diff --git a/MultiTerm.Wpf/View/SettingsView/UsbHidSettingsView.xaml b/MultiTerm.Wpf/View/SettingsView/UsbHidSettingsView.xaml index 08cf7a4..c949989 100644 --- a/MultiTerm.Wpf/View/SettingsView/UsbHidSettingsView.xaml +++ b/MultiTerm.Wpf/View/SettingsView/UsbHidSettingsView.xaml @@ -17,7 +17,7 @@