-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #21 Allow user to set their custom ActionKeyword
- Loading branch information
1 parent
e275ce6
commit 7bcbe5d
Showing
6 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters