From c17eb5fce5c6ccfff58d219ca036b8b2a1af0006 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 11 Nov 2019 08:00:31 +1100 Subject: [PATCH] Add user selection option for browserbookmark plugin --- Plugins/Wox.Plugin.BrowserBookmark/Main.cs | 41 ++++++++++++++++--- .../Models/Settings.cs | 7 ++++ .../Views/SettingsControl.xaml | 21 ++++++++++ .../Views/SettingsControl.xaml.cs | 32 +++++++++++++++ .../Wox.Plugin.BrowserBookmark.csproj | 13 ++++++ 5 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 Plugins/Wox.Plugin.BrowserBookmark/Models/Settings.cs create mode 100644 Plugins/Wox.Plugin.BrowserBookmark/Views/SettingsControl.xaml create mode 100644 Plugins/Wox.Plugin.BrowserBookmark/Views/SettingsControl.xaml.cs diff --git a/Plugins/Wox.Plugin.BrowserBookmark/Main.cs b/Plugins/Wox.Plugin.BrowserBookmark/Main.cs index cb1f0d654b..4b3bcff120 100644 --- a/Plugins/Wox.Plugin.BrowserBookmark/Main.cs +++ b/Plugins/Wox.Plugin.BrowserBookmark/Main.cs @@ -1,21 +1,34 @@ using System.Collections.Generic; using System.Linq; +using System.Windows.Controls; +using Wox.Infrastructure.Storage; using Wox.Plugin.BrowserBookmark.Commands; +using Wox.Plugin.BrowserBookmark.Models; +using Wox.Plugin.BrowserBookmark.Views; using Wox.Plugin.SharedCommands; namespace Wox.Plugin.BrowserBookmark { - public class Main : IPlugin, IReloadable, IPluginI18n + public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, ISavable { private PluginInitContext context; - private List cachedBookmarks = new List(); + private List cachedBookmarks = new List(); + + private readonly Settings _settings; + private readonly PluginJsonStorage _storage; + + public Main() + { + _storage = new PluginJsonStorage(); + _settings = _storage.Load(); + + cachedBookmarks = Bookmarks.LoadAllBookmarks(); + } public void Init(PluginInitContext context) { this.context = context; - - cachedBookmarks = Bookmarks.LoadAllBookmarks(); } public List Query(Query query) @@ -42,8 +55,15 @@ namespace Wox.Plugin.BrowserBookmark Score = 5, Action = (e) => { - context.API.HideApp(); - c.Url.NewBrowserWindow(""); + if (_settings.OpenInNewBrowserWindow) + { + c.Url.NewBrowserWindow(""); + } + else + { + c.Url.NewTabInBrowser(""); + } + return true; } }).ToList(); @@ -66,5 +86,14 @@ namespace Wox.Plugin.BrowserBookmark return context.API.GetTranslation("wox_plugin_browserbookmark_plugin_description"); } + public Control CreateSettingPanel() + { + return new SettingsControl(_settings); + } + + public void Save() + { + _storage.Save(); + } } } diff --git a/Plugins/Wox.Plugin.BrowserBookmark/Models/Settings.cs b/Plugins/Wox.Plugin.BrowserBookmark/Models/Settings.cs new file mode 100644 index 0000000000..27189d82fa --- /dev/null +++ b/Plugins/Wox.Plugin.BrowserBookmark/Models/Settings.cs @@ -0,0 +1,7 @@ +namespace Wox.Plugin.BrowserBookmark.Models +{ + public class Settings : BaseModel + { + public bool OpenInNewBrowserWindow { get; set; } = true; + } +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.BrowserBookmark/Views/SettingsControl.xaml b/Plugins/Wox.Plugin.BrowserBookmark/Views/SettingsControl.xaml new file mode 100644 index 0000000000..84fe812ee4 --- /dev/null +++ b/Plugins/Wox.Plugin.BrowserBookmark/Views/SettingsControl.xaml @@ -0,0 +1,21 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.BrowserBookmark/Views/SettingsControl.xaml.cs b/Plugins/Wox.Plugin.BrowserBookmark/Views/SettingsControl.xaml.cs new file mode 100644 index 0000000000..68095bff16 --- /dev/null +++ b/Plugins/Wox.Plugin.BrowserBookmark/Views/SettingsControl.xaml.cs @@ -0,0 +1,32 @@ +using System.Windows; +using System.Windows.Controls; +using Wox.Plugin.BrowserBookmark.Models; + +namespace Wox.Plugin.BrowserBookmark.Views +{ + /// + /// Interaction logic for BrowserBookmark.xaml + /// + public partial class SettingsControl : UserControl + { + private readonly Settings _settings; + + public SettingsControl(Settings settings) + { + InitializeComponent(); + _settings = settings; + NewWindowBrowser.IsChecked = _settings.OpenInNewBrowserWindow; + NewTabInBrowser.IsChecked = !_settings.OpenInNewBrowserWindow; + } + + private void OnNewBrowserWindowClick(object sender, RoutedEventArgs e) + { + _settings.OpenInNewBrowserWindow = true; + } + + private void OnNewTabClick(object sender, RoutedEventArgs e) + { + _settings.OpenInNewBrowserWindow = false; + } + } +} diff --git a/Plugins/Wox.Plugin.BrowserBookmark/Wox.Plugin.BrowserBookmark.csproj b/Plugins/Wox.Plugin.BrowserBookmark/Wox.Plugin.BrowserBookmark.csproj index 0be10b913a..b7d0690ab3 100644 --- a/Plugins/Wox.Plugin.BrowserBookmark/Wox.Plugin.BrowserBookmark.csproj +++ b/Plugins/Wox.Plugin.BrowserBookmark/Wox.Plugin.BrowserBookmark.csproj @@ -44,6 +44,7 @@ ..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll + @@ -57,6 +58,7 @@ ..\..\packages\System.Data.SQLite.Linq.1.0.111.0\lib\net451\System.Data.SQLite.Linq.dll + ..\..\packages\UnidecodeSharp.1.0.0.0\lib\net35\UnidecodeSharp.dll True @@ -69,7 +71,11 @@ + + + SettingsControl.xaml + @@ -111,6 +117,13 @@ PreserveNewest + + + MSBuild:Compile + Designer + + +