Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Src/Common/FwUtils/EventConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static class EventConstants
public const string PrepareToRefresh = "PrepareToRefresh";
public const string RecordNavigation = "RecordNavigation";
public const string RefreshCurrentList = "RefreshCurrentList";
public const string RefreshPopupWindowFonts = "RefreshPopupWindowFonts";
public const string ReloadAreaTools = "ReloadAreaTools";
public const string RemoveFilters = "RemoveFilters";
public const string RestoreScrollPosition = "RestoreScrollPosition";
Expand All @@ -36,6 +37,7 @@ public static class EventConstants
public const string SetToolFromName = "SetToolFromName";
public const string SFMImport = "SFMImport";
public const string ShowNotification = "ShowNotification";
public const string ShowParserReport = "ShowParserReport";
public const string StopParser = "StopParser";
/// <summary>
/// Called before opening and after closing UploadToWebonaryDlg to prevent bits of the main window from reloading (comment on LT-21480).
Expand Down
41 changes: 34 additions & 7 deletions Src/LexText/ParserUI/ParserListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class ParserListener : IxCoreColleague, IDisposable, IVwNotifyChange
private string m_sourceText = null;
private ObservableCollection<ParserReportViewModel> m_parserReports = null;
private ParserReportsDialog m_parserReportsDialog = null;
private IList<ParserReportDialog> m_parserReportDialogs = new List<ParserReportDialog>();
private string m_defaultComment = null;

public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configurationParameters)
Expand All @@ -85,6 +86,8 @@ public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configu
m_sda.AddNotification(this);

Subscriber.Subscribe(EventConstants.StopParser, StopParser);
Subscriber.Subscribe(EventConstants.ShowParserReport, ShowParserReport);
Subscriber.Subscribe(EventConstants.RefreshPopupWindowFonts, RefreshPopupWindowFonts);
}

/// <summary>
Expand Down Expand Up @@ -364,6 +367,8 @@ protected virtual void Dispose(bool disposing)
if (disposing)
{
Subscriber.Unsubscribe(EventConstants.StopParser, StopParser);
Subscriber.Unsubscribe(EventConstants.ShowParserReport, ShowParserReport);
Subscriber.Unsubscribe(EventConstants.RefreshPopupWindowFonts, RefreshPopupWindowFonts);

// other clients may now parse
// Dispose managed resources here.
Expand Down Expand Up @@ -626,7 +631,7 @@ private void UpdateWordforms(IEnumerable<IWfiWordform> wordforms, ParserPriority
// Write an empty parser report.
var parserReport = CreateParserReport();
ParserReportViewModel viewModel = AddParserReport(parserReport);
ShowParserReport(viewModel, m_mediator, m_cache);
ShowParserReport(viewModel);
}
}
m_parserConnection.UpdateWordforms(wordforms, priority, checkParser);
Expand Down Expand Up @@ -681,7 +686,7 @@ private void WordformUpdatedEventHandler(object sender, WordformUpdatedEventArgs
// Convert parse results into ParserReport.
var parserReport = CreateParserReport();
ParserReportViewModel viewModel = AddParserReport(parserReport);
ShowParserReport(viewModel, m_mediator, m_cache);
ShowParserReport(viewModel);
}
}

Expand Down Expand Up @@ -839,13 +844,25 @@ public void ShowParserReports()
{
ReadParserReports();
// Create parser reports window.
m_parserReportsDialog = new ParserReportsDialog(m_parserReports, m_mediator, m_cache, m_defaultComment);
m_parserReportsDialog = new ParserReportsDialog(m_parserReports, m_mediator, m_cache, m_propertyTable, m_defaultComment);
m_parserReportsDialog.Closed += ParserReportsDialog_Closed;
}
m_parserReportsDialog.Show(); // Show the dialog but do not block other app access
m_parserReportsDialog.BringIntoView();
}

public void RefreshPopupWindowFonts(object sender)
{
if (m_parserReportsDialog != null)
{
m_parserReportsDialog.SetFont();
}
foreach (ParserReportDialog dialog in m_parserReportDialogs)
{
dialog.SetFont();
}
}

