private void UpdateButtonEnabled(Button button, Command command)
{
var enabled = command != null && command.Enabled;
// DuplicatePage and DeletePage are a bit tricky to get right.
// See https://silbloom.myjetbrains.com/youtrack/issue/BL-2183.
if(enabled && command.Implementer != null)
{
var target = command.Implementer.Target as EditingModel;
if(target != null)
{
if(command is DuplicatePageCommand)
enabled = target.CanDuplicatePage;
else if(command is DeletePageCommand)
enabled = target.CanDeletePage;
}
}
//doesn't work because the forecolor is ignored when disabled...
var foreColor = enabled ? _enabledToolbarColor : _disabledToolbarColor; //.DimGray;
// BL-2338: signficant button flashing is apparently caused by setting these and
// invalidating when nothing actually changed. So only do it if something DID change.
if(enabled != button.Enabled || button.ForeColor != foreColor)
{
button.Enabled = enabled;
button.ForeColor = foreColor;
button.Invalidate();
}
}