-
Notifications
You must be signed in to change notification settings - Fork 7.8k
CmdPal: Actually observe Details #39263
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
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 |
|---|---|---|
|
|
@@ -61,6 +61,8 @@ public partial class ListViewModel : PageViewModel, IDisposable | |
| private Task? _initializeItemsTask; | ||
| private CancellationTokenSource? _cancellationTokenSource; | ||
|
|
||
| private ListItemViewModel? _lastSelectedItem; | ||
|
|
||
| public override bool IsInitialized | ||
| { | ||
| get => base.IsInitialized; protected set | ||
|
|
@@ -330,6 +332,11 @@ private void InvokeSecondaryCommand(ListItemViewModel? item) | |
| [RelayCommand] | ||
| private void UpdateSelectedItem(ListItemViewModel? item) | ||
| { | ||
| if (_lastSelectedItem != null) | ||
| { | ||
| _lastSelectedItem.PropertyChanged -= SelectedItemPropertyChanged; | ||
| } | ||
|
|
||
| if (item != null) | ||
| { | ||
| SetSelectedItem(item); | ||
|
|
@@ -367,6 +374,43 @@ private void SetSelectedItem(ListItemViewModel item) | |
|
|
||
| TextToSuggest = item.TextToSuggest; | ||
| }); | ||
|
|
||
| _lastSelectedItem = item; | ||
| _lastSelectedItem.PropertyChanged += SelectedItemPropertyChanged; | ||
| } | ||
|
|
||
| private void SelectedItemPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) | ||
| { | ||
| var item = _lastSelectedItem; | ||
|
Contributor
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. Should here be using the "sender" instead of assume it must be the "lastSelectedItem"? |
||
| if (item == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // already on the UI thread here | ||
| switch (e.PropertyName) | ||
| { | ||
| case nameof(item.Command): | ||
| case nameof(item.SecondaryCommand): | ||
| case nameof(item.AllCommands): | ||
| case nameof(item.Name): | ||
| WeakReferenceMessenger.Default.Send<UpdateCommandBarMessage>(new(item)); | ||
| break; | ||
| case nameof(item.Details): | ||
| if (ShowDetails && item.HasDetails) | ||
| { | ||
| WeakReferenceMessenger.Default.Send<ShowDetailsMessage>(new(item.Details)); | ||
| } | ||
| else | ||
| { | ||
| WeakReferenceMessenger.Default.Send<HideDetailsMessage>(); | ||
| } | ||
|
|
||
| break; | ||
| case nameof(item.TextToSuggest): | ||
| TextToSuggest = item.TextToSuggest; | ||
| break; | ||
|
Member
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. do you want a default case?
Member
Author
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. nah, these are the only properties that the List Page VM cares about on the selected item. Everything else doesn't bubble up through the page |
||
| } | ||
| } | ||
|
|
||
| private void ClearSelectedItem() | ||
|
|
||
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.
Should these two lines move to "UpdateSelectedItem", so that the lifecycle of _lastSelectItem and its PropertyChanged will only control by 1 method, which is cleaner.