Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion src/LogExpert.Core/Config/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public SelectionHighlightSettings SelectionHighlight
set => _selectionHighlight = value ?? new();
}

/// <summary>Custom-color palette shared by the Highlight Entry color pickers, as ColorDialog.CustomColors values.</summary>
/// <summary>Custom-color palette shared by the Highlight dialog's color pickers, as ColorDialog.CustomColors values.</summary>
public int[] HighlightCustomColors
{
get => _highlightCustomColors;
Expand Down
38 changes: 38 additions & 0 deletions src/LogExpert.UI.Tests/Dialogs/HighlightDialogEntryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,44 @@ public void EditorCancel_DiscardsItsPalette ()
Assert.That(_dialog.CustomColors, Is.EqualTo(new[] { 0x00102030 }));
}

[Test]
public void SelectionColorPickerOk_SharesThePaletteWithTheEntryEditors ()
{
int[] shown = null;
int[] received = null;
_dialog.ShowColorDialog = picker =>
{
shown = picker.CustomColors;
picker.CustomColors = [0x00ABCDEF];
return DialogResult.OK;
};
Find<Button>("btnSelectionColor").PerformClick();

_dialog.ShowEntryDialog = editor =>
{
received = editor.CustomColors;
return DialogResult.Cancel;
};
Find<Button>("btnAdd").PerformClick();

Assert.That(shown[0], Is.EqualTo(0x00102030));
Assert.That(received[0], Is.EqualTo(0x00ABCDEF));
}

[Test]
public void SelectionColorPickerCancel_KeepsThePalette ()
{
_dialog.ShowColorDialog = picker =>
{
picker.CustomColors = [0x00ABCDEF];
return DialogResult.Cancel;
};

Find<Button>("btnSelectionColor").PerformClick();

Assert.That(_dialog.CustomColors, Is.EqualTo(new[] { 0x00102030 }));
}

private static HighlightEntry EditedEntry (HighlightEntryDialog editor)
{
return (HighlightEntry)typeof(HighlightEntryDialog).GetField("_entry", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(editor);
Expand Down
11 changes: 8 additions & 3 deletions src/LogExpert.UI/Dialogs/Highlight/HighlightDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public HighlightDialog (IConfigManager configManager)
checkBoxSelectionOutline.Checked = configManager.Settings.Preferences.SelectionHighlight.Outline;
CustomColors = [.. configManager.Settings.Preferences.HighlightCustomColors];
ShowEntryDialog = dialog => dialog.ShowDialog(this);
ShowColorDialog = dialog => dialog.ShowDialog(this);
UpdateSelectionColorPreview();
Load += OnHighlightDialogLoad;
listBoxHighlight.DrawItem += OnHighlightListBoxDrawItem;
Expand Down Expand Up @@ -113,22 +114,26 @@ public List<HighlightGroup> HighlightGroupList
CustomColor = _selectionColor
};

/// <summary>Pending Highlight Entry color-picker palette; the caller persists it when the dialog is accepted.</summary>
/// <summary>Pending color-picker palette shared by the entry and selection pickers; the caller persists it when the dialog is accepted.</summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int[] CustomColors { get; private set; }

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
internal Func<HighlightEntryDialog, DialogResult> ShowEntryDialog { get; set; }

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
internal Func<ColorDialog, DialogResult> ShowColorDialog { get; set; }

#endregion

#region Event handling Methods

private void OnSelectionColorClick (object sender, EventArgs e)
{
using var dialog = new ColorDialog { Color = _selectionColor ?? SystemColors.Highlight, FullOpen = true };
if (dialog.ShowDialog(this) == DialogResult.OK)
using var dialog = new ColorDialog { Color = _selectionColor ?? SystemColors.Highlight, FullOpen = true, CustomColors = CustomColors };
if (ShowColorDialog(dialog) == DialogResult.OK)
{
CustomColors = dialog.CustomColors;
_selectionColor = dialog.Color;
UpdateSelectionColorPreview();
}
Expand Down
Loading