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

Teach CommandPalette model to natively support tabs and command lines #8420

Merged
13 commits merged into from
Dec 10, 2020

Conversation

Don-Vito
Copy link
Contributor

@Don-Vito Don-Vito commented Nov 27, 2020

First step towards #8415:

  • Introduce PaletteItem and derive from it to provide native support
    for tabs and command lines (ActionPaletteItem / TabPaletteItem,
    CommandLinePaltteItem)
  • Remove business logic behind PaletteItem from palette (aka dispatch
    commands and preview tabs externally)

@github-actions
Copy link

New misspellings found, please review:

  • Actionpalette
To accept these changes, run the following commands
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect/5757ec679b03a4240130c3c53766c91bbc5cd6a7.txt
.github/actions/spell-check/expect/655f007265b351e140d20b3976792523ad689241.txt
.github/actions/spell-check/expect/alphabet.txt
.github/actions/spell-check/expect/expect.txt
.github/actions/spell-check/expect/web.txt"');
@ARGV=@expect_files;
my @stale=qw('"AAAAA Bopomofo CParams CSV GENERATEPROJECTPRIFILE hhhh Inlines MAKEINTRESOURCEA renamer
 Reserialize rgus SGRXY tcon UDK UDKs Unfocus xe xlang "');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
  if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
  next if /^($re)(?:$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect/9301d8f4320589cdabc457f61ce5bc6ad1946dec.txt";
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"Actionpalette csv inlines Renamer reserialize udk unfocus "');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a) cmp lc($b)} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;'
git add .github/actions/spell-check/expect || echo '... you want to ensure .github/actions/spell-check/expect/9301d8f4320589cdabc457f61ce5bc6ad1946dec.txt is added to your repository...'
✏️ 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.

⚠️ The command is written for posix shells. You can copy the contents of each perl command excluding the outer ' marks and dropping any '"/"' quotation mark pairs into a file and then run perl file.pl from the root of the repository to run the code. Alternatively, you can manually insert the items...

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spell-check/dictionary/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spell-check/dictionary/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spell-check/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/spell-check/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. 😉

⚠️ Reviewers

At present, the action that triggered this message will not show its ❌ in this PR unless the branch is within this repository.
Thus, you should make sure that this comment has been addressed before encouraging the merge bot to merge this PR.

@Don-Vito
Copy link
Contributor Author

Don-Vito commented Nov 27, 2020

@DHowett , @zadjii-msft - the first one in the saga. Probably the most interesting one since it affects interface:

  • SwitchToTabCommand is fully eliminated - palette works directly with tabs.
  • CommandPalette is responsible only for presentation, the business logic is moved to subscribers.

It also fixes a crash in terminal - I will extract it as a separate PR

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

This looks very, very good. I love it. I have reviewed 27/31 (waiting to review CommandPalette.* just yet).

I have one question, though, about the overarching design.

Why'd you choose to dispatch three different types of event and make palette item management internal to the command palette? Is it just to hide the implementation details from the caller?

I wonder if there's a design that uses a single event, "I selected a thing, you can figure out what it is on your own," to decouple the palette even further form what it hosts?

In addition -- I know there'd be some code duplication, so it would be pretty annoying -- could PaletteItem become an interface? If it becomes an interface, TabBase itself could conform to the interface (it has all the same properties, and already does notifications for them(!)) (EDIT: it doesn't have KeyChordText, but... there actually are key chords that activate tabs!)

Perhaps that's too much coupling. I'm not sure how I feel, having suggested it.

This is an amazing start.

OBSERVABLE_GETSET_PROPERTY(winrt::hstring, Name, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, Icon, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, KeyChordText, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, FilterableValue, _PropertyChangedHandlers);
Copy link
Member

Choose a reason for hiding this comment

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

FilterableValue not mentioned in the idl!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry.. It was a part of the idl at some moment.. but then I decided to postpone this feature (until we generalize the filterable list.. and realized it will be implemented differently).. unfortunately, I forgot to cleanup it from the header..

@Don-Vito
Copy link
Contributor Author

Don-Vito commented Dec 3, 2020

This looks very, very good. I love it. I have reviewed 27/31 (waiting to review CommandPalette.* just yet).

I have one question, though, about the overarching design.

Why'd you choose to dispatch three different types of event and make palette item management internal to the command palette? Is it just to hide the implementation details from the caller?

I wonder if there's a design that uses a single event, "I selected a thing, you can figure out what it is on your own," to decouple the palette even further form what it hosts?

I was hesitating about that a lot.. the translation between the generic Item and the specific one should happen somewhere (either in the TerminalPage or in the palette). I decided to do it in the Palette.. not to complicate the Page even more... So the current idea is:

  • Extract a FilterablePaletteItemList (and later on generalized FilterableList) that
    • Contains PaletteItems
    • Triggers two events: "item selected" and "item activated"
  • Make CommandPalette to be the "glue" that connects between the FilterablePaletteItemList and the logic (like tabs).

In addition -- I know there'd be some code duplication, so it would be pretty annoying -- could PaletteItem become an interface? If it becomes an interface, TabBase itself could conform to the interface (it has all the same properties, and already does notifications for them(!)) (EDIT: it doesn't have KeyChordText, but... there actually are key chords that activate tabs!)

