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

Convert Tab to a WinRT type #4350

Merged
20 commits merged into from
Feb 4, 2020
Merged

Convert Tab to a WinRT type #4350

20 commits merged into from
Feb 4, 2020

Conversation

leonMSFT
Copy link
Contributor

@leonMSFT leonMSFT commented Jan 24, 2020

Summary of the Pull Request

This PR will make the existing Tab class into a WinRT type. This will allow any XAML to simply bind to the ObservableVector of Tabs.

This PR will be followed up with a future PR to change our TabView to use the ObservableVector, which will in turn eliminate the need for maintaining two vectors of Tabs. (We currently maintain _tabs in TerminalPage and we also maintain TabView().TabViewItems() at the same time as described here: #2740)

References

#3922

PR Checklist

  • CLA signed.
  • Tests added/passed

Detailed Description of the Pull Request / Additional comments

I've currently only exposed a Tab's Title and IconPath to keep things simple. I foresee XAML elements that bind to Tabs to only really need these two properties for displaying.

I've also converted TerminalPage's std::vector<std::shared_ptr> _tabs into a IObservableVector<winrt::TerminalPage::Tab> _tabs just so that future PRs will have the ground set for binding to this vector of tabs.

Validation Steps Performed

Played around with Tabs and Panes and all sorts of combinations of keybindings for interacting with tabs and dragging and whatnot, it all seemed fine! Tab Tests also all pass.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me. Shame that we can't have the observable vector on the implementation type directly, so we wouldn't need the 100 get_self calls, but w/e.

Hit me up on Teams if you need help with the unittests - I'll save my signoff for once you've made sure those work. Otherwise I've only got nits.

src/cascadia/inc/cppwinrt_utils.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/Tab.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
@leonMSFT leonMSFT marked this pull request as ready for review January 27, 2020 22:24
@leonMSFT leonMSFT added Product-Terminal The new Windows Terminal. Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. labels Jan 27, 2020
Copy link
Contributor

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

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

Good work! Only a few minor bits and bobs.

src/cascadia/TerminalApp/Tab.idl Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.h Outdated Show resolved Hide resolved
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Jan 28, 2020
Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

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

GH doesn't let me read my pending comments without a lot of work, so I'm hitting Comment. I don't think I had any major qualms with this, though. I'll probably hit Approve after you react to them.

src/cascadia/TerminalApp/Tab.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/Tab.cpp Show resolved Hide resolved
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

Looking over these comments, I guess they're just nits, so go for it :shipit:

src/cascadia/inc/cppwinrt_utils.h Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
Comment on lines 1428 to 1432
for (uint32_t idx = 0; idx < _tabs.Size(); ++idx)
{
auto tab{ _GetStrongTabImpl(idx) };
tab->SetFocused(false);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit: weird because GetStrongTabImpl takes an index not a tab, but these are better-formed as for(auto tab:_tabs) like in the original code.

I also don't care as much. :)

Copy link
Contributor Author

@leonMSFT leonMSFT Feb 4, 2020

Choose a reason for hiding this comment

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

I also was nitting about this, so I sort of wanted to make GetStrongTabImpl take a tab instead. Then I realized that the majority of the code passes in an index and so if it took a Tab, GetAt would be littered everywhere instead. I just prefer the index route over the tab route 🤷‍♂

Copy link
Contributor

Choose a reason for hiding this comment

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

You could, in theory, provide an overload. One takes a const uint32_t and one takes a ::winrt::TerminalApp::Tab 😀

Copy link
Contributor Author

@leonMSFT leonMSFT Feb 4, 2020

Choose a reason for hiding this comment

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

🤔 Do you think an overload for this function would be overkill?
EDIT: it would not be overkill

Copy link
Contributor

Choose a reason for hiding this comment

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

up to you. it would clean our iterators up again, but also I don't hate this

@@ -94,23 +95,23 @@ namespace winrt::TerminalApp::implementation
void _HookupKeyBindings(TerminalApp::AppKeyBindings bindings) noexcept;
void _RegisterActionCallbacks();

void _UpdateTitle(std::shared_ptr<Tab> tab);
void _UpdateTabIcon(std::shared_ptr<Tab> tab);
void _UpdateTitle(const Tab& tab);
Copy link
Contributor

Choose a reason for hiding this comment

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

why's this one const but the others aren't?

Copy link
Contributor Author

@leonMSFT leonMSFT Feb 4, 2020

Choose a reason for hiding this comment

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

_UpdateTitle doesn't change the tab directly, it actually just calls the handlers. _UpdateTabIcon directly calls the tab's UpdateIcon function, so it couldn't be const 😢

leonMSFT and others added 2 commits February 4, 2020 11:26
Co-Authored-By: Carlos Zamora <carlos.zamora@microsoft.com>
@DHowett-MSFT
Copy link
Contributor

re-queued only x86

@DHowett-MSFT DHowett-MSFT added the AutoMerge Marked for automatic merge by the bot when requirements are met label Feb 4, 2020
@ghost
Copy link

ghost commented Feb 4, 2020

Hello @DHowett-MSFT!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 99a28f9 into master Feb 4, 2020
@ghost ghost deleted the dev/lelian/WinRTTab branch February 4, 2020 21:51
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-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. AutoMerge Marked for automatic merge by the bot when requirements are met Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants