From cc1d049cad8efe8298e07aa6a094dbe2d773b0ce Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 6 Dec 2020 21:10:22 +1100 Subject: [PATCH] Plugins Manager scaffolding --- .../ContextMenu.cs | 29 ++++++++++ ...Flow.Launcher.Plugin.PluginsManager.csproj | 8 +++ .../Languages/en.xaml | 15 ++++++ .../Main.cs | 54 +++++++++++++++++-- .../{ => Models}/Plugins.cs | 2 +- .../{ => Models}/PluginsManifest.cs | 2 +- .../ViewModels/SettingsViewModel.cs | 26 +++++++++ .../Views/PluginsManagerSettings.xaml | 12 +++++ .../Views/PluginsManagerSettings.xaml.cs | 22 ++++++++ 9 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 Plugins/Flow.Launcher.Plugin.PluginManager/ContextMenu.cs create mode 100644 Plugins/Flow.Launcher.Plugin.PluginManager/Languages/en.xaml rename Plugins/Flow.Launcher.Plugin.PluginManager/{ => Models}/Plugins.cs (90%) rename Plugins/Flow.Launcher.Plugin.PluginManager/{ => Models}/PluginsManifest.cs (95%) create mode 100644 Plugins/Flow.Launcher.Plugin.PluginManager/ViewModels/SettingsViewModel.cs create mode 100644 Plugins/Flow.Launcher.Plugin.PluginManager/Views/PluginsManagerSettings.xaml create mode 100644 Plugins/Flow.Launcher.Plugin.PluginManager/Views/PluginsManagerSettings.xaml.cs diff --git a/Plugins/Flow.Launcher.Plugin.PluginManager/ContextMenu.cs b/Plugins/Flow.Launcher.Plugin.PluginManager/ContextMenu.cs new file mode 100644 index 000000000..d26c1ead4 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.PluginManager/ContextMenu.cs @@ -0,0 +1,29 @@ +using Flow.Launcher.Infrastructure.UserSettings; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Flow.Launcher.Plugin.PluginsManager +{ + internal class ContextMenu : IContextMenu + { + private PluginInitContext Context { get; set; } + + private Settings Settings { get; set; } + + public ContextMenu(PluginInitContext context, Settings settings) + { + Context = context; + Settings = settings; + } + + public List LoadContextMenus(Result selectedResult) + { + // Open website + // Go to source code + // Report an issue? + // Request a feature? + return new List(); + } + } +} diff --git a/Plugins/Flow.Launcher.Plugin.PluginManager/Flow.Launcher.Plugin.PluginsManager.csproj b/Plugins/Flow.Launcher.Plugin.PluginManager/Flow.Launcher.Plugin.PluginsManager.csproj index b1d0c6f68..43a1e089b 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginManager/Flow.Launcher.Plugin.PluginsManager.csproj +++ b/Plugins/Flow.Launcher.Plugin.PluginManager/Flow.Launcher.Plugin.PluginsManager.csproj @@ -27,4 +27,12 @@ PreserveNewest + + + + + + + + \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.PluginManager/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.PluginManager/Languages/en.xaml new file mode 100644 index 000000000..75caf81ec --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.PluginManager/Languages/en.xaml @@ -0,0 +1,15 @@ + + + + + + + + Plugins Manager + Management of installing, uninstalling or updating Flow Launcher plugins + + + + \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.PluginManager/Main.cs b/Plugins/Flow.Launcher.Plugin.PluginManager/Main.cs index 36e40bf1b..73d3f954c 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginManager/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginManager/Main.cs @@ -1,10 +1,58 @@ -using System; +using Flow.Launcher.Infrastructure.Storage; +using Flow.Launcher.Infrastructure.UserSettings; +using Flow.Launcher.Plugin.PluginsManager.ViewModels; +using Flow.Launcher.Plugin.PluginsManager.Views; using System.Collections.Generic; -using System.Text; +using System.Windows.Controls; namespace Flow.Launcher.Plugin.PluginsManager { - class Main + public class Main : ISettingProvider, IPlugin, ISavable, IContextMenu, IPluginI18n { + internal PluginInitContext Context { get; set; } + + internal Settings Settings; + + private SettingsViewModel viewModel; + + private IContextMenu contextMenu; + + public Control CreateSettingPanel() + { + return new PluginsManagerSettings(viewModel); + } + + public void Init(PluginInitContext context) + { + Context = context; + viewModel = new SettingsViewModel(context); + Settings = viewModel.Settings; + contextMenu = new ContextMenu(Context, Settings); + } + + public List LoadContextMenus(Result selectedResult) + { + return contextMenu.LoadContextMenus(selectedResult); + } + + public List Query(Query query) + { + return new List(); + } + + public void Save() + { + viewModel.Save(); + } + + public string GetTranslatedPluginTitle() + { + return Context.API.GetTranslation("plugin_pluginsmanager_plugin_name"); + } + + public string GetTranslatedPluginDescription() + { + return Context.API.GetTranslation("plugin_pluginsmanager_plugin_description"); + } } } diff --git a/Plugins/Flow.Launcher.Plugin.PluginManager/Plugins.cs b/Plugins/Flow.Launcher.Plugin.PluginManager/Models/Plugins.cs similarity index 90% rename from Plugins/Flow.Launcher.Plugin.PluginManager/Plugins.cs rename to Plugins/Flow.Launcher.Plugin.PluginManager/Models/Plugins.cs index 56f01e86b..d2f6348af 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginManager/Plugins.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginManager/Models/Plugins.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Flow.Launcher.Plugin.PluginsManager +namespace Flow.Launcher.Plugin.PluginsManager.Models { internal class Plugin { diff --git a/Plugins/Flow.Launcher.Plugin.PluginManager/PluginsManifest.cs b/Plugins/Flow.Launcher.Plugin.PluginManager/Models/PluginsManifest.cs similarity index 95% rename from Plugins/Flow.Launcher.Plugin.PluginManager/PluginsManifest.cs rename to Plugins/Flow.Launcher.Plugin.PluginManager/Models/PluginsManifest.cs index d470a996c..3609aba7d 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginManager/PluginsManifest.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginManager/Models/PluginsManifest.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Net; using System.Text; -namespace Flow.Launcher.Plugin.PluginsManager +namespace Flow.Launcher.Plugin.PluginsManager.Models { class PluginsManifest { diff --git a/Plugins/Flow.Launcher.Plugin.PluginManager/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.PluginManager/ViewModels/SettingsViewModel.cs new file mode 100644 index 000000000..f3cf117d3 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.PluginManager/ViewModels/SettingsViewModel.cs @@ -0,0 +1,26 @@ +using Flow.Launcher.Infrastructure.Storage; +using Flow.Launcher.Infrastructure.UserSettings; + +namespace Flow.Launcher.Plugin.PluginsManager.ViewModels +{ + public class SettingsViewModel + { + private readonly PluginJsonStorage storage; + + internal Settings Settings { get; set; } + + internal PluginInitContext Context { get; set; } + + public SettingsViewModel(PluginInitContext context) + { + Context = context; + storage = new PluginJsonStorage(); + Settings = storage.Load(); + } + + public void Save() + { + storage.Save(); + } + } +} diff --git a/Plugins/Flow.Launcher.Plugin.PluginManager/Views/PluginsManagerSettings.xaml b/Plugins/Flow.Launcher.Plugin.PluginManager/Views/PluginsManagerSettings.xaml new file mode 100644 index 000000000..7f6d7ba82 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.PluginManager/Views/PluginsManagerSettings.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Plugins/Flow.Launcher.Plugin.PluginManager/Views/PluginsManagerSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.PluginManager/Views/PluginsManagerSettings.xaml.cs new file mode 100644 index 000000000..14204eda9 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.PluginManager/Views/PluginsManagerSettings.xaml.cs @@ -0,0 +1,22 @@ + +using Flow.Launcher.Plugin.PluginsManager.ViewModels; + +namespace Flow.Launcher.Plugin.PluginsManager.Views +{ + /// + /// Interaction logic for PluginsManagerSettings.xaml + /// + public partial class PluginsManagerSettings + { + private readonly SettingsViewModel viewModel; + + public PluginsManagerSettings(SettingsViewModel viewModel) + { + InitializeComponent(); + + this.viewModel = viewModel; + + //RefreshView(); + } + } +}