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

fix: Reduce visual noise when loading in new properties in the property grid #2468

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,12 @@ public async Task<GraphViewModel> GenerateSelectionPropertiesAsync(IEnumerable<I

Selection = selectedObjects.ToList();

CanDisplayProperties = false;

ViewModel?.Destroy();

// We set to null now, in case this async method is invoked again while not being finished (otherwise it would dispose twice!)
ViewModel = null;

// No selection, just clean up
if (Selection.Count == 0)
{
ViewModel = null;
FallbackMessage = EmptySelectionFallbackMessage;
return null;
}

string message;
if (!CanDisplaySelectedObjects(Selection, out message))
string message = EmptySelectionFallbackMessage;
if (Selection.Count == 0 || !CanDisplaySelectedObjects(Selection, out message))
{
CanDisplayProperties = false;
ViewModel?.Destroy();
ViewModel = null;
FallbackMessage = message;
return null;
Expand All @@ -147,13 +135,17 @@ public async Task<GraphViewModel> GenerateSelectionPropertiesAsync(IEnumerable<I
if (localToken != currentToken)
return null;

ViewModel?.Destroy();
ViewModel = newViewModel;
CanDisplayProperties = true;
FallbackMessage = "";
}
catch (Exception exception)
{
CanDisplayProperties = false;
FeedbackException(Selection, exception, out message);
FallbackMessage = message;
ViewModel?.Destroy();
ViewModel = null;
}
return ViewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ private void PrepareItem(object sender, PropertyViewItemEventArgs e)
{
propertyItem.IsExpanded = false;
}
Dispatcher.BeginInvoke(new Action(() => ExpandSingleProperties(e.Container)));

Dispatcher.VerifyAccess();
ExpandSingleProperties(e.Container);
}

private PropertyViewItem GetPropertyItem(string propertyPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1462,18 +1462,18 @@ private void SelectedContentCollectionChanged(object sender, NotifyCollectionCha
}
else
{
if (e.NewItems != null)
{
selectedAssets.AddRange(e.NewItems.OfType<AssetViewModel>());
}

if (e.OldItems != null)
{
foreach (var item in e.OldItems.OfType<AssetViewModel>())
{
selectedAssets.Remove(item);
}
}

if (e.NewItems != null)
{
selectedAssets.AddRange(e.NewItems.OfType<AssetViewModel>());
}
}

if (discardSelectionChanges)
Expand Down
4 changes: 2 additions & 2 deletions sources/editor/Stride.GameStudio/View/GameStudioWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,6 @@
</DockPanel>
</DockPanel>

<TextBlock Grid.Row="4" Text="{Binding Session.ActiveProperties.FallbackMessage}" HorizontalAlignment="Center" VerticalAlignment="Center"
Visibility="{Binding Session.ActiveProperties.CanDisplayProperties, Converter={sd:Chained {sd:InvertBool}, {sd:VisibleOrCollapsed}}}"/>
<sd:PropertyView x:Name="AssetPropertyView" Grid.Row="4"
ItemsSource="{Binding Session.ActiveProperties.ViewModel.RootNode.Children}"
Visibility="{Binding Session.ActiveProperties.CanDisplayProperties, Converter={sd:VisibleOrCollapsed}}">
Expand Down Expand Up @@ -875,6 +873,8 @@
</i:Interaction.Behaviors>
</sd:PropertyView>

<TextBlock Grid.Row="4" Text="{Binding Session.ActiveProperties.FallbackMessage}" HorizontalAlignment="Center" VerticalAlignment="Center" Background="#99000000"/>

<GridSplitter Grid.Row="5" HorizontalAlignment="Stretch" Height="5" ResizeBehavior="PreviousAndNext"/>

<Border Grid.Row="6" Background="{StaticResource ToolBarBackgroundBrush}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ protected void ControlSelectionChanged(IEnumerable addedItems, IList removedItem
if (SelectedItems != null)
{
updatingCollection = true;

if (addedItems != null)
{
SelectedItems.AddRange(addedItems.Cast<object>().Where(x => !SelectedItems.Contains(x)));
}

if (removedItems != null)
{
// Optimize removal if most of the selected items are removed
Expand All @@ -140,11 +146,6 @@ protected void ControlSelectionChanged(IEnumerable addedItems, IList removedItem
}
}
}

if (addedItems != null)
{
SelectedItems.AddRange(addedItems.Cast<object>().Where(x => !SelectedItems.Contains(x)));
}
updatingCollection = false;
}
}
Expand Down