Skip to content

Commit 1f2486a

Browse files
authored
LT-22230: Add a method to increase the font size of parser test reports (#642)
* Fix LT-22230: Parser Test Report Font * Change "ShowParserReport" to Pub/Sub model * Change layout to work for different font sizes * Change BroadcastMessage("RefreshPopupWindows") to use Pub/Sub * Rename RefreshPopupWindows to RefreshPopupWindowFonts * Undo changes to using statements * Replace Pub/Sub with direct calls for ShowParserReport
1 parent 4052761 commit 1f2486a

7 files changed

Lines changed: 104 additions & 29 deletions

File tree

Src/Common/FwUtils/EventConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static class EventConstants
2828
public const string PrepareToRefresh = "PrepareToRefresh";
2929
public const string RecordNavigation = "RecordNavigation";
3030
public const string RefreshCurrentList = "RefreshCurrentList";
31+
public const string RefreshPopupWindowFonts = "RefreshPopupWindowFonts";
3132
public const string ReloadAreaTools = "ReloadAreaTools";
3233
public const string RemoveFilters = "RemoveFilters";
3334
public const string RestoreScrollPosition = "RestoreScrollPosition";

Src/LexText/ParserUI/ParserListener.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class ParserListener : IxCoreColleague, IDisposable, IVwNotifyChange
7070
private string m_sourceText = null;
7171
private ObservableCollection<ParserReportViewModel> m_parserReports = null;
7272
private ParserReportsDialog m_parserReportsDialog = null;
73+
private IList<ParserReportDialog> m_parserReportDialogs = new List<ParserReportDialog>();
7374
private string m_defaultComment = null;
7475

7576
public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configurationParameters)
@@ -85,6 +86,7 @@ public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configu
8586
m_sda.AddNotification(this);
8687

8788
Subscriber.Subscribe(EventConstants.StopParser, StopParser);
89+
Subscriber.Subscribe(EventConstants.RefreshPopupWindowFonts, RefreshPopupWindowFonts);
8890
}
8991

9092
/// <summary>
@@ -364,6 +366,7 @@ protected virtual void Dispose(bool disposing)
364366
if (disposing)
365367
{
366368
Subscriber.Unsubscribe(EventConstants.StopParser, StopParser);
369+
Subscriber.Unsubscribe(EventConstants.RefreshPopupWindowFonts, RefreshPopupWindowFonts);
367370

368371
// other clients may now parse
369372
// Dispose managed resources here.
@@ -626,7 +629,7 @@ private void UpdateWordforms(IEnumerable<IWfiWordform> wordforms, ParserPriority
626629
// Write an empty parser report.
627630
var parserReport = CreateParserReport();
628631
ParserReportViewModel viewModel = AddParserReport(parserReport);
629-
ShowParserReport(viewModel, m_mediator, m_cache);
632+
ShowParserReport(viewModel);
630633
}
631634
}
632635
m_parserConnection.UpdateWordforms(wordforms, priority, checkParser);
@@ -681,7 +684,7 @@ private void WordformUpdatedEventHandler(object sender, WordformUpdatedEventArgs
681684
// Convert parse results into ParserReport.
682685
var parserReport = CreateParserReport();
683686
ParserReportViewModel viewModel = AddParserReport(parserReport);
684-
ShowParserReport(viewModel, m_mediator, m_cache);
687+
ShowParserReport(viewModel);
685688
}
686689
}
687690

@@ -839,13 +842,25 @@ public void ShowParserReports()
839842
{
840843
ReadParserReports();
841844
// Create parser reports window.
842-
m_parserReportsDialog = new ParserReportsDialog(m_parserReports, m_mediator, m_cache, m_defaultComment);
845+
m_parserReportsDialog = new ParserReportsDialog(m_parserReports, this, m_mediator, m_cache, m_propertyTable, m_defaultComment);
843846
m_parserReportsDialog.Closed += ParserReportsDialog_Closed;
844847
}
845848
m_parserReportsDialog.Show(); // Show the dialog but do not block other app access
846849
m_parserReportsDialog.BringIntoView();
847850
}
848851

