mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
Add custom plugin hotkey feature.
This commit is contained in:
parent
2f5a4f63b6
commit
b3e5f09c83
@ -62,7 +62,7 @@ namespace Wox.Infrastructure
|
||||
Instance.UserSetting.Theme = "Default";
|
||||
Instance.UserSetting.ReplaceWinR = true;
|
||||
Instance.UserSetting.WebSearches = Instance.UserSetting.LoadDefaultWebSearches();
|
||||
Instance.UserSetting.Hotkey = "Win + W";
|
||||
Instance.UserSetting.Hotkey = "Alt + Space";
|
||||
}
|
||||
|
||||
public static CommonStorage Instance
|
||||
|
126
Wox.Infrastructure/HotkeyModel.cs
Normal file
126
Wox.Infrastructure/HotkeyModel.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
namespace Wox.Infrastructure
|
||||
{
|
||||
public class HotkeyModel
|
||||
{
|
||||
public bool Alt { get; set; }
|
||||
public bool Shift { get; set; }
|
||||
public bool Win { get; set; }
|
||||
public bool Ctrl { get; set; }
|
||||
public Key CharKey { get; set; }
|
||||
|
||||
public ModifierKeys ModifierKeys
|
||||
{
|
||||
get
|
||||
{
|
||||
ModifierKeys modifierKeys = ModifierKeys.None;
|
||||
if (Alt)
|
||||
{
|
||||
modifierKeys = ModifierKeys.Alt;
|
||||
}
|
||||
if (Shift)
|
||||
{
|
||||
modifierKeys = modifierKeys | ModifierKeys.Shift;
|
||||
}
|
||||
if (Win)
|
||||
{
|
||||
modifierKeys = modifierKeys | ModifierKeys.Windows;
|
||||
}
|
||||
if (Ctrl)
|
||||
{
|
||||
modifierKeys = modifierKeys | ModifierKeys.Control;
|
||||
}
|
||||
return modifierKeys;
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeyModel() { }
|
||||
|
||||
public HotkeyModel(string hotkeyString)
|
||||
{
|
||||
ParseHotkey(hotkeyString);
|
||||
}
|
||||
|
||||
public HotkeyModel(bool alt, bool shift, bool win, bool ctrl, Key key)
|
||||
{
|
||||
Alt = alt;
|
||||
Shift = shift;
|
||||
Win = win;
|
||||
Ctrl = ctrl;
|
||||
CharKey = key;
|
||||
}
|
||||
|
||||
private void ParseHotkey(string hotkeyString)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(hotkeyString))
|
||||
{
|
||||
List<string> keys = hotkeyString.Replace(" ", "").Split('+').ToList();
|
||||
if (keys.Contains("Alt"))
|
||||
{
|
||||
Alt = true;
|
||||
keys.Remove("Alt");
|
||||
}
|
||||
if (keys.Contains("Shift"))
|
||||
{
|
||||
Shift = true;
|
||||
keys.Remove("Shift");
|
||||
}
|
||||
if (keys.Contains("Win"))
|
||||
{
|
||||
Win = true;
|
||||
keys.Remove("Win");
|
||||
}
|
||||
if (keys.Contains("Ctrl"))
|
||||
{
|
||||
Ctrl = true;
|
||||
keys.Remove("Ctrl");
|
||||
}
|
||||
if (keys.Count > 0)
|
||||
{
|
||||
string charKey = keys[0];
|
||||
try
|
||||
{
|
||||
CharKey = (Key)Enum.Parse(typeof(Key), charKey);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string text = string.Empty;
|
||||
if (Ctrl)
|
||||
{
|
||||
text += "Ctrl";
|
||||
}
|
||||
if (Alt)
|
||||
{
|
||||
text += string.IsNullOrEmpty(text) ? "Alt" : " + Alt";
|
||||
}
|
||||
if (Shift)
|
||||
{
|
||||
text += string.IsNullOrEmpty(text) ? "Shift" : " + Shift";
|
||||
}
|
||||
if (Win)
|
||||
{
|
||||
text += string.IsNullOrEmpty(text) ? "Win" : " + Win";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(CharKey.ToString()))
|
||||
{
|
||||
text += string.IsNullOrEmpty(text) ? CharKey.ToString() : " + " + CharKey;
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
13
Wox.Infrastructure/UserSettings/PluginHotkey.cs
Normal file
13
Wox.Infrastructure/UserSettings/PluginHotkey.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Infrastructure.UserSettings
|
||||
{
|
||||
public class CustomPluginHotkey
|
||||
{
|
||||
public string Hotkey { get; set; }
|
||||
public string ActionKeyword { get; set; }
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ namespace Wox.Infrastructure.UserSettings
|
||||
public string Theme { get; set; }
|
||||
public bool ReplaceWinR { get; set; }
|
||||
public List<WebSearch> WebSearches { get; set; }
|
||||
|
||||
public List<CustomPluginHotkey> CustomPluginHotkeys { get; set; }
|
||||
public bool StartWoxOnSystemStartup { get; set; }
|
||||
|
||||
public List<WebSearch> LoadDefaultWebSearches()
|
||||
|
@ -55,6 +55,7 @@
|
||||
<Compile Include="IniParser.cs" />
|
||||
<Compile Include="UAC.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UserSettings\PluginHotkey.cs" />
|
||||
<Compile Include="UserSettings\UserSelectedRecords.cs" />
|
||||
<Compile Include="UserSettings\UserSetting.cs" />
|
||||
<Compile Include="UserSettings\WebSearch.cs" />
|
||||
|
35
Wox/CustomPluginHotkeySetting.xaml
Normal file
35
Wox/CustomPluginHotkeySetting.xaml
Normal file
@ -0,0 +1,35 @@
|
||||
<Window x:Class="Wox.CustomPluginHotkeySetting"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:wox="clr-namespace:Wox"
|
||||
Icon="Images\app.png"
|
||||
ResizeMode="NoResize"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Title="Custom Plugin Hotkey" Height="200" Width="674.766">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="150"></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Hotkey:</TextBlock>
|
||||
<wox:HotkeyControl x:Name="ctlHotkey" Margin="10" Grid.Column="1" />
|
||||
|
||||
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Action Keyword:</TextBlock>
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1" >
|
||||
<TextBox x:Name="tbAction" Margin="10" Width="400" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
|
||||
<Button x:Name="btnTestActionKeyword" Padding="10 5 10 5" Height="30" Click="BtnTestActionKeyword_OnClick">Test</Button>
|
||||
</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="btnAdd" Margin="10 0 10 0" Width="80" Height="25" Click="btnAdd_OnClick">
|
||||
<TextBlock x:Name="lblAdd">Add</TextBlock>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
111
Wox/CustomPluginHotkeySetting.xaml.cs
Normal file
111
Wox/CustomPluginHotkeySetting.xaml.cs
Normal file
@ -0,0 +1,111 @@
|
||||
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.Shapes;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
|
||||
namespace Wox
|
||||
{
|
||||
public partial class CustomPluginHotkeySetting : Window
|
||||
{
|
||||
private SettingWidow settingWidow;
|
||||
private bool update;
|
||||
private CustomPluginHotkey updateCustomHotkey;
|
||||
|
||||
|
||||
public CustomPluginHotkeySetting(SettingWidow settingWidow)
|
||||
{
|
||||
this.settingWidow = settingWidow;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!update)
|
||||
{
|
||||
if (!ctlHotkey.CurrentHotkeyAvailable)
|
||||
{
|
||||
MessageBox.Show("Hotkey is unavailable, please select a new hotkey");
|
||||
return;
|
||||
}
|
||||
|
||||
if (CommonStorage.Instance.UserSetting.CustomPluginHotkeys == null)
|
||||
{
|
||||
CommonStorage.Instance.UserSetting.CustomPluginHotkeys = new List<CustomPluginHotkey>();
|
||||
}
|
||||
|
||||
var pluginHotkey = new CustomPluginHotkey()
|
||||
{
|
||||
Hotkey = ctlHotkey.CurrentHotkey.ToString(),
|
||||
ActionKeyword = tbAction.Text
|
||||
};
|
||||
CommonStorage.Instance.UserSetting.CustomPluginHotkeys.Add(pluginHotkey);
|
||||
settingWidow.MainWindow.SetHotkey(ctlHotkey.CurrentHotkey.ToString(), delegate
|
||||
{
|
||||
settingWidow.MainWindow.ShowApp();
|
||||
settingWidow.MainWindow.ChangeQuery(pluginHotkey.ActionKeyword);
|
||||
});
|
||||
MessageBox.Show("Add hotkey successfully!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (updateCustomHotkey.Hotkey != ctlHotkey.CurrentHotkey.ToString() && !ctlHotkey.CurrentHotkeyAvailable)
|
||||
{
|
||||
MessageBox.Show("Hotkey is unavailable, please select a new hotkey");
|
||||
return;
|
||||
}
|
||||
var oldHotkey = updateCustomHotkey.Hotkey;
|
||||
updateCustomHotkey.ActionKeyword = tbAction.Text;
|
||||
updateCustomHotkey.Hotkey = ctlHotkey.CurrentHotkey.ToString();
|
||||
//remove origin hotkey
|
||||
settingWidow.MainWindow.RemoveHotkey(oldHotkey);
|
||||
settingWidow.MainWindow.SetHotkey(updateCustomHotkey.Hotkey, delegate
|
||||
{
|
||||
settingWidow.MainWindow.ShowApp();
|
||||
settingWidow.MainWindow.ChangeQuery(updateCustomHotkey.ActionKeyword);
|
||||
});
|
||||
MessageBox.Show("Update successfully!");
|
||||
}
|
||||
|
||||
CommonStorage.Instance.Save();
|
||||
settingWidow.ReloadCustomPluginHotkeyView();
|
||||
Close();
|
||||
}
|
||||
|
||||
public void UpdateItem(CustomPluginHotkey item)
|
||||
{
|
||||
updateCustomHotkey = CommonStorage.Instance.UserSetting.CustomPluginHotkeys.FirstOrDefault(o => o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
|
||||
if (updateCustomHotkey == null)
|
||||
{
|
||||
MessageBox.Show("Invalid plugin hotkey");
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
tbAction.Text = updateCustomHotkey.ActionKeyword;
|
||||
ctlHotkey.SetHotkey(updateCustomHotkey.Hotkey, false);
|
||||
update = true;
|
||||
lblAdd.Text = "Update";
|
||||
}
|
||||
|
||||
private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
settingWidow.MainWindow.ShowApp();
|
||||
settingWidow.MainWindow.ChangeQuery(tbAction.Text);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
<ColumnDefinition Width="150"></ColumnDefinition>
|
||||
<ColumnDefinition Width="120"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox x:Name="tbHotkey" VerticalContentAlignment="Center" Grid.Column="0" PreviewKeyDown="TbHotkey_OnPreviewKeyDown"></TextBox>
|
||||
<TextBox x:Name="tbHotkey" AcceptsTab="False" IsTabStop="False" TabIndex="100" VerticalContentAlignment="Center" Grid.Column="0" PreviewKeyDown="TbHotkey_OnPreviewKeyDown"></TextBox>
|
||||
<TextBlock x:Name="tbMsg" Visibility="Hidden" Margin="5 0 0 0" VerticalAlignment="Center" Grid.Column="1" ></TextBlock>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
@ -31,16 +32,9 @@ namespace Wox
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void SetHotkey(HotkeyModel model)
|
||||
{
|
||||
if (model != null)
|
||||
{
|
||||
SetHotkey(model.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
tbMsg.Visibility = Visibility.Hidden;
|
||||
|
||||
//when alt is pressed, the real key should be e.SystemKey
|
||||
@ -77,31 +71,41 @@ namespace Wox
|
||||
{
|
||||
text += " + Space";
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (text == tbHotkey.Text)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Dispatcher.DelayInvoke("HotkeyAvailableTest", o => SetHotkey(text), TimeSpan.FromMilliseconds(300));
|
||||
}
|
||||
|
||||
public void SetHotkey(string keyStr)
|
||||
public void SetHotkey(string keyStr, bool triggerValidate = true)
|
||||
{
|
||||
tbMsg.Visibility = Visibility.Visible;
|
||||
tbHotkey.Text = keyStr;
|
||||
tbHotkey.Select(tbHotkey.Text.Length, 0);
|
||||
|
||||
CurrentHotkey = new HotkeyModel(keyStr);
|
||||
CurrentHotkeyAvailable = CheckHotAvailabel(CurrentHotkey);
|
||||
tbMsg.Visibility = Visibility.Visible;
|
||||
if (!CurrentHotkeyAvailable)
|
||||
|
||||
if (triggerValidate)
|
||||
{
|
||||
tbMsg.Foreground = new SolidColorBrush(Colors.Red);
|
||||
tbMsg.Text = "hotkey unavailable";
|
||||
CurrentHotkeyAvailable = CheckHotAvailabel(CurrentHotkey);
|
||||
if (!CurrentHotkeyAvailable)
|
||||
{
|
||||
tbMsg.Foreground = new SolidColorBrush(Colors.Red);
|
||||
tbMsg.Text = "hotkey unavailable";
|
||||
}
|
||||
else
|
||||
{
|
||||
tbMsg.Foreground = new SolidColorBrush(Colors.Green);
|
||||
tbMsg.Text = "succeed";
|
||||
}
|
||||
OnOnHotkeyChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
tbMsg.Foreground = new SolidColorBrush(Colors.Green);
|
||||
tbMsg.Text = "hotkey available";
|
||||
}
|
||||
OnOnHotkeyChanged();
|
||||
}
|
||||
|
||||
private bool CheckHotAvailabel(HotkeyModel hotkey)
|
||||
|
@ -15,6 +15,7 @@ using NHotkey;
|
||||
using NHotkey.Wpf;
|
||||
using Wox.Commands;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.PluginLoader;
|
||||
using Application = System.Windows.Application;
|
||||
@ -58,18 +59,35 @@ namespace Wox
|
||||
Closing += MainWindow_Closing;
|
||||
}
|
||||
|
||||
public void SetHotkey(string hotkeyStr)
|
||||
public void SetHotkey(string hotkeyStr,EventHandler<HotkeyEventArgs> action)
|
||||
{
|
||||
HotkeyModel hotkey = new HotkeyModel(hotkeyStr);
|
||||
try
|
||||
{
|
||||
HotkeyManager.Current.AddOrReplace("ShowHideWox", hotkey.CharKey, hotkey.ModifierKeys, OnHotkey);
|
||||
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys,action);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show("Registe hotkey: " + CommonStorage.Instance.UserSetting.Hotkey + " failed.");
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveHotkey(string hotkeyStr)
|
||||
{
|
||||
HotkeyManager.Current.Remove(hotkeyStr);
|
||||
}
|
||||
|
||||
private void SetCustomPluginHotkey()
|
||||
{
|
||||
foreach (CustomPluginHotkey hotkey in CommonStorage.Instance.UserSetting.CustomPluginHotkeys)
|
||||
{
|
||||
CustomPluginHotkey hotkey1 = hotkey;
|
||||
SetHotkey(hotkey.Hotkey,delegate
|
||||
{
|
||||
ShowApp();
|
||||
ChangeQuery(hotkey1.ActionKeyword);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHotkey(object sender, HotkeyEventArgs e)
|
||||
@ -96,7 +114,7 @@ namespace Wox
|
||||
//This is caused by the Virtual Mermory Page Mechanisam. So, our solution is execute some codes in every min
|
||||
//which may prevent sysetem uninstall memory from RAM to disk.
|
||||
|
||||
var t = new Timer(1000*60*5) {AutoReset = true, Enabled = true};
|
||||
var t = new Timer(1000 * 60 * 5) { AutoReset = true, Enabled = true };
|
||||
t.Elapsed += (o, e) => Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
if (Visibility != Visibility.Visible)
|
||||
@ -126,21 +144,21 @@ namespace Wox
|
||||
|
||||
private void InitialTray()
|
||||
{
|
||||
notifyIcon = new NotifyIcon {Text = "Wox", Icon = Properties.Resources.app, Visible = true};
|
||||
notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true };
|
||||
notifyIcon.Click += (o, e) => ShowWox();
|
||||
var open = new MenuItem("Open");
|
||||
open.Click += (o, e) => ShowWox();
|
||||
var exit = new MenuItem("Exit");
|
||||
exit.Click += (o, e) => CloseApp();
|
||||
MenuItem[] childen = {open, exit};
|
||||
MenuItem[] childen = { open, exit };
|
||||
notifyIcon.ContextMenu = new ContextMenu(childen);
|
||||
}
|
||||
|
||||
private void resultCtrl_resultItemChangedEvent()
|
||||
{
|
||||
resultCtrl.Margin = resultCtrl.GetCurrentResultCount() > 0
|
||||
? new Thickness {Top = grid.Margin.Top}
|
||||
: new Thickness {Top = 0};
|
||||
? new Thickness { Top = grid.Margin.Top }
|
||||
: new Thickness { Top = 0 };
|
||||
}
|
||||
|
||||
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
@ -225,10 +243,11 @@ namespace Wox
|
||||
|
||||
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Left = (SystemParameters.PrimaryScreenWidth - ActualWidth)/2;
|
||||
Top = (SystemParameters.PrimaryScreenHeight - ActualHeight)/3;
|
||||
Left = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
|
||||
Top = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 3;
|
||||
|
||||
SetHotkey(CommonStorage.Instance.UserSetting.Hotkey);
|
||||
SetHotkey(CommonStorage.Instance.UserSetting.Hotkey,OnHotkey);
|
||||
SetCustomPluginHotkey();
|
||||
WakeupApp();
|
||||
Plugins.Init();
|
||||
|
||||
@ -240,13 +259,13 @@ namespace Wox
|
||||
if (CommonStorage.Instance.UserSetting.ReplaceWinR)
|
||||
{
|
||||
//todo:need refatoring. move those codes to CMD file or expose events
|
||||
if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int) Keys.R && state.WinPressed)
|
||||
if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed)
|
||||
{
|
||||
WinRStroked = true;
|
||||
Dispatcher.BeginInvoke(new Action(OnWinRPressed));
|
||||
return false;
|
||||
}
|
||||
if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int) Keys.LWin)
|
||||
if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin)
|
||||
{
|
||||
WinRStroked = false;
|
||||
keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
|
||||
@ -345,8 +364,6 @@ namespace Wox
|
||||
|
||||
#region Public API
|
||||
|
||||
//Those method can be invoked by plugins
|
||||
|
||||
public void ChangeQuery(string query)
|
||||
{
|
||||
tbQuery.Text = query;
|
||||
@ -371,14 +388,13 @@ namespace Wox
|
||||
|
||||
public void ShowMsg(string title, string subTitle, string iconPath)
|
||||
{
|
||||
var m = new Msg {Owner = GetWindow(this)};
|
||||
var m = new Msg { Owner = GetWindow(this) };
|
||||
m.Show(title, subTitle, iconPath);
|
||||
}
|
||||
|
||||
public void OpenSettingDialog()
|
||||
{
|
||||
var s = new SettingWidow(this);
|
||||
s.Show();
|
||||
new SettingWidow(this).Show();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -23,13 +23,55 @@
|
||||
<TextBlock Text="Theme:" />
|
||||
<ComboBox x:Name="themeComboBox" SelectionChanged="ThemeComboBox_OnSelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="10">
|
||||
<wox:HotkeyControl x:Name="ctlHotkey" />
|
||||
</StackPanel>
|
||||
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="Hotkey">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30"></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition Height="50"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock VerticalAlignment="Center" Margin="0 0 10 0">Wox Hotkey:</TextBlock>
|
||||
<wox:HotkeyControl x:Name="ctlHotkey"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="1" Orientation="Vertical" VerticalAlignment="Top">
|
||||
<TextBlock VerticalAlignment="Center" Margin="0 0 10 0">Custom Plugin Hotkey:</TextBlock>
|
||||
<ListView x:Name="lvCustomHotkey" Margin="0 5 0 0">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridView.Columns>
|
||||
<GridViewColumn Header="Hotkey" Width="180">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Path= Hotkey}"></TextBlock>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
<GridViewColumn Header="Action Keyword" Width="500">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Path= ActionKeyword}"></TextBlock>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
</GridView.Columns>
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<Button x:Name="btnDeleteCustomHotkey" Click="BtnDeleteCustomHotkey_OnClick" Width="100" Margin="10">Delete</Button>
|
||||
<Button x:Name="btnEditCustomHotkey" Click="BtnEditCustomHotkey_OnClick" Width="100" Margin="10">Edit</Button>
|
||||
<Button x:Name="btnAddCustomeHotkey" Click="BtnAddCustomeHotkey_OnClick" Width="100" Margin="10">Add</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="Web Search">
|
||||
<Grid>
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
<RowDefinition Height="50"></RowDefinition>
|
||||
|
@ -19,7 +19,7 @@ namespace Wox
|
||||
{
|
||||
public partial class SettingWidow : Window
|
||||
{
|
||||
private MainWindow mainWindow;
|
||||
public MainWindow MainWindow;
|
||||
|
||||
public SettingWidow()
|
||||
{
|
||||
@ -28,11 +28,17 @@ namespace Wox
|
||||
|
||||
public SettingWidow(MainWindow mainWindow)
|
||||
{
|
||||
this.mainWindow = mainWindow;
|
||||
this.MainWindow = mainWindow;
|
||||
InitializeComponent();
|
||||
Loaded += Setting_Loaded;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void Setting_Loaded(object sender, RoutedEventArgs ev)
|
||||
{
|
||||
ctlHotkey.OnHotkeyChanged += ctlHotkey_OnHotkeyChanged;
|
||||
ctlHotkey.SetHotkey(CommonStorage.Instance.UserSetting.Hotkey);
|
||||
ctlHotkey.SetHotkey(CommonStorage.Instance.UserSetting.Hotkey, false);
|
||||
cbReplaceWinR.Checked += (o, e) =>
|
||||
{
|
||||
CommonStorage.Instance.UserSetting.ReplaceWinR = true;
|
||||
@ -43,20 +49,7 @@ namespace Wox
|
||||
CommonStorage.Instance.UserSetting.ReplaceWinR = false;
|
||||
CommonStorage.Instance.Save();
|
||||
};
|
||||
}
|
||||
|
||||
void ctlHotkey_OnHotkeyChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
if (ctlHotkey.CurrentHotkeyAvailable)
|
||||
{
|
||||
mainWindow.SetHotkey(ctlHotkey.CurrentHotkey.ToString());
|
||||
CommonStorage.Instance.UserSetting.Hotkey = ctlHotkey.CurrentHotkey.ToString();
|
||||
CommonStorage.Instance.Save();
|
||||
}
|
||||
}
|
||||
|
||||
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
foreach (string theme in LoadAvailableThemes())
|
||||
{
|
||||
string themeName = theme.Substring(theme.LastIndexOf('\\') + 1).Replace(".xaml", "");
|
||||
@ -66,6 +59,7 @@ namespace Wox
|
||||
themeComboBox.SelectedItem = CommonStorage.Instance.UserSetting.Theme;
|
||||
cbReplaceWinR.IsChecked = CommonStorage.Instance.UserSetting.ReplaceWinR;
|
||||
webSearchView.ItemsSource = CommonStorage.Instance.UserSetting.WebSearches;
|
||||
lvCustomHotkey.ItemsSource = CommonStorage.Instance.UserSetting.CustomPluginHotkeys;
|
||||
cbStartWithWindows.IsChecked = CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup;
|
||||
}
|
||||
|
||||
@ -83,7 +77,7 @@ namespace Wox
|
||||
private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
string themeName = themeComboBox.SelectedItem.ToString();
|
||||
mainWindow.SetTheme(themeName);
|
||||
MainWindow.SetTheme(themeName);
|
||||
CommonStorage.Instance.UserSetting.Theme = themeName;
|
||||
CommonStorage.Instance.Save();
|
||||
}
|
||||
@ -91,7 +85,7 @@ namespace Wox
|
||||
private void btnAddWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
WebSearchSetting webSearch = new WebSearchSetting(this);
|
||||
webSearch.Show();
|
||||
webSearch.ShowDialog();
|
||||
}
|
||||
|
||||
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
@ -116,8 +110,8 @@ namespace Wox
|
||||
if (seletedWebSearch != null)
|
||||
{
|
||||
WebSearchSetting webSearch = new WebSearchSetting(this);
|
||||
webSearch.Show();
|
||||
webSearch.UpdateItem(seletedWebSearch);
|
||||
webSearch.ShowDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -171,6 +165,74 @@ namespace Wox
|
||||
}
|
||||
}
|
||||
|
||||
void ctlHotkey_OnHotkeyChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
if (ctlHotkey.CurrentHotkeyAvailable)
|
||||
{
|
||||
MainWindow.SetHotkey(ctlHotkey.CurrentHotkey.ToString(), delegate
|
||||
{
|
||||
if (!MainWindow.IsVisible)
|
||||
{
|
||||
MainWindow.ShowApp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MainWindow.HideApp();
|
||||
}
|
||||
});
|
||||
MainWindow.RemoveHotkey(CommonStorage.Instance.UserSetting.Hotkey);
|
||||
CommonStorage.Instance.UserSetting.Hotkey = ctlHotkey.CurrentHotkey.ToString();
|
||||
CommonStorage.Instance.Save();
|
||||
}
|
||||
}
|
||||
|
||||
#region Custom Plugin Hotkey
|
||||
|
||||
private void BtnDeleteCustomHotkey_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
|
||||
if (item != null &&
|
||||
MessageBox.Show("Are your sure to delete " + item.Hotkey + " plugin hotkey?","Delete Custom Plugin Hotkey",
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
CommonStorage.Instance.UserSetting.CustomPluginHotkeys.Remove(item);
|
||||
lvCustomHotkey.Items.Refresh();
|
||||
CommonStorage.Instance.Save();
|
||||
MainWindow.RemoveHotkey(item.Hotkey);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Please select an item");
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnEditCustomHotkey_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
|
||||
if (item != null)
|
||||
{
|
||||
CustomPluginHotkeySetting window = new CustomPluginHotkeySetting(this);
|
||||
window.UpdateItem(item);
|
||||
window.ShowDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Please select an item");
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnAddCustomeHotkey_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
new CustomPluginHotkeySetting(this).ShowDialog();
|
||||
}
|
||||
|
||||
public void ReloadCustomPluginHotkeyView()
|
||||
{
|
||||
lvCustomHotkey.Items.Refresh();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +125,9 @@
|
||||
<Compile Include="Commands\CommandFactory.cs" />
|
||||
<Compile Include="Commands\PluginCommand.cs" />
|
||||
<Compile Include="Commands\SystemCommand.cs" />
|
||||
<Compile Include="CustomPluginHotkeySetting.xaml.cs">
|
||||
<DependentUpon>CustomPluginHotkeySetting.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="DispatcherExtensions.cs" />
|
||||
<Compile Include="Helper\Log.cs" />
|
||||
<Compile Include="Helper\PluginInstaller.cs" />
|
||||
@ -153,6 +156,10 @@
|
||||
<Compile Include="WebSearchSetting.xaml.cs">
|
||||
<DependentUpon>WebSearchSetting.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Page Include="CustomPluginHotkeySetting.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="HotkeyControl.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
Loading…
Reference in New Issue
Block a user