I have created a custom Ribbon button that creates a new item. However, when clicking this button the Content Editor switches over to this new item, whereas I expected it to stay on the first item.
Why is it doing this, and how can I prevent this?
For those wondering, this is how I'm creating item from the custom button, with a complete (simplified) Command
implementation:
[Serializable]
public class MyCustomCommand : Command {
public override void Execute(CommandContext context) {
Assert.ArgumentNotNull(context, "context");
if (!context.Items.Any())
{
return;
}
Item item = context.Items[0];
using (new SecurityDisabler()) {
Item newItem = GetParentItem(item).Add("New Name", templateItem);
try {
newItem.Editing.BeginEdit();
newItem["Foo"] = "Bar";
newItem.Editing.EndEdit();
} catch (Exception) {
newItem?.Editing.CancelEdit();
}
}
}
public override CommandState QueryState(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
if (!context.Items.Any())
{
return CommandState.Disabled;
}
// Various enabled/disabled check
return CommandState.Enabled;
}
}