From 909ec80f97e87377e134932f873913a74fb9061b Mon Sep 17 00:00:00 2001 From: John Lewin Date: Mon, 13 Jul 2015 12:49:01 -0700 Subject: [PATCH 1/2] Add navigation mechanism for the Purchased folder --- ApplicationView/MainApplicationWidget.cs | 12 ++++++++++++ Library/LibraryDataView.cs | 2 +- Library/Provider/LibraryProviderSelector.cs | 11 ++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 685f89121..f4dafc7db 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -29,6 +29,8 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg; using MatterHackers.Agg.UI; +using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.PrintLibrary.Provider; using MatterHackers.MatterControl.PrintQueue; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.VectorMath; @@ -301,6 +303,16 @@ namespace MatterHackers.MatterControl ReloadAdvancedControlsPanelTrigger.CallEvents(this, null); } + public void SwitchToPurchasedLibrary() + { + // Switch to the purchased library + LibraryDataView.CurrentLibraryProvider = LibraryProviderSelector.Instance.PurchasedLibrary; + + // Force a rebuild + LibraryProviderSelector.Instance.PurchasedLibrary.KeywordFilter = "!"; + LibraryProviderSelector.Instance.PurchasedLibrary.KeywordFilter = ""; + } + public void ChangeCloudSyncStatus(bool userAuthenticated) { CloudSyncStatusChanged.CallEvents(this, new CloudSyncEventArgs() { IsAuthenticated = userAuthenticated }); diff --git a/Library/LibraryDataView.cs b/Library/LibraryDataView.cs index c1c22949f..0ef2243a8 100644 --- a/Library/LibraryDataView.cs +++ b/Library/LibraryDataView.cs @@ -113,7 +113,7 @@ namespace MatterHackers.MatterControl.PrintLibrary bool isChildOfCurrent = value.ParentLibraryProvider == currentLibraryProvider; // Dispose of all children below this one. - while (!isChildOfCurrent && currentLibraryProvider != value) + while (!isChildOfCurrent && currentLibraryProvider != value && currentLibraryProvider.ParentLibraryProvider != null) { LibraryProvider parent = currentLibraryProvider.ParentLibraryProvider; currentLibraryProvider.Dispose(); diff --git a/Library/Provider/LibraryProviderSelector.cs b/Library/Provider/LibraryProviderSelector.cs index f8e404699..d95fab833 100644 --- a/Library/Provider/LibraryProviderSelector.cs +++ b/Library/Provider/LibraryProviderSelector.cs @@ -48,6 +48,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider private List visibleProviders; + internal LibraryProvider PurchasedLibrary { get; private set; } + private event EventHandler unregisterEvents; private LibraryProviderSelector() @@ -66,7 +68,14 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider PluginFinder libraryProviderPlugins = new PluginFinder(); foreach (LibraryProviderPlugin libraryProviderPlugin in libraryProviderPlugins.Plugins) { - libraryProviders.Add(libraryProviderPlugin.CreateLibraryProvider(this)); + // This coupling is required to navigate to the Purchased folder after redemption or purchase updates + var pluginProvider = libraryProviderPlugin.CreateLibraryProvider(this); + if (pluginProvider.ProviderKey == "LibraryProviderPurchasedKey") + { + this.PurchasedLibrary = pluginProvider; + } + + libraryProviders.Add(pluginProvider); } // and any directory providers (sd card provider, etc...) From 66d01d555a24d93636c33a3bce5b371d58e148c1 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Mon, 13 Jul 2015 12:56:40 -0700 Subject: [PATCH 2/2] Remove forced reload --- ApplicationView/MainApplicationWidget.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index f4dafc7db..192ed6e0f 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -307,10 +307,6 @@ namespace MatterHackers.MatterControl { // Switch to the purchased library LibraryDataView.CurrentLibraryProvider = LibraryProviderSelector.Instance.PurchasedLibrary; - - // Force a rebuild - LibraryProviderSelector.Instance.PurchasedLibrary.KeywordFilter = "!"; - LibraryProviderSelector.Instance.PurchasedLibrary.KeywordFilter = ""; } public void ChangeCloudSyncStatus(bool userAuthenticated)