Skip to content

Commit 44e1d61

Browse files
authored
Merge pull request #16 from xboxoneresearch/feat/ui_stuff
feat: Support three different display modes for code-details
2 parents f4b1136 + 4f3823b commit 44e1d61

10 files changed

Lines changed: 264 additions & 60 deletions

File tree

PostCodeSerialMonitor/Assets/Resources.Designer.cs

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PostCodeSerialMonitor/Assets/Resources.pt-BR.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@
341341
<value>Mostrar timestamps</value>
342342
<comment>In Views/ConfigurationDialog.axaml</comment>
343343
</data>
344+
<data name="TimestampLabel" xml:space="preserve">
345+
<value>Hora: </value>
346+
<comment>In Views/MainWindow.axaml</comment>
347+
</data>
344348
<data name="FirmwareUpdateUrl" xml:space="preserve">
345349
<value>URL de atualização do firmware</value>
346350
<comment>In Views/ConfigurationDialog.axaml</comment>

PostCodeSerialMonitor/Assets/Resources.resx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,14 @@
345345
<value>Show timestamps</value>
346346
<comment>In Views/ConfigurationDialog.axaml</comment>
347347
</data>
348+
<data name="DescriptionDisplaySettings" xml:space="preserve">
349+
<value>Description display</value>
350+
<comment>In Views/ConfigurationDialog.axaml</comment>
351+
</data>
352+
<data name="TimestampLabel" xml:space="preserve">
353+
<value>Time: </value>
354+
<comment>In Views/MainWindow.axaml</comment>
355+
</data>
348356
<data name="FirmwareUpdateUrl" xml:space="preserve">
349357
<value>Firmware update URL</value>
350358
<comment>In Views/ConfigurationDialog.axaml</comment>

PostCodeSerialMonitor/Models/AppConfiguration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public class AppConfiguration
1414
public bool CheckForFwUpdates { get; set; } = true;
1515
public bool ShowTimestamps { get; set; } = false;
1616

17+
[Required]
18+
public string DescriptionDisplayMode { get; set; } = "NewLine";
19+
1720
[Required]
1821
public string Theme { get; set; } = "Dark";
1922

PostCodeSerialMonitor/Models/LogEntry.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
using System;
2+
using System.ComponentModel;
23

34
namespace PostCodeSerialMonitor.Models;
45
// Simple model to hold log entry data
5-
public class LogEntry
6+
public class LogEntry : INotifyPropertyChanged
67
{
8+
public event PropertyChangedEventHandler? PropertyChanged;
9+
10+
private bool isSelected;
11+
public bool IsSelected
12+
{
13+
get => isSelected;
14+
set
15+
{
16+
if (isSelected == value) return;
17+
isSelected = value;
18+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsSelected)));
19+
}
20+
}
21+
722
public string RawText { get; set; } = string.Empty;
823
public DateTime Timestamp { get; set; } = DateTime.Now;
924
public string TimestampText => Timestamp.ToString("HH:mm:ss.fff");
@@ -14,8 +29,18 @@ public class LogEntry
1429
public string FormattedText => FormatText();
1530
// Flavor, index and code (hex)
1631
public string CodeText => FormatCodeText();
32+
// Individual fields, for column-aligned display
33+
public string FlavorText => DecodedCode.Flavor.ToString();
34+
public string IndexText => $"({DecodedCode.Index}):";
35+
public string CodeHexText => $"{DecodedCode.Code:X4}";
36+
public string NameText => string.IsNullOrEmpty(DecodedCode?.Name) ? string.Empty : $"[{DecodedCode.Name}]";
37+
// Name + description on one line, for the truncated inline preview
38+
public string InlinePreviewText => string.IsNullOrEmpty(Description)
39+
? NameText
40+
: string.IsNullOrEmpty(NameText) ? Description : $"{NameText} {Description}";
1741
// Description or null
1842
public string? Description => string.IsNullOrEmpty(DecodedCode.Description) ? null : DecodedCode?.Description;
43+
public bool HasDescription => !string.IsNullOrEmpty(Description);
1944
public bool IsWarning => SeverityLevel == CodeSeverity.Warning;
2045
public bool IsError => SeverityLevel == CodeSeverity.Error;
2146
public CodeSeverity SeverityLevel => DecodedCode.SeverityLevel;

PostCodeSerialMonitor/ViewModels/ConfigurationDialogViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public partial class ConfigurationDialogViewModel : ViewModelBase
3232
[ObservableProperty]
3333
private bool showTimestamps;
3434

35+
[ObservableProperty]
36+
private ObservableCollection<string> descriptionDisplayModes = new(["Inline", "NewLine", "BottomPanel"]);
37+
38+
[ObservableProperty]
39+
private string selectedDescriptionDisplayMode;
40+
3541
[ObservableProperty]
3642
private string codesMetaBaseUrl;
3743

