-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
implement drag&drop path in '+' button (#10073) #10160
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#include "Utils.h" | ||
#include "../../types/inc/utils.hpp" | ||
|
||
#include <filesystem> | ||
#include <LibraryResources.h> | ||
|
||
#include "TerminalPage.g.cpp" | ||
|
@@ -172,40 +173,13 @@ namespace winrt::TerminalApp::implementation | |
_newTabButton.Click([weakThis{ get_weak() }](auto&&, auto&&) { | ||
if (auto page{ weakThis.get() }) | ||
{ | ||
// if alt is pressed, open a pane | ||
const CoreWindow window = CoreWindow::GetForCurrentThread(); | ||
const auto rAltState = window.GetKeyState(VirtualKey::RightMenu); | ||
const auto lAltState = window.GetKeyState(VirtualKey::LeftMenu); | ||
const bool altPressed = WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) || | ||
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); | ||
|
||
const auto shiftState{ window.GetKeyState(VirtualKey::Shift) }; | ||
const auto rShiftState = window.GetKeyState(VirtualKey::RightShift); | ||
const auto lShiftState = window.GetKeyState(VirtualKey::LeftShift); | ||
const auto shiftPressed{ WI_IsFlagSet(shiftState, CoreVirtualKeyStates::Down) || | ||
WI_IsFlagSet(lShiftState, CoreVirtualKeyStates::Down) || | ||
WI_IsFlagSet(rShiftState, CoreVirtualKeyStates::Down) }; | ||
|
||
// Check for DebugTap | ||
bool debugTap = page->_settings.GlobalSettings().DebugFeaturesEnabled() && | ||
WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) && | ||
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); | ||
|
||
if (altPressed && !debugTap) | ||
{ | ||
page->_SplitPane(SplitState::Automatic, | ||
SplitType::Manual, | ||
0.5f, | ||
nullptr); | ||
} | ||
else if (shiftPressed && !debugTap) | ||
{ | ||
page->_OpenNewWindow(false, NewTerminalArgs()); | ||
} | ||
else | ||
{ | ||
page->_OpenNewTab(nullptr); | ||
} | ||
page->_OpenNewTerminal(NewTerminalArgs()); | ||
} | ||
}); | ||
_newTabButton.Drop([weakThis{ get_weak() }](Windows::Foundation::IInspectable const&, winrt::Windows::UI::Xaml::DragEventArgs e) { | ||
if (auto page{ weakThis.get() }) | ||
{ | ||
page->NewTerminalByDrop(e); | ||
} | ||
}); | ||
_tabView.SelectionChanged({ this, &TerminalPage::_OnTabSelectionChanged }); | ||
|
@@ -262,6 +236,37 @@ namespace winrt::TerminalApp::implementation | |
CATCH_LOG(); | ||
} | ||
|
||
winrt::fire_and_forget TerminalPage::NewTerminalByDrop(winrt::Windows::UI::Xaml::DragEventArgs& e) | ||
{ | ||
Windows::Foundation::Collections::IVectorView<Windows::Storage::IStorageItem> items; | ||
try | ||
{ | ||
items = co_await e.DataView().GetStorageItemsAsync(); | ||
} | ||
CATCH_LOG(); | ||
|
||
if (items.Size() == 1) | ||
{ | ||
std::filesystem::path path(items.GetAt(0).Path().c_str()); | ||
if (!std::filesystem::is_directory(path)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder how well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tested it with
while |
||
{ | ||
path = path.parent_path(); | ||
} | ||
|
||
std::wstring pathText = path.wstring(); | ||
|
||
// Handle edge case of "C:\\", seems like the "StartingDirectory" doesn't like path which ends with '\' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait what? My experience with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This edge case happens when you press
D: drive
While trying to debug the value of |
||
if (pathText.back() == L'\\') | ||
{ | ||
pathText.erase(std::prev(pathText.end())); | ||
} | ||
|
||
NewTerminalArgs args; | ||
args.StartingDirectory(winrt::hstring{ pathText }); | ||
this->_OpenNewTerminal(args); | ||
} | ||
} | ||
|
||
// Method Description: | ||
// - This method is called once command palette action was chosen for dispatching | ||
// We'll use this event to dispatch this command. | ||
|
@@ -622,43 +627,7 @@ namespace winrt::TerminalApp::implementation | |
if (auto page{ weakThis.get() }) | ||
{ | ||
NewTerminalArgs newTerminalArgs{ profileIndex }; | ||
|
||
// if alt is pressed, open a pane | ||
const CoreWindow window = CoreWindow::GetForCurrentThread(); | ||
const auto rAltState = window.GetKeyState(VirtualKey::RightMenu); | ||
const auto lAltState = window.GetKeyState(VirtualKey::LeftMenu); | ||
const bool altPressed = WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) || | ||
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); | ||
|
||
const auto shiftState{ window.GetKeyState(VirtualKey::Shift) }; | ||
const auto rShiftState = window.GetKeyState(VirtualKey::RightShift); | ||
const auto lShiftState = window.GetKeyState(VirtualKey::LeftShift); | ||
const auto shiftPressed{ WI_IsFlagSet(shiftState, CoreVirtualKeyStates::Down) || | ||
WI_IsFlagSet(lShiftState, CoreVirtualKeyStates::Down) || | ||
WI_IsFlagSet(rShiftState, CoreVirtualKeyStates::Down) }; | ||
|
||
// Check for DebugTap | ||
bool debugTap = page->_settings.GlobalSettings().DebugFeaturesEnabled() && | ||
WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) && | ||
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); | ||
|
||
if (altPressed && !debugTap) | ||
{ | ||
page->_SplitPane(SplitState::Automatic, | ||
SplitType::Manual, | ||
0.5f, | ||
newTerminalArgs); | ||
} | ||
else if (shiftPressed && !debugTap) | ||
{ | ||
// Manually fill in the evaluated profile. | ||
newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(page->_settings.GetProfileForArgs(newTerminalArgs))); | ||
page->_OpenNewWindow(false, newTerminalArgs); | ||
} | ||
else | ||
{ | ||
page->_OpenNewTab(newTerminalArgs); | ||
} | ||
page->_OpenNewTerminal(newTerminalArgs); | ||
} | ||
}); | ||
newTabFlyout.Items().Append(profileMenuItem); | ||
|
@@ -752,6 +721,49 @@ namespace winrt::TerminalApp::implementation | |
_newTabButton.Flyout().ShowAt(_newTabButton); | ||
} | ||
|
||
void TerminalPage::_OpenNewTerminal(const NewTerminalArgs newTerminalArgs) | ||
{ | ||
// if alt is pressed, open a pane | ||
const CoreWindow window = CoreWindow::GetForCurrentThread(); | ||
const auto rAltState = window.GetKeyState(VirtualKey::RightMenu); | ||
const auto lAltState = window.GetKeyState(VirtualKey::LeftMenu); | ||
const bool altPressed = WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) || | ||
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); | ||
|
||
const auto shiftState{ window.GetKeyState(VirtualKey::Shift) }; | ||
const auto rShiftState = window.GetKeyState(VirtualKey::RightShift); | ||
const auto lShiftState = window.GetKeyState(VirtualKey::LeftShift); | ||
const auto shiftPressed{ WI_IsFlagSet(shiftState, CoreVirtualKeyStates::Down) || | ||
WI_IsFlagSet(lShiftState, CoreVirtualKeyStates::Down) || | ||
WI_IsFlagSet(rShiftState, CoreVirtualKeyStates::Down) }; | ||
|
||
// Check for DebugTap | ||
bool debugTap = this->_settings.GlobalSettings().DebugFeaturesEnabled() && | ||
WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) && | ||
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); | ||
|
||
if (altPressed && !debugTap) | ||
{ | ||
this->_SplitPane(SplitState::Automatic, | ||
SplitType::Manual, | ||
0.5f, | ||
newTerminalArgs); | ||
} | ||
else if (shiftPressed && !debugTap) | ||
{ | ||
// Manually fill in the evaluated profile. | ||
if (newTerminalArgs.ProfileIndex() != nullptr) | ||
{ | ||
newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(this->_settings.GetProfileForArgs(newTerminalArgs))); | ||
} | ||
this->_OpenNewWindow(false, newTerminalArgs); | ||
} | ||
else | ||
{ | ||
this->_OpenNewTab(newTerminalArgs); | ||
} | ||
} | ||
|
||
winrt::fire_and_forget TerminalPage::_RemoveOnCloseRoutine(Microsoft::UI::Xaml::Controls::TabViewItem tabViewItem, winrt::com_ptr<TerminalPage> page) | ||
{ | ||
co_await winrt::resume_foreground(page->_tabView.Dispatcher()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to make and bind this if nothing is going to happen? Is this some XAML trickery?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, I did copy-cat of the other Drag&Drop stuff.
I`ll try to remove it and see what happens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whichever way it works, I'm fine with it. It was just an interesting curiosity to me.