Perhaps that's too much coupling. I'm not sure how I feel, having suggested it.

Here I was hesitating as well - to allocate tons of objects or do some coupling. But then I assumed that since the number of objects is overall low, it's better to decouple (isn't the gang of four all about composition rather than inheritance? 😊)

This is an amazing start.

@microsoft microsoft deleted a comment Dec 3, 2020
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.

Okay, I understand it all, and it makes a lot of code WAY easier to read. I'm a go for this, but on the single condition of please keep going. I'm looking forward to where this is going.

@@ -28,14 +28,12 @@ namespace winrt::TerminalApp::implementation
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);

// The TabViewIndex is the index this Tab object resides in TerminalPage's _tabs vector.
// This is needed since Tab is going to be managing its own SwitchToTab command.
GETSET_PROPERTY(uint32_t, TabViewIndex, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Note to future self: TabViewIndex is still needed, just not for the SwitchToTab command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zadjii-msft - exactly. This is why I removed the comment, as it was misleading 😊

OBSERVABLE_GETSET_PROPERTY(winrt::hstring, Name, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, Icon, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, KeyChordText, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, FilterableValue, _PropertyChangedHandlers);
Copy link
Member

Choose a reason for hiding this comment

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

is FilterableValue unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is.. sorry... I will reintroduce it in some form, but later on - when extracting a generic filterable list view

_dispatch.DoAction(actionAndArgs);
}
const auto filteredCommand{ selectedCommand.try_as<winrt::TerminalApp::FilteredCommand>() };
_switchToTab(filteredCommand);
Copy link
Member

Choose a reason for hiding this comment

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

okay so let me get this right - whenever the selection changes, we'll try to _switchToTab to that item, regardless if it's an action, commandline, or tab. Then, _switchToTab will ignore the things it doesn't care about.

I see where this is going in the rest of #8415, with raising separate events for selected vs dispatched items, but right now it feels a little weird

Copy link
Contributor Author

@Don-Vito Don-Vito Dec 5, 2020

Choose a reason for hiding this comment

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

@zadjii-msft - are you addressing the readability or the runtime flow? From the code readability it is still far from perfect, but from the runtime perspective it will be applied only for tabs (as the function is invoked only in TabSwitch mode).

@zadjii-msft zadjii-msft assigned DHowett and leonMSFT and unassigned zadjii-msft Dec 8, 2020
@zadjii-msft zadjii-msft added Area-CmdPal Command Palette issues and features Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Product-Terminal The new Windows Terminal. labels Dec 8, 2020
@zadjii-msft
Copy link
Member

@Don-Vito Any reason this one's still marked a draft?

@Don-Vito Don-Vito marked this pull request as ready for review December 8, 2020 15:09
@Don-Vito Don-Vito requested a review from DHowett December 9, 2020 13:50
@Don-Vito
Copy link
Contributor Author

Don-Vito commented Dec 9, 2020

@zadjii-msft - this is not a draft anymore 😊
@DHowett - a week has passed, so bumping 👼

@DHowett
Copy link
Member

DHowett commented Dec 9, 2020

