Skip to content

Add a context menu entry to "Open Windows Terminal here" - #6100

Merged
26 commits merged into
masterfrom
dev/migrie/f/shell-extension
May 28, 2020
Merged

26 commits merged into
masterfrom
dev/migrie/f/shell-extension

Conversation

@zadjii-msft

Copy link
Copy Markdown
Member

Summary of the Pull Request

image

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

PR Checklist

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.

@ghost ghost added Area-UserInterface Issues pertaining to the user interface of the Console or Terminal Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal. labels May 21, 2020
@WSLUser

WSLUser commented May 21, 2020

Copy link
Copy Markdown
Contributor

If you're adding a COM interface then you may as well update the WPF control too. Nice screenshot! I wonder if there's a way to re-use "Open Here" for shells like Powershell, which already have their own. Maybe you could link to their context menu and use it to execute the profile?

@DHowett

Copy link
Copy Markdown
Member

If you're adding a COM interface then you may as well update the WPF control too.

I fail to see why adding a COM interface to make a shell extension should touch the WPF control whatsoever. What updates does it even need?

Comment on lines +25 to +37
namespace winrt::Microsoft::Terminal::ShellExtension::implementation
{
struct PlaceholderType : PlaceholderTypeT<PlaceholderType>
{
PlaceholderType() = default;
GETSET_PROPERTY(int32_t, Placeholder, 42);
};
}

namespace winrt::Microsoft::Terminal::ShellExtension::factory_implementation
{
BASIC_FACTORY(PlaceholderType);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WAT

Comment on lines +4 to +8
// This class is just here to make our .wapproj play nicely with this project.
// If we don't define any winrt types, then we won't generate a .winmd, and the
// .wapproj will become _very_ mad at this project. So we'll use this
// placeholder class just to trick cppwinrt into generating a winmd for us. If
// we ever _do_ add a real winrt type to this project, this can be removed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHY DO WE LIVE IN THIS HELLSCAPE

Comment thread src/cascadia/ShellExtension/dllmain.cpp Resolved
@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 21, 2020
@WSLUser

WSLUser commented May 21, 2020

Copy link
Copy Markdown
Contributor

I mean if someone builds the WPF control, they should also get this feature. Since this adds a COM interface, I would think it wouldn't be too much effort to add it there.

@DHowett

Copy link
Copy Markdown
Member

The WPF control is a DLL that gets integrated into your existing project. It is by no means a standalone terminal application. There's no reason for that WPF CONTROL to add a shell extension.

// https://github.com/microsoft/PowerToys/blob/master/
// src/modules/powerrename/dll/dllmain.cpp
// We don't need to implement DllGetActivationFactory or DllCanUnloadNow
// manually, since the generated module.g.cpp will handle it for us, and will

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised we get a module.g.cpp . . . did we make sure the cppwinrt WRL hookup works right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we get it because of PlaceholderType? It does seem to do some WRL magic. I have no idea how, but it does seem to work ¯\_(ツ)_/¯

@zadjii-msft

Copy link
Copy Markdown
Member Author

If the default Powershell $profile contains some sort of "cd path\to\folder", this overrides the path speification opened by WT through Explorer's Open WT here.

Maybe it is not recommened that $profile contain such a path specification, but I thought I'd flag this here.

Yea there's not really a way for the Terminal to prevent such a command from running in your powershell profile. I'd definitely recommend against doing that if you want to use this context menu entry.

@Stanzilla

Copy link
Copy Markdown
Contributor

No icon?

@DHowett

Copy link
Copy Markdown
Member

#6246

@Skyline404

Copy link
Copy Markdown

how i can disble this ?

@DHowett

Copy link
Copy Markdown
Member

Evdokimov Andrey (@Skyline404) discussion in #7008.

@timonsku

Copy link
Copy Markdown

Is there an ETA when the fix for not being able to launch it from an explorer window's "background", as was described in the release notes, will hit earlier Windows versions?

@zadjii-msft

Copy link
Copy Markdown
Member Author

@PTS93 I'd recommend subscribing to #6414 - we're at the mercy of the platform release cycle currently. When we have an update to share, we'll update that thread.

@tiagoboeing

Copy link
Copy Markdown

Clicking on the folder and opening the context menu works!
image

I also suggest adding the option when anywhere on the folder was clicked. (When the folder is not selected)
image

@DHowett

Copy link
Copy Markdown
Member

Tiago Boeing (@tiagoboeing) thanks! please read the comment directly above yours.

@tiagoboeing

Copy link
Copy Markdown

Dustin L. Howett (@DHowett) yeap. Subscribed to the topic. Thanks!!

@midnightelf

Copy link
Copy Markdown

for those who have an access error, there is such a solution
in HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command change default field value to wt.exe -d .

@AnderssonPeter

Copy link
Copy Markdown

I don't know if this is the right place to comment, but is there a task tracking

  1. Show this when you click directly in a folder?
  2. Allow the selection of what shell to open as a sub menu?

@zadjii-msft

Copy link
Copy Markdown
Member Author

Peter Andersson (@AnderssonPeter) I'd check the issues in this list to see if they match what you're looking for. That should have all the work we're tracking for this feature.

@NetMage

NetMage commented Jan 19, 2021

Copy link
Copy Markdown

When I open Windows Terminal, it opens a tab with TCC. When I press Ctrl+Shift+t, it opens with TCC. When I right-click Open in Windows Terminal, it opens Powershell - is there some different default profile that is being used here?

@zadjii-msft

Copy link
Copy Markdown
Member Author

NetMage I'm not sure I can really help you with that off the top of my head. I don't really know how TCC works - we might be able to help you investigate, but a 8 month old PR is probably not the place to have that discussion. Maybe try filing a new issue?

@roachsinai

This comment has been minimized.

@zadjii-msft

This comment has been minimized.

@roachsinai

This comment has been minimized.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-UserInterface Issues pertaining to the user interface of the Console or Terminal AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "open Windows terminal here" into right-click context menu