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

Pm mypackages - cherrypick package details extension #14278

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion src/DynamoCore/Search/BrowserInternalElement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;

namespace Dynamo.Search
{
Expand Down Expand Up @@ -29,6 +29,11 @@ public class BrowserInternalElement : BrowserItem
/// </summary>
public BrowserItem OldParent { get; set; }

/// <summary>
/// The framework element hosting the extension
/// </summary>
public object UIParent { get; set; }

internal void ReturnToOldParent()
{
if (this.OldParent == null) return;
Expand Down
13 changes: 8 additions & 5 deletions src/DynamoCoreWpf/Controls/InstalledPackagesControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@
</ResourceDictionary>
</UserControl.Resources>

<Grid>
<Grid KeyboardNavigation.IsTabStop="False">
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<ItemsControl Name="Filters"
Grid.Column="0" Grid.Row="0"
ItemsSource="{Binding Path=Filters}"
ItemsSource="{Binding Path=Filters}"
Background="Transparent"
KeyboardNavigation.IsTabStop="False"
Padding="0,5,0,5">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
Expand Down Expand Up @@ -70,9 +71,10 @@
</ItemsControl.ItemTemplate>
</ItemsControl>

<ScrollViewer Grid.Row="1"
VerticalScrollBarVisibility="Auto"
Background="{StaticResource PreferencesWindowBackgroundColor}">
<ScrollViewer Grid.Row="1"
VerticalScrollBarVisibility="Auto"
KeyboardNavigation.IsTabStop="False"
Background="{StaticResource PreferencesWindowBackgroundColor}">
<ScrollViewer.Height>
<MultiBinding Converter="{StaticResource SumConverter}">
<Binding Path="ActualHeight"
Expand All @@ -88,6 +90,7 @@
ItemsSource="{Binding Path=LocalPackages}"
HorizontalContentAlignment="Stretch"
VirtualizingPanel.ScrollUnit="Pixel"
KeyboardNavigation.IsTabStop="False"
BorderThickness="0"
Padding="0">

Expand Down
18 changes: 18 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2874,6 +2874,12 @@ This package will be unloaded after the next Dynamo restart.</value>
<value>New</value>
<comment>Displays next to the package name in the Package Search window if the package has been added in the last 30 days.</comment>
</data>
<data name="PackageManagerSearchPackagesControlName" xml:space="preserve">
<value>packageManagerSearchPackages</value>
</data>
<data name="PackageManagerMyPackagesControlName" xml:space="preserve">
<value>packageManagerMyPackages</value>
</data>
<data name="PackageDetailsDescription" xml:space="preserve">
<value>DESCRIPTION</value>
<comment>Header in the PackageDetailsViewExtension.</comment>
Expand Down Expand Up @@ -3651,4 +3657,4 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="PreferencesViewIncludeTimestampExportPathTooltip" xml:space="preserve">
<value>When toggled on, file names of exported images include date and time of export.</value>
</data>
</root>
</root>
8 changes: 7 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,12 @@ Don't worry, you'll have the option to save your work.</value>
<value>New</value>
<comment>Displays next to the package name in the Package Search window if the package has been added in the last 30 days.</comment>
</data>
<data name="PackageManagerSearchPackagesControlName" xml:space="preserve">
<value>packageManagerSearchPackages</value>
</data>
<data name="PackageManagerMyPackagesControlName" xml:space="preserve">
<value>packageManagerMyPackages</value>
</data>
<data name="PackageDetailsDescription" xml:space="preserve">
<value>DESCRIPTION</value>
<comment>Header in the PackageDetailsViewExtension.</comment>
Expand Down Expand Up @@ -3638,4 +3644,4 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="PreferencesViewIncludeTimestampExportPathTooltip" xml:space="preserve">
<value>When toggled on, file names of exported images include date and time of export.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Input;
using Dynamo.Configuration;
Expand Down Expand Up @@ -371,6 +372,25 @@ public PackageSearchState SearchState
RaisePropertyChanged(nameof(this.SearchState));
RaisePropertyChanged(nameof(this.SearchBoxPrompt));
RaisePropertyChanged(nameof(this.ShowSearchText));

if (value == PackageSearchState.Results && !this.InitialResultsLoaded)
{
this.InitialResultsLoaded = true;
}
}
}

private bool _initialResultsLoaded = false;
/// <summary>
/// Will only be set to true once after the initial search has been finished.
/// </summary>
public bool InitialResultsLoaded
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
{
get { return _initialResultsLoaded; }
set
{
_initialResultsLoaded = value;
RaisePropertyChanged(nameof(InitialResultsLoaded));
}
}

Expand Down Expand Up @@ -445,6 +465,19 @@ public IPreferences Preferences
get { return PackageManagerClientViewModel.DynamoViewModel.PreferenceSettings; }
}

private bool isDetailPackagesExtensionOpened;
public bool IsDetailPackagesExtensionOpened
{
get { return isDetailPackagesExtensionOpened; }
set
{
if (isDetailPackagesExtensionOpened != value)
{
isDetailPackagesExtensionOpened = value;
RaisePropertyChanged(nameof(IsDetailPackagesExtensionOpened));
}
}
}
#endregion Properties & Fields

