Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lhecker committed Nov 15, 2024
1 parent 83f3f55 commit 639c182
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 376 deletions.
205 changes: 81 additions & 124 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2345,18 +2345,14 @@ namespace winrt::TerminalApp::implementation
// reattach instead of create new content, so this method simply needs to
// parse the JSON and pump it into our action handler. Almost the same as
// doing something like `wt -w 0 nt`.
safe_void_coroutine TerminalPage::AttachContent(IVector<Settings::Model::ActionAndArgs> args,
uint32_t tabIndex)
void TerminalPage::AttachContent(IVector<Settings::Model::ActionAndArgs> args, uint32_t tabIndex)
{
if (args == nullptr ||
args.Size() == 0)
{
co_return;
return;
}

// Switch to the UI thread before selecting a tab or dispatching actions.
co_await wil::resume_foreground(Dispatcher(), CoreDispatcherPriority::High);

const auto& firstAction = args.GetAt(0);
const bool firstIsSplitPane{ firstAction.Action() == ShortcutAction::SplitPane };

Expand Down Expand Up @@ -4290,57 +4286,49 @@ namespace winrt::TerminalApp::implementation
// - <none>
// Return Value:
// - <none>
safe_void_coroutine TerminalPage::IdentifyWindow()
void TerminalPage::IdentifyWindow()
{
auto weakThis{ get_weak() };
co_await wil::resume_foreground(Dispatcher());
if (auto page{ weakThis.get() })
// If we haven't ever loaded the TeachingTip, then do so now and
// create the toast for it.
if (_windowIdToast == nullptr)
{
// If we haven't ever loaded the TeachingTip, then do so now and
// create the toast for it.
if (page->_windowIdToast == nullptr)
if (auto tip{ FindName(L"WindowIdToast").try_as<MUX::Controls::TeachingTip>() })
{
if (auto tip{ page->FindName(L"WindowIdToast").try_as<MUX::Controls::TeachingTip>() })
{
page->_windowIdToast = std::make_shared<Toast>(tip);
// Make sure to use the weak ref when setting up this
// callback.
tip.Closed({ page->get_weak(), &TerminalPage::_FocusActiveControl });
}
_windowIdToast = std::make_shared<Toast>(tip);
// IsLightDismissEnabled == true is bugged and poorly interacts with multi-windowing.
// It causes the tip to be immediately dismissed when another tip is opened in another window.
tip.IsLightDismissEnabled(false);
// Make sure to use the weak ref when setting up this callback.
tip.Closed({ get_weak(), &TerminalPage::_FocusActiveControl });
}
_UpdateTeachingTipTheme(WindowIdToast().try_as<winrt::Windows::UI::Xaml::FrameworkElement>());
}
_UpdateTeachingTipTheme(WindowIdToast().try_as<winrt::Windows::UI::Xaml::FrameworkElement>());

if (page->_windowIdToast != nullptr)
{
page->_windowIdToast->Open();
}
if (_windowIdToast != nullptr)
{
_windowIdToast->Open();
}
}

safe_void_coroutine TerminalPage::ShowTerminalWorkingDirectory()
void TerminalPage::ShowTerminalWorkingDirectory()
{
auto weakThis{ get_weak() };
co_await wil::resume_foreground(Dispatcher());
if (auto page{ weakThis.get() })
// If we haven't ever loaded the TeachingTip, then do so now and
// create the toast for it.
if (_windowCwdToast == nullptr)
{
// If we haven't ever loaded the TeachingTip, then do so now and
// create the toast for it.
if (page->_windowCwdToast == nullptr)
if (auto tip{ FindName(L"WindowCwdToast").try_as<MUX::Controls::TeachingTip>() })
{
if (auto tip{ page->FindName(L"WindowCwdToast").try_as<MUX::Controls::TeachingTip>() })
{
page->_windowCwdToast = std::make_shared<Toast>(tip);
// Make sure to use the weak ref when setting up this
// callback.
tip.Closed({ page->get_weak(), &TerminalPage::_FocusActiveControl });
}
_windowCwdToast = std::make_shared<Toast>(tip);
// Make sure to use the weak ref when setting up this
// callback.
tip.Closed({ get_weak(), &TerminalPage::_FocusActiveControl });
}
_UpdateTeachingTipTheme(WindowCwdToast().try_as<winrt::Windows::UI::Xaml::FrameworkElement>());
}
_UpdateTeachingTipTheme(WindowCwdToast().try_as<winrt::Windows::UI::Xaml::FrameworkElement>());

if (page->_windowCwdToast != nullptr)
{
page->_windowCwdToast->Open();
}
if (_windowCwdToast != nullptr)
{
_windowCwdToast->Open();
}
}

Expand Down Expand Up @@ -5045,25 +5033,18 @@ namespace winrt::TerminalApp::implementation

// Handler for our WindowProperties's PropertyChanged event. We'll use this
// to pop the "Identify Window" toast when the user renames our window.
safe_void_coroutine TerminalPage::_windowPropertyChanged(const IInspectable& /*sender*/,
const WUX::Data::PropertyChangedEventArgs& args)
void TerminalPage::_windowPropertyChanged(const IInspectable& /*sender*/, const WUX::Data::PropertyChangedEventArgs& args)
{
if (args.PropertyName() != L"WindowName")
{
co_return;
return;
}
auto weakThis{ get_weak() };
// On the foreground thread, raise property changed notifications, and
// display the success toast.
co_await wil::resume_foreground(Dispatcher());
if (auto page{ weakThis.get() })

// DON'T display the confirmation if this is the name we were
// given on startup!
if (_startupState == StartupState::Initialized)
{
// DON'T display the confirmation if this is the name we were
// given on startup!
if (page->_startupState == StartupState::Initialized)
{
page->IdentifyWindow();
}
IdentifyWindow();
}
}

Expand Down Expand Up @@ -5136,8 +5117,8 @@ namespace winrt::TerminalApp::implementation
// - Called on the TARGET of a tab drag/drop. We'll unpack the DataPackage
// to find who the tab came from. We'll then ask the Monarch to ask the
// sender to move that tab to us.
safe_void_coroutine TerminalPage::_onTabStripDrop(winrt::Windows::Foundation::IInspectable /*sender*/,
winrt::Windows::UI::Xaml::DragEventArgs e)
void TerminalPage::_onTabStripDrop(winrt::Windows::Foundation::IInspectable /*sender*/,
winrt::Windows::UI::Xaml::DragEventArgs e)
{
// Get the PID and make sure it is the same as ours.
if (const auto& pidObj{ e.DataView().Properties().TryLookup(L"pid") })
Expand All @@ -5146,59 +5127,53 @@ namespace winrt::TerminalApp::implementation
if (pid != GetCurrentProcessId())
{
// The PID doesn't match ours. We can't handle this drop.
co_return;
return;
}
}
else
{
// No PID? We can't handle this drop. Bail.
co_return;
return;
}

const auto& windowIdObj{ e.DataView().Properties().TryLookup(L"windowId") };
if (windowIdObj == nullptr)
{
// No windowId? Bail.
co_return;
return;
}
const uint64_t src{ winrt::unbox_value<uint64_t>(windowIdObj) };

// Figure out where in the tab strip we're dropping this tab. Add that
// index to the request. This is largely taken from the WinUI sample
// app.

// We need to be on OUR UI thread to figure out where we dropped
auto weakThis{ get_weak() };
co_await wil::resume_foreground(Dispatcher());
if (const auto& page{ weakThis.get() })
{
// First we need to get the position in the List to drop to
auto index = -1;
// First we need to get the position in the List to drop to
auto index = -1;

// Determine which items in the list our pointer is between.
for (auto i = 0u; i < _tabView.TabItems().Size(); i++)
// Determine which items in the list our pointer is between.
for (auto i = 0u; i < _tabView.TabItems().Size(); i++)
{
if (const auto& item{ _tabView.ContainerFromIndex(i).try_as<winrt::MUX::Controls::TabViewItem>() })
{
if (const auto& item{ _tabView.ContainerFromIndex(i).try_as<winrt::MUX::Controls::TabViewItem>() })
const auto posX{ e.GetPosition(item).X }; // The point of the drop, relative to the tab
const auto itemWidth{ item.ActualWidth() }; // The right of the tab
// If the drag point is on the left half of the tab, then insert here.
if (posX < itemWidth / 2)
{
const auto posX{ e.GetPosition(item).X }; // The point of the drop, relative to the tab
const auto itemWidth{ item.ActualWidth() }; // The right of the tab
// If the drag point is on the left half of the tab, then insert here.
if (posX < itemWidth / 2)
{
index = i;
break;
}
index = i;
break;
}
}
}

// `this` is safe to use
const auto request = winrt::make_self<RequestReceiveContentArgs>(src, _WindowProperties.WindowId(), index);
// `this` is safe to use
const auto request = winrt::make_self<RequestReceiveContentArgs>(src, _WindowProperties.WindowId(), index);

// This will go up to the monarch, who will then dispatch the request
// back down to the source TerminalPage, who will then perform a
// RequestMoveContent to move their tab to us.
RequestReceiveContent.raise(*this, *request);
}
// This will go up to the monarch, who will then dispatch the request
// back down to the source TerminalPage, who will then perform a
// RequestMoveContent to move their tab to us.
RequestReceiveContent.raise(*this, *request);
}

