LibraryPrividerPlugin is a plug in creator.
This commit is contained in:
parent
10fa7f4f61
commit
432ed5f505
7 changed files with 119 additions and 35 deletions
|
|
@ -343,7 +343,7 @@ namespace MatterHackers.MatterControl
|
|||
LibraryProviderSelector libraryProviderSelector = currentLibraryDataView.CurrentLibraryProvider.GetRootProvider() as LibraryProviderSelector;
|
||||
if(libraryProviderSelector != null)
|
||||
{
|
||||
currentLibraryDataView.CurrentLibraryProvider = libraryProviderSelector.PurchasedLibrary;
|
||||
currentLibraryDataView.CurrentLibraryProvider = libraryProviderSelector.GetPurchasedLibrary();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,10 +40,33 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
||||
{
|
||||
public class LibraryProviderFileSystemCreator : ILibraryCreator
|
||||
{
|
||||
string rootPath;
|
||||
public string Description { get; set; }
|
||||
|
||||
public LibraryProviderFileSystemCreator(string rootPath, string description)
|
||||
{
|
||||
this.rootPath = rootPath;
|
||||
this.Description = description;
|
||||
}
|
||||
|
||||
public string ProviderKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return "FileSystem_" + rootPath + "_Key";
|
||||
}
|
||||
}
|
||||
|
||||
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
|
||||
{
|
||||
return new LibraryProviderFileSystem(rootPath, Description, parentLibraryProvider);
|
||||
}
|
||||
}
|
||||
|
||||
public class LibraryProviderFileSystem : LibraryProvider
|
||||
{
|
||||
public string key;
|
||||
private static int keyCount = 0;
|
||||
private string currentDirectory = ".";
|
||||
private List<string> currentDirectoryDirectories = new List<string>();
|
||||
private List<string> currentDirectoryFiles = new List<string>();
|
||||
|
|
@ -58,9 +81,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
this.description = description;
|
||||
this.rootPath = rootPath;
|
||||
|
||||
key = keyCount.ToString();
|
||||
keyCount++;
|
||||
|
||||
directoryWatcher.Path = rootPath;
|
||||
|
||||
directoryWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
|
||||
|
|
@ -143,7 +163,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
get
|
||||
{
|
||||
return "FileSystem_" + key.ToString() + "_Key";
|
||||
return "FileSystem_" + rootPath + "_Key";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,22 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
||||
{
|
||||
public class LibraryProviderHistoryCreator : ILibraryCreator
|
||||
{
|
||||
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
|
||||
{
|
||||
return new LibraryProviderHistory(null, parentLibraryProvider);
|
||||
}
|
||||
|
||||
public string ProviderKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return LibraryProviderHistory.StaticProviderKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class LibraryProviderHistory : LibraryProvider
|
||||
{
|
||||
private static LibraryProviderHistory instance = null;
|
||||
|
|
|
|||
|
|
@ -37,13 +37,25 @@ using System.ComponentModel;
|
|||
|
||||
namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
||||
{
|
||||
public class LibraryProviderPlugin
|
||||
public interface ILibraryCreator
|
||||
{
|
||||
LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider);
|
||||
|
||||
string ProviderKey { get; }
|
||||
}
|
||||
|
||||
public class LibraryProviderPlugin : ILibraryCreator
|
||||
{
|
||||
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual string ProviderKey
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public virtual ImageBuffer GetFolderImage()
|
||||
{
|
||||
return LibraryProvider.NormalFolderImage;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,22 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
||||
{
|
||||
public class LibraryProviderQueueCreator : ILibraryCreator
|
||||
{
|
||||
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
|
||||
{
|
||||
return new LibraryProviderQueue(null, parentLibraryProvider);
|
||||
}
|
||||
|
||||
public string ProviderKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return LibraryProviderQueue.StaticProviderKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class LibraryProviderQueue : LibraryProvider
|
||||
{
|
||||
private static LibraryProviderQueue instance = null;
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
public class LibraryProviderSelector : LibraryProvider
|
||||
{
|
||||
Action<LibraryProvider> setCurrentLibraryProvider;
|
||||
private List<LibraryProvider> libraryProviders = new List<LibraryProvider>();
|
||||
private List<ILibraryCreator> libraryCreators = new List<ILibraryCreator>();
|
||||
|
||||
internal LibraryProvider PurchasedLibrary { get; private set; }
|
||||
private ILibraryCreator PurchasedLibraryCreator { get; set; }
|
||||
|
||||
private event EventHandler unregisterEvents;
|
||||
|
||||
|
|
@ -68,16 +68,16 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
// This is test code for how to add these when we get to it
|
||||
// put in the queue provider
|
||||
libraryProviders.Add(new LibraryProviderQueue(null, this));
|
||||
libraryCreators.Add(new LibraryProviderQueueCreator());
|
||||
AddFolderImage("queue_folder.png");
|
||||
|
||||
// put in the queue provider
|
||||
libraryProviders.Add(new LibraryProviderHistory(null, this));
|
||||
libraryCreators.Add(new LibraryProviderHistoryCreator());
|
||||
AddFolderImage("queue_folder.png");
|
||||
}
|
||||
|
||||
// put in the sqlite provider
|
||||
libraryProviders.Add(new LibraryProviderSQLite(null, this, "Local Library"));
|
||||
libraryCreators.Add(new LibraryProviderSQLiteCreator());
|
||||
AddFolderImage("library_folder.png");
|
||||
|
||||
// Check for LibraryProvider factories and put them in the list too.
|
||||
|
|
@ -85,14 +85,13 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
foreach (LibraryProviderPlugin libraryProviderPlugin in libraryProviderPlugins.Plugins)
|
||||
{
|
||||
// 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);
|
||||
libraryCreators.Add(libraryProviderPlugin);
|
||||
folderImagesForChildren.Add(libraryProviderPlugin.GetFolderImage());
|
||||
|
||||
if (libraryProviderPlugin.ProviderKey == "LibraryProviderPurchasedKey")
|
||||
{
|
||||
this.PurchasedLibraryCreator = libraryProviderPlugin;
|
||||
}
|
||||
}
|
||||
|
||||
// and any directory providers (sd card provider, etc...)
|
||||
|
|
@ -100,11 +99,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
string downloadsDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");
|
||||
if (Directory.Exists(downloadsDirectory))
|
||||
{
|
||||
libraryProviders.Add(new LibraryProviderFileSystem(downloadsDirectory, "Downloads", this));
|
||||
libraryCreators.Add(new LibraryProviderFileSystemCreator(downloadsDirectory, "Downloads"));
|
||||
AddFolderImage("download_folder.png");
|
||||
}
|
||||
|
||||
firstAddedDirectoryIndex = libraryProviders.Count;
|
||||
firstAddedDirectoryIndex = libraryCreators.Count;
|
||||
|
||||
#if !__ANDROID__
|
||||
MenuOptionFile.CurrentMenuOptionFile.AddLocalFolderToLibrary += (sender, e) =>
|
||||
|
|
@ -135,13 +134,13 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
public override void RenameCollection(int collectionIndexToRename, string newName)
|
||||
{
|
||||
if (collectionIndexToRename >= firstAddedDirectoryIndex
|
||||
&& libraryProviders[collectionIndexToRename].Name != newName)
|
||||
if (collectionIndexToRename >= firstAddedDirectoryIndex)
|
||||
{
|
||||
LibraryProviderFileSystem addedProvider = libraryProviders[collectionIndexToRename] as LibraryProviderFileSystem;
|
||||
if (addedProvider != null)
|
||||
LibraryProviderFileSystemCreator fileSystemLibraryCreator = libraryCreators[collectionIndexToRename] as LibraryProviderFileSystemCreator;
|
||||
if(fileSystemLibraryCreator != null
|
||||
&& fileSystemLibraryCreator.Description != newName)
|
||||
{
|
||||
addedProvider.ChangeName(newName);
|
||||
fileSystemLibraryCreator.Description = newName;
|
||||
UiThread.RunOnIdle(() => OnDataReloaded(null));
|
||||
}
|
||||
}
|
||||
|
|
@ -173,7 +172,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
get
|
||||
{
|
||||
return this.libraryProviders.Count;
|
||||
return this.libraryCreators.Count;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +231,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
UiThread.RunOnIdle(() =>
|
||||
FileDialog.SelectFolderDialog(new SelectFolderDialogParams("Select Folder"), (SelectFolderDialogParams folderParams) =>
|
||||
{
|
||||
libraryProviders.Add(new LibraryProviderFileSystem(folderParams.FolderPath, collectionName, this));
|
||||
libraryCreators.Add(new LibraryProviderFileSystemCreator(folderParams.FolderPath, collectionName));
|
||||
AddFolderImage("folder.png");
|
||||
UiThread.RunOnIdle(() => OnDataReloaded(null));
|
||||
}));
|
||||
|
|
@ -242,7 +241,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
if (Directory.Exists(itemToAdd.FileLocation))
|
||||
{
|
||||
libraryProviders.Add(new LibraryProviderFileSystem(itemToAdd.FileLocation, Path.GetFileName(itemToAdd.FileLocation), this));
|
||||
libraryCreators.Add(new LibraryProviderFileSystemCreator(itemToAdd.FileLocation, Path.GetFileName(itemToAdd.FileLocation)));
|
||||
AddFolderImage("folder.png");
|
||||
UiThread.RunOnIdle(() => OnDataReloaded(null));
|
||||
}
|
||||
|
|
@ -250,7 +249,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
public override PrintItemCollection GetCollectionItem(int collectionIndex)
|
||||
{
|
||||
LibraryProvider provider = libraryProviders[collectionIndex];
|
||||
LibraryProvider provider = libraryCreators[collectionIndex].CreateLibraryProvider(this);
|
||||
return new PrintItemCollection(provider.Name, provider.ProviderKey);
|
||||
}
|
||||
|
||||
|
|
@ -261,11 +260,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
public override LibraryProvider GetProviderForCollection(PrintItemCollection collection)
|
||||
{
|
||||
foreach (LibraryProvider libraryProvider in libraryProviders)
|
||||
foreach (ILibraryCreator libraryCreator in libraryCreators)
|
||||
{
|
||||
if (collection.Key == libraryProvider.ProviderKey)
|
||||
if (collection.Key == libraryCreator.ProviderKey)
|
||||
{
|
||||
return libraryProvider;
|
||||
return libraryCreator.CreateLibraryProvider(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +273,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
public override void RemoveCollection(int collectionIndexToRemove)
|
||||
{
|
||||
libraryProviders.RemoveAt(collectionIndexToRemove);
|
||||
libraryCreators.RemoveAt(collectionIndexToRemove);
|
||||
|
||||
UiThread.RunOnIdle(() => OnDataReloaded(null));
|
||||
}
|
||||
|
|
@ -285,5 +284,10 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
|
||||
#endregion Overriden Abstract Methods
|
||||
|
||||
public LibraryProvider GetPurchasedLibrary()
|
||||
{
|
||||
return PurchasedLibraryCreator.CreateLibraryProvider(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,22 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
||||
{
|
||||
public class LibraryProviderSQLiteCreator : ILibraryCreator
|
||||
{
|
||||
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
|
||||
{
|
||||
return new LibraryProviderSQLite(null, parentLibraryProvider, "Local Library");
|
||||
}
|
||||
|
||||
public string ProviderKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return LibraryProviderSQLite.StaticProviderKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class LibraryProviderSQLite : LibraryProvider
|
||||
{
|
||||
private static LibraryProviderSQLite instance = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue