2

我希望能够右键单击 Sitecore 中的内容项,然后在上下文菜单中选择“运行我的应用程序”之类的内容。然后在运行的应用程序中,我需要能够引用右键单击的内容项。这可能吗?

4

1 回答 1

2

是的,你可以做到这一点,它并不像听起来那么难。

您想进入核心数据库并打开内容编辑器。右键菜单定义在sitecore/content/Applications/Content Editor/Context Menus/Default

当您右键单击树中的项目时,您会看到该文件夹​​中的项目。因此,您可以使用Menu Item模板添加一个新项目。

如果您查看现有的,它们中的大多数都会向 Sitecore 桌面发送消息。这些消息是 /App_Config/Commands.config 中定义的命令。我在那里看不到任何会启动另一个 Sitecore 应用程序的东西,因此您需要创建一个新命令来执行此操作。要创建一个,只需从Sitecore.Shell.Framework.Commands.Command类继承。传入的CommandContext将包含一个项目集合。

    public class DemoCommand: Command
{
    #region Overrides of Command

    /// <summary>
    /// Executes the command in the specified context.
    /// </summary>
    /// <param name="context">The context.</param>
    public override void Execute(CommandContext context)
    {
        Assert.ArgumentNotNull(context, "context");

        var parameters = new NameValueCollection();
        if (context.Items != null && context.Items.Length == 1)
        {
            var item = context.Items[0];
            parameters["id"] = item.ID.ToString();
        }
        Context.ClientPage.Start(this, "Run", parameters);
    }

    #endregion

    public CommandState QueryStat(CommandContext context)
    {
        Assert.ArgumentNotNull(context, "context");
        return CommandState.Enabled;
    }

    protected static void Run(ClientPipelineArgs args)
    {
        Assert.ArgumentNotNull(args, "args");

        SheerResponse.CheckModified(false);
        SheerResponse.Broadcast(
                        SheerResponse.ShowModalDialog(
                            "[Path to your application here]"
                        ),
                        "Shell");
    }
}

要传递项目,在您的消息调用中 - 只需传递变量 $Target。

因此,菜单项中的消息字段将类似于:

item:runMyApplication(id=$Target)

希望这是有道理的:)

于 2013-06-04T21:01:45.113 回答