mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #786 from Wox-launcher/dev
MVVM refactoring for web search plugin
This commit is contained in:
commit
4f8dee8fcf
68 changed files with 887 additions and 965 deletions
|
|
@ -113,7 +113,7 @@ namespace Wox.Plugin.PluginManagement
|
|||
string json;
|
||||
try
|
||||
{
|
||||
json = Http.Get(pluginSearchUrl + pluginName, context.Proxy).Result;
|
||||
json = Http.Get(pluginSearchUrl + pluginName).Result;
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
|
|
@ -156,7 +156,7 @@ namespace Wox.Plugin.PluginManagement
|
|||
|
||||
try
|
||||
{
|
||||
Http.Download(pluginUrl, filePath, context.Proxy);
|
||||
Http.Download(pluginUrl, filePath);
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<system:String x:Key="wox_plugin_websearch_delete">Löschen</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_edit">Bearbeiten</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_add">Hinzufügen</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_confirm">Confirm</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_action_keyword">Aktionsschlüsselwort</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_url">URL</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_search">Suche</system:String>
|
||||
|
|
@ -12,7 +13,7 @@
|
|||
<system:String x:Key="wox_plugin_websearch_pls_select_web_search">Bitte wähle einen Suchdienst</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_delete_warning">Willst du wirklich {0} löschen?</system:String>
|
||||
|
||||
|
||||
|
||||
<!--web search edit-->
|
||||
<system:String x:Key="wox_plugin_websearch_title">Titel</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_enable">Aktivieren</system:String>
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@
|
|||
<system:String x:Key="wox_plugin_websearch_delete">Delete</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_edit">Edit</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_add">Add</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_confirm">Confirm</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_action_keyword">Action Keyword</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_url">URL</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_search">Search</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_enable_suggestion">Enable search suggestions</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_pls_select_web_search">Please select a web search</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_delete_warning">Are you sure you want to delete {0}?</system:String>
|
||||
|
||||
|
||||
<!--web search edit-->
|
||||
<system:String x:Key="wox_plugin_websearch_title">Title</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_enable">Enable</system:String>
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@
|
|||
<system:String x:Key="wox_plugin_websearch_delete">Usuń</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_edit">Edytuj</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_add">Dodaj</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_confirm">Confirm</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_action_keyword">Wyzwalacz</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_url">Adres URL</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_search">Szukaj</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_enable_suggestion">Pokazuj podpowiedzi wyszukiwania</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_pls_select_web_search">Musisz wybrać coś z listy</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_delete_warning">Czy jesteś pewnie że chcesz usunąć {0}?</system:String>
|
||||
|
||||
|
||||
<!--web search edit-->
|
||||
<system:String x:Key="wox_plugin_websearch_title">Tytuł</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_enable">Aktywne</system:String>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<system:String x:Key="wox_plugin_websearch_delete">删除</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_edit">编辑</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_add">添加</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_confirm">确认</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_action_keyword">触发关键字</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_url">URL</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_search">搜索</system:String>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<system:String x:Key="wox_plugin_websearch_delete">刪除</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_edit">編輯</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_add">添加</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_confirm">确认</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_action_keyword">觸發關鍵字</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_url">URL</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_search">搜索</system:String>
|
||||
|
|
@ -28,5 +29,5 @@
|
|||
|
||||
<system:String x:Key="wox_plugin_websearch_plugin_name">網頁搜索</system:String>
|
||||
<system:String x:Key="wox_plugin_websearch_plugin_description">提供網頁搜索能力</system:String>
|
||||
|
||||
|
||||
</ResourceDictionary>
|
||||
|
|
@ -6,28 +6,26 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using JetBrains.Annotations;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin.WebSearch.SuggestionSources;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public class Main : IPlugin, ISettingProvider, IPluginI18n, IMultipleActionKeywords, ISavable, IResultUpdated
|
||||
public class Main : IPlugin, ISettingProvider, IPluginI18n, ISavable, IResultUpdated
|
||||
{
|
||||
public PluginInitContext Context { get; private set; }
|
||||
private PluginInitContext _context;
|
||||
|
||||
private PluginJsonStorage<Settings> _storage;
|
||||
private Settings _settings;
|
||||
private readonly Settings _settings;
|
||||
private readonly SettingsViewModel _viewModel;
|
||||
private CancellationTokenSource _updateSource;
|
||||
private CancellationToken _updateToken;
|
||||
|
||||
public const string Images = "Images";
|
||||
public static string ImagesDirectory;
|
||||
public static readonly string ImagesDirectory;
|
||||
|
||||
public void Save()
|
||||
{
|
||||
_storage.Save();
|
||||
_viewModel.Save();
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
|
|
@ -36,23 +34,23 @@ namespace Wox.Plugin.WebSearch
|
|||
_updateSource = new CancellationTokenSource();
|
||||
_updateToken = _updateSource.Token;
|
||||
|
||||
WebSearch webSearch =
|
||||
_settings.WebSearches.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled);
|
||||
SearchSource searchSource =
|
||||
_settings.SearchSources.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled);
|
||||
|
||||
if (webSearch != null)
|
||||
if (searchSource != null)
|
||||
{
|
||||
string keyword = query.Search;
|
||||
string title = keyword;
|
||||
string subtitle = Context.API.GetTranslation("wox_plugin_websearch_search") + " " + webSearch.Title;
|
||||
string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " + searchSource.Title;
|
||||
if (string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
var result = new Result
|
||||
{
|
||||
Title = subtitle,
|
||||
SubTitle = string.Empty,
|
||||
IcoPath = webSearch.IconPath
|
||||
IcoPath = searchSource.IconPath
|
||||
};
|
||||
return new List<Result> { result };
|
||||
return new List<Result> {result};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -62,15 +60,15 @@ namespace Wox.Plugin.WebSearch
|
|||
Title = title,
|
||||
SubTitle = subtitle,
|
||||
Score = 6,
|
||||
IcoPath = webSearch.IconPath,
|
||||
IcoPath = searchSource.IconPath,
|
||||
Action = c =>
|
||||
{
|
||||
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
|
||||
Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
results.Add(result);
|
||||
UpdateResultsFromSuggestion(results, keyword, subtitle, webSearch, query);
|
||||
UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query);
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
|
@ -80,14 +78,15 @@ namespace Wox.Plugin.WebSearch
|
|||
}
|
||||
}
|
||||
|
||||
private void UpdateResultsFromSuggestion(List<Result> results, string keyword, string subtitle, WebSearch webSearch, Query query)
|
||||
private void UpdateResultsFromSuggestion(List<Result> results, string keyword, string subtitle,
|
||||
SearchSource searchSource, Query query)
|
||||
{
|
||||
if (_settings.EnableWebSearchSuggestion)
|
||||
if (_settings.EnableSuggestion)
|
||||
{
|
||||
const int waittime = 300;
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
var suggestions = await Suggestions(keyword, subtitle, webSearch);
|
||||
var suggestions = await Suggestions(keyword, subtitle, searchSource);
|
||||
results.AddRange(suggestions);
|
||||
}, _updateToken);
|
||||
|
||||
|
|
@ -102,21 +101,21 @@ namespace Wox.Plugin.WebSearch
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<Result>> Suggestions(string keyword, string subtitle, WebSearch webSearch)
|
||||
private async Task<IEnumerable<Result>> Suggestions(string keyword, string subtitle, SearchSource searchSource)
|
||||
{
|
||||
var source = SuggestionSource.GetSuggestionSource(_settings.WebSearchSuggestionSource, Context);
|
||||
var source = _settings.SelectedSuggestion;
|
||||
if (source != null)
|
||||
{
|
||||
var suggestions = await source.GetSuggestions(keyword);
|
||||
var suggestions = await source.Suggestions(keyword);
|
||||
var resultsFromSuggestion = suggestions.Select(o => new Result
|
||||
{
|
||||
Title = o,
|
||||
SubTitle = subtitle,
|
||||
Score = 5,
|
||||
IcoPath = webSearch.IconPath,
|
||||
IcoPath = searchSource.IconPath,
|
||||
Action = c =>
|
||||
{
|
||||
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o)));
|
||||
Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
@ -127,18 +126,21 @@ namespace Wox.Plugin.WebSearch
|
|||
|
||||
static Main()
|
||||
{
|
||||
var plugins = Infrastructure.Constant.Plugins;
|
||||
var assemblyName = typeof(Main).Assembly.GetName().Name;
|
||||
var pluginDirectory = Path.Combine(Infrastructure.Constant.SettingsPath, plugins, assemblyName);
|
||||
var plugins = Constant.Plugins;
|
||||
var assemblyName = typeof (Main).Assembly.GetName().Name;
|
||||
var pluginDirectory = Path.Combine(Constant.SettingsPath, plugins, assemblyName);
|
||||
ImagesDirectory = Path.Combine(pluginDirectory, Images);
|
||||
}
|
||||
|
||||
public Main()
|
||||
{
|
||||
_viewModel = new SettingsViewModel();
|
||||
_settings = _viewModel.Settings;
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
Context = context;
|
||||
|
||||
_storage = new PluginJsonStorage<Settings>();
|
||||
_settings = _storage.Load();
|
||||
_context = context;
|
||||
|
||||
var pluginDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
||||
var bundledImagesDirectory = Path.Combine(pluginDirectory, Images);
|
||||
|
|
@ -149,43 +151,21 @@ namespace Wox.Plugin.WebSearch
|
|||
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
return new WebSearchesSetting(this, _settings);
|
||||
return new SettingsControl(_context, _viewModel);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public string GetTranslatedPluginTitle()
|
||||
{
|
||||
return Context.API.GetTranslation("wox_plugin_websearch_plugin_name");
|
||||
return _context.API.GetTranslation("wox_plugin_websearch_plugin_name");
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginDescription()
|
||||
{
|
||||
return Context.API.GetTranslation("wox_plugin_websearch_plugin_description");
|
||||
return _context.API.GetTranslation("wox_plugin_websearch_plugin_description");
|
||||
}
|
||||
|
||||
public bool IsInstantQuery(string query) => false;
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
public void NotifyActionKeywordsUpdated(string oldActionKeywords, string newActionKeywords)
|
||||
{
|
||||
ActionKeywordsChanged?.Invoke(this, new ActionKeywordsChangedEventArgs
|
||||
{
|
||||
OldActionKeyword = oldActionKeywords,
|
||||
NewActionKeyword = newActionKeywords
|
||||
});
|
||||
}
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
public void NotifyActionKeywordsAdded(string newActionKeywords)
|
||||
{
|
||||
ActionKeywordsChanged?.Invoke(this, new ActionKeywordsChangedEventArgs
|
||||
{
|
||||
NewActionKeyword = newActionKeywords
|
||||
});
|
||||
}
|
||||
|
||||
public event ActionKeywordsChangedEventHandler ActionKeywordsChanged;
|
||||
public event ResultUpdatedEventHandler ResultsUpdated;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
Plugins/Wox.Plugin.WebSearch/SearchSource.cs
Normal file
44
Plugins/Wox.Plugin.WebSearch/SearchSource.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Image;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public class SearchSource : BaseModel
|
||||
{
|
||||
public const string DefaultIcon = "web_search.png";
|
||||
public string Title { get; set; }
|
||||
public string ActionKeyword { get; set; }
|
||||
|
||||
[NotNull]
|
||||
public string Icon { private get; set; } = DefaultIcon;
|
||||
|
||||
/// <summary>
|
||||
/// All icon should be put under Images directory
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[JsonIgnore]
|
||||
internal string IconPath => Path.Combine(Main.ImagesDirectory, Icon);
|
||||
|
||||
[JsonIgnore]
|
||||
public ImageSource Image => ImageLoader.Load(IconPath);
|
||||
|
||||
public string Url { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public SearchSource DeepCopy()
|
||||
{
|
||||
var webSearch = new SearchSource
|
||||
{
|
||||
Title = string.Copy(Title),
|
||||
ActionKeyword = string.Copy(ActionKeyword),
|
||||
Url = string.Copy(Url),
|
||||
Icon = string.Copy(Icon),
|
||||
Enabled = Enabled
|
||||
};
|
||||
return webSearch;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml
Normal file
63
Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<Window x:Class="Wox.Plugin.WebSearch.SearchSourceSettingWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:vm="clr-namespace:Wox.Plugin.WebSearch"
|
||||
mc:Ignorable="d"
|
||||
ResizeMode="NoResize"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Title="Search Source Setting" Height="300" Width="500"
|
||||
d:DataContext="{d:DesignInstance vm:SearchSourceViewModel}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="60" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right" Text="{DynamicResource wox_plugin_websearch_title}" />
|
||||
<TextBox Text="{Binding SearchSource.Title}" Margin="10" Grid.Row="0" Width="300" Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Left" />
|
||||
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right" Text="{DynamicResource wox_plugin_websearch_url}" />
|
||||
<TextBox Text="{Binding SearchSource.Url}" Margin="10" Grid.Row="1" Width="300" Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Left" />
|
||||
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right" Text="{DynamicResource wox_plugin_websearch_action_keyword}" />
|
||||
<TextBox Text="{Binding SearchSource.ActionKeyword}" Margin="10" Grid.Row="2" Width="300" Grid.Column="1"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Left" />
|
||||
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right" Text="{DynamicResource wox_plugin_websearch_enable}" />
|
||||
<CheckBox IsChecked="{Binding SearchSource.Enabled}" Margin="10" Grid.Row="3" Grid.Column="1"
|
||||
VerticalAlignment="Center" />
|
||||
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right" Text="{DynamicResource wox_plugin_websearch_icon}" />
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="1" Margin="10">
|
||||
<Image Source="{Binding SearchSource.Image ,IsAsync=True}" Width="24" Height="24" Margin="0 0 10 0" />
|
||||
<Button Click="OnSelectIconClick" Height="24"
|
||||
Content="{DynamicResource wox_plugin_websearch_select_icon}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="5" Grid.Column="1">
|
||||
<Button Click="OnCancelButtonClick"
|
||||
Margin="10 0 10 0" Width="80" Height="25"
|
||||
Content="{DynamicResource wox_plugin_websearch_cancel}" />
|
||||
<Button Click="OnConfirmButtonClick"
|
||||
Margin="10 0 10 0" Width="80" Height="25"
|
||||
Content="{DynamicResource wox_plugin_websearch_confirm}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
149
Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml.cs
Normal file
149
Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml.cs
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using Microsoft.Win32;
|
||||
using Wox.Core.Plugin;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public partial class SearchSourceSettingWindow
|
||||
{
|
||||
private readonly SearchSource _oldSearchSource;
|
||||
private SearchSource _searchSource;
|
||||
private IList<SearchSource> _searchSources;
|
||||
private Action _action;
|
||||
private PluginInitContext _context;
|
||||
private IPublicAPI _api;
|
||||
private SearchSourceViewModel _viewModel;
|
||||
|
||||
|
||||
public SearchSourceSettingWindow(IList<SearchSource> sources, PluginInitContext context, SearchSource old)
|
||||
{
|
||||
_oldSearchSource = old;
|
||||
_viewModel = new SearchSourceViewModel {SearchSource = old.DeepCopy()};
|
||||
Initilize(sources, context, Action.Edit);
|
||||
}
|
||||
|
||||
public SearchSourceSettingWindow(IList<SearchSource> sources, PluginInitContext context)
|
||||
{
|
||||
_viewModel = new SearchSourceViewModel {SearchSource = new SearchSource()};
|
||||
Initilize(sources, context, Action.Add);
|
||||
}
|
||||
|
||||
private void Initilize(IList<SearchSource> sources, PluginInitContext context, Action action)
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = _viewModel;
|
||||
_searchSource = _viewModel.SearchSource;
|
||||
_searchSources = sources;
|
||||
_action = action;
|
||||
_context = context;
|
||||
_api = _context.API;
|
||||
}
|
||||
|
||||
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_searchSource.Title))
|
||||
{
|
||||
var warning = _api.GetTranslation("wox_plugin_websearch_input_title");
|
||||
MessageBox.Show(warning);
|
||||
}
|
||||
else if (string.IsNullOrEmpty(_searchSource.Url))
|
||||
{
|
||||
var warning = _api.GetTranslation("wox_plugin_websearch_input_url");
|
||||
MessageBox.Show(warning);
|
||||
}
|
||||
else if (string.IsNullOrEmpty(_searchSource.ActionKeyword))
|
||||
{
|
||||
var warning = _api.GetTranslation("wox_plugin_websearch_input_action_keyword");
|
||||
MessageBox.Show(warning);
|
||||
}
|
||||
else if (_action == Action.Add)
|
||||
{
|
||||
AddSearchSource();
|
||||
}
|
||||
else if (_action == Action.Edit)
|
||||
{
|
||||
EditSearchSource();
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSearchSource()
|
||||
{
|
||||
var keyword = _searchSource.ActionKeyword;
|
||||
if (!PluginManager.ActionKeywordRegistered(keyword))
|
||||
{
|
||||
var id = _context.CurrentPluginMetadata.ID;
|
||||
PluginManager.AddActionKeyword(id, keyword);
|
||||
|
||||
_searchSources.Add(_searchSource);
|
||||
|
||||
var info = _api.GetTranslation("succeed");
|
||||
MessageBox.Show(info);
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
var warning = _api.GetTranslation("newActionKeywordsHasBeenAssigned");
|
||||
MessageBox.Show(warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void EditSearchSource()
|
||||
{
|
||||
var keyword = _searchSource.ActionKeyword;
|
||||
if (!PluginManager.ActionKeywordRegistered(keyword))
|
||||
{
|
||||
var newKeyword = keyword;
|
||||
var oldKeyword = _oldSearchSource.ActionKeyword;
|
||||
var id = _context.CurrentPluginMetadata.ID;
|
||||
PluginManager.ReplaceActionKeyword(id, oldKeyword, newKeyword);
|
||||
|
||||
var index = _searchSources.IndexOf(_oldSearchSource);
|
||||
_searchSources[index] = _searchSource;
|
||||
|
||||
var info = _api.GetTranslation("succeed");
|
||||
MessageBox.Show(info);
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
var warning = _api.GetTranslation("newActionKeywordsHasBeenAssigned");
|
||||
MessageBox.Show(warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSelectIconClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var directory = Path.Combine(Main.ImagesDirectory, Main.Images);
|
||||
const string filter = "Image files (*.jpg, *.jpeg, *.gif, *.png, *.bmp) |*.jpg; *.jpeg; *.gif; *.png; *.bmp";
|
||||
var dialog = new OpenFileDialog {InitialDirectory = directory, Filter = filter};
|
||||
|
||||
var result = dialog.ShowDialog();
|
||||
if (result == true)
|
||||
{
|
||||
var fullpath = dialog.FileName;
|
||||
if (!string.IsNullOrEmpty(fullpath))
|
||||
{
|
||||
_searchSource.Icon = Path.GetFileName(fullpath);
|
||||
if (!File.Exists(_searchSource.IconPath))
|
||||
{
|
||||
_searchSource.Icon = SearchSource.DefaultIcon;
|
||||
MessageBox.Show($"The file should be put under {directory}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Action
|
||||
{
|
||||
Add,
|
||||
Edit
|
||||
}
|
||||
}
|
||||
7
Plugins/Wox.Plugin.WebSearch/SearchSourceViewModel.cs
Normal file
7
Plugins/Wox.Plugin.WebSearch/SearchSourceViewModel.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public class SearchSourceViewModel
|
||||
{
|
||||
public SearchSource SearchSource { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,183 +1,223 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Plugin.WebSearch.SuggestionSources;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public class Settings
|
||||
public class Settings : BaseModel
|
||||
{
|
||||
public List<WebSearch> WebSearches { get; set; } = new List<WebSearch>
|
||||
public Settings()
|
||||
{
|
||||
SelectedSuggestion = Suggestions[0];
|
||||
if (SearchSources.Count > 0)
|
||||
{
|
||||
new WebSearch
|
||||
SelectedSearchSource = SearchSources[0];
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<SearchSource> SearchSources { get; set; } = new ObservableCollection<SearchSource>
|
||||
{
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Google",
|
||||
ActionKeyword = "g",
|
||||
Icon = "google.png",
|
||||
Url = "https://www.google.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Google Scholar",
|
||||
ActionKeyword = "sc",
|
||||
Icon = "google.png",
|
||||
Url = "https://scholar.google.com/scholar?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Wikipedia",
|
||||
ActionKeyword = "wiki",
|
||||
Icon = "wiki.png",
|
||||
Url = "https://en.wikipedia.org/wiki/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "FindIcon",
|
||||
ActionKeyword = "findicon",
|
||||
Icon = "pictures.png",
|
||||
Url = "http://findicons.com/search/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Facebook",
|
||||
ActionKeyword = "facebook",
|
||||
Icon = "facebook.png",
|
||||
Url = "https://www.facebook.com/search/?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Twitter",
|
||||
ActionKeyword = "twitter",
|
||||
Icon = "twitter.png",
|
||||
Url = "https://twitter.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Google Maps",
|
||||
ActionKeyword = "maps",
|
||||
Icon = "google_maps.png",
|
||||
Url = "https://maps.google.com/maps?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Google Translate",
|
||||
ActionKeyword = "translate",
|
||||
Icon = "google_translate.png",
|
||||
Url = "https://translate.google.com/#auto|en|{q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Duckduckgo",
|
||||
ActionKeyword = "duckduckgo",
|
||||
Icon = "duckduckgo.png",
|
||||
Url = "https://duckduckgo.com/?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Github",
|
||||
ActionKeyword = "github",
|
||||
Icon = "github.png",
|
||||
Url = "https://github.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Github Gist",
|
||||
ActionKeyword = "gist",
|
||||
Icon = "gist.png",
|
||||
Url = "https://gist.github.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Gmail",
|
||||
ActionKeyword = "gmail",
|
||||
Icon = "gmail.png",
|
||||
Url = "https://mail.google.com/mail/ca/u/0/#apps/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Google Drive",
|
||||
ActionKeyword = "drive",
|
||||
Icon = "google_drive.png",
|
||||
Url = "https://drive.google.com/?hl=en&tab=bo#search/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Wolframalpha",
|
||||
ActionKeyword = "wolframalpha",
|
||||
Icon = "wolframalpha.png",
|
||||
Url = "https://www.wolframalpha.com/input/?i={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Stackoverflow",
|
||||
ActionKeyword = "stackoverflow",
|
||||
Icon = "stackoverflow.png",
|
||||
Url = "https://stackoverflow.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "I'm Feeling Lucky",
|
||||
ActionKeyword = "lucky",
|
||||
Icon = "google.png",
|
||||
Url = "https://google.com/search?q={q}&btnI=I",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Google Image",
|
||||
ActionKeyword = "image",
|
||||
Icon = "google.png",
|
||||
Url = "https://www.google.com/search?q={q}&tbm=isch",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Youtube",
|
||||
ActionKeyword = "youtube",
|
||||
Icon = "youtube.png",
|
||||
Url = "https://www.youtube.com/results?search_query={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Bing",
|
||||
ActionKeyword = "bing",
|
||||
Icon = "bing.png",
|
||||
Url = "https://www.bing.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Yahoo",
|
||||
ActionKeyword = "yahoo",
|
||||
Icon = "yahoo.png",
|
||||
Url = "https://www.search.yahoo.com/search?p={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new SearchSource
|
||||
{
|
||||
Title = "Baidu",
|
||||
ActionKeyword = "bd",
|
||||
Icon = "baidu.png",
|
||||
Url = "https://www.baidu.com/#ie=UTF-8&wd={q}",
|
||||
Enabled = true
|
||||
}
|
||||
};
|
||||
|
||||
[JsonIgnore]
|
||||
public SearchSource SelectedSearchSource { get; set; }
|
||||
|
||||
public bool EnableSuggestion { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public SuggestionSource[] Suggestions { get; set; } = {
|
||||
new Google(),
|
||||
new Baidu()
|
||||
};
|
||||
|
||||
[JsonIgnore]
|
||||
public SuggestionSource SelectedSuggestion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// used to store Settings.json only
|
||||
/// </summary>
|
||||
public string Suggestion
|
||||
{
|
||||
get { return SelectedSuggestion.ToString(); }
|
||||
set
|
||||
{
|
||||
foreach (var s in Suggestions)
|
||||
{
|
||||
Title = "Google",
|
||||
ActionKeyword = "g",
|
||||
Icon = "google.png",
|
||||
Url = "https://www.google.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Google Scholar",
|
||||
ActionKeyword = "sc",
|
||||
Icon = "google.png",
|
||||
Url = "https://scholar.google.com/scholar?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Wikipedia",
|
||||
ActionKeyword = "wiki",
|
||||
Icon = "wiki.png",
|
||||
Url = "https://en.wikipedia.org/wiki/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "FindIcon",
|
||||
ActionKeyword = "findicon",
|
||||
Icon = "pictures.png",
|
||||
Url = "http://findicons.com/search/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Facebook",
|
||||
ActionKeyword = "facebook",
|
||||
Icon = "facebook.png",
|
||||
Url = "https://www.facebook.com/search/?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Twitter",
|
||||
ActionKeyword = "twitter",
|
||||
Icon = "twitter.png",
|
||||
Url = "https://twitter.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Google Maps",
|
||||
ActionKeyword = "maps",
|
||||
Icon = "google_maps.png",
|
||||
Url = "https://maps.google.com/maps?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Google Translate",
|
||||
ActionKeyword = "translate",
|
||||
Icon = "google_translate.png",
|
||||
Url = "https://translate.google.com/#auto|en|{q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Duckduckgo",
|
||||
ActionKeyword = "duckduckgo",
|
||||
Icon = "duckduckgo.png",
|
||||
Url = "https://duckduckgo.com/?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Github",
|
||||
ActionKeyword = "github",
|
||||
Icon = "github.png",
|
||||
Url = "https://github.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Github Gist",
|
||||
ActionKeyword = "gist",
|
||||
Icon = "gist.png",
|
||||
Url = "https://gist.github.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Gmail",
|
||||
ActionKeyword = "gmail",
|
||||
Icon = "gmail.png",
|
||||
Url = "https://mail.google.com/mail/ca/u/0/#apps/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Google Drive",
|
||||
ActionKeyword = "drive",
|
||||
Icon = "google_drive.png",
|
||||
Url = "https://drive.google.com/?hl=en&tab=bo#search/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Wolframalpha",
|
||||
ActionKeyword = "wolframalpha",
|
||||
Icon = "wolframalpha.png",
|
||||
Url = "https://www.wolframalpha.com/input/?i={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Stackoverflow",
|
||||
ActionKeyword = "stackoverflow",
|
||||
Icon = "stackoverflow.png",
|
||||
Url = "https://stackoverflow.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "I'm Feeling Lucky",
|
||||
ActionKeyword = "lucky",
|
||||
Icon = "google.png",
|
||||
Url = "https://google.com/search?q={q}&btnI=I",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Google Image",
|
||||
ActionKeyword = "image",
|
||||
Icon = "google.png",
|
||||
Url = "https://www.google.com/search?q={q}&tbm=isch",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Youtube",
|
||||
ActionKeyword = "youtube",
|
||||
Icon = "youtube.png",
|
||||
Url = "https://www.youtube.com/results?search_query={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Bing",
|
||||
ActionKeyword = "bing",
|
||||
Icon = "bing.png",
|
||||
Url = "https://www.bing.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title = "Yahoo",
|
||||
ActionKeyword = "yahoo",
|
||||
Icon = "yahoo.png",
|
||||
Url = "https://www.search.yahoo.com/search?p={q}",
|
||||
Enabled = true
|
||||
},
|
||||
new WebSearch
|
||||
{
|
||||
Title= "Baidu",
|
||||
ActionKeyword= "bd",
|
||||
Icon= "baidu.png",
|
||||
Url="https://www.baidu.com/#ie=UTF-8&wd={q}",
|
||||
Enabled= true
|
||||
if (string.Equals(s.ToString(), value, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
SelectedSuggestion = s;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public bool EnableWebSearchSuggestion { get; set; }
|
||||
|
||||
public string WebSearchSuggestionSource { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
58
Plugins/Wox.Plugin.WebSearch/SettingsControl.xaml
Normal file
58
Plugins/Wox.Plugin.WebSearch/SettingsControl.xaml
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<UserControl x:Class="Wox.Plugin.WebSearch.SettingsControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:vm="clr-namespace:Wox.Plugin.WebSearch"
|
||||
mc:Ignorable="d"
|
||||
Background="White"
|
||||
d:DataContext="{d:DesignInstance vm:SettingsViewModel}"
|
||||
d:DesignHeight="300" d:DesignWidth="500">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40" />
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="40" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="0">
|
||||
<CheckBox IsChecked="{Binding Settings.EnableSuggestion}"
|
||||
Margin="0 10 10 10"
|
||||
Name="EnableSuggestion"
|
||||
Content="{DynamicResource wox_plugin_websearch_enable_suggestion}" />
|
||||
<ComboBox ItemsSource="{Binding Settings.Suggestions}"
|
||||
SelectedItem="{Binding Settings.SelectedSuggestion}"
|
||||
IsEnabled="{Binding ElementName=EnableSuggestion, Path=IsChecked}" Margin="10" />
|
||||
<!-- Not sure why binding IsEnabled directly to Settings.EnableWebSaerchSuggestion is not working -->
|
||||
</StackPanel>
|
||||
<ListView ItemsSource="{Binding Settings.SearchSources}"
|
||||
SelectedItem="{Binding Settings.SelectedSearchSource}"
|
||||
Grid.Row="1">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="{DynamicResource wox_plugin_websearch_action_keyword}">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding ActionKeyword}" />
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
<GridViewColumn Header="{DynamicResource wox_plugin_websearch_url}">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Url}" />
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
<StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<Button Click="OnDeleteSearchSearchClick" Width="100" Margin="10"
|
||||
Content="{DynamicResource wox_plugin_websearch_delete}" />
|
||||
<Button Click="OnEditSearchSourceClick" Width="100" Margin="10"
|
||||
Content="{DynamicResource wox_plugin_websearch_edit}" />
|
||||
<Button Click="OnAddSearchSearchClick" Width="100" Margin="10"
|
||||
Content="{DynamicResource wox_plugin_websearch_add}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
54
Plugins/Wox.Plugin.WebSearch/SettingsControl.xaml.cs
Normal file
54
Plugins/Wox.Plugin.WebSearch/SettingsControl.xaml.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Core.Plugin;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for WebSearchesSetting.xaml
|
||||
/// </summary>
|
||||
public partial class SettingsControl : UserControl
|
||||
{
|
||||
private readonly Settings _settings;
|
||||
private readonly PluginInitContext _context;
|
||||
|
||||
public SettingsControl(PluginInitContext context, SettingsViewModel viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
_context = context;
|
||||
_settings = viewModel.Settings;
|
||||
DataContext = viewModel;
|
||||
}
|
||||
|
||||
private void OnAddSearchSearchClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var setting = new SearchSourceSettingWindow(_settings.SearchSources, _context);
|
||||
setting.ShowDialog();
|
||||
}
|
||||
|
||||
private void OnDeleteSearchSearchClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selected = _settings.SelectedSearchSource;
|
||||
var warning = _context.API.GetTranslation("wox_plugin_websearch_delete_warning");
|
||||
var formated = string.Format(warning, selected.Title);
|
||||
|
||||
var result = MessageBox.Show(formated, string.Empty, MessageBoxButton.YesNo);
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
var id = _context.CurrentPluginMetadata.ID;
|
||||
PluginManager.RemoveActionKeyword(id, selected.ActionKeyword);
|
||||
_settings.SearchSources.Remove(selected);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEditSearchSourceClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selected = _settings.SelectedSearchSource;
|
||||
var webSearch = new SearchSourceSettingWindow
|
||||
(
|
||||
_settings.SearchSources, _context, selected
|
||||
);
|
||||
webSearch.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Plugins/Wox.Plugin.WebSearch/SettingsViewModel.cs
Normal file
22
Plugins/Wox.Plugin.WebSearch/SettingsViewModel.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public class SettingsViewModel
|
||||
{
|
||||
private readonly JsonStrorage<Settings> _storage;
|
||||
|
||||
public SettingsViewModel()
|
||||
{
|
||||
_storage = new PluginJsonStorage<Settings>();
|
||||
Settings = _storage.Load();
|
||||
}
|
||||
|
||||
public Settings Settings { get; set; }
|
||||
|
||||
public void Save()
|
||||
{
|
||||
_storage.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,29 +13,27 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
|||
{
|
||||
public class Baidu : SuggestionSource
|
||||
{
|
||||
public override string Domain { get; set; } = "www.baidu.com";
|
||||
private readonly Regex _reg = new Regex("window.baidu.sug\\((.*)\\)");
|
||||
|
||||
Regex reg = new Regex("window.baidu.sug\\((.*)\\)");
|
||||
|
||||
public override async Task<List<string>> GetSuggestions(string query)
|
||||
public override async Task<List<string>> Suggestions(string query)
|
||||
{
|
||||
string result;
|
||||
|
||||
try
|
||||
{
|
||||
const string api = "http://suggestion.baidu.com/su?json=1&wd=";
|
||||
result = await Http.Get(api + Uri.EscapeUriString(query), Proxy, "GB2312");
|
||||
result = await Http.Get(api + Uri.EscapeUriString(query), "GB2312");
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
Log.Warn("Can't get suggestion from baidu");
|
||||
Log.Exception(e);
|
||||
return new List<string>(); ;
|
||||
return new List<string>();
|
||||
;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result)) return new List<string>();
|
||||
|
||||
Match match = reg.Match(result);
|
||||
Match match = _reg.Match(result);
|
||||
if (match.Success)
|
||||
{
|
||||
JContainer json;
|
||||
|
|
@ -62,8 +60,9 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
|||
return new List<string>();
|
||||
}
|
||||
|
||||
public Baidu(IHttpProxy httpProxy) : base(httpProxy)
|
||||
public override string ToString()
|
||||
{
|
||||
return "Baidu";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,20 +12,20 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
|||
{
|
||||
public class Google : SuggestionSource
|
||||
{
|
||||
public override string Domain { get; set; } = "www.google.com";
|
||||
public override async Task<List<string>> GetSuggestions(string query)
|
||||
public override async Task<List<string>> Suggestions(string query)
|
||||
{
|
||||
string result;
|
||||
try
|
||||
{
|
||||
const string api = "https://www.google.com/complete/search?output=chrome&q=";
|
||||
result = await Http.Get(api + Uri.EscapeUriString(query), Proxy);
|
||||
result = await Http.Get(api + Uri.EscapeUriString(query));
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
Log.Warn("Can't get suggestion from google");
|
||||
Log.Exception(e);
|
||||
return new List<string>(); ;
|
||||
return new List<string>();
|
||||
;
|
||||
}
|
||||
if (string.IsNullOrEmpty(result)) return new List<string>();
|
||||
JContainer json;
|
||||
|
|
@ -49,8 +49,9 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
|||
return new List<string>();
|
||||
}
|
||||
|
||||
public Google(IHttpProxy httpProxy) : base(httpProxy)
|
||||
public override string ToString()
|
||||
{
|
||||
return "Google";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
public abstract class SuggestionSource
|
||||
{
|
||||
public virtual string Domain { get; set; }
|
||||
public IHttpProxy Proxy { get; set; }
|
||||
|
||||
public SuggestionSource(IHttpProxy httpProxy)
|
||||
{
|
||||
Proxy = httpProxy;
|
||||
}
|
||||
|
||||
public abstract Task<List<string>> GetSuggestions(string query);
|
||||
|
||||
public static SuggestionSource GetSuggestionSource(string name, PluginInitContext context)
|
||||
{
|
||||
switch (name.ToLower())
|
||||
{
|
||||
case "google":
|
||||
return new Google(context.Proxy);
|
||||
|
||||
case "baidu":
|
||||
return new Baidu(context.Proxy);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
public abstract class SuggestionSource
|
||||
{
|
||||
public abstract Task<List<string>> Suggestions(string query);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
using System.IO;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public class WebSearch
|
||||
{
|
||||
public const string DefaultIcon = "web_search.png";
|
||||
public string Title { get; set; }
|
||||
public string ActionKeyword { get; set; }
|
||||
[NotNull]
|
||||
private string _icon = DefaultIcon;
|
||||
|
||||
[NotNull]
|
||||
public string Icon
|
||||
{
|
||||
get { return _icon; }
|
||||
set
|
||||
{
|
||||
_icon = value;
|
||||
IconPath = Path.Combine(Main.ImagesDirectory, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All icon should be put under Images directory
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[JsonIgnore]
|
||||
internal string IconPath { get; private set; } = Path.Combine
|
||||
(
|
||||
Main.ImagesDirectory, DefaultIcon
|
||||
);
|
||||
|
||||
public string Url { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
<Window x:Class="Wox.Plugin.WebSearch.WebSearchSetting"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
ResizeMode="NoResize"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Title="WebSearchSetting" Height="350" Width="674.766">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition Height="60"></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120"></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource wox_plugin_websearch_title}"></TextBlock>
|
||||
<TextBox x:Name="WebSearchName" Margin="10" Grid.Row="0" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
|
||||
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource wox_plugin_websearch_url}"></TextBlock>
|
||||
<TextBox x:Name="Url" Margin="10" Grid.Row="1" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
|
||||
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource wox_plugin_websearch_action_keyword}"></TextBlock>
|
||||
<TextBox x:Name="Actionword" Margin="10" Grid.Row="2" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
|
||||
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource wox_plugin_websearch_enable}"></TextBlock>
|
||||
<CheckBox x:Name="EnableCheckBox" IsChecked="True" Margin="10" Grid.Row="3" Grid.Column="1" VerticalAlignment="Center"></CheckBox>
|
||||
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource wox_plugin_websearch_icon}"></TextBlock>
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="1" Margin="10">
|
||||
<Image x:Name="WebSearchIcon" Width="24" Height="24" Margin="0 0 10 0" />
|
||||
<Button x:Name="SelectIconButton" Height="24" Click="SelectIconButtonOnClick" Content="{DynamicResource wox_plugin_websearch_select_icon}"></Button>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="5" Grid.Column="1">
|
||||
<Button x:Name="CancelButton" Click="CancelButtonOnClick" Margin="10 0 10 0" Width="80" Height="25" Content="{DynamicResource wox_plugin_websearch_cancel}"/>
|
||||
<Button x:Name="ConfirmButton" Margin="10 0 10 0" Width="80" Height="25" Click="ConfirmButtonOnClick" Content="{DynamicResource wox_plugin_websearch_add}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Microsoft.Win32;
|
||||
using Wox.Infrastructure.Exception;
|
||||
using Wox.Infrastructure.Image;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public partial class WebSearchSetting
|
||||
{
|
||||
private readonly WebSearchesSetting _settingWindow;
|
||||
private bool _isUpdate;
|
||||
private WebSearch _webSearch;
|
||||
private readonly PluginInitContext _context;
|
||||
private readonly Main _plugin;
|
||||
private readonly Settings _settings;
|
||||
|
||||
public WebSearchSetting(WebSearchesSetting settingWidow, Settings settings)
|
||||
{
|
||||
InitializeComponent();
|
||||
WebSearchName.Focus();
|
||||
_plugin = settingWidow.Plugin;
|
||||
_context = settingWidow.Context;
|
||||
_settingWindow = settingWidow;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public void UpdateItem(WebSearch webSearch)
|
||||
{
|
||||
_webSearch = _settings.WebSearches.FirstOrDefault(o => o == webSearch);
|
||||
if (_webSearch == null || string.IsNullOrEmpty(_webSearch.Url))
|
||||
{
|
||||
|
||||
string warning = _context.API.GetTranslation("wox_plugin_websearch_invalid_web_search");
|
||||
MessageBox.Show(warning);
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
_isUpdate = true;
|
||||
ConfirmButton.Content = "Update";
|
||||
WebSearchIcon.Source = ImageLoader.Load(webSearch.IconPath);
|
||||
EnableCheckBox.IsChecked = webSearch.Enabled;
|
||||
WebSearchName.Text = webSearch.Title;
|
||||
Url.Text = webSearch.Url;
|
||||
Actionword.Text = webSearch.ActionKeyword;
|
||||
}
|
||||
|
||||
public void AddItem(WebSearch webSearch)
|
||||
{
|
||||
_webSearch = webSearch;
|
||||
WebSearchIcon.Source = ImageLoader.Load(webSearch.IconPath);
|
||||
}
|
||||
|
||||
private void CancelButtonOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Confirm button for both add and update
|
||||
/// </summary>
|
||||
private void ConfirmButtonOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string title = WebSearchName.Text;
|
||||
if (string.IsNullOrEmpty(title))
|
||||
{
|
||||
string warning = _context.API.GetTranslation("wox_plugin_websearch_input_title");
|
||||
MessageBox.Show(warning);
|
||||
return;
|
||||
}
|
||||
|
||||
string url = Url.Text;
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
string warning = _context.API.GetTranslation("wox_plugin_websearch_input_url");
|
||||
MessageBox.Show(warning);
|
||||
return;
|
||||
}
|
||||
|
||||
string newActionKeyword = Actionword.Text.Trim();
|
||||
|
||||
if (_isUpdate)
|
||||
{
|
||||
try
|
||||
{
|
||||
_plugin.NotifyActionKeywordsUpdated(_webSearch.ActionKeyword, newActionKeyword);
|
||||
}
|
||||
catch (WoxPluginException exception)
|
||||
{
|
||||
MessageBox.Show(exception.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
_plugin.NotifyActionKeywordsAdded(newActionKeyword);
|
||||
}
|
||||
catch (WoxPluginException exception)
|
||||
{
|
||||
MessageBox.Show(exception.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
_settings.WebSearches.Add(_webSearch);
|
||||
}
|
||||
|
||||
_webSearch.ActionKeyword = newActionKeyword;
|
||||
_webSearch.Enabled = EnableCheckBox.IsChecked ?? false;
|
||||
_webSearch.Url = url;
|
||||
_webSearch.Title = title;
|
||||
|
||||
_settingWindow.ReloadWebSearchView();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void SelectIconButtonOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var directory = Path.Combine(Main.ImagesDirectory, Main.Images);
|
||||
var dlg = new OpenFileDialog
|
||||
{
|
||||
InitialDirectory = directory,
|
||||
Filter = "Image files (*.jpg, *.jpeg, *.gif, *.png, *.bmp) |*.jpg; *.jpeg; *.gif; *.png; *.bmp"
|
||||
};
|
||||
|
||||
bool? result = dlg.ShowDialog();
|
||||
if (result != null && result == true)
|
||||
{
|
||||
string fullpath = dlg.FileName;
|
||||
if (fullpath != null)
|
||||
{
|
||||
_webSearch.Icon = Path.GetFileName(fullpath);
|
||||
if (File.Exists(_webSearch.IconPath))
|
||||
{
|
||||
WebSearchIcon.Source = ImageLoader.Load(_webSearch.IconPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
_webSearch.Icon = WebSearch.DefaultIcon;
|
||||
MessageBox.Show($"The file should be put under {directory}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
<UserControl x:Class="Wox.Plugin.WebSearch.WebSearchesSetting"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="500">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="42"/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="50"/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="0">
|
||||
<CheckBox x:Name="cbEnableWebSearchSuggestion" Unchecked="CbEnableWebSearchSuggestion_OnUnchecked" Checked="CbEnableWebSearchSuggestion_OnChecked" Margin="0 10 10 10" Content="{DynamicResource wox_plugin_websearch_enable_suggestion}"></CheckBox>
|
||||
<ComboBox x:Name="comboBoxSuggestionSource" SelectionChanged="ComboBoxSuggestionSource_OnSelectionChanged" Margin="10">
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
<ListView x:Name="webSearchView" Grid.Row="1">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="{DynamicResource wox_plugin_websearch_action_keyword}" Width="180">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding ActionKeyword}"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
<GridViewColumn Header="{DynamicResource wox_plugin_websearch_url}" Width="500">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Url}"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
<StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<Button x:Name="btnDeleteWebSearch" Click="btnDeleteWebSearch_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_websearch_delete}"/>
|
||||
<Button x:Name="btnEditWebSearch" Click="btnEditWebSearch_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_websearch_edit}"/>
|
||||
<Button x:Name="btnAddWebSearch" Click="btnAddWebSearch_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_websearch_add}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for WebSearchesSetting.xaml
|
||||
/// </summary>
|
||||
public partial class WebSearchesSetting : UserControl
|
||||
{
|
||||
private Settings _settings;
|
||||
public PluginInitContext Context { get; }
|
||||
public Main Plugin { get; }
|
||||
|
||||
public WebSearchesSetting(Main plugin, Settings settings)
|
||||
{
|
||||
Context = plugin.Context;
|
||||
Plugin = plugin;
|
||||
InitializeComponent();
|
||||
Loaded += Setting_Loaded;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
webSearchView.ItemsSource = _settings.WebSearches;
|
||||
cbEnableWebSearchSuggestion.IsChecked = _settings.EnableWebSearchSuggestion;
|
||||
comboBoxSuggestionSource.Visibility = _settings.EnableWebSearchSuggestion
|
||||
? Visibility.Visible
|
||||
: Visibility.Collapsed;
|
||||
|
||||
List<ComboBoxItem> items = new List<ComboBoxItem>
|
||||
{
|
||||
new ComboBoxItem {Content = "Google"},
|
||||
new ComboBoxItem {Content = "Baidu"}
|
||||
};
|
||||
ComboBoxItem selected = items.FirstOrDefault(o => o.Content.ToString() == _settings.WebSearchSuggestionSource);
|
||||
if (selected == null)
|
||||
{
|
||||
selected = items[0];
|
||||
}
|
||||
comboBoxSuggestionSource.ItemsSource = items;
|
||||
comboBoxSuggestionSource.SelectedItem = selected;
|
||||
}
|
||||
|
||||
public void ReloadWebSearchView()
|
||||
{
|
||||
webSearchView.Items.Refresh();
|
||||
}
|
||||
|
||||
|
||||
private void btnAddWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var setting = new WebSearchSetting(this, _settings);
|
||||
var webSearch = new WebSearch();
|
||||
|
||||
|
||||
setting.AddItem(webSearch);
|
||||
setting.ShowDialog();
|
||||
}
|
||||
|
||||
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch;
|
||||
if (selectedWebSearch != null)
|
||||
{
|
||||
string msg = string.Format(Context.API.GetTranslation("wox_plugin_websearch_delete_warning"), selectedWebSearch.Title);
|
||||
|
||||
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
_settings.WebSearches.Remove(selectedWebSearch);
|
||||
webSearchView.Items.Refresh();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string warning = Context.API.GetTranslation("wox_plugin_websearch_pls_select_web_search");
|
||||
MessageBox.Show(warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch;
|
||||
if (selectedWebSearch != null)
|
||||
{
|
||||
WebSearchSetting webSearch = new WebSearchSetting(this, _settings);
|
||||
webSearch.UpdateItem(selectedWebSearch);
|
||||
webSearch.ShowDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
string warning = Context.API.GetTranslation("wox_plugin_websearch_pls_select_web_search");
|
||||
MessageBox.Show(warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void CbEnableWebSearchSuggestion_OnChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
comboBoxSuggestionSource.Visibility = Visibility.Visible;
|
||||
_settings.EnableWebSearchSuggestion = true;
|
||||
}
|
||||
|
||||
private void CbEnableWebSearchSuggestion_OnUnchecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
comboBoxSuggestionSource.Visibility = Visibility.Collapsed;
|
||||
_settings.EnableWebSearchSuggestion = false;
|
||||
}
|
||||
|
||||
private void ComboBoxSuggestionSource_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (e.AddedItems.Count > 0)
|
||||
{
|
||||
_settings.WebSearchSuggestionSource = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -59,16 +59,18 @@
|
|||
<Link>Properties\SolutionAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SearchSourceViewModel.cs" />
|
||||
<Compile Include="SettingsViewModel.cs" />
|
||||
<Compile Include="SuggestionSources\Baidu.cs" />
|
||||
<Compile Include="SuggestionSources\Google.cs" />
|
||||
<Compile Include="SuggestionSources\ISuggestionSource.cs" />
|
||||
<Compile Include="WebSearch.cs" />
|
||||
<Compile Include="WebSearchesSetting.xaml.cs">
|
||||
<DependentUpon>WebSearchesSetting.xaml</DependentUpon>
|
||||
<Compile Include="SuggestionSources\SuggestionSource.cs" />
|
||||
<Compile Include="SearchSource.cs" />
|
||||
<Compile Include="SettingsControl.xaml.cs">
|
||||
<DependentUpon>SettingsControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="WebSearchSetting.xaml.cs">
|
||||
<DependentUpon>WebSearchSetting.xaml</DependentUpon>
|
||||
<Compile Include="SearchSourceSetting.xaml.cs">
|
||||
<DependentUpon>SearchSourceSetting.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Settings.cs" />
|
||||
</ItemGroup>
|
||||
|
|
@ -152,16 +154,20 @@
|
|||
<SubType>Designer</SubType>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Page Include="WebSearchesSetting.xaml">
|
||||
<Page Include="SettingsControl.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="WebSearchSetting.xaml">
|
||||
<Page Include="SearchSourceSetting.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Wox.Core\Wox.Core.csproj">
|
||||
<Project>{B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}</Project>
|
||||
<Name>Wox.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
||||
<Name>Wox.Infrastructure</Name>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="JetBrains.Annotations" version="10.1.4" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" />
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System.Reflection;
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
#if DEBUG
|
||||
|
||||
[assembly: AssemblyConfiguration("Debug")]
|
||||
[assembly: AssemblyDescription("Debug build, https://github.com/Wox-launcher/Wox")]
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
|
|
@ -28,7 +27,6 @@ namespace Wox.Core.Plugin
|
|||
{
|
||||
Method = "query",
|
||||
Parameters = new object[] { query.Search },
|
||||
HttpProxy = HttpProxy.Instance
|
||||
};
|
||||
|
||||
_startInfo.Arguments = $"\"{request}\"";
|
||||
|
|
|
|||
|
|
@ -100,18 +100,6 @@ namespace Wox.Core.Plugin
|
|||
/// </summary>
|
||||
public class JsonRPCServerRequestModel : JsonRPCRequestModel
|
||||
{
|
||||
public IHttpProxy HttpProxy { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string rpc = base.ToString();
|
||||
if (HttpProxy != null)
|
||||
{
|
||||
rpc += string.Format(@",\""proxy\"":{{\""enabled\"":{0},\""server\"":\""{1}\"",\""port\"":{2},\""username\"":\""{3}\"",\""password\"":\""{4}\""}}",
|
||||
HttpProxy.Enabled.ToString().ToLower(), HttpProxy.Server, HttpProxy.Port, HttpProxy.UserName, HttpProxy.Password);
|
||||
}
|
||||
return rpc + "}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Exception;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
|
|
@ -30,16 +29,17 @@ namespace Wox.Core.Plugin
|
|||
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
|
||||
|
||||
public static IPublicAPI API { private set; get; }
|
||||
|
||||
// todo happlebao, this should not be public, the indicator function should be embeded
|
||||
public static PluginsSettings Settings;
|
||||
private static List<PluginMetadata> _metadatas;
|
||||
private static readonly string[] Directories = { Infrastructure.Constant.PreinstalledDirectory, Infrastructure.Constant.UserDirectory };
|
||||
private static readonly string[] Directories = { Constant.PreinstalledDirectory, Constant.UserDirectory };
|
||||
|
||||
private static void ValidateUserDirectory()
|
||||
{
|
||||
if (!Directory.Exists(Infrastructure.Constant.UserDirectory))
|
||||
if (!Directory.Exists(Constant.UserDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(Infrastructure.Constant.UserDirectory);
|
||||
Directory.CreateDirectory(Constant.UserDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +83,6 @@ namespace Wox.Core.Plugin
|
|||
pair.Plugin.Init(new PluginInitContext
|
||||
{
|
||||
CurrentPluginMetadata = pair.Metadata,
|
||||
Proxy = HttpProxy.Instance,
|
||||
API = API
|
||||
});
|
||||
});
|
||||
|
|
@ -239,59 +238,58 @@ namespace Wox.Core.Plugin
|
|||
|
||||
}
|
||||
|
||||
public static void UpdateActionKeywordForPlugin(PluginPair plugin, string oldActionKeyword, string newActionKeyword)
|
||||
public static bool ActionKeywordRegistered(string actionKeyword)
|
||||
{
|
||||
var actionKeywords = plugin.Metadata.ActionKeywords;
|
||||
if (string.IsNullOrEmpty(newActionKeyword))
|
||||
if (actionKeyword != Query.GlobalPluginWildcardSign &&
|
||||
NonGlobalPlugins.ContainsKey(actionKeyword))
|
||||
{
|
||||
string msg = InternationalizationManager.Instance.GetTranslation("newActionKeywordsCannotBeEmpty");
|
||||
throw new WoxPluginException(plugin.Metadata.Name, msg);
|
||||
return true;
|
||||
}
|
||||
// do nothing if they are same
|
||||
if (oldActionKeyword == newActionKeyword) return;
|
||||
if (NonGlobalPlugins.ContainsKey(newActionKeyword))
|
||||
{
|
||||
string msg = InternationalizationManager.Instance.GetTranslation("newActionKeywordsHasBeenAssigned");
|
||||
throw new WoxPluginException(plugin.Metadata.Name, msg);
|
||||
}
|
||||
|
||||
// add new action keyword
|
||||
if (string.IsNullOrEmpty(oldActionKeyword))
|
||||
{
|
||||
actionKeywords.Add(newActionKeyword);
|
||||
if (newActionKeyword == Query.GlobalPluginWildcardSign)
|
||||
{
|
||||
GlobalPlugins.Add(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
NonGlobalPlugins[newActionKeyword] = plugin;
|
||||
}
|
||||
}
|
||||
// update existing action keyword
|
||||
else
|
||||
{
|
||||
int index = actionKeywords.IndexOf(oldActionKeyword);
|
||||
actionKeywords[index] = newActionKeyword;
|
||||
if (oldActionKeyword == Query.GlobalPluginWildcardSign)
|
||||
{
|
||||
GlobalPlugins.Remove(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
NonGlobalPlugins.Remove(oldActionKeyword);
|
||||
}
|
||||
if (newActionKeyword == Query.GlobalPluginWildcardSign)
|
||||
{
|
||||
GlobalPlugins.Add(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
NonGlobalPlugins[newActionKeyword] = plugin;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void AddActionKeyword(string id, string newActionKeyword)
|
||||
{
|
||||
var plugin = GetPluginForId(id);
|
||||
if (newActionKeyword == Query.GlobalPluginWildcardSign)
|
||||
{
|
||||
GlobalPlugins.Add(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
NonGlobalPlugins[newActionKeyword] = plugin;
|
||||
}
|
||||
AllPlugins.Add(plugin);
|
||||
|
||||
plugin.Metadata.ActionKeywords.Add(newActionKeyword);
|
||||
}
|
||||
|
||||
public static void RemoveActionKeyword(string id, string oldActionkeyword)
|
||||
{
|
||||
var plugin = GetPluginForId(id);
|
||||
if (oldActionkeyword == Query.GlobalPluginWildcardSign)
|
||||
{
|
||||
GlobalPlugins.Remove(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
NonGlobalPlugins.Remove(oldActionkeyword);
|
||||
}
|
||||
AllPlugins.Remove(plugin);
|
||||
|
||||
plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
|
||||
}
|
||||
|
||||
public static void ReplaceActionKeyword(string id, string oldActionKeyword, string newActionKeyword)
|
||||
{
|
||||
if (oldActionKeyword != newActionKeyword)
|
||||
{
|
||||
AddActionKeyword(id, newActionKeyword);
|
||||
RemoveActionKeyword(id, oldActionKeyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.Exception;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
|
|
@ -28,7 +27,6 @@ namespace Wox.Core.Plugin
|
|||
{
|
||||
Method = "query",
|
||||
Parameters = new object[] { query.Search },
|
||||
HttpProxy = HttpProxy.Instance
|
||||
};
|
||||
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
|
||||
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\"";
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@ using System.Linq;
|
|||
using System.Windows;
|
||||
using Wox.Infrastructure.Exception;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Resource
|
||||
{
|
||||
public class Internationalization : Resource
|
||||
{
|
||||
public UserSettings.Settings Settings { get; set; }
|
||||
public Settings Settings { get; set; }
|
||||
|
||||
public Internationalization()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ using System.Windows;
|
|||
using System.Windows.Controls;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
|
||||
namespace Wox.Core.Resource
|
||||
{
|
||||
public class Theme : Resource
|
||||
{
|
||||
private static List<string> themeDirectories = new List<string>();
|
||||
public UserSettings.Settings Settings { get; set; }
|
||||
public Settings Settings { get; set; }
|
||||
|
||||
public Theme()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using System.Threading.Tasks;
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Squirrel;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.Http;
|
||||
using Wox.Infrastructure.Logger;
|
||||
|
||||
|
|
@ -19,7 +18,7 @@ namespace Wox.Core
|
|||
public static async void UpdateApp()
|
||||
{
|
||||
|
||||
var client = new WebClient {Proxy = Http.WebProxy(HttpProxy.Instance)};
|
||||
var client = new WebClient {Proxy = Http.WebProxy()};
|
||||
var downloader = new FileDownloader(client);
|
||||
|
||||
try
|
||||
|
|
@ -67,7 +66,7 @@ namespace Wox.Core
|
|||
string response;
|
||||
try
|
||||
{
|
||||
response = await Http.Get(githubAPI, HttpProxy.Instance);
|
||||
response = await Http.Get(githubAPI);
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.UserSettings
|
||||
{
|
||||
public class HttpProxy : IHttpProxy
|
||||
{
|
||||
private static readonly HttpProxy instance = new HttpProxy();
|
||||
public Settings Settings { get; set; }
|
||||
public static HttpProxy Instance => instance;
|
||||
|
||||
public bool Enabled => Settings.ProxyEnabled;
|
||||
public string Server => Settings.ProxyServer;
|
||||
public int Port => Settings.ProxyPort;
|
||||
public string UserName => Settings.ProxyUserName;
|
||||
public string Password => Settings.ProxyPassword;
|
||||
}
|
||||
}
|
||||
|
|
@ -110,7 +110,6 @@
|
|||
<Compile Include="Plugin\ExecutablePlugin.cs" />
|
||||
<Compile Include="Plugin\PluginsLoader.cs" />
|
||||
<Compile Include="Updater.cs" />
|
||||
<Compile Include="UserSettings\HttpProxy.cs" />
|
||||
<Compile Include="Resource\AvailableLanguages.cs" />
|
||||
<Compile Include="Resource\Internationalization.cs" />
|
||||
<Compile Include="Resource\InternationalizationManager.cs" />
|
||||
|
|
@ -127,9 +126,6 @@
|
|||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Resource\FontHelper.cs" />
|
||||
<Compile Include="Resource\Theme.cs" />
|
||||
<Compile Include="UserSettings\PluginSettings.cs" />
|
||||
<Compile Include="UserSettings\PluginHotkey.cs" />
|
||||
<Compile Include="UserSettings\Settings.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
|
|
|||
|
|
@ -14,9 +14,5 @@
|
|||
{
|
||||
PluginName = pluginName;
|
||||
}
|
||||
|
||||
public WoxPluginException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,26 +3,27 @@ using System.Net;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Wox.Plugin;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
|
||||
namespace Wox.Infrastructure.Http
|
||||
{
|
||||
public static class Http
|
||||
{
|
||||
public static IWebProxy WebProxy(IHttpProxy proxy)
|
||||
public static HttpProxy Proxy { private get; set; }
|
||||
public static IWebProxy WebProxy()
|
||||
{
|
||||
if (proxy != null && proxy.Enabled && !string.IsNullOrEmpty(proxy.Server))
|
||||
if (Proxy != null && Proxy.Enabled && !string.IsNullOrEmpty(Proxy.Server))
|
||||
{
|
||||
if (string.IsNullOrEmpty(proxy.UserName) || string.IsNullOrEmpty(proxy.Password))
|
||||
if (string.IsNullOrEmpty(Proxy.UserName) || string.IsNullOrEmpty(Proxy.Password))
|
||||
{
|
||||
var webProxy = new WebProxy(proxy.Server, proxy.Port);
|
||||
var webProxy = new WebProxy(Proxy.Server, Proxy.Port);
|
||||
return webProxy;
|
||||
}
|
||||
else
|
||||
{
|
||||
var webProxy = new WebProxy(proxy.Server, proxy.Port)
|
||||
var webProxy = new WebProxy(Proxy.Server, Proxy.Port)
|
||||
{
|
||||
Credentials = new NetworkCredential(proxy.UserName, proxy.Password)
|
||||
Credentials = new NetworkCredential(Proxy.UserName, Proxy.Password)
|
||||
};
|
||||
return webProxy;
|
||||
}
|
||||
|
|
@ -34,20 +35,20 @@ namespace Wox.Infrastructure.Http
|
|||
}
|
||||
|
||||
/// <exception cref="WebException">Can't download file </exception>
|
||||
public static void Download([NotNull] string url, [NotNull] string filePath, IHttpProxy proxy)
|
||||
public static void Download([NotNull] string url, [NotNull] string filePath)
|
||||
{
|
||||
var client = new WebClient { Proxy = WebProxy(proxy) };
|
||||
var client = new WebClient { Proxy = WebProxy() };
|
||||
client.DownloadFile(url, filePath);
|
||||
}
|
||||
|
||||
/// <exception cref="WebException">Can't get response from http get </exception>
|
||||
public static async Task<string> Get([NotNull] string url, IHttpProxy proxy, string encoding = "UTF-8")
|
||||
public static async Task<string> Get([NotNull] string url, string encoding = "UTF-8")
|
||||
{
|
||||
|
||||
HttpWebRequest request = WebRequest.CreateHttp(url);
|
||||
request.Method = "GET";
|
||||
request.Timeout = 10 * 1000;
|
||||
request.Proxy = WebProxy(proxy);
|
||||
request.Proxy = WebProxy();
|
||||
request.UserAgent = @"Mozilla/5.0 (Trident/7.0; rv:11.0) like Gecko";
|
||||
var response = await request.GetResponseAsync() as HttpWebResponse;
|
||||
if (response != null)
|
||||
|
|
|
|||
11
Wox.Infrastructure/UserSettings/HttpProxy.cs
Normal file
11
Wox.Infrastructure/UserSettings/HttpProxy.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
namespace Wox.Infrastructure.UserSettings
|
||||
{
|
||||
public class HttpProxy
|
||||
{
|
||||
public bool Enabled { get; set; } = false;
|
||||
public string Server { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.UserSettings
|
||||
namespace Wox.Infrastructure.UserSettings
|
||||
{
|
||||
public class CustomPluginHotkey : BaseModel
|
||||
{
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.UserSettings
|
||||
namespace Wox.Infrastructure.UserSettings
|
||||
{
|
||||
public class PluginsSettings : BaseModel
|
||||
{
|
||||
|
|
@ -34,12 +34,6 @@ namespace Wox.Core.UserSettings
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateActionKeyword(PluginMetadata metadata)
|
||||
{
|
||||
var settings = Plugins[metadata.ID];
|
||||
settings.ActionKeywords = metadata.ActionKeywords;
|
||||
}
|
||||
}
|
||||
public class Plugin
|
||||
{
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.UserSettings
|
||||
namespace Wox.Infrastructure.UserSettings
|
||||
{
|
||||
public class Settings : BaseModel
|
||||
{
|
||||
|
|
@ -49,12 +48,7 @@ namespace Wox.Core.UserSettings
|
|||
public bool RememberLastLaunchLocation { get; set; }
|
||||
public bool IgnoreHotkeysOnFullscreen { get; set; }
|
||||
|
||||
public string ProxyServer { get; set; }
|
||||
public bool ProxyEnabled { get; set; }
|
||||
public int ProxyPort { get; set; }
|
||||
public string ProxyUserName { get; set; }
|
||||
public string ProxyPassword { get; set; }
|
||||
|
||||
public HttpProxy Proxy { get; set; } = new HttpProxy();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
|
|
@ -92,6 +92,10 @@
|
|||
<Compile Include="Hotkey\HotkeyModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Alphabet.cs" />
|
||||
<Compile Include="UserSettings\HttpProxy.cs" />
|
||||
<Compile Include="UserSettings\PluginHotkey.cs" />
|
||||
<Compile Include="UserSettings\PluginSettings.cs" />
|
||||
<Compile Include="UserSettings\Settings.cs" />
|
||||
<Compile Include="Wox.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace Wox.Plugin
|
||||
{
|
||||
|
|
@ -37,19 +38,6 @@ namespace Wox.Plugin
|
|||
string GetTranslatedPluginDescription();
|
||||
}
|
||||
|
||||
public interface IMultipleActionKeywords : IFeatures
|
||||
{
|
||||
event ActionKeywordsChangedEventHandler ActionKeywordsChanged;
|
||||
}
|
||||
|
||||
public class ActionKeywordsChangedEventArgs : EventArgs
|
||||
{
|
||||
public string OldActionKeyword { get; set; }
|
||||
public string NewActionKeyword { get; set; }
|
||||
}
|
||||
|
||||
public delegate void ActionKeywordsChangedEventHandler(IMultipleActionKeywords sender, ActionKeywordsChangedEventArgs e);
|
||||
|
||||
public interface IResultUpdated : IFeatures
|
||||
{
|
||||
event ResultUpdatedEventHandler ResultsUpdated;
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
namespace Wox.Plugin
|
||||
{
|
||||
public interface IHttpProxy
|
||||
{
|
||||
bool Enabled { get; }
|
||||
string Server { get; }
|
||||
int Port { get; }
|
||||
string UserName { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
namespace Wox.Plugin
|
||||
using System;
|
||||
|
||||
namespace Wox.Plugin
|
||||
{
|
||||
public class PluginInitContext
|
||||
{
|
||||
|
|
@ -8,7 +10,5 @@
|
|||
/// Public APIs for plugin invocation
|
||||
/// </summary>
|
||||
public IPublicAPI API { get; set; }
|
||||
|
||||
public IHttpProxy Proxy { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@
|
|||
<Compile Include="Features\IContextMenu.cs" />
|
||||
<Compile Include="Features\IExclusiveQuery.cs" />
|
||||
<Compile Include="Features\IInstantQuery.cs" />
|
||||
<Compile Include="IHttpProxy.cs" />
|
||||
<Compile Include="IPlugin.cs" />
|
||||
<Compile Include="IPublicAPI.cs" />
|
||||
<Compile Include="ISettingProvider.cs" />
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
using System.Windows;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.Exception;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox
|
||||
|
|
@ -11,6 +11,7 @@ namespace Wox
|
|||
{
|
||||
private PluginPair _plugin;
|
||||
private Settings _settings;
|
||||
private readonly Internationalization _translater = InternationalizationManager.Instance;
|
||||
|
||||
public ActionKeywords(string pluginId, Settings settings)
|
||||
{
|
||||
|
|
@ -19,7 +20,7 @@ namespace Wox
|
|||
_settings = settings;
|
||||
if (_plugin == null)
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("cannotFindSpecifiedPlugin"));
|
||||
MessageBox.Show(_translater.GetTranslation("cannotFindSpecifiedPlugin"));
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
|
@ -39,21 +40,18 @@ namespace Wox
|
|||
{
|
||||
var oldActionKeyword = _plugin.Metadata.ActionKeywords[0];
|
||||
var newActionKeyword = tbAction.Text.Trim();
|
||||
try
|
||||
if (!PluginManager.ActionKeywordRegistered(newActionKeyword))
|
||||
{
|
||||
// update in-memory data
|
||||
PluginManager.UpdateActionKeywordForPlugin(_plugin, oldActionKeyword, newActionKeyword);
|
||||
var id = _plugin.Metadata.ID;
|
||||
PluginManager.ReplaceActionKeyword(id, oldActionKeyword, newActionKeyword);
|
||||
MessageBox.Show(_translater.GetTranslation("succeed"));
|
||||
Close();
|
||||
}
|
||||
catch (WoxPluginException e)
|
||||
else
|
||||
{
|
||||
MessageBox.Show(e.Message);
|
||||
return;
|
||||
string msg = _translater.GetTranslation("newActionKeywordsHasBeenAssigned");
|
||||
MessageBox.Show(msg);
|
||||
}
|
||||
// update persistant data
|
||||
_settings.PluginSettings.UpdateActionKeyword(_plugin.Metadata);
|
||||
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ using System.Timers;
|
|||
using System.Windows;
|
||||
using Wox.Core;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure.Image;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.ViewModel;
|
||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ using System.Windows;
|
|||
using NHotkey;
|
||||
using NHotkey.Wpf;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
|
||||
namespace Wox
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@
|
|||
<system:String x:Key="deleteCustomHotkeyWarning">Wollen Sie die {0} Plugin Tastenkombination wirklich löschen?</system:String>
|
||||
|
||||
<!--Setting Proxy-->
|
||||
<system:String x:Key="proxy">Proxy</system:String>
|
||||
<system:String x:Key="enableProxy">Aktiviere Proxy</system:String>
|
||||
<system:String x:Key="server">Server</system:String>
|
||||
<system:String x:Key="proxy">HTTP Proxy</system:String>
|
||||
<system:String x:Key="enableProxy">Aktiviere HTTP Proxy</system:String>
|
||||
<system:String x:Key="server">HTTP Server</system:String>
|
||||
<system:String x:Key="port">Port</system:String>
|
||||
<system:String x:Key="userName">Benutzername</system:String>
|
||||
<system:String x:Key="password">Passwort</system:String>
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@
|
|||
<system:String x:Key="deleteCustomHotkeyWarning">Are you sure you want to delete {0} plugin hotkey?</system:String>
|
||||
|
||||
<!--Setting Proxy-->
|
||||
<system:String x:Key="proxy">Proxy</system:String>
|
||||
<system:String x:Key="enableProxy">Enable Proxy</system:String>
|
||||
<system:String x:Key="server">Server</system:String>
|
||||
<system:String x:Key="proxy">HTTP Proxy</system:String>
|
||||
<system:String x:Key="enableProxy">Enable HTTP Proxy</system:String>
|
||||
<system:String x:Key="server">HTTP Server</system:String>
|
||||
<system:String x:Key="port">Port</system:String>
|
||||
<system:String x:Key="userName">User Name</system:String>
|
||||
<system:String x:Key="password">Password</system:String>
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@
|
|||
<system:String x:Key="deleteCustomHotkeyWarning">Voulez-vous vraiment supprimer {0} raccourci(s) ?</system:String>
|
||||
|
||||
<!--Setting Proxy-->
|
||||
<system:String x:Key="proxy">Proxy</system:String>
|
||||
<system:String x:Key="enableProxy">Activer le proxy</system:String>
|
||||
<system:String x:Key="server">Serveur</system:String>
|
||||
<system:String x:Key="proxy">HTTP Proxy</system:String>
|
||||
<system:String x:Key="enableProxy">Activer le HTTP proxy</system:String>
|
||||
<system:String x:Key="server">HTTP Serveur</system:String>
|
||||
<system:String x:Key="port">Port</system:String>
|
||||
<system:String x:Key="userName">Utilisateur</system:String>
|
||||
<system:String x:Key="password">Mot de passe</system:String>
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@
|
|||
<system:String x:Key="deleteCustomHotkeyWarning">{0} プラグインのホットキーを本当に削除しますか?</system:String>
|
||||
|
||||
<!--Setting Proxy-->
|
||||
<system:String x:Key="proxy">プロキシ</system:String>
|
||||
<system:String x:Key="enableProxy">プロキシを有効化</system:String>
|
||||
<system:String x:Key="server">サーバ</system:String>
|
||||
<system:String x:Key="proxy">HTTP プロキシ</system:String>
|
||||
<system:String x:Key="enableProxy">HTTP プロキシを有効化</system:String>
|
||||
<system:String x:Key="server">HTTP サーバ</system:String>
|
||||
<system:String x:Key="port">ポート</system:String>
|
||||
<system:String x:Key="userName">ユーザ名</system:String>
|
||||
<system:String x:Key="password">パスワード</system:String>
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@
|
|||
<system:String x:Key="deleteCustomHotkeyWarning">Weet u zeker dat je {0} plugin sneltoets wilt verwijderen?</system:String>
|
||||
|
||||
<!--Setting Proxy-->
|
||||
<system:String x:Key="proxy">Proxy</system:String>
|
||||
<system:String x:Key="enableProxy">Enable Proxy</system:String>
|
||||
<system:String x:Key="server">Server</system:String>
|
||||
<system:String x:Key="proxy">HTTP Proxy</system:String>
|
||||
<system:String x:Key="enableProxy">Enable HTTP Proxy</system:String>
|
||||
<system:String x:Key="server">HTTP Server</system:String>
|
||||
<system:String x:Key="port">Poort</system:String>
|
||||
<system:String x:Key="userName">Gebruikersnaam</system:String>
|
||||
<system:String x:Key="password">Wachtwoord</system:String>
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@
|
|||
<system:String x:Key="deleteCustomHotkeyWarning">Czy jesteś pewien że chcesz usunąć skrót klawiszowy {0} wtyczki?</system:String>
|
||||
|
||||
<!--Setting Proxy-->
|
||||
<system:String x:Key="proxy">Serwer proxy</system:String>
|
||||
<system:String x:Key="enableProxy">Używaj proxy</system:String>
|
||||
<system:String x:Key="server">Serwer</system:String>
|
||||
<system:String x:Key="proxy">Serwer proxy HTTP</system:String>
|
||||
<system:String x:Key="enableProxy">Używaj HTTP proxy</system:String>
|
||||
<system:String x:Key="server">HTTP Serwer</system:String>
|
||||
<system:String x:Key="port">Port</system:String>
|
||||
<system:String x:Key="userName">Nazwa użytkownika</system:String>
|
||||
<system:String x:Key="password">Hasło</system:String>
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@
|
|||
<system:String x:Key="deleteCustomHotkeyWarning">Вы уверены что хотите удалить горячую клавишу для плагина {0}?</system:String>
|
||||
|
||||
<!--Setting Proxy-->
|
||||
<system:String x:Key="proxy">Прокси</system:String>
|
||||
<system:String x:Key="enableProxy">Включить прокси</system:String>
|
||||
<system:String x:Key="server">Сервер</system:String>
|
||||
<system:String x:Key="proxy">HTTP Прокси</system:String>
|
||||
<system:String x:Key="enableProxy">Включить HTTP прокси</system:String>
|
||||
<system:String x:Key="server">HTTP Сервер</system:String>
|
||||
<system:String x:Key="port">Порт</system:String>
|
||||
<system:String x:Key="userName">Логин</system:String>
|
||||
<system:String x:Key="password">Пароль</system:String>
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@
|
|||
<system:String x:Key="deleteCustomHotkeyWarning">你确定要删除插件 {0} 的热键吗?</system:String>
|
||||
|
||||
<!--设置,代理-->
|
||||
<system:String x:Key="proxy">代理</system:String>
|
||||
<system:String x:Key="enableProxy">启用代理</system:String>
|
||||
<system:String x:Key="server">服务器</system:String>
|
||||
<system:String x:Key="proxy">HTTP 代理</system:String>
|
||||
<system:String x:Key="enableProxy">启用 HTTP 代理</system:String>
|
||||
<system:String x:Key="server">HTTP 服务器</system:String>
|
||||
<system:String x:Key="port">端口</system:String>
|
||||
<system:String x:Key="userName">用户名</system:String>
|
||||
<system:String x:Key="password">密码</system:String>
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@
|
|||
<system:String x:Key="deleteCustomHotkeyWarning">確定要刪除外掛 {0} 的熱鍵嗎?</system:String>
|
||||
|
||||
<!--設置,代理-->
|
||||
<system:String x:Key="proxy">代理</system:String>
|
||||
<system:String x:Key="enableProxy">啟用代理</system:String>
|
||||
<system:String x:Key="server">伺服器</system:String>
|
||||
<system:String x:Key="proxy">HTTP 代理</system:String>
|
||||
<system:String x:Key="enableProxy">啟用 HTTP 代理</system:String>
|
||||
<system:String x:Key="server">HTTP 伺服器</system:String>
|
||||
<system:String x:Key="Port">Port</system:String>
|
||||
<system:String x:Key="userName">使用者</system:String>
|
||||
<system:String x:Key="password">密碼</system:String>
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ using System.Windows.Media.Animation;
|
|||
using System.Windows.Controls;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.ViewModel;
|
||||
using Screen = System.Windows.Forms.Screen;
|
||||
using ContextMenu = System.Windows.Forms.ContextMenu;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:wox="clr-namespace:Wox"
|
||||
xmlns:s="clr-namespace:Wox.Core.UserSettings;assembly=Wox.Core"
|
||||
xmlns:vm="clr-namespace:Wox.ViewModel"
|
||||
xmlns:userSettings="clr-namespace:Wox.Infrastructure.UserSettings;assembly=Wox.Infrastructure"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
x:Class="Wox.SettingWindow"
|
||||
mc:Ignorable="d"
|
||||
Icon="Images\app.png"
|
||||
|
|
@ -82,10 +83,10 @@
|
|||
<Image Source="{Binding Image, IsAsync=True}"
|
||||
Width="32" Height="32" />
|
||||
<StackPanel Margin="3 0 3 0">
|
||||
<TextBlock Text="{Binding Metadata.Name}"
|
||||
ToolTip="{Binding Metadata.Name}" />
|
||||
<TextBlock Text="{Binding Metadata.Description}"
|
||||
ToolTip="{Binding Metadata.Description}"
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Name}"
|
||||
ToolTip="{Binding PluginPair.Metadata.Name}" />
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Description}"
|
||||
ToolTip="{Binding PluginPair.Metadata.Description}"
|
||||
Opacity="0.5" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
|
@ -118,8 +119,8 @@
|
|||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding Metadata.Name}"
|
||||
ToolTip="{Binding Metadata.Name}"
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Name}"
|
||||
ToolTip="{Binding PluginPair.Metadata.Name}"
|
||||
Grid.Column="0"
|
||||
Cursor="Hand" MouseUp="OnPluginNameClick" FontSize="24"
|
||||
HorizontalAlignment="Left" />
|
||||
|
|
@ -127,14 +128,14 @@
|
|||
VerticalAlignment="Bottom" Opacity="0.5">
|
||||
<TextBlock Text="{DynamicResource author}" />
|
||||
<TextBlock Text=": " />
|
||||
<TextBlock Text="{Binding Metadata.Author}" ToolTip="{Binding Metadata.Author}" />
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Author}" ToolTip="{Binding PluginPair.Metadata.Author}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<TextBlock Text="{Binding Metadata.Description}"
|
||||
ToolTip="{Binding Metadata.Description}"
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Description}"
|
||||
ToolTip="{Binding PluginPair.Metadata.Description}"
|
||||
Grid.Row="1" Opacity="0.5" />
|
||||
<DockPanel Grid.Row="2" Margin="0 10 0 8">
|
||||
<CheckBox IsChecked="{Binding Metadata.Disabled}" Checked="OnPluginToggled"
|
||||
<CheckBox IsChecked="{Binding PluginPair.Metadata.Disabled}" Checked="OnPluginToggled"
|
||||
Unchecked="OnPluginToggled">
|
||||
<TextBlock Text="{DynamicResource disable}" />
|
||||
</CheckBox>
|
||||
|
|
@ -276,14 +277,14 @@
|
|||
<GridView>
|
||||
<GridViewColumn Header="{DynamicResource hotkey}" Width="180">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate DataType="s:CustomPluginHotkey">
|
||||
<DataTemplate DataType="userSettings:CustomPluginHotkey">
|
||||
<TextBlock Text="{Binding Hotkey}" />
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
<GridViewColumn Header="{DynamicResource actionKeywords}" Width="500">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate DataType="s:CustomPluginHotkey">
|
||||
<DataTemplate DataType="userSettings:CustomPluginHotkey">
|
||||
<TextBlock Text="{Binding ActionKeyword}" />
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
|
|
@ -304,10 +305,10 @@
|
|||
</TabItem>
|
||||
<TabItem Header="{DynamicResource proxy}">
|
||||
<StackPanel>
|
||||
<CheckBox Margin="10" IsChecked="{Binding Settings.ProxyEnabled}">
|
||||
<CheckBox Margin="10" IsChecked="{Binding Settings.Proxy.Enabled}">
|
||||
<TextBlock Text="{DynamicResource enableProxy}" />
|
||||
</CheckBox>
|
||||
<Grid Margin="10" IsEnabled="{Binding Settings.ProxyEnabled}">
|
||||
<Grid Margin="10" IsEnabled="{Binding Settings.Proxy.Enabled}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
|
|
@ -319,15 +320,15 @@
|
|||
<ColumnDefinition Width="200" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{DynamicResource server}" Grid.Row="0" Grid.Column="0" Padding="5" />
|
||||
<TextBox Text="{Binding Settings.ProxyServer}" Grid.Row="0" Grid.Column="1" Padding="5" />
|
||||
<TextBox Text="{Binding Settings.Proxy.Server}" Grid.Row="0" Grid.Column="1" Padding="5" />
|
||||
<TextBlock Text="{DynamicResource port}" Grid.Row="0" Grid.Column="2" Padding="5" />
|
||||
<TextBox Text="{Binding Settings.ProxyPort}" Grid.Row="0" Grid.Column="3" Padding="5" />
|
||||
<TextBox Text="{Binding Settings.Proxy.Port, TargetNullValue={x:Static sys:String.Empty} }" Grid.Row="0" Grid.Column="3" Padding="5" />
|
||||
<TextBlock Text="{DynamicResource userName}" Grid.Row="1" Grid.Column="0" Padding="5" />
|
||||
<TextBox Text="{Binding Settings.ProxyUserName}" Grid.Row="1" Grid.Column="1" Padding="5" />
|
||||
<TextBox Text="{Binding Settings.Proxy.UserName}" Grid.Row="1" Grid.Column="1" Padding="5" />
|
||||
<TextBlock Text="{DynamicResource password}" Grid.Row="1" Grid.Column="2" Padding="5" />
|
||||
<TextBox Text="{Binding Settings.ProxyPassword}" Grid.Row="1" Grid.Column="3" Padding="5" />
|
||||
<TextBox Text="{Binding Settings.Proxy.Password}" Grid.Row="1" Grid.Column="3" Padding="5" />
|
||||
</Grid>
|
||||
<Button Content="{DynamicResource testProxy}" IsEnabled="{Binding Settings.ProxyEnabled}"
|
||||
<Button Content="{DynamicResource testProxy}" IsEnabled="{Binding Settings.Proxy.Enabled}"
|
||||
Width="80" HorizontalAlignment="Left" Margin="10" Click="OnTestProxyClick" />
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ using NHotkey.Wpf;
|
|||
using Wox.Core;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.ViewModel;
|
||||
|
||||
|
|
@ -214,15 +214,15 @@ namespace Wox
|
|||
|
||||
private void OnPluginToggled(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var id = _viewModel.SelectedPlugin.Metadata.ID;
|
||||
_settings.PluginSettings.Plugins[id].Disabled = _viewModel.SelectedPlugin.Metadata.Disabled;
|
||||
var id = _viewModel.SelectedPlugin.PluginPair.Metadata.ID;
|
||||
_settings.PluginSettings.Plugins[id].Disabled = _viewModel.SelectedPlugin.PluginPair.Metadata.Disabled;
|
||||
}
|
||||
|
||||
private void OnPluginActionKeywordsClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var id = _viewModel.SelectedPlugin.Metadata.ID;
|
||||
var id = _viewModel.SelectedPlugin.PluginPair.Metadata.ID;
|
||||
ActionKeywords changeKeywordsWindow = new ActionKeywords(id, _settings);
|
||||
changeKeywordsWindow.ShowDialog();
|
||||
}
|
||||
|
|
@ -234,7 +234,7 @@ namespace Wox
|
|||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var website = _viewModel.SelectedPlugin.Metadata.Website;
|
||||
var website = _viewModel.SelectedPlugin.PluginPair.Metadata.Website;
|
||||
if (!string.IsNullOrEmpty(website))
|
||||
{
|
||||
var uri = new Uri(website);
|
||||
|
|
@ -251,7 +251,7 @@ namespace Wox
|
|||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var directory = _viewModel.SelectedPlugin.Metadata.PluginDirectory;
|
||||
var directory = _viewModel.SelectedPlugin.PluginPair.Metadata.PluginDirectory;
|
||||
if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
|
||||
{
|
||||
Process.Start(directory);
|
||||
|
|
@ -264,29 +264,27 @@ namespace Wox
|
|||
|
||||
private void OnTestProxyClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_settings.ProxyServer))
|
||||
if (string.IsNullOrEmpty(_settings.Proxy.Server))
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
|
||||
return;
|
||||
}
|
||||
if (_settings.ProxyPort > 0)
|
||||
if (_settings.Proxy.Port <= 0)
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
|
||||
return;
|
||||
}
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Infrastructure.Constant.Github);
|
||||
request.Timeout = 1000 * 5;
|
||||
request.ReadWriteTimeout = 1000 * 5;
|
||||
if (string.IsNullOrEmpty(_settings.ProxyUserName) || string.IsNullOrEmpty(_settings.ProxyPassword))
|
||||
if (string.IsNullOrEmpty(_settings.Proxy.UserName) || string.IsNullOrEmpty(_settings.Proxy.Password))
|
||||
{
|
||||
request.Proxy = new WebProxy(_settings.ProxyServer, _settings.ProxyPort);
|
||||
request.Proxy = new WebProxy(_settings.Proxy.Server, _settings.Proxy.Port);
|
||||
}
|
||||
else
|
||||
{
|
||||
request.Proxy = new WebProxy(_settings.ProxyServer, _settings.ProxyPort)
|
||||
request.Proxy = new WebProxy(_settings.Proxy.Server, _settings.Proxy.Port)
|
||||
{
|
||||
Credentials = new NetworkCredential(_settings.ProxyUserName, _settings.ProxyPassword)
|
||||
Credentials = new NetworkCredential(_settings.Proxy.UserName, _settings.Proxy.Password)
|
||||
};
|
||||
}
|
||||
try
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ using NHotkey;
|
|||
using NHotkey.Wpf;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using Wox.Infrastructure.Image;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.Storage;
|
||||
|
||||
|
|
@ -57,12 +57,6 @@ namespace Wox.ViewModel
|
|||
|
||||
_settings = settings;
|
||||
|
||||
// happlebao todo temp fix for instance code logic
|
||||
HttpProxy.Instance.Settings = _settings;
|
||||
InternationalizationManager.Instance.Settings = _settings;
|
||||
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
|
||||
ThemeManager.Instance.Settings = _settings;
|
||||
|
||||
_queryHistoryStorage = new JsonStrorage<QueryHistory>();
|
||||
_userSelectedRecordStorage = new JsonStrorage<UserSelectedRecord>();
|
||||
_topMostRecordStorage = new JsonStrorage<TopMostRecord>();
|
||||
|
|
|
|||
|
|
@ -9,15 +9,13 @@ namespace Wox.ViewModel
|
|||
public class PluginViewModel : BaseModel
|
||||
{
|
||||
public PluginPair PluginPair { get; set; }
|
||||
public PluginMetadata Metadata { get; set; }
|
||||
public IPlugin Plugin { get; set; }
|
||||
|
||||
private readonly Internationalization _translator = InternationalizationManager.Instance;
|
||||
|
||||
public ImageSource Image => ImageLoader.Load(Metadata.IcoPath);
|
||||
public Visibility ActionKeywordsVisibility => Metadata.ActionKeywords.Count > 1 ? Visibility.Collapsed : Visibility.Visible;
|
||||
public string InitilizaTime => string.Format(_translator.GetTranslation("plugin_init_time"), Metadata.InitTime);
|
||||
public string QueryTime => string.Format(_translator.GetTranslation("plugin_query_time"), Metadata.AvgQueryTime);
|
||||
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeperater, Metadata.ActionKeywords);
|
||||
public ImageSource Image => ImageLoader.Load(PluginPair.Metadata.IcoPath);
|
||||
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.ActionKeywords.Count > 1 ? Visibility.Collapsed : Visibility.Visible;
|
||||
public string InitilizaTime => string.Format(_translator.GetTranslation("plugin_init_time"), PluginPair.Metadata.InitTime);
|
||||
public string QueryTime => string.Format(_translator.GetTranslation("plugin_query_time"), PluginPair.Metadata.AvgQueryTime);
|
||||
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeperater, PluginPair.Metadata.ActionKeywords);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,14 +36,7 @@ namespace Wox.ViewModel
|
|||
|
||||
public string PluginID => RawResult.PluginID;
|
||||
|
||||
public ImageSource Image
|
||||
{
|
||||
get
|
||||
{
|
||||
var image = ImageLoader.Load(RawResult.IcoPath);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
public ImageSource Image => ImageLoader.Load(RawResult.IcoPath);
|
||||
|
||||
public int Score
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Collections.ObjectModel;
|
|||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.ViewModel
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@ using System.Windows.Media;
|
|||
using System.Windows.Media.Imaging;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Http;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.ViewModel
|
||||
|
|
@ -31,6 +32,12 @@ namespace Wox.ViewModel
|
|||
OnPropertyChanged(nameof(ActivatedTimes));
|
||||
}
|
||||
};
|
||||
|
||||
// happlebao todo temp fix for instance code logic
|
||||
InternationalizationManager.Instance.Settings = Settings;
|
||||
InternationalizationManager.Instance.ChangeLanguage(Settings.Language);
|
||||
ThemeManager.Instance.Settings = Settings;
|
||||
Http.Proxy = Settings.Proxy;
|
||||
}
|
||||
|
||||
public Settings Settings { get; set; }
|
||||
|
|
@ -77,8 +84,6 @@ namespace Wox.ViewModel
|
|||
var metadatas = plugins.Select(p => new PluginViewModel
|
||||
{
|
||||
PluginPair = p,
|
||||
Metadata = p.Metadata,
|
||||
Plugin = p.Plugin
|
||||
}).ToList();
|
||||
return metadatas;
|
||||
}
|
||||
|
|
@ -88,23 +93,9 @@ namespace Wox.ViewModel
|
|||
{
|
||||
get
|
||||
{
|
||||
var settingProvider = SelectedPlugin.Plugin as ISettingProvider;
|
||||
var settingProvider = SelectedPlugin.PluginPair.Plugin as ISettingProvider;
|
||||
if (settingProvider != null)
|
||||
{
|
||||
var multipleActionKeywordsProvider = settingProvider as IMultipleActionKeywords;
|
||||
if (multipleActionKeywordsProvider != null)
|
||||
{
|
||||
multipleActionKeywordsProvider.ActionKeywordsChanged += (o, e) =>
|
||||
{
|
||||
// update in-memory data
|
||||
PluginManager.UpdateActionKeywordForPlugin(SelectedPlugin.PluginPair, e.OldActionKeyword,
|
||||
e.NewActionKeyword);
|
||||
// update persistant data
|
||||
Settings.PluginSettings.UpdateActionKeyword(SelectedPlugin.Metadata);
|
||||
|
||||
MessageBox.Show(_translater.GetTranslation("succeed"));
|
||||
};
|
||||
}
|
||||
var control = settingProvider.CreateSettingPanel();
|
||||
control.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
control.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
|
|
@ -117,6 +108,8 @@ namespace Wox.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region theme
|
||||
|
|
|
|||
Loading…
Reference in a new issue