private void ParserReportsDialog_Closed(object sender, EventArgs e)
{
ParserReportsDialog dialog = (ParserReportsDialog)sender;
Expand Down Expand Up @@ -888,12 +905,22 @@ private ParserReportViewModel AddParserReport(ParserReport parserReport)
/// <summary>
/// Display a parser report window.
/// </summary>
/// <param name="parserReport"></param>
/// <param name="mediator">the mediator is used to call TryAWord</param>
public static void ShowParserReport(ParserReportViewModel parserReport, Mediator mediator, LcmCache cache)
private void ShowParserReport(object obj)
{
ParserReportDialog dialog = new ParserReportDialog(parserReport, mediator, cache);
ParserReportViewModel parserReport = obj as ParserReportViewModel;
ParserReportDialog dialog = new ParserReportDialog(parserReport, m_mediator, m_cache, m_propertyTable);
dialog.Show();
m_parserReportDialogs.Add(dialog);
dialog.Closed += ParserReportDialog_Closed;
}

private void ParserReportDialog_Closed(object sender, EventArgs e)
{
ParserReportDialog dialog = (ParserReportDialog)sender;
if (dialog != null)
{
m_parserReportDialogs.Remove(dialog);
}
}

public bool OnParseAllWords(object argument)
Expand Down
10 changes: 5 additions & 5 deletions Src/LexText/ParserUI/ParserReportDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding ErrorMessage}" Width="100">
<DataGridTextColumn Binding="{Binding ErrorMessage}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}"
BasedOn="{StaticResource {x:Type TextBlock}}">
Expand Down Expand Up @@ -185,13 +185,13 @@
</DataGrid.Columns>
</DataGrid>
</ScrollViewer>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Height="40">
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left">
<Button Content="{x:Static local:ParserUIStrings.ksSaveReport}"
ToolTip="{x:Static local:ParserUIStrings.ksSaveReportToolTip}"
IsEnabled="{Binding CanSaveReport}"
Click="SaveParserReport" Width="100" Margin="5"/>
<Label x:Name="commentLabel" Height="27"/>
<Label Content="{Binding DisplayComment, Mode=OneWay}" Height="27"/>
Click="SaveParserReport" Margin="5"/>
<Label x:Name="commentLabel" VerticalContentAlignment="Center"/>
<Label Content="{Binding DisplayComment, Mode=OneWay}" VerticalContentAlignment="Center"/>
</StackPanel>
</Grid>
</Window>
23 changes: 20 additions & 3 deletions Src/LexText/ParserUI/ParserReportDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using SIL.FieldWorks.Common.FwUtils;
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
using SIL.FieldWorks.Common.Widgets;
using SIL.FieldWorks.WordWorks.Parser;
using SIL.LCModel;
using SIL.LCModel.Core.Text;
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -17,18 +20,32 @@ public partial class ParserReportDialog : Window
public Mediator Mediator { get; set; }
public LcmCache Cache { get; set; }

private readonly PropertyTable m_propertyTable;

public ParserReportDialog()
{
InitializeComponent();
}

public ParserReportDialog(ParserReportViewModel parserReport, Mediator mediator, LcmCache cache)
public ParserReportDialog(ParserReportViewModel parserReport, Mediator mediator, LcmCache cache, PropertyTable propertyTable)
{
InitializeComponent();
Mediator = mediator;
Cache = cache;
m_propertyTable = propertyTable;
DataContext = parserReport;
commentLabel.Content = ParserUIStrings.ksComment + ":";
SetFont();
}

public void SetFont()
{
Font font = FontHeightAdjuster.GetFontForNormalStyle(Cache.DefaultVernWs, Cache.WritingSystemFactory, m_propertyTable);
if (font != null)
{
FontFamily = new System.Windows.Media.FontFamily(font.FontFamily.Name);
FontSize = font.Size;
}
}

public void SaveParserReport(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -86,7 +103,7 @@ private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
if (sender is DataGrid dataGrid)
{
if (dataGrid.SelectedItem is ParserReportViewModel selectedItem)
ParserListener.ShowParserReport(selectedItem, Mediator, Cache);
Publisher.Publish(new PublisherParameterObject(EventConstants.ShowParserReport, selectedItem));
}
else
Debug.Fail("Type of Contents of DataGrid changed, adjust double click code.");
Expand Down
12 changes: 6 additions & 6 deletions Src/LexText/ParserUI/ParserReportsDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<Label Content="{x:Static local:ParserUIStrings.ksText}" ToolTip="{x:Static local:ParserUIStrings.ksTextToolTip}"/>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding DisplayComment, Mode=OneWay}" Width="100">
<DataGridTextColumn Binding="{Binding DisplayComment, Mode=OneWay}">
<DataGridTextColumn.Header>
<Label Content="{x:Static local:ParserUIStrings.ksComment}" ToolTip="{x:Static local:ParserUIStrings.ksCommentToolTip}"/>
</DataGridTextColumn.Header>
Expand Down Expand Up @@ -109,23 +109,23 @@
</DataGrid>
</ScrollViewer>

