Skip to content

Commit

Permalink
Passing on FontConfig to Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
RNoeldner committed Jun 6, 2023
1 parent ec902db commit d1ebbbf
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Application/FindSkipRows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void HighlightVisibleRange(int skipRows)

private void ButtonSkipLine_Click(object? sender, EventArgs e)
{
using var formProgress = new FormProgress("Check", true, CancellationToken.None);
using var formProgress = new FormProgress("Check", true, FontConfig, CancellationToken.None);
formProgress.ShowWithFont(this);
formProgress.Maximum = 0;
using var stream = new ImprovedStream(new SourceAccess(m_CsvFile));
Expand Down
2 changes: 1 addition & 1 deletion Application/FormEditSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private async void BtnOpenFile_Click(object? sender, EventArgs e)
if (m_FileSetting == null)
{
SetDefaultInspectionResult();
using var formProgress = new FormProgress("Examining file", false, m_CancellationTokenSource.Token);
using var formProgress = new FormProgress("Examining file", false, FontConfig, m_CancellationTokenSource.Token);
formProgress.Maximum = 0;
formProgress.ShowWithFont(this);

Expand Down
2 changes: 1 addition & 1 deletion Application/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ private async Task OpenDataReaderAsync(CancellationToken cancellationToken)
});
Logger.Debug("Loading Batch");
using (var formProgress = new FormProgress(fileNameShort, false, cancellationToken))
using (var formProgress = new FormProgress(fileNameShort, false, FontConfig, cancellationToken))
{
formProgress.ShowWithFont(this);
noError = await detailControl.LoadSettingAsync(m_FileSetting, false, true, m_ViewSettings.DurationTimeSpan,
Expand Down
14 changes: 14 additions & 0 deletions Library/ClassLibraryCSV/IFontConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ public interface IFontConfig : INotifyPropertyChanged
string Font { get; }
float FontSize { get; }
}

public class FontConfig : ObservableObject, IFontConfig
{
private readonly string m_Font;
private readonly float m_FontSize;

public FontConfig(string? font = null, float? fontSize = null)
{
m_Font=font ?? "Segoe UI";
m_FontSize=fontSize ?? 8.25F;
}
public string Font => m_Font;
public float FontSize => m_FontSize;
}
}
4 changes: 2 additions & 2 deletions Library/WinFormControls/DetailControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ public async Task SafeCurrentFile(string fileName)
for (var i = 0; i < physSource.SkipRows; i++)
skippedLines.AppendLine(await sr.ReadLineAsync());
}
using var formProgress = new FormProgress("Writing file", true, m_CancellationToken);
using var formProgress = new FormProgress("Writing file", true, new FontConfig(Font.Name, Font.Size), m_CancellationToken);
try
{
formProgress.ShowWithFont(this);
Expand Down Expand Up @@ -851,7 +851,7 @@ private async void ToolStripButtonLoadRemaining_Click(object? sender, EventArgs
// ReSharper disable once LocalizableElement
m_ToolStripLabelCount.Text = " loading...";
using var formProgress = new FormProgress("Load more...", false, m_CancellationToken);
using var formProgress = new FormProgress("Load more...", false, new FontConfig(Font.Name, Font.Size), m_CancellationToken);
formProgress.ShowWithFont(this);
formProgress.Maximum = 100;
Expand Down
2 changes: 1 addition & 1 deletion Library/WinFormControls/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static void CtrlA(this Form frm, object? sender, KeyEventArgs e)
{
if (!fileSetting.ShowProgress)
return null;
var formProgress = new FormProgress(fileSetting.ToString(), withLogger, cancellationToken);
var formProgress = new FormProgress(fileSetting.ToString(), withLogger, new FontConfig(owner?.Font.Name, owner?.Font.Size), cancellationToken);
formProgress.ShowWithFont(owner);
return formProgress;
}
Expand Down
6 changes: 3 additions & 3 deletions Library/WinFormControls/FormColumnUIRead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void AddDateFormat(string format)

private async Task DisplayValues()
{
using var formProgress = new FormProgress("Display Values", true, m_CancellationTokenSource.Token);
using var formProgress = new FormProgress("Display Values", true, FontConfig, m_CancellationTokenSource.Token);

formProgress.ShowWithFont(this);
var values = await GetSampleValuesAsync(comboBoxColumnName.Text, formProgress, formProgress.CancellationToken);
Expand Down Expand Up @@ -165,7 +165,7 @@ private async Task Guess()

await buttonGuess.RunWithHourglassAsync(async () =>
{
using var formProgress = new FormProgress("Guess Value", true, m_CancellationTokenSource.Token);
using var formProgress = new FormProgress("Guess Value", true, FontConfig, m_CancellationTokenSource.Token);
formProgress.ShowWithFont(this);
{
var samples = await GetSampleValuesAsync(columnName, formProgress, formProgress.CancellationToken);
Expand Down Expand Up @@ -533,7 +533,7 @@ private async void ColumnFormatUI_Load(object? sender, EventArgs e)
columnBindingSource.DataSource = m_ColumnEdit;
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
using var formProgress = new FormProgress("Getting column headers", false, m_CancellationTokenSource.Token);
using var formProgress = new FormProgress("Getting column headers", false, FontConfig, m_CancellationTokenSource.Token);
formProgress.ShowWithFont(this);
formProgress.SetProcess("Getting columns from source");
HashSet<string> allColumns = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
Expand Down
4 changes: 2 additions & 2 deletions Library/WinFormControls/FormCsvTextDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private async Task OriginalStream(CancellationToken cancellationToken)
{
await textBox.RunWithHourglassAsync(async () =>
{
using var formProgress = new FormProgress("Display Source", false, cancellationToken);
using var formProgress = new FormProgress("Display Source", false, FontConfig, cancellationToken);
formProgress.ShowWithFont(this);
textBox.ClearUndo();
formProgress.Report(new ProgressInfo("Display of read file"));
Expand All @@ -121,7 +121,7 @@ private void PrettyPrintStream(CancellationToken cancellationToken)
{
textBox.RunWithHourglass(() =>
{
using var formProgress = new FormProgress("Pretty Print Source", false, cancellationToken);
using var formProgress = new FormProgress("Pretty Print Source", false, FontConfig, cancellationToken);
formProgress.ShowWithFont(this);
formProgress.Maximum = 0;
formProgress.Report(new ProgressInfo("Parsing Text as Json"));
Expand Down
2 changes: 1 addition & 1 deletion Library/WinFormControls/FormDuplicatesDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void Work(string dataColumnName, bool ignoreNull)
return;
this.SafeInvoke(() => Text = $@"Duplicate Display - {dataColumnName}");

using var formProgress = new FormProgress($"Processing {dataColumnName}", false, m_CancellationTokenSource.Token)
using var formProgress = new FormProgress($"Processing {dataColumnName}", false, FontConfig, m_CancellationTokenSource.Token)
{ Maximum = m_DataRow.Length };
formProgress.ShowWithFont(this);
var intervalAction = new IntervalAction();
Expand Down
4 changes: 2 additions & 2 deletions Library/WinFormControls/FormHierarchyDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void BuildTree(string parent, string id, string? display1 = null, string?
{
this.RunWithHourglass(() =>
{
using var formProgress = new FormProgress("Building Tree", false, m_CancellationTokenSource.Token);
using var formProgress = new FormProgress("Building Tree", false, FontConfig, m_CancellationTokenSource.Token);
formProgress.ShowWithFont(this);
formProgress.Maximum = m_DataRow.GetLength(0) * 2;
Expand Down Expand Up @@ -317,7 +317,7 @@ private void FilterValueChangedElapsed(object? sender, ElapsedEventArgs e)
{
try
{
using var formProgress = new FormProgress("Searching", false, m_CancellationTokenSource.Token);
using var formProgress = new FormProgress("Searching", false, FontConfig, m_CancellationTokenSource.Token);
formProgress.ShowWithFont(this);
Search(m_TextBoxValue!.Text, m_TreeView.Nodes, formProgress.CancellationToken);
}
Expand Down
7 changes: 3 additions & 4 deletions Library/WinFormControls/FormProcessDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrayNotify;

// ReSharper disable RedundantDelegateCreation
// ReSharper disable RedundantNameQualifier
Expand All @@ -48,7 +47,7 @@ public sealed class FormProgress : ResizeForm, IProgressTime, ILogger
public event EventHandler<ProgressInfo>? ProgressChanged;

public FormProgress(in string windowTitle)
: this(windowTitle, true, CancellationToken.None)
: this(windowTitle, true, new FontConfig(), CancellationToken.None)
{
}

Expand All @@ -58,7 +57,7 @@ public FormProgress(in string windowTitle)
/// <param name="windowTitle">The description / form title</param>
/// <param name="withLoggerDisplay">True if a debug logging windows should be shown</param>
/// <param name="cancellationToken">Cancellation token to stop a possibly long running process</param>
public FormProgress(in string? windowTitle, bool withLoggerDisplay, in CancellationToken cancellationToken)
public FormProgress(in string? windowTitle, bool withLoggerDisplay, in IFontConfig fontConfig, in CancellationToken cancellationToken) : base(fontConfig)
{
CancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
InitializeComponent();
Expand Down Expand Up @@ -90,7 +89,7 @@ public FormProgress(in string? windowTitle, bool withLoggerDisplay, in Cancellat
}

public FormProgress()
: this(string.Empty, true, CancellationToken.None)
: this(string.Empty, true, new FontConfig(), CancellationToken.None)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Library/WinFormControls/FormUniqueDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void Work(string dataColumnName, bool ignoreNull)
var dictIDToRow = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);

using var formProgress =
new FormProgress($"Processing {dataColumnName}", false, m_CancellationTokenSource.Token)
new FormProgress($"Processing {dataColumnName}", false, FontConfig, m_CancellationTokenSource.Token)
{
Maximum = m_DataRow.Length
};
Expand Down
17 changes: 10 additions & 7 deletions Library/WinFormControls/ResizeForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,34 @@ namespace CsvTools

public class ResizeForm : Form
{
private IFontConfig? m_FontConfig;
private IFontConfig m_FontConfig;

public ResizeForm() : this(null)
public ResizeForm() : this(new FontConfig())
{
}

[Browsable(false)]
[Bindable(false)]
public IFontConfig? FontConfig
public IFontConfig FontConfig
{
get => m_FontConfig;
set
{
if (m_FontConfig != null)
m_FontConfig.PropertyChanged -= FontSettingChanged;
m_FontConfig = value;

if (m_FontConfig != null)
{
m_FontConfig = value;
m_FontConfig.PropertyChanged += FontSettingChanged;
FontSettingChanged(value, new PropertyChangedEventArgs(nameof(IFontConfig.Font)));
}
}
}

protected ResizeForm(in IFontConfig? fontConfig)
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
protected ResizeForm(in IFontConfig fontConfig)
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
InitializeComponent();
FontConfig = fontConfig;
Expand All @@ -59,8 +62,7 @@ private void FontSettingChanged(object? sender, PropertyChangedEventArgs e)
}
}

public void SetFont(Font newFont) =>
SetFonts(this, newFont);
public void SetFont(Font newFont) => SetFonts(this, newFont);

/// <summary>
/// Recursively change the font of all controls, needed on Windows 8 / 2012
Expand All @@ -75,6 +77,7 @@ private static void SetFonts(in Control container, in Font newFont)
foreach (Control ctrl in container.Controls)
SetFonts(ctrl, newFont);
}

#pragma warning disable CS8600
private void InitializeComponent()
{
Expand Down
12 changes: 6 additions & 6 deletions UnitTest/WinFormControlsUnitTest/FormProcessDisplayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class FormProgressTests
[Timeout(1000)]
public void FormProcessCancel()
{
using var formProgress = new FormProgress("Test Logger", true, UnitTestStatic.Token);
using var formProgress = new FormProgress("Test Logger", true, new FontConfig(), UnitTestStatic.Token);
formProgress.ShowInTaskbar = true;
formProgress.Show();
UnitTestStaticForms.WaitSomeTime(.2, UnitTestStatic.Token);
Expand All @@ -39,7 +39,7 @@ public void FormProcessCancel()
public void FormProgress()
{
// Log
using (var formProgress = new FormProgress("Test Logger", true, UnitTestStatic.Token))
using (var formProgress = new FormProgress("Test Logger", true, new FontConfig(),UnitTestStatic.Token))
{
formProgress.ShowInTaskbar = false;
formProgress.Show();
Expand All @@ -66,7 +66,7 @@ public void FormProgress()
}

// marquee
using (var formProgress = new FormProgress("Test Marquee", false, UnitTestStatic.Token))
using (var formProgress = new FormProgress("Test Marquee", false, new FontConfig(),UnitTestStatic.Token))
{
formProgress.ShowInTaskbar = false;
formProgress.Show();
Expand All @@ -81,7 +81,7 @@ public void FormProgress()
}

// NoLog
using (var formProgress = new FormProgress("Test", false, UnitTestStatic.Token))
using (var formProgress = new FormProgress("Test", false,new FontConfig(), UnitTestStatic.Token))
{
formProgress.ShowInTaskbar = false;
formProgress.Show();
Expand Down Expand Up @@ -109,7 +109,7 @@ public void FormprogressTest()
public void FormprogressTest1()
{
using var tokenSrc = new CancellationTokenSource();
using var formProgress = new FormProgress("Title", false, tokenSrc.Token);
using var formProgress = new FormProgress("Title", false,new FontConfig(), tokenSrc.Token);
Assert.AreEqual("Title", formProgress.Text);
Assert.AreEqual(false, formProgress.CancellationToken.IsCancellationRequested);
tokenSrc.Cancel();
Expand All @@ -121,7 +121,7 @@ public void FormprogressTest1()
public void CancelTest()
{
using var tokenSrc = new CancellationTokenSource();
using var formProgress = new FormProgress("Title", true, tokenSrc.Token);
using var formProgress = new FormProgress("Title", true, new FontConfig(),tokenSrc.Token);
Assert.AreEqual(false, formProgress.CancellationToken.IsCancellationRequested);
formProgress.Close();
Assert.AreEqual(true, formProgress.CancellationToken.IsCancellationRequested);
Expand Down

0 comments on commit d1ebbbf

Please sign in to comment.