// Method Description:
Expand All @@ -5208,33 +5183,23 @@ namespace winrt::TerminalApp::implementation
// the destination window.
// - Fortunately, sending the tab is basically just a MoveTab action, so we
// can largely reuse that.
safe_void_coroutine TerminalPage::SendContentToOther(winrt::TerminalApp::RequestReceiveContentArgs args)
void TerminalPage::SendContentToOther(winrt::TerminalApp::RequestReceiveContentArgs args)
{
// validate that we're the source window of the tab in this request
if (args.SourceWindow() != _WindowProperties.WindowId())
{
co_return;
return;
}
if (!_stashed.draggedTab)
{
co_return;
return;
}

// must do the work of adding/removing tabs on the UI thread.
auto weakThis{ get_weak() };
co_await wil::resume_foreground(Dispatcher(), CoreDispatcherPriority::Normal);
if (const auto& page{ weakThis.get() })
{
// `this` is safe to use in here.

_sendDraggedTabToWindow(winrt::to_hstring(args.TargetWindow()),
args.TabIndex(),
std::nullopt);
}
_sendDraggedTabToWindow(winrt::to_hstring(args.TargetWindow()), args.TabIndex(), std::nullopt);
}

safe_void_coroutine TerminalPage::_onTabDroppedOutside(winrt::IInspectable sender,
winrt::MUX::Controls::TabViewTabDroppedOutsideEventArgs e)
void TerminalPage::_onTabDroppedOutside(winrt::IInspectable sender,
winrt::MUX::Controls::TabViewTabDroppedOutsideEventArgs e)
{
// Get the current pointer point from the CoreWindow
const auto& pointerPoint{ CoreWindow::GetForCurrentThread().PointerPosition() };
Expand All @@ -5246,29 +5211,21 @@ namespace winrt::TerminalApp::implementation

if (!_stashed.draggedTab)
{
co_return;
return;
}

// must do the work of adding/removing tabs on the UI thread.
auto weakThis{ get_weak() };
co_await wil::resume_foreground(Dispatcher(), CoreDispatcherPriority::Normal);
if (const auto& page{ weakThis.get() })
{
// `this` is safe to use in here.

// We need to convert the pointer point to a point that we can use
// to position the new window. We'll use the drag offset from before
// so that the tab in the new window is positioned so that it's
// basically still directly under the cursor.
// We need to convert the pointer point to a point that we can use
// to position the new window. We'll use the drag offset from before
// so that the tab in the new window is positioned so that it's
// basically still directly under the cursor.

// -1 is the magic number for "new window"
// 0 as the tab index, because we don't care. It's making a new window. It'll be the only tab.
const winrt::Windows::Foundation::Point adjusted = {
pointerPoint.X - _stashed.dragOffset.X,
pointerPoint.Y - _stashed.dragOffset.Y,
};
_sendDraggedTabToWindow(winrt::hstring{ L"-1" }, 0, adjusted);
}
// -1 is the magic number for "new window"
// 0 as the tab index, because we don't care. It's making a new window. It'll be the only tab.
const winrt::Windows::Foundation::Point adjusted = {
pointerPoint.X - _stashed.dragOffset.X,
pointerPoint.Y - _stashed.dragOffset.Y,
};
_sendDraggedTabToWindow(winrt::hstring{ L"-1" }, 0, adjusted);
}