852+
public void RefreshPopupWindowFonts(object sender)
853+
{
854+
if (m_parserReportsDialog != null)
855+
{
856+
m_parserReportsDialog.SetFont();
857+
}
858+
foreach (ParserReportDialog dialog in m_parserReportDialogs)
859+
{
860+
dialog.SetFont();
861+
}
862+
}
863+
849864
private void ParserReportsDialog_Closed(object sender, EventArgs e)
850865
{
851866
ParserReportsDialog dialog = (ParserReportsDialog)sender;
@@ -888,12 +903,22 @@ private ParserReportViewModel AddParserReport(ParserReport parserReport)
888903
/// <summary>
889904
/// Display a parser report window.
890905
/// </summary>
891-
/// <param name="parserReport"></param>
892-
/// <param name="mediator">the mediator is used to call TryAWord</param>
893-
public static void ShowParserReport(ParserReportViewModel parserReport, Mediator mediator, LcmCache cache)
906+
public void ShowParserReport(object obj)
894907
{
895-
ParserReportDialog dialog = new ParserReportDialog(parserReport, mediator, cache);
908+
ParserReportViewModel parserReport = obj as ParserReportViewModel;
909+
ParserReportDialog dialog = new ParserReportDialog(parserReport, m_mediator, m_cache, m_propertyTable);
896910
dialog.Show();
911+
m_parserReportDialogs.Add(dialog);
912+
dialog.Closed += ParserReportDialog_Closed;
913+
}
914+
915+
private void ParserReportDialog_Closed(object sender, EventArgs e)
916+
{
917+
ParserReportDialog dialog = (ParserReportDialog)sender;
918+
if (dialog != null)
919+
{
920+
m_parserReportDialogs.Remove(dialog);
921+
}
897922
}
898923

899924
public bool OnParseAllWords(object argument)

Src/LexText/ParserUI/ParserReportDialog.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
</DataTemplate>
134134
</DataGridTemplateColumn.CellTemplate>
135135
</DataGridTemplateColumn>
136-
<DataGridTextColumn Binding="{Binding ErrorMessage}" Width="100">
136+
<DataGridTextColumn Binding="{Binding ErrorMessage}">
137137
<DataGridTextColumn.ElementStyle>
138138
<Style TargetType="{x:Type TextBlock}"
139139
BasedOn="{StaticResource {x:Type TextBlock}}">
@@ -185,13 +185,13 @@
185185
</DataGrid.Columns>
186186
</DataGrid>
187187
</ScrollViewer>
188-
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Height="40">
188+
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left">
189189
<Button Content="{x:Static local:ParserUIStrings.ksSaveReport}"
190190
ToolTip="{x:Static local:ParserUIStrings.ksSaveReportToolTip}"
191191
IsEnabled="{Binding CanSaveReport}"
192-
Click="SaveParserReport" Width="100" Margin="5"/>
193-
<Label x:Name="commentLabel" Height="27"/>
194-
<Label Content="{Binding DisplayComment, Mode=OneWay}" Height="27"/>
192+
Click="SaveParserReport" Margin="5"/>
193+
<Label x:Name="commentLabel" VerticalContentAlignment="Center"/>
194+
<Label Content="{Binding DisplayComment, Mode=OneWay}" VerticalContentAlignment="Center"/>
195195
</StackPanel>
196196
</Grid>
197197
</Window>

Src/LexText/ParserUI/ParserReportDialog.xaml.cs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using SIL.FieldWorks.Common.FwUtils;
2+
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
3+
using SIL.FieldWorks.Common.Widgets;
24
using SIL.FieldWorks.WordWorks.Parser;
35
using SIL.LCModel;
46
using SIL.LCModel.Core.Text;
5-
using System.Diagnostics;
67
using System;
8+
using System.Diagnostics;
9+
using System.Drawing;
710
using System.Windows;
811
using System.Windows.Controls;
912
using System.Windows.Input;
@@ -17,18 +20,32 @@ public partial class ParserReportDialog : Window
1720
public Mediator Mediator { get; set; }
1821
public LcmCache Cache { get; set; }
1922

23+
private readonly PropertyTable m_propertyTable;
24+
2025
public ParserReportDialog()
2126
{
2227
InitializeComponent();
2328
}
2429

25-
public ParserReportDialog(ParserReportViewModel parserReport, Mediator mediator, LcmCache cache)
30+
public ParserReportDialog(ParserReportViewModel parserReport, Mediator mediator, LcmCache cache, PropertyTable propertyTable)
2631
{
2732
InitializeComponent();
2833
Mediator = mediator;
2934
Cache = cache;
35+
m_propertyTable = propertyTable;
3036
DataContext = parserReport;
3137
commentLabel.Content = ParserUIStrings.ksComment + ":";
38+
SetFont();
39+
}
40+
41+
public void SetFont()
42+
{
43+
Font font = FontHeightAdjuster.GetFontForNormalStyle(Cache.DefaultVernWs, Cache.WritingSystemFactory, m_propertyTable);
44+
if (font != null)
45+
{
46+
FontFamily = new System.Windows.Media.FontFamily(font.FontFamily.Name);
47+
FontSize = font.Size;
48+
}
3249
}
3350

3451
public void SaveParserReport(object sender, RoutedEventArgs e)
@@ -47,8 +64,17 @@ public void ReparseWord(object sender, RoutedEventArgs e)
4764

4865
public void ShowWordAnalyses(object sender, RoutedEventArgs e)
4966
{
50-
var button = sender as Button;
51-
var parseReport = button.CommandParameter as ParseReport;
67+
ParseReport parseReport = null;
68+
if (sender is Button button)
69+
{
70+
parseReport = button.CommandParameter as ParseReport;
71+
}
72+
else if (sender is ParseReport report)
73+
{
74+
parseReport = report;
75+
}
76+
if (parseReport == null)
77+
return;
5278
var tsString = TsStringUtils.MakeString(RemoveArrow(parseReport.Word), Cache.DefaultVernWs);
5379
IWfiWordform wordform;
5480
if (Cache.ServiceLocator.GetInstance<IWfiWordformRepository>().TryGetObject(tsString, out wordform))
@@ -85,8 +111,8 @@ private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
85111
{
86112
if (sender is DataGrid dataGrid)
87113
{
88-
if (dataGrid.SelectedItem is ParserReportViewModel selectedItem)
89-
ParserListener.ShowParserReport(selectedItem, Mediator, Cache);
114+
if (dataGrid.SelectedItem is ParseReport selectedItem)
115+
ShowWordAnalyses(selectedItem, null);
90116
}
91117
else
92118
Debug.Fail("Type of Contents of DataGrid changed, adjust double click code.");

Src/LexText/ParserUI/ParserReportsDialog.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<Label Content="{x:Static local:ParserUIStrings.ksText}" ToolTip="{x:Static local:ParserUIStrings.ksTextToolTip}"/>
4040
</DataGridTextColumn.Header>
4141
</DataGridTextColumn>
42-
<DataGridTextColumn Binding="{Binding DisplayComment, Mode=OneWay}" Width="100">
42+
<DataGridTextColumn Binding="{Binding DisplayComment, Mode=OneWay}">
4343
<DataGridTextColumn.Header>
4444
<Label Content="{x:Static local:ParserUIStrings.ksComment}" ToolTip="{x:Static local:ParserUIStrings.ksCommentToolTip}"/>
4545
</DataGridTextColumn.Header>
@@ -109,23 +109,23 @@
109109
</DataGrid>
110110
</ScrollViewer>
111111

112-
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Height="40">
112+
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left">
113113
<Button Content="{x:Static local:ParserUIStrings.ksShowReport}"
114114
ToolTip="{x:Static local:ParserUIStrings.ksShowReportToolTip}"
115115
IsEnabled="{Binding CanShowReport}"
116-
Click="ShowParserReport" Width="100" Margin="5"/>
116+
Click="ShowParserReport" Margin="5"/>
117117
<Button Content="{x:Static local:ParserUIStrings.ksSaveReport}"
118118
ToolTip="{x:Static local:ParserUIStrings.ksSaveReportToolTip}"
119119
IsEnabled="{Binding CanSaveReport}"
120-
Click="SaveParserReport" Width="100" Margin="5"/>
120+
Click="SaveParserReport" Margin="5"/>
121121
<Button Content="{x:Static local:ParserUIStrings.ksDiffButton}"
122122
ToolTip="{x:Static local:ParserUIStrings.ksDiffButtonToolTip}"
123123
IsEnabled="{Binding CanDiffReports}"
124-
Click="DiffParserReports" Width="100" Margin="5" />
124+
Click="DiffParserReports" Margin="5" />
125125
<Button Content="{Binding DeleteButtonContent}"
126126
ToolTip="{x:Static local:ParserUIStrings.ksDeleteToolTip}"
127127
IsEnabled="{Binding CanDeleteReports}"
128-
Click="DeleteParserReport" Width="100" Margin="5" />
128+
Click="DeleteParserReport" Margin="5" />
129129
</StackPanel>
130130
</Grid>
131131
</Window>

Src/LexText/ParserUI/ParserReportsDialog.xaml.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using SIL.Extensions;
2-
using SIL.FieldWorks.WordWorks.Parser;
2+
using SIL.FieldWorks.Common.FwUtils;
3+
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
4+
using SIL.FieldWorks.Common.Widgets;
35
using SIL.LCModel;
46
using System;
57
using System.Collections.ObjectModel;
68
using System.Diagnostics;
9+
using System.Drawing;
710
using System.Linq;
811
using System.Windows;
912
using System.Windows.Controls;
@@ -25,22 +28,39 @@ public partial class ParserReportsDialog : Window
2528

2629
public LcmCache Cache { get; set; }
2730

31+
public ParserListener Listener { get; set; }
32+
2833
public string DefaultComment = null;
2934

35+
private PropertyTable m_propertyTable;
36+
3037
public ParserReportsDialog()
3138
{
3239
InitializeComponent();
3340
}
3441

35-
public ParserReportsDialog(ObservableCollection<ParserReportViewModel> parserReports, Mediator mediator, LcmCache cache, string defaultComment)
42+
public ParserReportsDialog(ObservableCollection<ParserReportViewModel> parserReports, ParserListener listener, Mediator mediator, LcmCache cache, PropertyTable propertyTable, string defaultComment)
3643
{
3744
InitializeComponent();
3845
parserReports.Sort((x, y) => y.Timestamp.CompareTo(x.Timestamp));
3946
ParserReports = parserReports;
47+
Listener = listener;
4048
Mediator = mediator;
4149
Cache = cache;
50+
m_propertyTable = propertyTable;
4251
DataContext = new ParserReportsViewModel { ParserReports = parserReports };
4352
DefaultComment = defaultComment;
53+
SetFont();
54+
}
55+
56+
public void SetFont()
57+
{
58+
Font font = FontHeightAdjuster.GetFontForNormalStyle(Cache.DefaultVernWs, Cache.WritingSystemFactory, m_propertyTable);
59+
if (font != null)
60+
{
61+
FontFamily = new System.Windows.Media.FontFamily(font.FontFamily.Name);
62+
FontSize = font.Size;
63+
}
4464
}
4565

4666
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
@@ -60,7 +80,7 @@ public void ShowParserReport(object sender, RoutedEventArgs e)
6080
{
6181
if (report.IsSelected)
6282
{
63-
ParserListener.ShowParserReport(report, Mediator, Cache);
83+
Listener.ShowParserReport(report);
6484
break;
6585
}
6686
}
@@ -129,14 +149,14 @@ public void DiffParserReports(object sender, RoutedEventArgs e)
129149
}
130150
var diff = parserReport.ParserReport.DiffParserReports(parserReport2.ParserReport);
131151
ParserReportViewModel viewModel = new ParserReportViewModel() { ParserReport = diff };
132-
ParserListener.ShowParserReport(viewModel, Mediator, Cache);
152+
Listener.ShowParserReport(viewModel);
133153
}
134154
private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
135155
{
136156
if (sender is DataGrid dataGrid)
137157
{
138158
if(dataGrid.SelectedItem is ParserReportViewModel selectedItem)
139-
ParserListener.ShowParserReport(selectedItem, Mediator, Cache);
159+
Listener.ShowParserReport(selectedItem);
140160
}
141161
else
142162
Debug.Fail("Type of Contents of DataGrid changed, adjust double click code.");

Src/xWorks/FwXWindow.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,9 @@ public bool ShowStylesDialog(string paraStyleName, string charStyleName,
18751875
{
18761876
// Need to refresh to reload the cache. See LT-6265.
18771877
(m_app as FwXApp).OnMasterRefresh(null);
1878+
1879+
// Refresh the fonts on popup windows.
1880+
Publisher.Publish(new PublisherParameterObject(EventConstants.RefreshPopupWindowFonts, null));
18781881
}
18791882
return false; // refresh already called if needed
18801883
}

0 commit comments

Comments
 (0)