优化部分代码,尝试修复热键回调多次bug
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
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"
|
||||
xmlns:cvt="clr-namespace:GeekDesk.Converts"
|
||||
xmlns:local="clr-namespace:GeekDesk.Control.UserControls.PannelCard"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
mc:Ignorable="d"
|
||||
@@ -10,7 +11,7 @@
|
||||
d:DesignHeight="400" d:DesignWidth="500">
|
||||
|
||||
<UserControl.Resources>
|
||||
|
||||
<cvt:UpdateTypeConvert x:Key="UpdateTypeConvert"/>
|
||||
</UserControl.Resources>
|
||||
<hc:SimplePanel Margin="20,50,20,20">
|
||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Top">
|
||||
@@ -66,10 +67,10 @@
|
||||
<TextBlock Text="更新源:" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||
<RadioButton Margin="10,0,0,0" Background="{DynamicResource SecondaryRegionBrush}"
|
||||
Style="{StaticResource RadioButtonIcon}" Content="Gitee"
|
||||
IsChecked="{Binding AppHideType, Mode=TwoWay, Converter={StaticResource HideTypeConvert}, ConverterParameter=1}"/>
|
||||
IsChecked="{Binding UpdateType, Mode=TwoWay, Converter={StaticResource UpdateTypeConvert}, ConverterParameter=1}"/>
|
||||
<RadioButton Margin="10,0,0,0" Background="{DynamicResource SecondaryRegionBrush}"
|
||||
Style="{StaticResource RadioButtonIcon}" Content="GitHub"
|
||||
IsChecked="{Binding AppHideType, Mode=TwoWay, Converter={StaticResource HideTypeConvert}, ConverterParameter=2}"/>
|
||||
IsChecked="{Binding UpdateType, Mode=TwoWay, Converter={StaticResource UpdateTypeConvert}, ConverterParameter=2}"/>
|
||||
</hc:UniformSpacingPanel>
|
||||
</StackPanel>
|
||||
</hc:SimplePanel>
|
||||
|
||||
@@ -54,8 +54,9 @@
|
||||
<TextBlock Text="热键设置" VerticalAlignment="Center" Margin="-26,0,26,0"/>
|
||||
</hc:UniformSpacingPanel>
|
||||
<hc:UniformSpacingPanel Spacing="10" Margin="30,193,0,-180.337" Grid.ColumnSpan="4">
|
||||
<TextBlock Text="当前热键:"/>
|
||||
<TextBlock Text="主面板:" Width="55"/>
|
||||
<hc:TextBox HorizontalAlignment="Left"
|
||||
Tag="Main"
|
||||
VerticalAlignment="Top"
|
||||
IsReadOnly="True"
|
||||
IsReadOnlyCaretVisible="True"
|
||||
@@ -65,6 +66,20 @@
|
||||
KeyUp="HotKeyUp"
|
||||
Margin="12.967,-7.38,-12.967,0"/>
|
||||
</hc:UniformSpacingPanel>
|
||||
<hc:UniformSpacingPanel Spacing="10" Margin="30,229,0,-216.337" Grid.ColumnSpan="4">
|
||||
<TextBlock Text="新建待办:" Width="55"/>
|
||||
<hc:TextBox HorizontalAlignment="Left"
|
||||
Tag="ToDo"
|
||||
VerticalAlignment="Top"
|
||||
IsReadOnly="True"
|
||||
IsReadOnlyCaretVisible="True"
|
||||
Width="200"
|
||||
Text="{Binding ToDoHotkeyStr}"
|
||||
KeyDown="HotKeyDown"
|
||||
KeyUp="HotKeyUp"
|
||||
Margin="12.967,-7.38,-12.967,0"/>
|
||||
</hc:UniformSpacingPanel>
|
||||
<StackPanel hc:Growl.GrowlParent="True" hc:Growl.Token="HotKeyGrowl" VerticalAlignment="Top"/>
|
||||
</hc:SimplePanel>
|
||||
|
||||
</UserControl>
|
||||
|
||||
@@ -46,23 +46,48 @@ namespace GeekDesk.Control.UserControls.Config
|
||||
/// <param name="e"></param>
|
||||
private void HotKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
string tag = (sender as TextBox).Tag.ToString();
|
||||
|
||||
bool main = false;
|
||||
if ("Main".Equals(tag))
|
||||
{
|
||||
main = true;
|
||||
}
|
||||
|
||||
if (!e.IsRepeat)
|
||||
{
|
||||
if (hotkeyFinished)
|
||||
{
|
||||
appConfig.Hotkey = 0;
|
||||
appConfig.HotkeyStr = "";
|
||||
appConfig.HotkeyModifiers = 0;
|
||||
if (main)
|
||||
{
|
||||
appConfig.Hotkey = 0;
|
||||
appConfig.HotkeyStr = "";
|
||||
appConfig.HotkeyModifiers = 0;
|
||||
} else
|
||||
{
|
||||
appConfig.ToDoHotkey = 0;
|
||||
appConfig.ToDoHotkeyStr = "";
|
||||
appConfig.ToDoHotkeyModifiers = 0;
|
||||
}
|
||||
hotkeyFinished = false;
|
||||
|
||||
}
|
||||
//首次按下按键
|
||||
if (appConfig.HotkeyStr == null || appConfig.HotkeyStr.Length == 0)
|
||||
if ((main && (appConfig.HotkeyStr == null || appConfig.HotkeyStr.Length == 0))
|
||||
|| (!main && (appConfig.ToDoHotkeyStr == null || appConfig.ToDoHotkeyStr.Length == 0)))
|
||||
{
|
||||
if (CheckModifierKeys(e))
|
||||
{
|
||||
//辅助键
|
||||
appConfig.HotkeyStr = GetKeyName(e);
|
||||
appConfig.HotkeyModifiers = GetModifierKeys(e);
|
||||
if (main)
|
||||
{
|
||||
appConfig.HotkeyStr = GetKeyName(e);
|
||||
appConfig.HotkeyModifiers = GetModifierKeys(e);
|
||||
} else
|
||||
{
|
||||
appConfig.ToDoHotkeyStr = GetKeyName(e);
|
||||
appConfig.ToDoHotkeyModifiers = GetModifierKeys(e);
|
||||
}
|
||||
prevKeyTemp = e;
|
||||
keysTemp.Add(e);
|
||||
}
|
||||
@@ -75,15 +100,30 @@ namespace GeekDesk.Control.UserControls.Config
|
||||
|| (e.Key >= Key.F1 && e.Key <= Key.F12)
|
||||
|| (e.Key >= Key.D0 && e.Key <= Key.D9)))
|
||||
{
|
||||
appConfig.Hotkey = e.Key;
|
||||
appConfig.HotkeyStr += e.Key.ToString();
|
||||
if (main)
|
||||
{
|
||||
appConfig.Hotkey = e.Key;
|
||||
appConfig.HotkeyStr += e.Key.ToString();
|
||||
} else
|
||||
{
|
||||
appConfig.ToDoHotkey = e.Key;
|
||||
appConfig.ToDoHotkeyStr += e.Key.ToString();
|
||||
}
|
||||
prevKeyTemp = e;
|
||||
keysTemp.Add(e);
|
||||
}
|
||||
else if (CheckModifierKeys(e))
|
||||
{
|
||||
appConfig.HotkeyStr += GetKeyName(e);
|
||||
appConfig.HotkeyModifiers |= GetModifierKeys(e);
|
||||
if (main)
|
||||
{
|
||||
appConfig.HotkeyStr += GetKeyName(e);
|
||||
appConfig.HotkeyModifiers |= GetModifierKeys(e);
|
||||
} else
|
||||
{
|
||||
appConfig.ToDoHotkeyStr += GetKeyName(e);
|
||||
appConfig.ToDoHotkeyModifiers |= GetModifierKeys(e);
|
||||
}
|
||||
|
||||
prevKeyTemp = e;
|
||||
keysTemp.Add(e);
|
||||
}
|
||||
@@ -146,13 +186,18 @@ namespace GeekDesk.Control.UserControls.Config
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
private void HotKeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
string tag = (sender as TextBox).Tag.ToString();
|
||||
bool main = false;
|
||||
if ("Main".Equals(tag))
|
||||
{
|
||||
main = true;
|
||||
}
|
||||
lock(this)
|
||||
{
|
||||
bool allKeyUp = true;
|
||||
//判断所有键是否都松开
|
||||
foreach (KeyEventArgs key in keysTemp)
|
||||
{
|
||||
HandyControl.Controls.Growl.SuccessGlobal(key.Key.ToString() + "=" + key.KeyStates);
|
||||
if (key.KeyStates == KeyStates.Down)
|
||||
{
|
||||
allKeyUp = false;
|
||||
@@ -163,11 +208,24 @@ namespace GeekDesk.Control.UserControls.Config
|
||||
{
|
||||
keysTemp.Clear();
|
||||
hotkeyFinished = true;
|
||||
if (MainWindow.hotKeyId != -1)
|
||||
|
||||
if (main)
|
||||
{
|
||||
Hotkey.UnRegist(new WindowInteropHelper(MainWindow.mainWindow).Handle, Hotkey.keymap[MainWindow.hotKeyId]);
|
||||
if (MainWindow.hotKeyId != -1)
|
||||
{
|
||||
Hotkey.UnRegist(new WindowInteropHelper(MainWindow.mainWindow).Handle, Hotkey.keymap[MainWindow.hotKeyId]);
|
||||
}
|
||||
MainWindow.RegisterHotKey(false);
|
||||
} else
|
||||
{
|
||||
if (MainWindow.toDoHotKeyId != -1)
|
||||
{
|
||||
Hotkey.UnRegist(new WindowInteropHelper(MainWindow.toDoInfoWindow).Handle, Hotkey.keymap[MainWindow.toDoHotKeyId]);
|
||||
}
|
||||
MainWindow.RegisterCreateToDoHotKey(false);
|
||||
}
|
||||
MainWindow.RegisterHotKey();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<UserControl x:Class="GeekDesk.Control.UserControls.Backlog.BacklogControl"
|
||||
<UserControl x:Class="GeekDesk.Control.UserControls.Backlog.TodoControl"
|
||||
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"
|
||||
@@ -22,22 +22,22 @@ namespace GeekDesk.Control.UserControls.Backlog
|
||||
/// <summary>
|
||||
/// BacklogControl.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class BacklogControl : UserControl
|
||||
public partial class TodoControl : UserControl
|
||||
{
|
||||
private AppData appData = MainWindow.appData;
|
||||
public BacklogControl()
|
||||
public TodoControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void DeleteMenu_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BacklogInfo info = BacklogList.SelectedItem as BacklogInfo;
|
||||
ToDoInfo info = BacklogList.SelectedItem as ToDoInfo;
|
||||
Growl.Ask("确认删除吗?", isConfirmed =>
|
||||
{
|
||||
if (isConfirmed)
|
||||
{
|
||||
appData.ExeBacklogList.Remove(info);
|
||||
appData.ToDoList.Remove(info);
|
||||
CommonCode.SaveAppData(MainWindow.appData);
|
||||
}
|
||||
return true;
|
||||
@@ -46,8 +46,8 @@ namespace GeekDesk.Control.UserControls.Backlog
|
||||
|
||||
private void DetailMenu_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BacklogInfo info = BacklogList.SelectedItem as BacklogInfo;
|
||||
BacklogInfoWindow.ShowDetail(info);
|
||||
ToDoInfo info = BacklogList.SelectedItem as ToDoInfo;
|
||||
ToDoInfoWindow.ShowDetail(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
Reference in New Issue
Block a user