WinForms: Fix command text changes propagation

This commit is contained in:
Ben Olden-Cooligan 2022-12-29 15:44:26 -08:00
parent fbb4f31963
commit 5eab26dcad
3 changed files with 13 additions and 6 deletions

View File

@ -206,8 +206,13 @@ public class WinFormsDesktopForm : DesktopForm
private wf.ToolStripItem ApplyCommand(wf.ToolStripItem item, Command command)
{
void SetItemText() => item.Text = item is wf.ToolStripMenuItem ? command.MenuText : command.ToolBarText;
item.Image = command.Image.ToSD();
item.Text = item is wf.ToolStripMenuItem ? command.MenuText : command.ToolBarText;
SetItemText();
if (command is ActionCommand actionCommand)
{
actionCommand.TextChanged += (_, _) => SetItemText();
}
if (item is wf.ToolStripMenuItem menuItem)
{
menuItem.ShortcutKeys = command.Shortcut.ToSWF();

View File

@ -23,6 +23,9 @@ public class ActionCommand : Command
{
ToolBarText = value;
MenuText = value;
TextChanged?.Invoke(this, EventArgs.Empty);
}
}
public event EventHandler? TextChanged;
}

View File

@ -424,16 +424,15 @@ public abstract class DesktopForm : EtoFormBase
Commands.ReorderMenu.Enabled =
Commands.EmailPdf.Enabled = Commands.Print.Enabled = ImageList.Images.Any();
// TODO: Changing the text on the command doesn't actually propagate to the widget
// "All" dropdown items
Commands.SaveAllPdf.MenuText = Commands.SaveAllImages.MenuText = Commands.EmailAll.MenuText =
Commands.ReverseAll.MenuText = string.Format(MiscResources.AllCount, ImageList.Images.Count);
Commands.SaveAllPdf.Text = Commands.SaveAllImages.Text = Commands.EmailAll.Text =
Commands.ReverseAll.Text = string.Format(MiscResources.AllCount, ImageList.Images.Count);
Commands.SaveAllPdf.Enabled = Commands.SaveAllImages.Enabled = Commands.EmailAll.Enabled =
Commands.ReverseAll.Enabled = ImageList.Images.Any();
// "Selected" dropdown items
Commands.SaveSelectedPdf.MenuText = Commands.SaveSelectedImages.MenuText = Commands.EmailSelected.MenuText =
Commands.ReverseSelected.MenuText = string.Format(MiscResources.SelectedCount, ImageList.Selection.Count);
Commands.SaveSelectedPdf.Text = Commands.SaveSelectedImages.Text = Commands.EmailSelected.Text =
Commands.ReverseSelected.Text = string.Format(MiscResources.SelectedCount, ImageList.Selection.Count);
Commands.SaveSelectedPdf.Enabled = Commands.SaveSelectedImages.Enabled = Commands.EmailSelected.Enabled =
Commands.ReverseSelected.Enabled = ImageList.Selection.Any();