Repository: microsoft/terminal (language: cpp)

Issue:
Terminal shouldn't be offered as an option in the context menu for Quick Access background
From MSFT:37831236

> When I right-click on the background of File Explorer "Quick Access," Terminal shouldn't be offered as an option because it doesn't do anything there

Presumably we can filter if we're visible based on the path that was provided to us. 




Discussion / hints:
From internal mail:


> So, in their `IExplorerCommand::GetState`, I think they could have a check for that against the `IShellItemArray` that gets passed in.

```c++
bool IsFileSystemItem(IShellItem* shellItem)
{
    SFGAOF attributes;
    return (shellItem->GetAttributes(SFGAO_FILESYSTEM, &attributes) == S_OK);
}
```

We may also want to compare notes with MSFT:36909951
Open with... dialog cannot choose the All the Apps from Microsoft Store

Fix patch:
diff --git a/.github/actions/spelling/expect/expect.txt b/.github/actions/spelling/expect/expect.txt
index 2cc27be650e..f4f432cb1a3 100644
--- a/.github/actions/spelling/expect/expect.txt
+++ b/.github/actions/spelling/expect/expect.txt
@@ -2179,6 +2179,8 @@ SETTITLE
 setw
 Setwindow
 SETWINDOWINFO
+SFGAO
+SFGAOF
 sfi
 SFINAE
 SFUI
diff --git a/src/cascadia/ShellExtension/OpenTerminalHere.cpp b/src/cascadia/ShellExtension/OpenTerminalHere.cpp
index 5f472d72f4b..d9b872136da 100644
--- a/src/cascadia/ShellExtension/OpenTerminalHere.cpp
+++ b/src/cascadia/ShellExtension/OpenTerminalHere.cpp
@@ -97,7 +97,7 @@ HRESULT OpenTerminalHere::GetTitle(IShellItemArray* /*psiItemArray*/,
     return SHStrDup(resource.data(), ppszName);
 }
 
-HRESULT OpenTerminalHere::GetState(IShellItemArray* /*psiItemArray*/,
+HRESULT OpenTerminalHere::GetState(IShellItemArray* psiItemArray,
                                    BOOL /*fOkToBeSlow*/,
                                    EXPCMDSTATE* pCmdState)
 {
@@ -106,10 +106,25 @@ HRESULT OpenTerminalHere::GetState(IShellItemArray* /*psiItemArray*/,
     // E_PENDING and this object will be called back on a background thread with
     // fOkToBeSlow == TRUE
 
-    // We however don't need to bother with any of that, so we'll just return
-    // ECS_ENABLED.
+    // We however don't need to bother with any of that.
+
+    // If no item was selected when the context menu was opened and Explorer
+    // is not at a valid path (e.g. This PC or Quick Access), we should hide
+    // the verb from the context menu.
+    if (psiItemArray == nullptr)
+    {
+        const auto path = this->_GetPathFromExplorer();
+        *pCmdState = path.empty() ? ECS_HIDDEN : ECS_ENABLED;
+    }
+    else
+    {
+        winrt::com_ptr<IShellItem> psi;
+        psiItemArray->GetItemAt(0, psi.put());
+        SFGAOF attributes;
+        const bool isFileSystemItem = (psi->GetAttributes(SFGAO_FILESYSTEM, &attributes) == S_OK);
+        *pCmdState = isFileSystemItem ? ECS_ENABLED : ECS_HIDDEN;
+    }
 
-    *pCmdState = ECS_ENABLED;
     return S_OK;
 }
 


Test patch: