Skip to content

Commit

Permalink
close #21 Allow user to set their custom ActionKeyword
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlifeng committed Jul 4, 2014
1 parent e275ce6 commit 7bcbe5d
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 2 deletions.
35 changes: 35 additions & 0 deletions Wox/ActionKeyword.xaml
Original file line number Diff line number Diff line change
@@ -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 changes: 89 additions & 0 deletions Wox/ActionKeyword.xaml.cs
Original file line number Diff line number Diff line change
@@ -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();
}


}
}
8 changes: 8 additions & 0 deletions Wox/PluginLoader/BasePluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows.Forms;
using Newtonsoft.Json;
using Wox.Helper;
using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin;
using Wox.Plugin.SystemPlugins;

Expand Down Expand Up @@ -104,6 +105,13 @@ public abstract class BasePluginLoader {
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;
}
}
Expand Down
5 changes: 4 additions & 1 deletion Wox/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
20 changes: 19 additions & 1 deletion Wox/SettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -433,7 +434,7 @@ private void lbPlugins_OnSelectionChanged(object sender, SelectionChangedEventAr
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;
Expand Down Expand Up @@ -532,5 +533,22 @@ private void CbDisablePlugin_OnClick(object sender, RoutedEventArgs e)
}
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;
}
}
}
}
}
7 changes: 7 additions & 0 deletions Wox/Wox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 7bcbe5d

Please sign in to comment.