优化部分代码,尝试修复热键回调多次bug
This commit is contained in:
@@ -24,7 +24,7 @@ namespace GeekDesk.Control.Other
|
||||
{
|
||||
|
||||
private AppData appData = MainWindow.appData;
|
||||
public BacklogNotificatin(BacklogInfo info)
|
||||
public BacklogNotificatin(ToDoInfo info)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = info;
|
||||
@@ -32,12 +32,12 @@ namespace GeekDesk.Control.Other
|
||||
|
||||
private void BacklogDone_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BacklogInfo info = this.DataContext as BacklogInfo;
|
||||
ToDoInfo info = this.DataContext as ToDoInfo;
|
||||
info.DoneTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
appData.ExeBacklogList.Remove(info); //执行任务删除
|
||||
appData.HiBacklogList.Add(info); //添加历史任务
|
||||
BacklogTask.activityBacklog[info].Close(); //关闭桌面通知
|
||||
BacklogTask.activityBacklog.Remove(info);//激活任务删除
|
||||
appData.ToDoList.Remove(info); //执行任务删除
|
||||
appData.HiToDoList.Add(info); //添加历史任务
|
||||
ToDoTask.activityBacklog[info].Close(); //关闭桌面通知
|
||||
ToDoTask.activityBacklog.Remove(info);//激活任务删除
|
||||
CommonCode.SaveAppData(appData);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace GeekDesk.Control.Other
|
||||
/// <param name="e"></param>
|
||||
private void DelayButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BacklogInfo info = this.DataContext as BacklogInfo;
|
||||
ToDoInfo info = this.DataContext as ToDoInfo;
|
||||
int time = int.Parse(DelayTime.Text);
|
||||
string type = DelayType.Text;
|
||||
switch(type)
|
||||
@@ -98,8 +98,8 @@ namespace GeekDesk.Control.Other
|
||||
info.ExeTime = DateTime.Now.AddHours(time).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
break;
|
||||
}
|
||||
BacklogTask.activityBacklog[info].Close(); //关闭桌面通知
|
||||
BacklogTask.activityBacklog.Remove(info);//激活任务删除
|
||||
ToDoTask.activityBacklog[info].Close(); //关闭桌面通知
|
||||
ToDoTask.activityBacklog.Remove(info);//激活任务删除
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -1,4 +1,4 @@
|
||||
<Window x:Class="GeekDesk.Control.Windows.BacklogInfoWindow"
|
||||
<Window x:Class="GeekDesk.Control.Windows.ToDoInfoWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
@@ -20,24 +20,24 @@ namespace GeekDesk.Control.Windows
|
||||
/// <summary>
|
||||
/// BacklogInfoWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class BacklogInfoWindow
|
||||
public partial class ToDoInfoWindow
|
||||
{
|
||||
|
||||
private static int windowType = -1;
|
||||
private static readonly int NEW_BACKLOG = 1;
|
||||
private static readonly int DETAIL_BACKLOG = 2;
|
||||
private static readonly int NEW_TODO = 1;
|
||||
private static readonly int DETAIL_TODO = 2;
|
||||
|
||||
private AppData appData = MainWindow.appData;
|
||||
|
||||
private BacklogInfo info;
|
||||
private ToDoInfo info;
|
||||
|
||||
private BacklogInfoWindow()
|
||||
private ToDoInfoWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
ExeTime.SelectedDateTime = DateTime.Now.AddMinutes(10);
|
||||
this.Topmost = true;
|
||||
}
|
||||
private BacklogInfoWindow(BacklogInfo info)
|
||||
private ToDoInfoWindow(ToDoInfo info)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Topmost = true;
|
||||
@@ -96,24 +96,24 @@ namespace GeekDesk.Control.Windows
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (windowType == NEW_BACKLOG)
|
||||
if (windowType == NEW_TODO)
|
||||
{
|
||||
info = new BacklogInfo
|
||||
info = new ToDoInfo
|
||||
{
|
||||
Title = Title.Text,
|
||||
Msg = Msg.Text,
|
||||
ExeTime = ExeTime.Text
|
||||
};
|
||||
appData.ExeBacklogList.Add(info);
|
||||
appData.ToDoList.Add(info);
|
||||
} else
|
||||
{
|
||||
int index =appData.ExeBacklogList.IndexOf(info);
|
||||
appData.ExeBacklogList.Remove(info);
|
||||
int index =appData.ToDoList.IndexOf(info);
|
||||
appData.ToDoList.Remove(info);
|
||||
info.Title = Title.Text;
|
||||
info.Msg = Msg.Text;
|
||||
info.ExeTime = ExeTime.Text;
|
||||
info.DoneTime = DoneTime.Text;
|
||||
appData.ExeBacklogList.Insert(index, info);
|
||||
appData.ToDoList.Insert(index, info);
|
||||
}
|
||||
CommonCode.SaveAppData(MainWindow.appData);
|
||||
this.Close();
|
||||
@@ -124,21 +124,33 @@ namespace GeekDesk.Control.Windows
|
||||
{
|
||||
if (window == null || !window.Activate())
|
||||
{
|
||||
window = new BacklogInfoWindow();
|
||||
window = new ToDoInfoWindow();
|
||||
|
||||
}
|
||||
windowType = NEW_BACKLOG;
|
||||
windowType = NEW_TODO;
|
||||
window.Show();
|
||||
}
|
||||
|
||||
|
||||
public static System.Windows.Window GetThis()
|
||||
{
|
||||
if (window == null || !window.Activate())
|
||||
{
|
||||
window = new ToDoInfoWindow();
|
||||
|
||||
}
|
||||
windowType = NEW_TODO;
|
||||
return window;
|
||||
}
|
||||
|
||||
private static System.Windows.Window window2 = null;
|
||||
public static void ShowDetail(BacklogInfo info)
|
||||
public static void ShowDetail(ToDoInfo info)
|
||||
{
|
||||
if (window2 == null || !window2.Activate())
|
||||
{
|
||||
window2 = new BacklogInfoWindow(info);
|
||||
window2 = new ToDoInfoWindow(info);
|
||||
}
|
||||
windowType = DETAIL_BACKLOG;
|
||||
windowType = DETAIL_TODO;
|
||||
window2.Show();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Window x:Class="GeekDesk.Control.Windows.BacklogWindow"
|
||||
<Window x:Class="GeekDesk.Control.Windows.ToDoWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
@@ -21,15 +21,15 @@ namespace GeekDesk.Control.Windows
|
||||
/// <summary>
|
||||
/// BacklogWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class BacklogWindow
|
||||
public partial class ToDoWindow
|
||||
{
|
||||
private static BacklogControl backlog = new BacklogControl();
|
||||
private static TodoControl backlog = new TodoControl();
|
||||
private AppData appData = MainWindow.appData;
|
||||
private BacklogWindow()
|
||||
private ToDoWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
RightCard.Content = backlog;
|
||||
backlog.BacklogList.ItemsSource = appData.ExeBacklogList;
|
||||
backlog.BacklogList.ItemsSource = appData.ToDoList;
|
||||
this.Topmost = true;
|
||||
}
|
||||
|
||||
@@ -63,10 +63,10 @@ namespace GeekDesk.Control.Windows
|
||||
switch (smi.Tag.ToString())
|
||||
{
|
||||
case "History":
|
||||
backlog.BacklogList.ItemsSource = appData.HiBacklogList;
|
||||
backlog.BacklogList.ItemsSource = appData.HiToDoList;
|
||||
break;
|
||||
default:
|
||||
backlog.BacklogList.ItemsSource = appData.ExeBacklogList;
|
||||
backlog.BacklogList.ItemsSource = appData.ToDoList;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ namespace GeekDesk.Control.Windows
|
||||
/// <param name="e"></param>
|
||||
private void CreateBacklog_BtnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BacklogInfoWindow.ShowNone();
|
||||
ToDoInfoWindow.ShowNone();
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace GeekDesk.Control.Windows
|
||||
{
|
||||
if (window == null || !window.Activate())
|
||||
{
|
||||
window = new BacklogWindow();
|
||||
window = new ToDoWindow();
|
||||
}
|
||||
window.Show();
|
||||
}
|
||||
Reference in New Issue
Block a user