示例#1
0
        /// <summary>
        ///     Updates the ribbon.
        /// </summary>
        private void UpdateRibbon()
        {
            var ribbon = new Ribbon {
                ID = "PowerShellRibbon"
            };
            var item = ScriptItem;

            ribbon.CommandContext     = new CommandContext(item);
            ribbon.ShowContextualTabs = false;
            ribbon.CommandContext.Parameters["ScriptRunning"]    = ScriptRunning ? "1" : "0";
            ribbon.CommandContext.Parameters["currentSessionId"] = CurrentSessionId ?? string.Empty;
            ribbon.CommandContext.Parameters["scriptLength"]     = Editor.Value.Length.ToString();
            ribbon.CommandContext.Parameters["selectionLength"]  = SelectionText.Value.Trim().Length.ToString();
            ribbon.CommandContext.Parameters["modified"]         = ScriptModified.ToString();
            ribbon.CommandContext.Parameters["debugging"]        = Debugging ? "1" : "0";
            ribbon.CommandContext.Parameters["inBreakpoint"]     = InBreakpoint ? "1" : "0";


            var sessionName         = CurrentSessionId ?? string.Empty;
            var persistentSessionId = sessionName;

            if (string.Equals(sessionName, StringTokens.PersistentSessionId, StringComparison.OrdinalIgnoreCase))
            {
                var name =
                    item != null &&
                    !string.IsNullOrEmpty(item[ScriptItemFieldNames.PersistentSessionId])
                        ? item[ScriptItemFieldNames.PersistentSessionId]
                        : null;
                sessionName         = string.Format(Texts.PowerShellIse_UpdateRibbon_Script_defined___0_, name ?? Texts.PowerShellIse_UpdateRibbon_Single_execution);
                persistentSessionId = name ?? string.Empty;
            }

            ribbon.CommandContext.Parameters["persistentSessionId"] = persistentSessionId;
            ribbon.CommandContext.Parameters["currentSessionName"]  = string.IsNullOrEmpty(sessionName)
                ? Texts.PowerShellIse_UpdateRibbon_Single_execution
                : (sessionName == DefaultSessionName)
                    ? Factory.GetDatabase("core")
                                                                      .GetItem(
                "/sitecore/content/Applications/PowerShell/PowerShellIse/Menus/Sessions/ISE editing session")?
                                                                      .DisplayName ?? DefaultSessionName
                    : sessionName;
            var obj2 = Context.Database.GetItem("/sitecore/content/Applications/PowerShell/PowerShellIse/Ribbon");

            Error.AssertItemFound(obj2, "/sitecore/content/Applications/PowerShell/PowerShellIse/Ribbon");
            ribbon.CommandContext.RibbonSourceUri = obj2.Uri;

            ribbon.CommandContext.Parameters["currentUser"]     = string.IsNullOrEmpty(CurrentUser) ? DefaultUser : CurrentUser;
            ribbon.CommandContext.Parameters["currentLanguage"] = string.IsNullOrEmpty(CurrentLanguage) ? DefaultLanguage : CurrentLanguage;

            ribbon.CommandContext.Parameters.Add("contextDB", UseContext ? ContextItemDb : string.Empty);
            ribbon.CommandContext.Parameters.Add("contextItem", UseContext ? ContextItemId : string.Empty);
            ribbon.CommandContext.Parameters.Add("scriptDB", ScriptItemDb);
            ribbon.CommandContext.Parameters.Add("scriptItem", ScriptItemId);
            RibbonPanel.InnerHtml = HtmlUtil.RenderControl(ribbon);
        }
        private void UpdateRibbon()
        {
            var ribbon = new Ribbon()
            {
                ID = "TurboConsoleRibbon"
            };

            ribbon.CommandContext = new Sitecore.Shell.Framework.Commands.CommandContext();
            ribbon.CommandContext.Parameters["ScriptRunning"]    = ScriptRunning ? "1" : "0";
            ribbon.CommandContext.Parameters["ScriptModified"]   = ScriptModified.ToString();
            ribbon.CommandContext.Parameters["currentSessionId"] = CurrentSessionId ?? String.Empty;

            var ribbonItem = Sitecore.Context.Database.GetItem("/sitecore/content/Applications/Turbo Console/Turbo Console/Ribbon");

            Error.AssertItemFound(ribbonItem, "/sitecore/content/Applications/Turbo Console/Turbo Console/Ribbon");
            ribbon.CommandContext.RibbonSourceUri = ribbonItem.Uri;
            RibbonPanel.InnerHtml = HtmlUtil.RenderControl(ribbon);
        }