Well, not since you marked it as reviewable 😉

I'll put this one on my list!

@Don-Vito
Copy link
Contributor Author

Don-Vito commented Dec 9, 2020

Well, not since you marked it as reviewable 😉

I'll put this one on my list!

I am not sure if this one reviewable even if it is marked as one 😄
Thanks!
I want to move to the next chapters, but afraid to get too far from the main.

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

I love it. It's excellent!

src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
@Don-Vito Don-Vito requested a review from DHowett December 9, 2020 21:54
@DHowett
Copy link
Member

DHowett commented Dec 9, 2020

@msftbot merge this in 1 minute

@ghost ghost added the AutoMerge Marked for automatic merge by the bot when requirements are met label Dec 9, 2020
@ghost
Copy link

ghost commented Dec 9, 2020

Hello @DHowett!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I won't merge this pull request until after the UTC date Wed, 09 Dec 2020 22:00:26 GMT, which is in 1 minute

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

@DHowett
Copy link
Member

DHowett commented Dec 9, 2020

Thanks so much :D

@Don-Vito
Copy link
Contributor Author

Don-Vito commented Dec 9, 2020

Thanks so much :D

Glad to work on this 😊

And I guess that more joy is ahead - as now I seem to conflict myself 😄
Fixing it.

@ghost ghost removed the AutoMerge Marked for automatic merge by the bot when requirements are met label Dec 9, 2020
@Don-Vito Don-Vito requested a review from DHowett December 9, 2020 22:27
@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Dec 9, 2020
@ghost
Copy link

ghost commented Dec 9, 2020

Hello @DHowett!

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.

Do note that I've been instructed to only help merge pull requests of this repository that have been opened for at least 8 hours, a condition that will be fulfilled in about -1642 seconds. No worries though, I will be back when the time is right! 😉

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.

@Don-Vito
Copy link
Contributor Author

Don-Vito commented Dec 9, 2020

Something bad is happening to this build:
image

@DHowett
Copy link
Member

DHowett commented Dec 9, 2020

kicked

@Don-Vito
Copy link
Contributor Author

Don-Vito commented Dec 9, 2020

kicked

@DHowett - what are the odds that #8536 could affect the CI? Seems that NuGet restore is not happy

@DHowett
Copy link
Member

DHowett commented Dec 9, 2020

Very minimal. Those files are used by a build task that isn't even included in the CI build 😄

@Don-Vito
Copy link
Contributor Author

Don-Vito commented Dec 9, 2020

Very minimal. Those files are used by a build task that isn't even included in the CI build 😄

Lol. Sorry.
The day that Mike fixed the tests CI surprises us with something new 😄

@ghost ghost merged commit 89d82ff into microsoft:main Dec 10, 2020
DHowett pushed a commit that referenced this pull request Dec 10, 2020
#8420 removed `SwitchToTab()` as a responsibility of `TabBase` and replaces `_mruTabActions` with `_mruTabs` (conceptually). This PR fixes the build break by...
- replacing `TerminalPage`'s reference to the SettingsTab's SwitchToTab command, with a reference to the tab itself
- using that reference to maintain existing tab switching behavior

## References
#1564 - Settings UI
#8420 - Command Palette + SwitchToTab refactoring

## PR Checklist
* [X] Closes #8538

## Validation Steps Performed
✅ Open SUI --> switch to a different tab --> try opening SUI again --> switches to existing SUI
✅ Open SUI --> switch to a different tab --> reorder tabs --> try opening SUI again --> switches to existing SUI
@ghost
Copy link

ghost commented Jan 28, 2021

🎉Windows Terminal Preview v1.6.10272.0 has been released which incorporates this pull request.:tada:

Handy links:

mpela81 pushed a commit to mpela81/terminal that referenced this pull request Jan 28, 2021
…microsoft#8420)

First step towards microsoft#8415:
* Introduce `PaletteItem` and derive from it to provide native support
  for tabs and command lines (`ActionPaletteItem` / `TabPaletteItem`,
  `CommandLinePaltteItem`)
* Remove business logic behind PaletteItem from palette (aka dispatch
  commands and preview tabs externally)
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-CmdPal Command Palette issues and features 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.

None yet

4 participants