mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 19:19:23 +08:00
close #21 Allow user to set their custom ActionKeyword
This commit is contained in:
parent
e275ce6063
commit
7bcbe5d791
35
Wox/ActionKeyword.xaml
Normal file
35
Wox/ActionKeyword.xaml
Normal file
@ -0,0 +1,35 @@
|
||||
<Window x:Class="Wox.ActionKeyword"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="ActionKeyword"
|
||||
Icon="Images\app.png"
|
||||
ResizeMode="NoResize"
|
||||
Loaded="ActionKeyword_OnLoaded"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Height="200" Width="674.766">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Old ActionKeyword:</TextBlock>
|
||||
<TextBlock x:Name="tbOldActionKeyword" Margin="10" FontSize="14" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left">Old ActionKeyword:</TextBlock>
|
||||
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">New ActionKeyword:</TextBlock>
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1" >
|
||||
<TextBox x:Name="tbAction" Margin="10" Width="400" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="2" Grid.Column="1">
|
||||
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="25">Cancel</Button>
|
||||
<Button x:Name="btnDone" Margin="10 0 10 0" Width="80" Height="25" Click="btnDone_OnClick">
|
||||
<TextBlock x:Name="lblAdd">Done</TextBlock>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
89
Wox/ActionKeyword.xaml.cs
Normal file
89
Wox/ActionKeyword.xaml.cs
Normal file
@ -0,0 +1,89 @@
|
||||
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.Storage.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.PluginLoader;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace Wox
|
||||
{
|
||||
public partial class ActionKeyword : Window
|
||||
{
|
||||
private PluginMetadata pluginMetadata;
|
||||
|
||||
public ActionKeyword(string pluginId)
|
||||
{
|
||||
InitializeComponent();
|
||||
PluginPair plugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ID == pluginId);
|
||||
if (plugin == null)
|
||||
{
|
||||
MessageBox.Show("Can't find specific plugin");
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
pluginMetadata = plugin.Metadata;
|
||||
}
|
||||
|
||||
private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
tbOldActionKeyword.Text = pluginMetadata.ActionKeyword;
|
||||
tbAction.Focus();
|
||||
}
|
||||
|
||||
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnDone_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tbAction.Text))
|
||||
{
|
||||
MessageBox.Show("New ActionKeyword can't be empty");
|
||||
return;
|
||||
}
|
||||
|
||||
//check new action keyword didn't used by other plugin
|
||||
if (Plugins.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim()))
|
||||
{
|
||||
MessageBox.Show("New ActionKeyword has been assigned to other plugin, please assign another new action keyword");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
pluginMetadata.ActionKeyword = tbAction.Text.Trim();
|
||||
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginMetadata.ID);
|
||||
if (customizedPluginConfig == null)
|
||||
{
|
||||
UserSettingStorage.Instance.CustomizedPluginConfigs.Add(new CustomizedPluginConfig()
|
||||
{
|
||||
Disabled = false,
|
||||
ID = pluginMetadata.ID,
|
||||
Name = pluginMetadata.Name,
|
||||
Actionword = tbAction.Text.Trim()
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
customizedPluginConfig.Actionword = tbAction.Text.Trim();
|
||||
}
|
||||
UserSettingStorage.Instance.Save();
|
||||
MessageBox.Show("Sucessfully applied the new action keyword");
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.SystemPlugins;
|
||||
|
||||
@ -104,6 +105,13 @@ namespace Wox.PluginLoader {
|
||||
return null;
|
||||
}
|
||||
|
||||
var customizedPluginConfig =
|
||||
UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID);
|
||||
if (customizedPluginConfig != null && !string.IsNullOrEmpty(customizedPluginConfig.Actionword))
|
||||
{
|
||||
metadata.ActionKeyword = customizedPluginConfig.Actionword;
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,10 @@
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock x:Name="pluginTitle" ToolTip="{Binding Source=pluginTitle, Path=Text}" FontSize="24"></TextBlock>
|
||||
<TextBlock Grid.Row="1" x:Name="pluginSubTitle" Opacity="0.5" ToolTip="{Binding Source=pluginSubTitle, Path=Text}" Visibility="{Binding Source=pluginSubTitle, Path=Text, Converter={converters:StringNullOrEmptyToVisibilityConverter}}" ></TextBlock>
|
||||
<TextBlock Grid.Row="2" Opacity="0.5" x:Name="pluginActionKeyword"></TextBlock>
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal">
|
||||
<TextBlock>ActionKeyword: </TextBlock>
|
||||
<TextBlock Cursor="Hand" MouseUp="PluginActionKeyword_OnMouseUp" Foreground="Blue" x:Name="pluginActionKeyword"></TextBlock>
|
||||
</StackPanel>
|
||||
<DockPanel Grid.Row="3">
|
||||
<TextBlock Opacity="0.5" x:Name="pluginAuthor"></TextBlock>
|
||||
<TextBlock Opacity="0.5" x:Name="pluginWebsite" HorizontalAlignment="Right"></TextBlock>
|
||||
|
@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using IWshRuntimeLibrary;
|
||||
@ -433,7 +434,7 @@ namespace Wox
|
||||
pluginActionKeyword.Visibility = Visibility.Visible;
|
||||
pluginWebsite.Visibility = Visibility.Visible;
|
||||
pluginTitle.Text = pair.Metadata.Name;
|
||||
pluginActionKeyword.Text = "ActionKeyword: " + pair.Metadata.ActionKeyword;
|
||||
pluginActionKeyword.Text = pair.Metadata.ActionKeyword;
|
||||
pluginAuthor.Text = "Author: " + pair.Metadata.Author;
|
||||
pluginWebsite.Text = "Website: " + pair.Metadata.Website;
|
||||
pluginSubTitle.Text = pair.Metadata.Description;
|
||||
@ -532,5 +533,22 @@ namespace Wox
|
||||
}
|
||||
UserSettingStorage.Instance.Save();
|
||||
}
|
||||
|
||||
private void PluginActionKeyword_OnMouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var pair = lbPlugins.SelectedItem as PluginPair;
|
||||
if (pair != null)
|
||||
{
|
||||
//third-party plugin
|
||||
string id = pair.Metadata.ID;
|
||||
ActionKeyword changeKeywordWindow = new ActionKeyword(id);
|
||||
changeKeywordWindow.ShowDialog();
|
||||
PluginPair plugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
||||
if (plugin != null) pluginActionKeyword.Text = plugin.Metadata.ActionKeyword;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,9 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="ActionKeyword.xaml.cs">
|
||||
<DependentUpon>ActionKeyword.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Commands\BaseCommand.cs" />
|
||||
<Compile Include="Commands\CommandFactory.cs" />
|
||||
<Compile Include="Commands\PluginCommand.cs" />
|
||||
@ -152,6 +155,10 @@
|
||||
</Compile>
|
||||
<Compile Include="Converters\StringEmptyConverter.cs" />
|
||||
<Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" />
|
||||
<Page Include="ActionKeyword.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Helper\ErrorReporting\WPFErrorReportingDialog.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
Loading…
Reference in New Issue
Block a user