updated class diagrams,

added checks before adding something to history,
implemented copying everything when nothing is selected
master
Jonas Arnold 3 years ago
parent 3597cac75d
commit 39cd61307e
  1. 14
      Common/Common.cd
  2. 11
      MultiTerm.Core/TerminalViewModel.cd
  3. 26
      MultiTerm.Core/ViewModel/MultiFormatDataViewModel.cs
  4. 9
      MultiTerm.Core/ViewModel/TerminalViewModel.cs

@ -16,7 +16,7 @@
<Position X="9.717" Y="0.5" Height="0.291" Width="2.25" /> <Position X="9.717" Y="0.5" Height="0.291" Width="2.25" />
</Comment> </Comment>
<Comment CommentText="Context"> <Comment CommentText="Context">
<Position X="12.158" Y="0.5" Height="0.291" Width="2.25" /> <Position X="0.5" Y="4" Height="0.291" Width="2.25" />
</Comment> </Comment>
<Class Name="Common.AppSettings.AppSetting" Collapsed="true"> <Class Name="Common.AppSettings.AppSetting" Collapsed="true">
<Position X="0.5" Y="2.75" Width="1.5" /> <Position X="0.5" Y="2.75" Width="1.5" />
@ -43,7 +43,7 @@
<Class Name="Common.Helpers.EnumHelpers" Collapsed="true"> <Class Name="Common.Helpers.EnumHelpers" Collapsed="true">
<Position X="3" Y="1.75" Width="1.5" /> <Position X="3" Y="1.75" Width="1.5" />
<TypeIdentifier> <TypeIdentifier>
<HashCode>AAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAIAAAAA=</HashCode> <HashCode>AAAAAAAAAAAAEAAAAAAAAAAAAAAAEAgAAAAAAIABAAA=</HashCode>
<FileName>Helpers\EnumHelpers.cs</FileName> <FileName>Helpers\EnumHelpers.cs</FileName>
</TypeIdentifier> </TypeIdentifier>
</Class> </Class>
@ -92,8 +92,16 @@
<FileName>StartupHelpers\ServiceExtensions.cs</FileName> <FileName>StartupHelpers\ServiceExtensions.cs</FileName>
</TypeIdentifier> </TypeIdentifier>
</Class> </Class>
<Class Name="Common.Helpers.RecurringTimer" Collapsed="true">
<Position X="3" Y="2.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAACAgAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAA=</HashCode>
<FileName>Helpers\RecurringTimer.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Interface Name="Common.IContext" Collapsed="true"> <Interface Name="Common.IContext" Collapsed="true">
<Position X="12.25" Y="1" Width="2" /> <Position X="0.5" Y="4.5" Width="2" />
<TypeIdentifier> <TypeIdentifier>
<HashCode>AAAAAAAAAACYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode> <HashCode>AAAAAAAAAACYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>IContext.cs</FileName> <FileName>IContext.cs</FileName>

@ -15,18 +15,25 @@
</Path> </Path>
</InheritanceLine> </InheritanceLine>
<TypeIdentifier> <TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAACAAAAgA=</HashCode> <HashCode>AAAAAAKAAAAIIAAAAUAAAAAAAAAAAAAAAQAACAAAAgA=</HashCode>
<FileName>ViewModel\SendReceiveViewModel.cs</FileName> <FileName>ViewModel\SendReceiveViewModel.cs</FileName>
</TypeIdentifier> </TypeIdentifier>
</Class> </Class>
<Class Name="MultiTerm.Core.ViewModel.TerminalViewModel" Collapsed="true"> <Class Name="MultiTerm.Core.ViewModel.TerminalViewModel" Collapsed="true">
<Position X="4.75" Y="4.25" Width="4.25" /> <Position X="4.75" Y="4.25" Width="4.25" />
<TypeIdentifier> <TypeIdentifier>
<HashCode>EAQCUCCAQIAAIgAgEEAGBAgAAAAFRKYAAARgCAAAAAA=</HashCode> <HashCode>EAQAUKIAQIAMAgQgEUAGBAhAAAAFRKYAAQRgCAAAABA=</HashCode>
<FileName>ViewModel\TerminalViewModel.cs</FileName> <FileName>ViewModel\TerminalViewModel.cs</FileName>
</TypeIdentifier> </TypeIdentifier>
<Lollipop Position="0.2" /> <Lollipop Position="0.2" />
</Class> </Class>
<Class Name="MultiTerm.Core.ViewModel.ConsoleViewModel" Collapsed="true">
<Position X="7" Y="5.75" Width="2" />
<TypeIdentifier>
<HashCode>AgAAAAIgBAAIAgACgUAAggAAAACAAEAAAYAQCAAAiAM=</HashCode>
<FileName>ViewModel\ConsoleViewModel.cs</FileName>
</TypeIdentifier>
</Class>
<Interface Name="MultiTerm.Core.ViewModel.ITerminalViewModel"> <Interface Name="MultiTerm.Core.ViewModel.ITerminalViewModel">
<Position X="0.5" Y="4" Width="4" /> <Position X="0.5" Y="4" Width="4" />
<TypeIdentifier> <TypeIdentifier>

