Skip to content

Commit 1fc0997

Browse files
authored
Add a context menu entry to "Open Windows Terminal here" (#6100)
## Summary of the Pull Request ![image](https://user-images.githubusercontent.com/18356694/82586680-94447680-9b5d-11ea-9cf1-a85d2b32db10.png) I went with the simple option - just open the Terminal with the default profile in the selected directory. I'd love to add another entry for "Open Terminal here with Profile...", but that's going to be follow-up work, once we sort out pulling the Terminal Settings into their own dll. ## References * I'm going to need to file a bunch of follow-ups on this one. - We should add another entry to let the user select which profile - We should add the icon - I've got to do it in `dllname.dll,1` format, which is annoying. - These strings should be localized. - Should this only appear on <kbd>Shift</kbd>+right click? Probably! However, I don't know how to do that. * [A Win7 Explorer Command Sample](https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/winui/shell/appshellintegration/ExplorerCommandVerb) which hasn't aged well * [cppwinrt tutorial](https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/author-coclasses) on using COM in cppwinrt * [This is PowerToys' manifest](https://github.com/microsoft/PowerToys/blob/d2a60c7287eb5667b5282a519c92b759664c9e30/installer/MSIX/appxmanifest.xml#L53-L65) and then [their implementation](https://github.com/microsoft/PowerToys/blob/d16ebba9e0f06e7a0d41d981aeb1fd0a78192dc0/src/modules/powerrename/dll/PowerRenameExt.cpp) which were both helpful * [This ](https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-extensions#instructions) was the sample I followed for how to actually set up the manifest, with the added magic that [`desktop5` lets you specify "Directory"](https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-desktop5-itemtype) ## PR Checklist * [x] Closes #1060 * [x] I work here * [ ] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments This adds a COM class that implements `IExplorerCommand`, which is what lets us populate the context menu entry. We expose that type through a new DLL that is simply responsible for the shell extension, so that explorer doesn't need to load the entire Terminal just to populate that entry. The COM class is tied to the application through some new entries in the manifest. The Clsid values are IMPORTANT - they must match the UUID of the implementation type. However, the `Verb` in the manifest didn't seem important.
1 parent cc472c2 commit 1fc0997

22 files changed

+580
-11
lines changed

.github/actions/spell-check/dictionary/apis.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@ ACCEPTFILES
22
ACCESSDENIED
33
bitfield
44
bitfields
5+
CLASSNOTAVAILABLE
6+
EXPCMDFLAGS
7+
EXPCMDSTATE
58
href
69
IBox
10+
IBind
711
ICustom
12+
IClass
13+
IExplorer
814
IMap
915
IObject
1016
IStorage
1117
LCID
1218
NCHITTEST
1319
NCLBUTTONDBLCLK
1420
NCRBUTTONDBLCLK
21+
NOAGGREGATION
1522
NOREDIRECTIONBITMAP
1623
oaidl
1724
ocidl

.github/actions/spell-check/dictionary/microsoft.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mfcribbon
33
microsoft
44
microsoftonline
55
osgvsowi
6+
powerrename
67
powershell
78
tdbuildteamid
89
vcruntime

.github/actions/spell-check/expect/expect.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ dllexport
603603
DLLGETVERSIONPROC
604604
dllimport
605605
dllinit
606+
dllmain
606607
DLLVERSIONINFO
607608
DLOAD
608609
DLOOK
@@ -2088,6 +2089,7 @@ SHIFTJIS
20882089
Shl
20892090
shlguid
20902091
shlobj
2092+
shobjidl
20912093
shlwapi
20922094
SHORTPATH
20932095
SHOWCURSOR

.github/actions/spell-check/expect/web.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ www
44
ecma
55
rapidtables
66
WCAG
7+
winui
8+
appshellintegration

.github/actions/spell-check/patterns/patterns.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
https://(?:(?:[-a-zA-Z0-9?&=]*\.|)microsoft\.com)/[-a-zA-Z0-9?&=_\/.]*
1+
https://(?:(?:[-a-zA-Z0-9?&=]*\.|)microsoft\.com)/[-a-zA-Z0-9?&=_#\/.]*
22
https://aka\.ms/[-a-zA-Z0-9?&=\/_]*
33
https://www.w3.org/[-a-zA-Z0-9?&=\/_#]*
44
https://(?:(?:www\.|)youtube\.com|youtu.be)/[-a-zA-Z0-9?&=]*

OpenConsole.sln

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Terminal", "Terminal", "{59840756-302F-44DF-AA47-441A9D673202}"
77
EndProject
88
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "CascadiaPackage", "src\cascadia\CascadiaPackage\CascadiaPackage.wapproj", "{CA5CAD1A-224A-4171-B13A-F16E576FDD12}"
9+
ProjectSection(ProjectDependencies) = postProject
10+
{F2ED628A-DB22-446F-A081-4CC845B51A2B} = {F2ED628A-DB22-446F-A081-4CC845B51A2B}
11+
EndProjectSection
912
EndProject
1013
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Host.EXE", "src\host\exe\Host.EXE.vcxproj", "{9CBD7DFA-1754-4A9D-93D7-857A9D17CB1B}"
1114
ProjectSection(ProjectDependencies) = postProject
@@ -85,6 +88,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Host.Tests.Feature", "src\h
8588
{18D09A24-8240-42D6-8CB6-236EEE820263} = {18D09A24-8240-42D6-8CB6-236EEE820263}
8689
{FC802440-AD6A-4919-8F2C-7701F2B38D79} = {FC802440-AD6A-4919-8F2C-7701F2B38D79}
8790
{9CBD7DFA-1754-4A9D-93D7-857A9D17CB1B} = {9CBD7DFA-1754-4A9D-93D7-857A9D17CB1B}
91+
{58A03BB2-DF5A-4B66-91A0-7EF3BA01269A} = {58A03BB2-DF5A-4B66-91A0-7EF3BA01269A}
8892
EndProjectSection
8993
EndProject
9094
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TerminalParser.UnitTests", "src\terminal\parser\ut_parser\Parser.UnitTests.vcxproj", "{12144E07-FE63-4D33-9231-748B8D8C3792}"
@@ -188,6 +192,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TerminalApp", "src\cascadia
188192
EndProject
189193
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TerminalSettings", "src\cascadia\TerminalSettings\TerminalSettings.vcxproj", "{CA5CAD1A-D7EC-4107-B7C6-79CB77AE2907}"
190194
EndProject
195+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WindowsTerminalShellExt", "src\cascadia\ShellExtension\WindowsTerminalShellExt.vcxproj", "{F2ED628A-DB22-446F-A081-4CC845B51A2B}"
196+
EndProject
191197
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests_TerminalCore", "src\cascadia\UnitTests_TerminalCore\UnitTests.vcxproj", "{2C2BEEF4-9333-4D05-B12A-1905CBF112F9}"
192198
ProjectSection(ProjectDependencies) = postProject
193199
{06EC74CB-9A12-429C-B551-8562EC954747} = {06EC74CB-9A12-429C-B551-8562EC954747}
@@ -1108,6 +1114,25 @@ Global
11081114
{CA5CAD1A-D7EC-4107-B7C6-79CB77AE2907}.Release|x64.Build.0 = Release|x64
11091115
{CA5CAD1A-D7EC-4107-B7C6-79CB77AE2907}.Release|x86.ActiveCfg = Release|Win32
11101116
{CA5CAD1A-D7EC-4107-B7C6-79CB77AE2907}.Release|x86.Build.0 = Release|Win32
1117+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.AuditMode|Any CPU.ActiveCfg = Release|Win32
1118+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.AuditMode|ARM64.ActiveCfg = Release|ARM64
1119+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.AuditMode|x64.ActiveCfg = Release|x64
1120+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.AuditMode|x64.Build.0 = Release|x64
1121+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.AuditMode|x86.ActiveCfg = Release|Win32
1122+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Debug|Any CPU.ActiveCfg = Debug|Win32
1123+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Debug|ARM64.ActiveCfg = Debug|ARM64
1124+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Debug|ARM64.Build.0 = Debug|ARM64
1125+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Debug|x64.ActiveCfg = Debug|x64
1126+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Debug|x64.Build.0 = Debug|x64
1127+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Debug|x86.ActiveCfg = Debug|Win32
1128+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Debug|x86.Build.0 = Debug|Win32
1129+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Release|Any CPU.ActiveCfg = Release|Win32
1130+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Release|ARM64.ActiveCfg = Release|ARM64
1131+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Release|ARM64.Build.0 = Release|ARM64
1132+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Release|x64.ActiveCfg = Release|x64
1133+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Release|x64.Build.0 = Release|x64
1134+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Release|x86.ActiveCfg = Release|Win32
1135+
{F2ED628A-DB22-446F-A081-4CC845B51A2B}.Release|x86.Build.0 = Release|Win32
11111136
{2C2BEEF4-9333-4D05-B12A-1905CBF112F9}.AuditMode|Any CPU.ActiveCfg = AuditMode|Win32
11121137
{2C2BEEF4-9333-4D05-B12A-1905CBF112F9}.AuditMode|ARM64.ActiveCfg = AuditMode|ARM64
11131138
{2C2BEEF4-9333-4D05-B12A-1905CBF112F9}.AuditMode|x64.ActiveCfg = AuditMode|x64
@@ -1558,6 +1583,7 @@ Global
15581583
{CA5CAD1A-1754-4A9D-93D7-857A9D17CB1B} = {59840756-302F-44DF-AA47-441A9D673202}
15591584
{CA5CAD1A-44BD-4AC7-AC72-F16E576FDD12} = {59840756-302F-44DF-AA47-441A9D673202}
15601585
{CA5CAD1A-D7EC-4107-B7C6-79CB77AE2907} = {59840756-302F-44DF-AA47-441A9D673202}
1586+
{F2ED628A-DB22-446F-A081-4CC845B51A2B} = {59840756-302F-44DF-AA47-441A9D673202}
15611587
{2C2BEEF4-9333-4D05-B12A-1905CBF112F9} = {BDB237B6-1D1D-400F-84CC-40A58FA59C8E}
15621588
{EF3E32A7-5FF6-42B4-B6E2-96CD7D033F00} = {E8F24881-5E37-4362-B191-A3BA0ED7F4EB}
15631589
{16376381-CE22-42BE-B667-C6B35007008D} = {81C352DB-1818-45B7-A284-18E259F1CC87}

src/cascadia/CascadiaPackage/CascadiaPackage.wapproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
<ProjectReference Include="..\WindowsTerminal\WindowsTerminal.vcxproj" />
6565
<ProjectReference Include="..\..\host\exe\Host.EXE.vcxproj" />
6666
<ProjectReference Include="..\TerminalAzBridge\TerminalAzBridge.vcxproj" />
67+
<ProjectReference Include="..\ShellExtension\WindowsTerminalShellExt.vcxproj" />
6768
</ItemGroup>
69+
6870
<Target Name="OpenConsoleStompSourceProjectForWapProject" BeforeTargets="_ConvertItems">
6971
<ItemGroup>
7072
<!-- Stomp all "SourceProject" values for all incoming dependencies to flatten the package. -->

src/cascadia/CascadiaPackage/Package-Dev.appxmanifest

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
<Package
44
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
55
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
6+
xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10"
67
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
78
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
9+
xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4"
810
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
11+
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
12+
xmlns:desktop5="http://schemas.microsoft.com/appx/manifest/desktop/windows10/5"
913
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
1014
IgnorableNamespaces="uap mp rescap">
1115

@@ -39,7 +43,7 @@
3943
Square150x150Logo="Images\Square150x150Logo.png"
4044
Square44x44Logo="Images\Square44x44Logo.png">
4145
<uap:DefaultTile
42-
Wide310x150Logo="Images\Wide310x150Logo.png"
46+
Wide310x150Logo="Images\Wide310x150Logo.png"
4347
Square71x71Logo="Images\SmallTile.png"
4448
Square310x310Logo="Images\LargeTile.png"
4549
ShortName="ms-resource:AppShortNameDev">
@@ -58,6 +62,25 @@
5862
<desktop:ExecutionAlias Alias="wtd.exe" />
5963
</uap3:AppExecutionAlias>
6064
</uap3:Extension>
65+
66+
<com:Extension Category="windows.comServer">
67+
<com:ComServer>
68+
<com:SurrogateServer DisplayName="WindowsTerminalShellExt">
69+
<com:Class Id="9f156763-7844-4dc4-b2b1-901f640f5155" Path="WindowsTerminalShellExt.dll" ThreadingModel="STA"/>
70+
</com:SurrogateServer>
71+
</com:ComServer>
72+
</com:Extension>
73+
<desktop4:Extension Category="windows.fileExplorerContextMenus">
74+
<desktop4:FileExplorerContextMenus>
75+
<desktop5:ItemType Type="Directory">
76+
<desktop5:Verb Id="Command1" Clsid="9f156763-7844-4dc4-b2b1-901f640f5155" />
77+
</desktop5:ItemType>
78+
<desktop5:ItemType Type="Directory\Background">
79+
<desktop5:Verb Id="Command2" Clsid="9f156763-7844-4dc4-b2b1-901f640f5155" />
80+
</desktop5:ItemType>
81+
</desktop4:FileExplorerContextMenus>
82+
</desktop4:Extension>
83+
6184
</Extensions>
6285

6386
</Application>

src/cascadia/CascadiaPackage/Package-Pre.appxmanifest

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
Square150x150Logo="Images\Square150x150Logo.png"
4242
Square44x44Logo="Images\Square44x44Logo.png">
4343
<uap:DefaultTile
44-
Wide310x150Logo="Images\Wide310x150Logo.png"
44+
Wide310x150Logo="Images\Wide310x150Logo.png"
4545
Square71x71Logo="Images\SmallTile.png"
4646
Square310x310Logo="Images\LargeTile.png"
4747
ShortName="ms-resource:AppShortNamePre">
@@ -60,6 +60,25 @@
6060
<desktop:ExecutionAlias Alias="wt.exe" />
6161
</uap3:AppExecutionAlias>
6262
</uap3:Extension>
63+
64+
<com:Extension Category="windows.comServer">
65+
<com:ComServer>
66+
<com:SurrogateServer DisplayName="WindowsTerminalShellExt">
67+
<com:Class Id="9f156763-7844-4dc4-b2b1-901f640f5155" Path="WindowsTerminalShellExt.dll" ThreadingModel="STA"/>
68+
</com:SurrogateServer>
69+
</com:ComServer>
70+
</com:Extension>
71+
<desktop4:Extension Category="windows.fileExplorerContextMenus">
72+
<desktop4:FileExplorerContextMenus>
73+
<desktop5:ItemType Type="Directory">
74+
<desktop5:Verb Id="Command1" Clsid="9f156763-7844-4dc4-b2b1-901f640f5155" />
75+
</desktop5:ItemType>
76+
<desktop5:ItemType Type="Directory\Background">
77+
<desktop5:Verb Id="Command2" Clsid="9f156763-7844-4dc4-b2b1-901f640f5155" />
78+
</desktop5:ItemType>
79+
</desktop4:FileExplorerContextMenus>
80+
</desktop4:Extension>
81+
6382
</Extensions>
6483

6584
</Application>

src/cascadia/CascadiaPackage/Package.appxmanifest

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
Square150x150Logo="Images\Square150x150Logo.png"
4242
Square44x44Logo="Images\Square44x44Logo.png">
4343
<uap:DefaultTile
44-
Wide310x150Logo="Images\Wide310x150Logo.png"
44+
Wide310x150Logo="Images\Wide310x150Logo.png"
4545
Square71x71Logo="Images\SmallTile.png"
4646
Square310x310Logo="Images\LargeTile.png"
4747
ShortName="ms-resource:AppShortName">
@@ -60,6 +60,25 @@
6060
<desktop:ExecutionAlias Alias="wt.exe" />
6161
</uap3:AppExecutionAlias>
6262
</uap3:Extension>
63+
64+
<com:Extension Category="windows.comServer">
65+
<com:ComServer>
66+
<com:SurrogateServer DisplayName="WindowsTerminalShellExt">
67+
<com:Class Id="9f156763-7844-4dc4-b2b1-901f640f5155" Path="WindowsTerminalShellExt.dll" ThreadingModel="STA"/>
68+
</com:SurrogateServer>
69+
</com:ComServer>
70+
</com:Extension>
71+
<desktop4:Extension Category="windows.fileExplorerContextMenus">
72+
<desktop4:FileExplorerContextMenus>
73+
<desktop5:ItemType Type="Directory">
74+
<desktop5:Verb Id="Command1" Clsid="9f156763-7844-4dc4-b2b1-901f640f5155" />
75+
</desktop5:ItemType>
76+
<desktop5:ItemType Type="Directory\Background">
77+
<desktop5:Verb Id="Command2" Clsid="9f156763-7844-4dc4-b2b1-901f640f5155" />
78+
</desktop5:ItemType>
79+
</desktop4:FileExplorerContextMenus>
80+
</desktop4:Extension>
81+
6382
</Extensions>
6483

6584
</Application>

0 commit comments

Comments
 (0)