mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
@@ -12,7 +12,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Google",
|
||||
ActionKeyword = "g",
|
||||
IconPath = "Images\\google.png",
|
||||
IconPath = "google.png",
|
||||
Url = "https://www.google.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -20,7 +20,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Wikipedia",
|
||||
ActionKeyword = "wiki",
|
||||
IconPath = "Images\\wiki.png",
|
||||
IconPath = "wiki.png",
|
||||
Url = "http://en.wikipedia.org/wiki/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -28,7 +28,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "FindIcon",
|
||||
ActionKeyword = "findicon",
|
||||
IconPath = "Images\\pictures.png",
|
||||
IconPath = "pictures.png",
|
||||
Url = "http://findicons.com/search/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -36,7 +36,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Facebook",
|
||||
ActionKeyword = "facebook",
|
||||
IconPath = "Images\\facebook.png",
|
||||
IconPath = "facebook.png",
|
||||
Url = "http://www.facebook.com/search/?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -44,7 +44,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Twitter",
|
||||
ActionKeyword = "twitter",
|
||||
IconPath = "Images\\twitter.png",
|
||||
IconPath = "twitter.png",
|
||||
Url = "http://twitter.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -52,7 +52,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Google Maps",
|
||||
ActionKeyword = "maps",
|
||||
IconPath = "Images\\google_maps.png",
|
||||
IconPath = "google_maps.png",
|
||||
Url = "http://maps.google.com/maps?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -60,7 +60,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Google Translate",
|
||||
ActionKeyword = "translate",
|
||||
IconPath = "Images\\google_translate.png",
|
||||
IconPath = "google_translate.png",
|
||||
Url = "http://translate.google.com/#auto|en|{q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -68,7 +68,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Duckduckgo",
|
||||
ActionKeyword = "duckduckgo",
|
||||
IconPath = "Images\\duckduckgo.png",
|
||||
IconPath = "duckduckgo.png",
|
||||
Url = "https://duckduckgo.com/?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -76,7 +76,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Github",
|
||||
ActionKeyword = "github",
|
||||
IconPath = "Images\\github.png",
|
||||
IconPath = "github.png",
|
||||
Url = "https://github.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -84,7 +84,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Github Gist",
|
||||
ActionKeyword = "gist",
|
||||
IconPath = "Images\\gist.png",
|
||||
IconPath = "gist.png",
|
||||
Url = "https://gist.github.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -92,7 +92,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Gmail",
|
||||
ActionKeyword = "gmail",
|
||||
IconPath = "Images\\gmail.png",
|
||||
IconPath = "gmail.png",
|
||||
Url = "https://mail.google.com/mail/ca/u/0/#apps/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -100,7 +100,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Google Drive",
|
||||
ActionKeyword = "drive",
|
||||
IconPath = "Images\\google_drive.png",
|
||||
IconPath = "google_drive.png",
|
||||
Url = "http://drive.google.com/?hl=en&tab=bo#search/{q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -108,7 +108,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Wolframalpha",
|
||||
ActionKeyword = "wolframalpha",
|
||||
IconPath = "Images\\wolframalpha.png",
|
||||
IconPath = "wolframalpha.png",
|
||||
Url = "http://www.wolframalpha.com/input/?i={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -116,7 +116,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Stackoverflow",
|
||||
ActionKeyword = "stackoverflow",
|
||||
IconPath = "Images\\stackoverflow.png",
|
||||
IconPath = "stackoverflow.png",
|
||||
Url = "http://stackoverflow.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -124,7 +124,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "I'm Feeling Lucky",
|
||||
ActionKeyword = "lucky",
|
||||
IconPath = "Images\\google.png",
|
||||
IconPath = "google.png",
|
||||
Url = "http://google.com/search?q={q}&btnI=I",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -132,7 +132,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Google Image",
|
||||
ActionKeyword = "image",
|
||||
IconPath = "Images\\google.png",
|
||||
IconPath = "google.png",
|
||||
Url = "https://www.google.com/search?q={q}&tbm=isch",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -140,7 +140,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Youtube",
|
||||
ActionKeyword = "youtube",
|
||||
IconPath = "Images\\youtube.png",
|
||||
IconPath = "youtube.png",
|
||||
Url = "http://www.youtube.com/results?search_query={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -148,7 +148,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Bing",
|
||||
ActionKeyword = "bing",
|
||||
IconPath = "Images\\bing.png",
|
||||
IconPath = "bing.png",
|
||||
Url = "https://www.bing.com/search?q={q}",
|
||||
Enabled = true
|
||||
},
|
||||
@@ -156,7 +156,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
Title = "Yahoo",
|
||||
ActionKeyword = "yahoo",
|
||||
IconPath = "Images\\yahoo.png",
|
||||
IconPath = "yahoo.png",
|
||||
Url = "http://www.search.yahoo.com/search?p={q}",
|
||||
Enabled = true
|
||||
}
|
||||
|
||||
@@ -18,27 +18,25 @@
|
||||
<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="tbTitle" Margin="10" Grid.Row="0" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
|
||||
<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="tbUrl" Margin="10" Grid.Row="1" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
|
||||
<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="tbActionword" Margin="10" Grid.Row="2" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
|
||||
<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="cbEnable" IsChecked="True" Margin="10" Grid.Row="3" Grid.Column="1" VerticalAlignment="Center"></CheckBox>
|
||||
<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="imgIcon" Width="24" Height="24" Margin="0 0 10 0" />
|
||||
<Button x:Name="btnSelectIcon" Height="24" Click="BtnSelectIcon_OnClick" Content="{DynamicResource wox_plugin_websearch_select_icon}"></Button>
|
||||
<TextBlock x:Name="tbIconPath" Visibility="Hidden"></TextBlock>
|
||||
<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="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="25" Content="{DynamicResource wox_plugin_websearch_cancel}"></Button>
|
||||
<Button x:Name="btnConfirm" Margin="10 0 10 0" Width="80" Height="25" Click="btnConfirm_OnClick">
|
||||
<TextBlock x:Name="lblAdd" Text="{DynamicResource wox_plugin_websearch_add}"></TextBlock></Button>
|
||||
<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>
|
||||
|
||||
@@ -2,37 +2,41 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Microsoft.Win32;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Exception;
|
||||
using Wox.Infrastructure.Image;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public partial class WebSearchSetting : Window
|
||||
{
|
||||
private const string _imageDirectoryName = "Images";
|
||||
private string _pluginDirectory = WoxDirectroy.Executable;
|
||||
private const string ImageDirectory = "Images";
|
||||
private const string DefaultIcon = "web_search.png";
|
||||
private readonly string _pluginDirectory;
|
||||
private readonly WebSearchesSetting _settingWindow;
|
||||
private bool _isUpdate;
|
||||
private WebSearch _updateWebSearch;
|
||||
private WebSearch _webSearch;
|
||||
private readonly PluginInitContext _context;
|
||||
private readonly WebSearchPlugin _plugin;
|
||||
private Settings _settings;
|
||||
private readonly Settings _settings;
|
||||
|
||||
public WebSearchSetting(WebSearchesSetting settingWidow, Settings settings)
|
||||
{
|
||||
InitializeComponent();
|
||||
_plugin = settingWidow.Plugin;
|
||||
_context = settingWidow.Context;
|
||||
_settingWindow = settingWidow;
|
||||
InitializeComponent();
|
||||
_settings = settings;
|
||||
_pluginDirectory = _settingWindow.Context.CurrentPluginMetadata.PluginDirectory;
|
||||
}
|
||||
|
||||
public void UpdateItem(WebSearch webSearch)
|
||||
{
|
||||
_updateWebSearch = _settings.WebSearches.FirstOrDefault(o => o == webSearch);
|
||||
if (_updateWebSearch == null || string.IsNullOrEmpty(_updateWebSearch.Url))
|
||||
_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");
|
||||
@@ -42,31 +46,61 @@ namespace Wox.Plugin.WebSearch
|
||||
}
|
||||
|
||||
_isUpdate = true;
|
||||
lblAdd.Text = "Update";
|
||||
tbIconPath.Text = webSearch.IconPath;
|
||||
ShowIcon(webSearch.IconPath);
|
||||
cbEnable.IsChecked = webSearch.Enabled;
|
||||
tbTitle.Text = webSearch.Title;
|
||||
tbUrl.Text = webSearch.Url;
|
||||
tbActionword.Text = webSearch.ActionKeyword;
|
||||
ConfirmButton.Content = "Update";
|
||||
WebSearchIcon.Source = LoadIcon(webSearch.IconPath);
|
||||
EnableCheckBox.IsChecked = webSearch.Enabled;
|
||||
WebSearchName.Text = webSearch.Title;
|
||||
Url.Text = webSearch.Url;
|
||||
Actionword.Text = webSearch.ActionKeyword;
|
||||
}
|
||||
|
||||
private void ShowIcon(string path)
|
||||
public void AddItem(WebSearch websearch)
|
||||
{
|
||||
imgIcon.Source = new BitmapImage(new Uri(Path.Combine(_pluginDirectory, path), UriKind.Absolute));
|
||||
_webSearch = websearch;
|
||||
if (string.IsNullOrEmpty(_webSearch.IconPath))
|
||||
{
|
||||
_webSearch.IconPath = DefaultIcon;
|
||||
WebSearchIcon.Source = LoadIcon(_webSearch.IconPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
||||
private void CancelButtonOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private ImageSource LoadIcon(string path)
|
||||
{
|
||||
if (path != null)
|
||||
{
|
||||
var releativePath = Path.Combine(_pluginDirectory, ImageDirectory, Path.GetFileName(path));
|
||||
if (File.Exists(releativePath))
|
||||
{
|
||||
_webSearch.IconPath = path;
|
||||
var source = ImageLoader.Load(releativePath);
|
||||
return source;
|
||||
}
|
||||
else
|
||||
{
|
||||
_webSearch.IconPath = path;
|
||||
var source = ImageLoader.Load(path);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var source = ImageLoader.Load(Path.Combine(_pluginDirectory, ImageDirectory, DefaultIcon));
|
||||
return source;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Confirm button for both add and update
|
||||
/// </summary>
|
||||
private void btnConfirm_OnClick(object sender, RoutedEventArgs e)
|
||||
private void ConfirmButtonOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string title = tbTitle.Text;
|
||||
string title = WebSearchName.Text;
|
||||
if (string.IsNullOrEmpty(title))
|
||||
{
|
||||
string warning = _context.API.GetTranslation("wox_plugin_websearch_input_title");
|
||||
@@ -74,7 +108,7 @@ namespace Wox.Plugin.WebSearch
|
||||
return;
|
||||
}
|
||||
|
||||
string url = tbUrl.Text;
|
||||
string url = Url.Text;
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
string warning = _context.API.GetTranslation("wox_plugin_websearch_input_url");
|
||||
@@ -82,24 +116,19 @@ namespace Wox.Plugin.WebSearch
|
||||
return;
|
||||
}
|
||||
|
||||
string newActionKeyword = tbActionword.Text.Trim();
|
||||
string newActionKeyword = Actionword.Text.Trim();
|
||||
|
||||
if (_isUpdate)
|
||||
{
|
||||
try
|
||||
{
|
||||
_plugin.NotifyActionKeywordsUpdated(_updateWebSearch.ActionKeyword, newActionKeyword);
|
||||
_plugin.NotifyActionKeywordsUpdated(_webSearch.ActionKeyword, newActionKeyword);
|
||||
}
|
||||
catch (WoxPluginException exception)
|
||||
{
|
||||
MessageBox.Show(exception.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
_updateWebSearch.ActionKeyword = newActionKeyword;
|
||||
_updateWebSearch.IconPath = tbIconPath.Text;
|
||||
_updateWebSearch.Enabled = cbEnable.IsChecked ?? false;
|
||||
_updateWebSearch.Url = url;
|
||||
_updateWebSearch.Title = title;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -112,42 +141,34 @@ namespace Wox.Plugin.WebSearch
|
||||
MessageBox.Show(exception.Message);
|
||||
return;
|
||||
}
|
||||
_settings.WebSearches.Add(new WebSearch
|
||||
{
|
||||
ActionKeyword = newActionKeyword,
|
||||
Enabled = cbEnable.IsChecked ?? false,
|
||||
IconPath = tbIconPath.Text,
|
||||
Url = url,
|
||||
Title = title
|
||||
});
|
||||
|
||||
_settings.WebSearches.Add(_webSearch);
|
||||
}
|
||||
|
||||
_webSearch.ActionKeyword = newActionKeyword;
|
||||
_webSearch.Enabled = EnableCheckBox.IsChecked ?? false;
|
||||
_webSearch.Url = url;
|
||||
_webSearch.Title = title;
|
||||
|
||||
_settingWindow.ReloadWebSearchView();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void BtnSelectIcon_OnClick(object sender, RoutedEventArgs e)
|
||||
private void SelectIconButtonOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!Directory.Exists(_pluginDirectory))
|
||||
{
|
||||
_pluginDirectory =
|
||||
Path.GetDirectoryName(WoxDirectroy.Executable);
|
||||
}
|
||||
|
||||
var dlg = new OpenFileDialog
|
||||
{
|
||||
InitialDirectory = Path.Combine(_pluginDirectory, _imageDirectoryName),
|
||||
InitialDirectory = Path.Combine(_pluginDirectory, ImageDirectory),
|
||||
Filter = "Image files (*.jpg, *.jpeg, *.gif, *.png, *.bmp) |*.jpg; *.jpeg; *.gif; *.png; *.bmp"
|
||||
};
|
||||
|
||||
bool? result = dlg.ShowDialog();
|
||||
if (result == true)
|
||||
if (result != null && result == true)
|
||||
{
|
||||
string filename = dlg.FileName;
|
||||
if (filename != null)
|
||||
string fullpath = dlg.FileName;
|
||||
if (fullpath != null)
|
||||
{
|
||||
tbIconPath.Text = Path.Combine(_imageDirectoryName, Path.GetFileName(filename));
|
||||
ShowIcon(tbIconPath.Text);
|
||||
WebSearchIcon.Source = LoadIcon(fullpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +53,12 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
private void btnAddWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
WebSearchSetting webSearch = new WebSearchSetting(this, _settings);
|
||||
webSearch.ShowDialog();
|
||||
var setting = new WebSearchSetting(this, _settings);
|
||||
var webSearch = new WebSearch();
|
||||
|
||||
|
||||
setting.AddItem(webSearch);
|
||||
setting.ShowDialog();
|
||||
}
|
||||
|
||||
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user