mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
Move WebSearch into featureBox
This commit is contained in:
@@ -11,7 +11,7 @@ using Wox.Plugin.SystemPlugins.SuggestionSources;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins
|
||||
{
|
||||
public class WebSearchPlugin : BaseSystemPlugin
|
||||
public class WebSearchPlugin : BaseSystemPlugin, ISettingProvider
|
||||
{
|
||||
private PluginInitContext context;
|
||||
|
||||
@@ -96,5 +96,14 @@ namespace Wox.Plugin.SystemPlugins
|
||||
{
|
||||
get { return base.Description; }
|
||||
}
|
||||
|
||||
#region ISettingProvider Members
|
||||
|
||||
public System.Windows.Controls.Control CreateSettingPanel()
|
||||
{
|
||||
return new WebSearchesSetting();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
43
Wox.Plugin.SystemPlugins/WebSearchSetting.xaml
Normal file
43
Wox.Plugin.SystemPlugins/WebSearchSetting.xaml
Normal file
@@ -0,0 +1,43 @@
|
||||
<Window x:Class="Wox.Plugin.SystemPlugins.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">Title:</TextBlock>
|
||||
<TextBox x:Name="tbTitle" 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">URL:</TextBlock>
|
||||
<TextBox x:Name="tbUrl" 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">ActionWord:</TextBlock>
|
||||
<TextBox x:Name="tbActionword" 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">Enable:</TextBlock>
|
||||
<CheckBox x:Name="cbEnable" 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">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">Select Icon</Button>
|
||||
<TextBlock x:Name="tbIconPath" Visibility="Hidden"></TextBlock>
|
||||
</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">Cancel</Button>
|
||||
<Button x:Name="btnAdd" Margin="10 0 10 0" Width="80" Height="25" Click="btnAdd_OnClick"><TextBlock x:Name="lblAdd">Add</TextBlock></Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
147
Wox.Plugin.SystemPlugins/WebSearchSetting.xaml.cs
Normal file
147
Wox.Plugin.SystemPlugins/WebSearchSetting.xaml.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins
|
||||
{
|
||||
public partial class WebSearchSetting : Window
|
||||
{
|
||||
private WebSearchesSetting settingWindow;
|
||||
private bool update;
|
||||
private WebSearch updateWebSearch;
|
||||
|
||||
public WebSearchSetting(WebSearchesSetting settingWidow)
|
||||
{
|
||||
this.settingWindow = settingWidow;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void UpdateItem(WebSearch webSearch)
|
||||
{
|
||||
updateWebSearch = UserSettingStorage.Instance.WebSearches.FirstOrDefault(o => o == webSearch);
|
||||
if (updateWebSearch == null || string.IsNullOrEmpty(updateWebSearch.Url))
|
||||
{
|
||||
MessageBox.Show("Invalid web search");
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
update = 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.ActionWord;
|
||||
}
|
||||
|
||||
private void ShowIcon(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
imgIcon.Source = new BitmapImage(new Uri(path));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string title = tbTitle.Text;
|
||||
if (string.IsNullOrEmpty(title))
|
||||
{
|
||||
MessageBox.Show("Please input Title field");
|
||||
return;
|
||||
}
|
||||
|
||||
string url = tbUrl.Text;
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
MessageBox.Show("Please input URL field");
|
||||
return;
|
||||
}
|
||||
|
||||
string action = tbActionword.Text;
|
||||
if (string.IsNullOrEmpty(action))
|
||||
{
|
||||
MessageBox.Show("Please input ActionWord field");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!update)
|
||||
{
|
||||
if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == action))
|
||||
{
|
||||
MessageBox.Show("ActionWord has existed, please input a new one.");
|
||||
return;
|
||||
}
|
||||
UserSettingStorage.Instance.WebSearches.Add(new WebSearch()
|
||||
{
|
||||
ActionWord = action,
|
||||
Enabled = cbEnable.IsChecked ?? false,
|
||||
IconPath = tbIconPath.Text,
|
||||
Url = url,
|
||||
Title = title
|
||||
});
|
||||
MessageBox.Show(string.Format("Add {0} web search successfully!", title));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == action && o != updateWebSearch))
|
||||
{
|
||||
MessageBox.Show("ActionWord has existed, please input a new one.");
|
||||
return;
|
||||
}
|
||||
updateWebSearch.ActionWord = action;
|
||||
updateWebSearch.IconPath = tbIconPath.Text;
|
||||
updateWebSearch.Enabled = cbEnable.IsChecked ?? false;
|
||||
updateWebSearch.Url = url;
|
||||
updateWebSearch.Title= title;
|
||||
MessageBox.Show(string.Format("Update {0} web search successfully!", title));
|
||||
}
|
||||
UserSettingStorage.Instance.Save();
|
||||
settingWindow.ReloadWebSearchView();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void BtnSelectIcon_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dlg = new Microsoft.Win32.OpenFileDialog
|
||||
{
|
||||
DefaultExt = ".png",
|
||||
Filter =
|
||||
"JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif"
|
||||
};
|
||||
|
||||
bool? result = dlg.ShowDialog();
|
||||
if (result == true)
|
||||
{
|
||||
string filename = dlg.FileName;
|
||||
tbIconPath.Text = filename;
|
||||
ShowIcon(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Wox.Plugin.SystemPlugins/WebSearchesSetting.xaml
Normal file
39
Wox.Plugin.SystemPlugins/WebSearchesSetting.xaml
Normal file
@@ -0,0 +1,39 @@
|
||||
<UserControl x:Class="Wox.Plugin.SystemPlugins.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="300">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="50"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ListView x:Name="webSearchView" Grid.Row="0">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="ActionWord" Width="180">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding ActionWord}"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
<GridViewColumn Header="Url" Width="500">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Url}"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<Button x:Name="btnDeleteWebSearch" Click="btnDeleteWebSearch_OnClick" Width="100" Margin="10" Content="Delete"/>
|
||||
<Button x:Name="btnEditWebSearch" Click="btnEditWebSearch_OnClick" Width="100" Margin="10" Content="Edit"/>
|
||||
<Button x:Name="btnAddWebSearch" Click="btnAddWebSearch_OnClick" Width="100" Margin="10" Content="Add"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
79
Wox.Plugin.SystemPlugins/WebSearchesSetting.xaml.cs
Normal file
79
Wox.Plugin.SystemPlugins/WebSearchesSetting.xaml.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for WebSearchesSetting.xaml
|
||||
/// </summary>
|
||||
public partial class WebSearchesSetting : UserControl
|
||||
{
|
||||
public WebSearchesSetting()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Loaded += Setting_Loaded;
|
||||
}
|
||||
|
||||
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
webSearchView.ItemsSource = UserSettingStorage.Instance.WebSearches;
|
||||
}
|
||||
|
||||
public void ReloadWebSearchView()
|
||||
{
|
||||
webSearchView.Items.Refresh();
|
||||
}
|
||||
|
||||
|
||||
private void btnAddWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
WebSearchSetting webSearch = new WebSearchSetting(this);
|
||||
webSearch.ShowDialog();
|
||||
}
|
||||
|
||||
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
WebSearch seletedWebSearch = webSearchView.SelectedItem as WebSearch;
|
||||
if (seletedWebSearch != null &&
|
||||
MessageBox.Show("Are your sure to delete " + seletedWebSearch.Title, "Delete WebSearch",
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
UserSettingStorage.Instance.WebSearches.Remove(seletedWebSearch);
|
||||
webSearchView.Items.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Please select a web search");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
WebSearch seletedWebSearch = webSearchView.SelectedItem as WebSearch;
|
||||
if (seletedWebSearch != null)
|
||||
{
|
||||
WebSearchSetting webSearch = new WebSearchSetting(this);
|
||||
webSearch.UpdateItem(seletedWebSearch);
|
||||
webSearch.ShowDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Please select a web search");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,9 @@
|
||||
<Compile Include="Calculator.cs" />
|
||||
<Compile Include="ProgramSources\FileSystemProgramSource.cs" />
|
||||
<Compile Include="ProgramSources\UserStartMenuProgramSource.cs" />
|
||||
<Compile Include="WebSearchesSetting.xaml.cs">
|
||||
<DependentUpon>WebSearchesSetting.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="WebSearchPlugin.cs" />
|
||||
<Compile Include="CMD\CMD.cs" />
|
||||
<Compile Include="DirectoryIndicator.cs" />
|
||||
@@ -80,6 +83,9 @@
|
||||
<Compile Include="ThirdpartyPluginIndicator.cs" />
|
||||
<Compile Include="SuggestionSources\Google.cs" />
|
||||
<Compile Include="SuggestionSources\ISuggestionSource.cs" />
|
||||
<Compile Include="WebSearchSetting.xaml.cs">
|
||||
<DependentUpon>WebSearchSetting.xaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||
@@ -103,6 +109,14 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="WebSearchesSetting.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="WebSearchSetting.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user