@ -150,20 +150,32 @@ public partial class MultiFormatDataViewModel : ObservableObject
} }
} }
/// <summary>
/// Returns the selected Data as string in the <paramref name="format"/> given.
/// If nothing is selected, returns the whole content of Data.
/// </summary>
/// <param name="format">format to return data in</param>
/// <returns>the data in the given format</returns>
public string GetSelectedDataAsString(FormatType format) public string GetSelectedDataAsString(FormatType format)
{ {
// nothing selected => return empty string List<ByteDataViewModel>? dataCopy = new();
if(this.Selected == null || this.Selected.Count == 0) { return string.Empty; }
// shallow copy of the selected items // nothing selected => return whole data
var selectedCopy = this.Selected.Select(item => (ByteDataViewModel)item.Clone()).ToList(); if(this.Selected == null || this.Selected.Count == 0)
{
dataCopy = this.Data.Select(item => (ByteDataViewModel)item.Clone()).ToList();
}
else // something is selected: shallow copy of the selected items
{
dataCopy = this.Selected.Select(item => (ByteDataViewModel)item.Clone()).ToList();
}
string dataAsString = string.Empty; string dataAsString = string.Empty;
dataAsString = format switch dataAsString = format switch
{ {
FormatType.Character => ByteDataViewModelHelpers.GetCharacterStringOfBytesDataViewModels(selectedCopy), FormatType.Character => ByteDataViewModelHelpers.GetCharacterStringOfBytesDataViewModels(dataCopy),
FormatType.Hexadecimal => ByteDataViewModelHelpers.GetHexadecimalStringOfBytesDataViewModels(selectedCopy), FormatType.Hexadecimal => ByteDataViewModelHelpers.GetHexadecimalStringOfBytesDataViewModels(dataCopy),
FormatType.Binary => ByteDataViewModelHelpers.GetBinaryStringOfEBytesDataViewModels(selectedCopy), FormatType.Binary => ByteDataViewModelHelpers.GetBinaryStringOfEBytesDataViewModels(dataCopy),
_ => throw new ArgumentException($"'{GetSelectedDataAsString}()' does not have handling implemented for {nameof(FormatType)} {format}") _ => throw new ArgumentException($"'{GetSelectedDataAsString}()' does not have handling implemented for {nameof(FormatType)} {format}")
}; };

@ -345,6 +345,15 @@ public abstract partial class TerminalViewModel : ObservableObject, ITerminalVie
/// <param name="element">element to add to the history</param> /// <param name="element">element to add to the history</param>
protected void AddToSendHistory(IHistoryElement element) protected void AddToSendHistory(IHistoryElement element)
{ {
// ignore elements that are of zero length
if(element.DisplayText.Length <= 0)
{ return; }
// do not insert elements that have the same content as the last element
if (this.SentMessagesHistory.Count > 0 &&
element.DisplayText.Equals(this.SentMessagesHistory.First().DisplayText))
{ return; }
// shallow copy of element (so that element can be changed externally) // shallow copy of element (so that element can be changed externally)
var copy = (IHistoryElement)element.Clone(); var copy = (IHistoryElement)element.Clone();

Loading…
Cancel
Save