<commit_before>﻿using System;
using System.Collections.Specialized;
using System.IdentityModel.Protocols.WSTrust;
using System.Web.UI;
using Cognifide.PowerShell.Core.Extensions;
using Cognifide.PowerShell.Core.Settings;
using Cognifide.PowerShell.Core.Utility;
using Sitecore;
using Sitecore.Configuration;
using Sitecore.Data.Items;
using Sitecore.Data.Managers;
using Sitecore.Diagnostics;
using Sitecore.Globalization;
using Sitecore.Shell.Applications.ContentEditor.Galleries;
using Sitecore.Shell.Framework.Commands;
using Sitecore.Shell.Web.UI.WebControls;
using Sitecore.Text;
using Sitecore.Web.UI.WebControls.Ribbons;
using Control = Sitecore.Web.UI.HtmlControls.Control;

namespace Cognifide.PowerShell.Client.Controls
{
    public class IseContextPanel : RibbonPanel
    {
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            Assert.ArgumentNotNull(output, "output");
            Assert.ArgumentNotNull(ribbon, "ribbon");
            Assert.ArgumentNotNull(button, "button");
            Assert.ArgumentNotNull(context, "context");

            var contextDB = context.Parameters["contextDB"];
            var contextItemId = context.Parameters["contextItem"];
            var currentSessionId = context.Parameters["currentSessionId"];
            var currentSessionName = context.Parameters["currentSessionName"];
            var persistentSessionId = context.Parameters["persistentSessionId"];
            var contextItem = !string.IsNullOrEmpty(contextDB) && !string.IsNullOrEmpty(contextItemId)
                ? Factory.GetDatabase(contextDB).GetItem(contextItemId)
                : null;

            output.Write(string.Format("<div class=\"iseRibbonContextPanel {0}\">", context.Parameters["ScriptRunning"] == "1" ? "disabled" : string.Empty));
            output.Write("<div class=\"scRibbonToolbarSmallButtons scRibbonContextLabels\">");
            output.Write("<div class=\"iseRibbonContextPanelLabel\">");
            output.Write(Translate.Text("Context"));
            output.Write("</div>");
            output.Write("<div class=\"iseRibbonContextPanelLabel\">");
            output.Write(Translate.Text("Session"));
            output.Write("</div>");
            output.Write("</div>");
            var contextEnabled = string.IsNullOrEmpty(persistentSessionId); 
            //RenderContext(output, contextItem, ribbon, contextEnabled);
            var contextButton = Factory.GetDatabase("core").GetItem("{C733DE04-FFA2-4DCB-8D18-18EB1CB898A3}");
            string path = contextItem != null ? PathUtilities.GetItemPsPath(contextItem).EllipsisString(50) : "none";
            string icon = contextItem != null ? contextItem.Appearance.Icon : "Office/32x32/sign_forbidden.png";
            RenderSmallGalleryButton(output, contextButton, context, ribbon, path, icon);
            var sessionButton = Factory.GetDatabase("core").GetItem("{0C784F54-2B46-4EE2-B0BA-72384125E123}");
            RenderSmallGalleryButton(output, sessionButton, context, ribbon, currentSessionName, string.Empty);
            output.Write("</div>");
        }

        private void RenderContext(HtmlTextWriter output, Item contextItem, Ribbon ribbon, bool contextEnabled)<commit_msg>Issue #275, #276 - cosmetic improvements - oops<commit_after>﻿using System;
using System.Collections.Specialized;
using System.IdentityModel.Protocols.WSTrust;
using System.Web.UI;
using Cognifide.PowerShell.Core.Extensions;
using Cognifide.PowerShell.Core.Settings;
using Cognifide.PowerShell.Core.Utility;
using Sitecore;
using Sitecore.Configuration;
using Sitecore.Data.Items;
using Sitecore.Data.Managers;
using Sitecore.Diagnostics;
using Sitecore.Globalization;
using Sitecore.Shell.Applications.ContentEditor.Galleries;
using Sitecore.Shell.Framework.Commands;
using Sitecore.Shell.Web.UI.WebControls;
using Sitecore.Text;
using Sitecore.Web.UI.WebControls.Ribbons;
using Control = Sitecore.Web.UI.HtmlControls.Control;

namespace Cognifide.PowerShell.Client.Controls
{
    public class IseContextPanel : RibbonPanel
    {
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            Assert.ArgumentNotNull(output, "output");
            Assert.ArgumentNotNull(ribbon, "ribbon");
            Assert.ArgumentNotNull(button, "button");
            Assert.ArgumentNotNull(context, "context");

            var contextDB = context.Parameters["contextDB"];
            var contextItemId = context.Parameters["contextItem"];
            var currentSessionId = context.Parameters["currentSessionId"];
            var currentSessionName = context.Parameters["currentSessionName"];
            var persistentSessionId = context.Parameters["persistentSessionId"];
            var contextItem = !string.IsNullOrEmpty(contextDB) && !string.IsNullOrEmpty(contextItemId)
                ? Factory.GetDatabase(contextDB).GetItem(contextItemId)
                : null;

            output.Write("<div class=\"iseRibbonContextPanel {0}\">", context.Parameters["ScriptRunning"] == "1" ? "disabled" : string.Empty);
            output.Write("<div class=\"scRibbonToolbarSmallButtons scRibbonContextLabels\">");
            output.Write("<div class=\"iseRibbonContextPanelLabel\">");
            output.Write(Translate.Text("Context"));
            output.Write("</div>");
            output.Write("<div class=\"iseRibbonContextPanelLabel\">");
            output.Write(Translate.Text("Session"));
            output.Write("</div>");
            output.Write("</div>");
            var contextEnabled = string.IsNullOrEmpty(persistentSessionId); 
            //RenderContext(output, contextItem, ribbon, contextEnabled);
            var contextButton = Factory.GetDatabase("core").GetItem("{C733DE04-FFA2-4DCB-8D18-18EB1CB898A3}");
            string path = contextItem != null ? PathUtilities.GetItemPsPath(contextItem).EllipsisString(50) : "none";
            string icon = contextItem != null ? contextItem.Appearance.Icon : "Office/32x32/sign_forbidden.png";
            RenderSmallGalleryButton(output, contextButton, context, ribbon, path, icon);
            var sessionButton = Factory.GetDatabase("core").GetItem("{0C784F54-2B46-4EE2-B0BA-72384125E123}");
            RenderSmallGalleryButton(output, sessionButton, context, ribbon, currentSessionName, string.Empty);
            output.Write("</div>");
        }

        private void RenderContext(HtmlTextWriter output, Item contextItem, Ribbon ribbon, bool contextEnabled)
{'fraction_non_alphanumeric': 0.11813061348759324, 'fraction_numerical': 0.015527477546049627, 'mean_word_length': 3.6496815286624202, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2535523', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1774, 'n_words': 308}