<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Height="40">
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left">
<Button Content="{x:Static local:ParserUIStrings.ksShowReport}"
ToolTip="{x:Static local:ParserUIStrings.ksShowReportToolTip}"
IsEnabled="{Binding CanShowReport}"
Click="ShowParserReport" Width="100" Margin="5"/>
Click="ShowParserReport" Margin="5"/>
<Button Content="{x:Static local:ParserUIStrings.ksSaveReport}"
ToolTip="{x:Static local:ParserUIStrings.ksSaveReportToolTip}"
IsEnabled="{Binding CanSaveReport}"
Click="SaveParserReport" Width="100" Margin="5"/>
Click="SaveParserReport" Margin="5"/>
<Button Content="{x:Static local:ParserUIStrings.ksDiffButton}"
ToolTip="{x:Static local:ParserUIStrings.ksDiffButtonToolTip}"
IsEnabled="{Binding CanDiffReports}"
Click="DiffParserReports" Width="100" Margin="5" />
Click="DiffParserReports" Margin="5" />
<Button Content="{Binding DeleteButtonContent}"
ToolTip="{x:Static local:ParserUIStrings.ksDeleteToolTip}"
IsEnabled="{Binding CanDeleteReports}"
Click="DeleteParserReport" Width="100" Margin="5" />
Click="DeleteParserReport" Margin="5" />
</StackPanel>
</Grid>
</Window>
27 changes: 22 additions & 5 deletions Src/LexText/ParserUI/ParserReportsDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using SIL.Extensions;
using SIL.FieldWorks.WordWorks.Parser;
using SIL.FieldWorks.Common.FwUtils;
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
using SIL.FieldWorks.Common.Widgets;
using SIL.LCModel;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -27,20 +30,34 @@ public partial class ParserReportsDialog : Window

public string DefaultComment = null;

private PropertyTable m_propertyTable;

public ParserReportsDialog()
{
InitializeComponent();
}

public ParserReportsDialog(ObservableCollection<ParserReportViewModel> parserReports, Mediator mediator, LcmCache cache, string defaultComment)
public ParserReportsDialog(ObservableCollection<ParserReportViewModel> parserReports, Mediator mediator, LcmCache cache, PropertyTable propertyTable, string defaultComment)
{
InitializeComponent();
parserReports.Sort((x, y) => y.Timestamp.CompareTo(x.Timestamp));
ParserReports = parserReports;
Mediator = mediator;
Cache = cache;
m_propertyTable = propertyTable;
DataContext = new ParserReportsViewModel { ParserReports = parserReports };
DefaultComment = defaultComment;
SetFont();
}

public void SetFont()
{
Font font = FontHeightAdjuster.GetFontForNormalStyle(Cache.DefaultVernWs, Cache.WritingSystemFactory, m_propertyTable);
if (font != null)
{
FontFamily = new System.Windows.Media.FontFamily(font.FontFamily.Name);
FontSize = font.Size;
}
}

private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
Expand All @@ -60,7 +77,7 @@ public void ShowParserReport(object sender, RoutedEventArgs e)
{
if (report.IsSelected)
{
ParserListener.ShowParserReport(report, Mediator, Cache);
Publisher.Publish(new PublisherParameterObject(EventConstants.ShowParserReport, report));
break;
}
}
Expand Down Expand Up @@ -129,14 +146,14 @@ public void DiffParserReports(object sender, RoutedEventArgs e)
}
var diff = parserReport.ParserReport.DiffParserReports(parserReport2.ParserReport);
ParserReportViewModel viewModel = new ParserReportViewModel() { ParserReport = diff };
ParserListener.ShowParserReport(viewModel, Mediator, Cache);
Publisher.Publish(new PublisherParameterObject(EventConstants.ShowParserReport, viewModel));
}
private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (sender is DataGrid dataGrid)
{
if(dataGrid.SelectedItem is ParserReportViewModel selectedItem)
ParserListener.ShowParserReport(selectedItem, Mediator, Cache);
Publisher.Publish(new PublisherParameterObject(EventConstants.ShowParserReport, selectedItem));
}
else
Debug.Fail("Type of Contents of DataGrid changed, adjust double click code.");
Expand Down
3 changes: 3 additions & 0 deletions Src/xWorks/FwXWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,9 @@ public bool ShowStylesDialog(string paraStyleName, string charStyleName,
{
// Need to refresh to reload the cache. See LT-6265.
(m_app as FwXApp).OnMasterRefresh(null);

// Refresh the fonts on popup windows.
Publisher.Publish(new PublisherParameterObject(EventConstants.RefreshPopupWindowFonts, null));
}
return false; // refresh already called if needed
}
Expand Down
Loading