Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
26 commits merged into from May 28, 2020

Conversation

zadjii-msft
Copy link
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-User Interface 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
Copy link
Contributor

WSLUser commented May 21, 2020

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
Member

DHowett commented May 21, 2020

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
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
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

src/cascadia/ShellExtension/ShellExtension.vcxproj Outdated Show resolved Hide resolved
src/cascadia/ShellExtension/dllmain.cpp Outdated Show resolved Hide 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
Copy link
Contributor

WSLUser commented May 21, 2020

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
Member

DHowett commented May 21, 2020

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.

src/cascadia/ShellExtension/OpenTerminalHere.h Outdated Show resolved Hide resolved
// 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
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
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 ¯\_(ツ)_/¯

src/cascadia/ShellExtension/OpenTerminalHere.cpp Outdated Show resolved Hide resolved
@wigster
Copy link

wigster commented Jun 19, 2020

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.

@zadjii-msft
Copy link
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
Contributor

No icon?

@DHowett
Copy link
Member

DHowett commented Jun 29, 2020

#6246

@Skyline404
Copy link

how i can disble this ?

@DHowett
Copy link
Member

DHowett commented Jul 28, 2020

@Skyline404 discussion in #7008.

@timonsku
Copy link

timonsku commented Aug 7, 2020

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
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

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
Member

DHowett commented Aug 24, 2020

@tiagoboeing thanks! please read the comment directly above yours.

@tiagoboeing
Copy link

@DHowett yeap. Subscribed to the topic. Thanks!!

@midnightelf
Copy link

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

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
Member Author

@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
Copy link

NetMage commented Jan 19, 2021

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
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-User Interface 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