@@ -66,6 +72,7 @@ public ConfigurationDialogViewModel(ConfigurationService configurationService)
6672
CheckForCodeUpdates = _originalConfiguration.CheckForCodeUpdates;
6773
CheckForFwUpdates = _originalConfiguration.CheckForFwUpdates;
6874
ShowTimestamps = _originalConfiguration.ShowTimestamps;
75+
SelectedDescriptionDisplayMode = _originalConfiguration.DescriptionDisplayMode;
6976
CodesMetaBaseUrl = _originalConfiguration.CodesMetaBaseUrl.ToString();
7077
SelectedLanguage = _originalConfiguration.Language;
7178
SelectedTheme = _originalConfiguration.Theme;
@@ -85,6 +92,7 @@ await _configurationService.UpdateConfigurationAsync(config =>
8592
config.CheckForCodeUpdates = CheckForCodeUpdates;
8693
config.CheckForFwUpdates = CheckForFwUpdates;
8794
config.ShowTimestamps = ShowTimestamps;
95+
config.DescriptionDisplayMode = SelectedDescriptionDisplayMode;
8896
config.CodesMetaBaseUrl = new Uri(CodesMetaBaseUrl);
8997
config.Language = SelectedLanguage;
9098
config.Theme = SelectedTheme;

PostCodeSerialMonitor/ViewModels/MainWindowViewModel.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ public partial class MainWindowViewModel : ViewModelBase
8080
[ObservableProperty]
8181
private bool showTimestamps;
8282

83+
[ObservableProperty]
84+
[NotifyPropertyChangedFor(nameof(IsDescriptionInlineMode))]
85+
[NotifyPropertyChangedFor(nameof(IsDescriptionNewLineMode))]
86+
[NotifyPropertyChangedFor(nameof(IsDescriptionBottomPanelMode))]
87+
private string descriptionDisplayMode = "NewLine";
88+
89+
public bool IsDescriptionInlineMode => DescriptionDisplayMode == "Inline";
90+
public bool IsDescriptionNewLineMode => DescriptionDisplayMode == "NewLine";
91+
public bool IsDescriptionBottomPanelMode => DescriptionDisplayMode == "BottomPanel";
92+
8393
[ObservableProperty]
8494
private string i2cScanOutput = Assets.Resources.ScanButtonText;
8595

@@ -98,6 +108,9 @@ public partial class MainWindowViewModel : ViewModelBase
98108
[ObservableProperty]
99109
private bool debugModeUnlocked;
100110

111+
[ObservableProperty]
112+
private LogEntry? selectedLogEntry;
113+
101114
private int _appVersionClickCount;
102115

103116
public IStorageProvider? StorageProvider
@@ -137,6 +150,7 @@ public MainWindowViewModel(
137150
}
138151
SelectedConsoleModel = ConsoleModels.FirstOrDefault();
139152
ShowTimestamps = _configurationService.Config.ShowTimestamps;
153+
DescriptionDisplayMode = _configurationService.Config.DescriptionDisplayMode;
140154

141155
RefreshPorts();
142156
_serialService.DataReceived += OnDataReceived;
@@ -243,6 +257,24 @@ private void ClearLog()
243257
{
244258
LogEntries.Clear();
245259
RawLogEntries.Clear();
260+
SelectedLogEntry = null;
261+
}
262+
263+
[RelayCommand]
264+
private void SelectLogEntry(LogEntry entry)
265+
{
266+
if (SelectedLogEntry == entry)
267+
{
268+
entry.IsSelected = false;
269+
SelectedLogEntry = null;
270+
return;
271+
}
272+
273+
if (SelectedLogEntry != null)
274+
SelectedLogEntry.IsSelected = false;
275+
276+
entry.IsSelected = true;
277+
SelectedLogEntry = entry;
246278
}
247279

248280
[RelayCommand]
@@ -420,6 +452,7 @@ private async Task ShowConfigurationAsync()
420452
await dialog.ShowDialog(GetParentWindow());
421453

422454
ShowTimestamps = _configurationService.Config.ShowTimestamps;
455+
DescriptionDisplayMode = _configurationService.Config.DescriptionDisplayMode;
423456
}
424457

425458
[RelayCommand]

PostCodeSerialMonitor/Views/ConfigurationDialog.axaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
<TextBlock Text="{x:Static assets:Resources.LogSettings}" FontWeight="Bold" Margin="0,10,0,5"/>
4545
<CheckBox Content="{x:Static assets:Resources.ShowTimestamps}"
4646
IsChecked="{Binding ShowTimestamps}"/>
47+
48+
<TextBlock Text="{x:Static assets:Resources.DescriptionDisplaySettings}" FontWeight="Bold" Margin="0,10,0,5"/>
49+
<ComboBox Width="150"
50+
ItemsSource="{Binding DescriptionDisplayModes}"
51+
SelectedItem="{Binding SelectedDescriptionDisplayMode, Mode=TwoWay}"/>
4752
</StackPanel>
4853
</ScrollViewer>
4954

PostCodeSerialMonitor/Views/Converters/NullFontSizeConverter.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)