void TerminalPage::_sendDraggedTabToWindow(const winrt::hstring& windowId,
Expand Down
14 changes: 7 additions & 7 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ namespace winrt::TerminalApp::implementation
void ShowKeyboardServiceWarning() const;
winrt::hstring KeyboardServiceDisabledText();

safe_void_coroutine IdentifyWindow();
void IdentifyWindow();
void ActionSaved(winrt::hstring input, winrt::hstring name, winrt::hstring keyChord);
void ActionSaveFailed(winrt::hstring message);
safe_void_coroutine ShowTerminalWorkingDirectory();
void ShowTerminalWorkingDirectory();

safe_void_coroutine ProcessStartupActions(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> actions,
const bool initial,
Expand All @@ -159,8 +159,8 @@ namespace winrt::TerminalApp::implementation

bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);

safe_void_coroutine AttachContent(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> args, uint32_t tabIndex);
safe_void_coroutine SendContentToOther(winrt::TerminalApp::RequestReceiveContentArgs args);
void AttachContent(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> args, uint32_t tabIndex);
void SendContentToOther(winrt::TerminalApp::RequestReceiveContentArgs args);

uint32_t NumberOfTabs() const;

Expand Down Expand Up @@ -527,12 +527,12 @@ namespace winrt::TerminalApp::implementation
Windows::Foundation::IAsyncOperation<Windows::Foundation::Collections::IVectorView<winrt::Microsoft::Management::Deployment::MatchResult>> _FindPackageAsync(hstring query);

void _WindowSizeChanged(const IInspectable sender, const winrt::Microsoft::Terminal::Control::WindowSizeChangedEventArgs args);
safe_void_coroutine _windowPropertyChanged(const IInspectable& sender, const winrt::Windows::UI::Xaml::Data::PropertyChangedEventArgs& args);
void _windowPropertyChanged(const IInspectable& sender, const winrt::Windows::UI::Xaml::Data::PropertyChangedEventArgs& args);

void _onTabDragStarting(const winrt::Microsoft::UI::Xaml::Controls::TabView& sender, const winrt::Microsoft::UI::Xaml::Controls::TabViewTabDragStartingEventArgs& e);
void _onTabStripDragOver(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::DragEventArgs& e);
safe_void_coroutine _onTabStripDrop(winrt::Windows::Foundation::IInspectable sender, winrt::Windows::UI::Xaml::DragEventArgs e);
safe_void_coroutine _onTabDroppedOutside(winrt::Windows::Foundation::IInspectable sender, winrt::Microsoft::UI::Xaml::Controls::TabViewTabDroppedOutsideEventArgs e);
void _onTabStripDrop(winrt::Windows::Foundation::IInspectable sender, winrt::Windows::UI::Xaml::DragEventArgs e);
void _onTabDroppedOutside(winrt::Windows::Foundation::IInspectable sender, winrt::Microsoft::UI::Xaml::Controls::TabViewTabDroppedOutsideEventArgs e);

void _DetachPaneFromWindow(std::shared_ptr<Pane> pane);
void _DetachTabFromWindow(const winrt::com_ptr<TabBase>& terminalTab);
Expand Down
Loading

1 comment on commit 639c182

@github-actions
Copy link

Choose a reason for hiding this comment

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

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (5)

cds
COPYDATA
COPYDATASTRUCT
ERRORONEXIT
remoting

Previously acknowledged words that are now absent barbaz DISPATCHNOTIFY Ralph 🫥
To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:microsoft/terminal.git repository
on the dev/lhecker/dethronement branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/11848286226/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (2227) from .github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt and unrecognized words (5)

Dictionary Entries Covers Uniquely
cspell:cpp/src/lang-jargon.txt 11 1 1
cspell:swift/src/swift.txt 53 1 1
cspell:gaming-terms/dict/gaming-terms.txt 59 1 1
cspell:monkeyc/src/monkeyc_keywords.txt 123 1 1
cspell:cryptocurrencies/cryptocurrencies.txt 125 1 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

      with:
        extra_dictionaries:
          cspell:cpp/src/lang-jargon.txt
          cspell:swift/src/swift.txt
          cspell:gaming-terms/dict/gaming-terms.txt
          cspell:monkeyc/src/monkeyc_keywords.txt
          cspell:cryptocurrencies/cryptocurrencies.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

check_extra_dictionaries: ''
Errors (1)

See the 📜action log or 📝 job summary for details.

❌ Errors Count
❌ ignored-expect-variant 6

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.