internal PackageManagerSearchViewModel()
Expand Down Expand Up @@ -816,6 +849,8 @@ public IEnumerable<PackageManagerSearchElementViewModel> RefreshAndSearch()

public void RefreshAndSearchAsync()
{
StartTimer(); // Times out according to MAX_LOAD_TIME

this.ClearSearchResults();
this.SearchState = PackageSearchState.Syncing;

Expand All @@ -835,6 +870,7 @@ public void RefreshAndSearchAsync()
this.AddToSearchResults(result);
}
this.SearchState = HasNoResults ? PackageSearchState.NoResults : PackageSearchState.Results;
TimedOut = false;

if (!DynamoModel.IsTestMode)
{
Expand All @@ -852,6 +888,50 @@ public void RefreshAndSearchAsync()
, TaskScheduler.FromCurrentSynchronizationContext()); // run continuation in ui thread
}

#region Time Out

// maximum loading time for packages - 30 seconds
// if exceeded will trigger `timed out` event and failure screen
internal int MAX_LOAD_TIME = 30 * 1000;
private bool _timedOut;
/// <summary>
/// Will trigger timed out event
/// </summary>
public bool TimedOut
{
get { return _timedOut; }
set
{
_timedOut = value;
RaisePropertyChanged(nameof(TimedOut));
}
}

private void StartTimer()
{
var aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = MAX_LOAD_TIME;
aTimer.AutoReset = false;
aTimer.Enabled = true;
}

private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
var aTimer = (System.Timers.Timer)sender;
aTimer.Dispose();

// If we have managed to get all the results
// Simply dispose of the timer
// Otherwise act
if (this.SearchState != PackageSearchState.Results)
{
TimedOut = true;
}
}

#endregion

internal void RefreshInfectedPackages()
{
//do not call a protected route, if user is not logged in already.
Expand Down Expand Up @@ -1319,5 +1399,15 @@ public void DisableSearchTextBox()
RequestDisableTextSearch(null, null);
}
}

/// <summary>
/// Clear after closing down
/// </summary>
internal void Close()
{
TimedOut = false; // reset the timedout screen
InitialResultsLoaded = false; // reset the loading screen settings
RequestShowFileDialog -= OnRequestShowFileDialog;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Dynamo.PackageManager.ViewModels;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Dynamo.PackageManager.ViewModels;
using Dynamo.Utilities;

namespace Dynamo.PackageManager.UI
{
Expand Down Expand Up @@ -89,6 +90,34 @@ private void ViewDetailsButton_OnClick(object sender, RoutedEventArgs e)
if (!(button.DataContext is PackageManagerSearchElementViewModel packageManagerSearchElementViewModel)) return;

var PkgSearchVM = this.DataContext as PackageManagerSearchViewModel;

var name = this.Name;
if (name.Equals(Dynamo.Wpf.Properties.Resources.PackageManagerSearchPackagesControlName))
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a common practice to store the name of the control as resources because they will get localized, unless that was your intention? Maybe we can use static readonly strings

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes ... this didn't feel right I remember. I replaced them with private read-only static strings now. We cannot set the framework element name to code-behind value, at least I don't think so. Meaning that the values we check still come from two separate places, but I cannot think of a different way of doing it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If that's ok, I will remove the redundant localized strings in the next PR, as there are quite a few changes in the resources files lined up.

Copy link
Contributor

@QilongTang QilongTang Aug 21, 2023

Choose a reason for hiding this comment

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

sure, please do

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed the resource with this commit cc58820

{
var parent = WpfUtilities.FindUpVisualTree<PackageManagerSearchControl>(this) as PackageManagerSearchControl;
if (parent == null) return;

packageManagerSearchElementViewModel.Model.UIParent = parent.packageDetailsGrid;
if (parent.packageDetailsGrid.Width.Value <= 1.0)
{
var width = (parent.packageDetailsGrid.Parent as Grid).ActualWidth * 0.5;
parent.packageDetailsGrid.Width = new GridLength(width, GridUnitType.Pixel);
}
}
else if (name.Equals(Dynamo.Wpf.Properties.Resources.PackageManagerMyPackagesControlName))
{
var parent = WpfUtilities.FindUpVisualTree<PackageManagerView>(this) as PackageManagerView;
if (parent == null) return;

packageManagerSearchElementViewModel.Model.UIParent = parent.packageDetailsGrid;
if (parent.packageDetailsGrid.Width.Value <= 1.0)
{
var width = (parent.packageDetailsGrid.Parent as Grid).ActualWidth * 0.5;
parent.packageDetailsGrid.Width = new GridLength(width, GridUnitType.Pixel);
}
}

PkgSearchVM.IsDetailPackagesExtensionOpened = true;
PkgSearchVM?.ViewPackageDetailsCommand.Execute(packageManagerSearchElementViewModel.Model);
}
}
Expand Down
Loading