From 3ced607a6400b19bee5b254a0972daa7a290e91d Mon Sep 17 00:00:00 2001
From: Adam Najmanowicz <adam@najmanowicz.com>
Date: Fri, 3 May 2024 18:16:36 +0200
Subject: [PATCH] #1329 : Script execution results should be less in-the-way

---
 .../PowerShell/Scripts/ise.js                 | 25 +++++++++++++------
 .../PowerShell/Styles/ise.css                 | 16 +++++-------
 .../Shell/PowerShell/PowerShellIse.xml        |  5 +++-
 3 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/src/Spe/sitecore modules/PowerShell/Scripts/ise.js b/src/Spe/sitecore modules/PowerShell/Scripts/ise.js
index 98e22b727..e029293ce 100644
--- a/src/Spe/sitecore modules/PowerShell/Scripts/ise.js	
+++ b/src/Spe/sitecore modules/PowerShell/Scripts/ise.js	
@@ -29,6 +29,7 @@
         var debugMarkers = [];
         var resultsBottomOffset = 10;
         var typingTimer;
+        var resultsVisibilityIntent = true;
         
         var editor = $($("#Editor")[0]);
         editor.hide();
@@ -465,6 +466,9 @@
                 spe.preventCloseWhenRunning(false);
             }
             clearVariablesCache();
+            if(!resultsVisibilityIntent){
+                setTimeout(spe.closeResults, 2000);
+            }
         };
 
         spe.clearBreakpoints = function() {
@@ -510,7 +514,6 @@
 	        $("#Result").height(resultsHeight);
             $("#Result").width($(window).width() - $("#Result").offset().left * 2);
             $("#ProgressOverlay").css("top",($("#Result").offset().top+4)+"px");
-            $("#ResultsClose").css("top", ($("#Result").offset().top + 4) + "px");
         };
 
         function isEmpty(val) {
@@ -536,7 +539,8 @@
         spe.restoreResults = function() {
             $("#ResultsSplitter").show();
             $("#ResultsRow").show();
-            codeeditor.resize();
+            spe.resizeEditor();
+            $("#ResultsStatusBarAction").removeClass("status-bar-results-hidden")
         };
 
         spe.closeResults = function() {
@@ -544,6 +548,7 @@
             $("#ResultsRow").hide("slow", function() {
                 codeeditor.resize();
             });
+            $("#ResultsStatusBarAction").addClass("status-bar-results-hidden")
         };
 
         function getCachedVariableValue(storageKey, variableName) {
@@ -677,13 +682,17 @@
 
         });
 
-        $("#ResultsClose").click(function() {
-            $("#ResultsSplitter").hide();
-            $("#ResultsRow").hide("slow", function() {
-                codeeditor.resize(); /* do something cool here? */
-            });
+        
+        $("#ShowHideResults").click(function() {
+            if ($("#ResultsRow").is(":visible")) {
+                resultsVisibilityIntent = false;
+                spe.closeResults();
+            } else {
+                resultsVisibilityIntent = true;
+                spe.restoreResults();
+            }
         });
-
+        
         function _getCommandHelp(str) {
             getPowerShellResponse({ "guid": guid, "command": str }, "GetHelpForCommand",
                 function(json) {
diff --git a/src/Spe/sitecore modules/PowerShell/Styles/ise.css b/src/Spe/sitecore modules/PowerShell/Styles/ise.css
index 04e87d70e..0d092dc54 100644
--- a/src/Spe/sitecore modules/PowerShell/Styles/ise.css	
+++ b/src/Spe/sitecore modules/PowerShell/Styles/ise.css	
@@ -146,7 +146,7 @@ a.ps-link {
     text-transform: uppercase;
 }
 
-#HelpClose, #ResultsClose {
+#HelpClose {
     -moz-border-radius-bottomleft: 9px;
     -moz-border-radius-bottomright: 9px;
     -moz-border-radius-topleft: 9px;
@@ -183,25 +183,17 @@ a.ps-link {
     top: 0;
 }
 
-#HelpClose:hover, #ResultsClose:hover {
+#HelpClose:hover {
     background: -moz-linear-gradient(center top, #dfdfdf 5%, #ededed 100%);
     background-color: #e3e3e3;
     filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed');
 }
 
-#ResultsClose:active {
-    top: 1px;
-}
-
 #ResultsSplitter {
     background: url(/sitecore%20modules/PowerShell/Assets/Splitter.png) no-repeat center;
     padding: 0 4px 0 4px;
 }
 
-#ResultsClose { 
-    position: fixed;
-}
-
 #Result {
     position: fixed;
     bottom: 27px;
@@ -421,4 +413,8 @@ a.ps-link {
 
 #CodeEditor * {
     font-family: inherit !important;
+}
+
+#ResultsStatusBarAction.status-bar-results-hidden {
+    background-color: rgb(1, 36, 86);
 }
\ No newline at end of file
diff --git a/src/Spe/sitecore modules/Shell/PowerShell/PowerShellIse.xml b/src/Spe/sitecore modules/Shell/PowerShell/PowerShellIse.xml
index 6c6b64a18..6ea8206cf 100644
--- a/src/Spe/sitecore modules/Shell/PowerShell/PowerShellIse.xml	
+++ b/src/Spe/sitecore modules/Shell/PowerShell/PowerShellIse.xml	
@@ -104,7 +104,6 @@
                     </p>
                   </Border>
                 </Border>
-                <Border ID="ResultsClose">x</Border>
                 <Border ID="ScriptResult" class="console">
                   <pre ID="ScriptResultCode"></pre>
                 </Border>
@@ -123,6 +122,10 @@
             <Image ID="CopyResultsToClipboard" src="/~/icon/office/16x16/element_copy.png"
                    Alt="Copy results to clipboard" Title="Copy results to clipboard" />
           </Border>
+          <Border  ID="ResultsStatusBarAction" class="status-bar-panel status-bar-right-icon">
+            <Image ID="ShowHideResults" src="/~/icon/office/16x16/text_align_left.png"
+                   Alt="Show/Hide Execution results pane" Title="Show/Hide Execution results pane" />
+          </Border>
           <Border class="status-bar-panel status-bar-text">
             <Image ID="RefreshHint" src="/~/icon/office/16x16/nav_refresh.png"
                    Alt="Show next usability hint..." Title="Show next usability hint..." />
