代码清理/拾色器功能/部分程序优化

This commit is contained in:
liufei
2022-05-20 15:39:52 +08:00
parent 5cfaf9a37d
commit d01a27b827
83 changed files with 1320 additions and 627 deletions

View File

@@ -1,20 +1,9 @@
using System;
using GeekDesk.Constant;
using GeekDesk.Util;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;
using GeekDesk.Util;
using GeekDesk.Constant;
namespace GeekDesk.Control.UserControls.Config
{

View File

@@ -4,10 +4,13 @@
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:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel"
d:DataContext="{d:DesignInstance Type=viewmodel:AppConfig}"
xmlns:cst="clr-namespace:GeekDesk.Constant"
Background="Transparent"
d:DesignHeight="300" d:DesignWidth="450">
d:DesignHeight="400" d:DesignWidth="450">
<UserControl.Resources>
<cvt:HideTypeConvert x:Key="HideTypeConvert"/>
@@ -109,30 +112,74 @@
<TextBlock Text="热键设置" VerticalAlignment="Center"/>
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="10" Margin="10,5,0,0" Grid.ColumnSpan="4">
<TextBlock Text="主面板:" VerticalAlignment="Center" Width="55"/>
<TextBlock Text="主面板:" VerticalAlignment="Center" Margin="0,5,0,0" Width="55"/>
<hc:TextBox HorizontalAlignment="Left"
Tag="Main"
Tag="{x:Static cst:HotKeyType.Main}"
VerticalAlignment="Top"
IsReadOnly="True"
IsReadOnlyCaretVisible="True"
Width="200"
Width="170"
Text="{Binding HotkeyStr}"
KeyDown="HotKeyDown"
KeyUp="HotKeyUp"
/>
<CheckBox Content="启用"
Click="EnableHotKey_Click"
Tag="{x:Static cst:HotKeyType.Main}"
IsChecked="{Binding EnableAppHotKey}">
<CheckBox.Background>
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
<GradientStop Color="#FF9EA3A6"/>
</LinearGradientBrush>
</CheckBox.Background>
</CheckBox>
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="10" Margin="10,5,0,0" Grid.ColumnSpan="4">
<TextBlock Text="新建待办:" Width="55"/>
<TextBlock Text="新建待办:" Margin="0,5,0,0" Width="55"/>
<hc:TextBox HorizontalAlignment="Left"
Tag="ToDo"
Tag="{x:Static cst:HotKeyType.ToDo}"
VerticalAlignment="Top"
IsReadOnly="True"
IsReadOnlyCaretVisible="True"
Width="200"
Width="170"
Text="{Binding ToDoHotkeyStr}"
KeyDown="HotKeyDown"
KeyUp="HotKeyUp"
/>
<CheckBox Content="启用"
Click="EnableHotKey_Click"
Tag="{x:Static cst:HotKeyType.ToDo}"
IsChecked="{Binding EnableTodoHotKey}">
<CheckBox.Background>
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
<GradientStop Color="#FF9EA3A6"/>
</LinearGradientBrush>
</CheckBox.Background>
</CheckBox>
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="10" Margin="10,5,0,0" Grid.ColumnSpan="4">
<TextBlock Text="拾色器:" Margin="0,5,0,0" Width="55"/>
<hc:TextBox HorizontalAlignment="Left"
Tag="{x:Static cst:HotKeyType.ColorPicker}"
VerticalAlignment="Top"
IsReadOnly="True"
IsReadOnlyCaretVisible="True"
Width="170"
Text="{Binding ColorPickerHotkeyStr}"
KeyDown="HotKeyDown"
KeyUp="HotKeyUp"
/>
<CheckBox Content="启用"
Tag="{x:Static cst:HotKeyType.ColorPicker}"
Click="EnableHotKey_Click"
IsChecked="{Binding EnableColorPickerHotKey}">
<CheckBox.Background>
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
<GradientStop Color="#FF9EA3A6"/>
</LinearGradientBrush>
</CheckBox.Background>
</CheckBox>
</hc:UniformSpacingPanel>
</StackPanel>
</Grid>

View File

@@ -1,26 +1,12 @@
using GeekDesk.Constant;
using GeekDesk.Control.Windows;
using GeekDesk.MyThread;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using HandyControl.Data;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using static GeekDesk.Util.GlobalHotKey;
namespace GeekDesk.Control.UserControls.Config
@@ -48,7 +34,7 @@ namespace GeekDesk.Control.UserControls.Config
/// <param name="e"></param>
private void HotKeyDown(object sender, KeyEventArgs e)
{
string tag = (sender as TextBox).Tag.ToString();
HotKeyType hkType = (HotKeyType)(sender as TextBox).Tag;
Key downKey = e.Key;
if (downKey == Key.System)
@@ -56,47 +42,59 @@ namespace GeekDesk.Control.UserControls.Config
downKey = e.SystemKey;
}
bool main = false;
if ("Main".Equals(tag))
{
main = true;
}
if (!CheckIsEnable(hkType)) return;
if (prevKeyTemp == Key.None || prevKeyTemp != downKey)
{
if (hotkeyFinished)
{
if (main)
switch (hkType)
{
appConfig.Hotkey = 0;
appConfig.HotkeyStr = "";
appConfig.HotkeyModifiers = 0;
}
else
{
appConfig.ToDoHotkey = 0;
appConfig.ToDoHotkeyStr = "";
appConfig.ToDoHotkeyModifiers = 0;
case HotKeyType.Main:
appConfig.Hotkey = 0;
appConfig.HotkeyStr = "";
appConfig.HotkeyModifiers = 0;
break;
case HotKeyType.ToDo:
appConfig.ToDoHotkey = 0;
appConfig.ToDoHotkeyStr = "";
appConfig.ToDoHotkeyModifiers = 0;
break;
case HotKeyType.ColorPicker:
appConfig.ColorPickerHotkey = 0;
appConfig.ColorPickerHotkeyStr = "";
appConfig.ColorPickerHotkeyModifiers = 0;
break;
}
hotkeyFinished = false;
}
//首次按下按键
if ((main && (appConfig.HotkeyStr == null || appConfig.HotkeyStr.Length == 0))
|| (!main && (appConfig.ToDoHotkeyStr == null || appConfig.ToDoHotkeyStr.Length == 0)))
if ((HotKeyType.Main == hkType && (appConfig.HotkeyStr == null || appConfig.HotkeyStr.Length == 0))
|| (HotKeyType.ToDo == hkType && (appConfig.ToDoHotkeyStr == null || appConfig.ToDoHotkeyStr.Length == 0))
|| (HotKeyType.ColorPicker == hkType && (appConfig.ColorPickerHotkeyStr == null || appConfig.ColorPickerHotkeyStr.Length == 0))
)
{
if (CheckModifierKeys(downKey))
{
//辅助键
if (main)
switch (hkType)
{
appConfig.HotkeyStr = GetKeyName(downKey);
appConfig.HotkeyModifiers = GetModifierKeys(downKey);
}
else
{
appConfig.ToDoHotkeyStr = GetKeyName(downKey);
appConfig.ToDoHotkeyModifiers = GetModifierKeys(downKey);
case HotKeyType.Main:
appConfig.HotkeyStr = GetKeyName(downKey);
appConfig.HotkeyModifiers = GetModifierKeys(downKey);
break;
case HotKeyType.ToDo:
appConfig.ToDoHotkeyStr = GetKeyName(downKey);
appConfig.ToDoHotkeyModifiers = GetModifierKeys(downKey);
break;
case HotKeyType.ColorPicker:
appConfig.ColorPickerHotkeyStr = GetKeyName(downKey);
appConfig.ColorPickerHotkeyModifiers = GetModifierKeys(downKey);
break;
}
prevKeyTemp = downKey;
keysTemp.Add(e);
}
@@ -109,30 +107,41 @@ namespace GeekDesk.Control.UserControls.Config
|| (downKey >= Key.F1 && downKey <= Key.F12)
|| (downKey >= Key.D0 && downKey <= Key.D9)))
{
if (main)
switch (hkType)
{
appConfig.Hotkey = downKey;
appConfig.HotkeyStr += downKey.ToString();
}
else
{
appConfig.ToDoHotkey = downKey;
appConfig.ToDoHotkeyStr += downKey.ToString();
case HotKeyType.Main:
appConfig.Hotkey = downKey;
appConfig.HotkeyStr += downKey.ToString();
break;
case HotKeyType.ToDo:
appConfig.ToDoHotkey = downKey;
appConfig.ToDoHotkeyStr += downKey.ToString();
break;
case HotKeyType.ColorPicker:
appConfig.ColorPickerHotkey = downKey;
appConfig.ColorPickerHotkeyStr += downKey.ToString();
break;
}
prevKeyTemp = downKey;
keysTemp.Add(e);
}
else if (CheckModifierKeys(downKey))
{
if (main)
switch (hkType)
{
appConfig.HotkeyStr += GetKeyName(downKey);
appConfig.HotkeyModifiers |= GetModifierKeys(downKey);
}
else
{
appConfig.ToDoHotkeyStr += GetKeyName(downKey);
appConfig.ToDoHotkeyModifiers |= GetModifierKeys(downKey);
case HotKeyType.Main:
appConfig.HotkeyStr += GetKeyName(downKey);
appConfig.HotkeyModifiers |= GetModifierKeys(downKey);
break;
case HotKeyType.ToDo:
appConfig.ToDoHotkeyStr += GetKeyName(downKey);
appConfig.ToDoHotkeyModifiers |= GetModifierKeys(downKey);
break;
case HotKeyType.ColorPicker:
appConfig.ColorPickerHotkeyStr += GetKeyName(downKey);
appConfig.ColorPickerHotkeyModifiers |= GetModifierKeys(downKey);
break;
}
prevKeyTemp = downKey;
@@ -194,12 +203,10 @@ 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;
}
HotKeyType hkType = (HotKeyType)(sender as TextBox).Tag;
if (!CheckIsEnable(hkType)) return;
lock (this)
{
bool allKeyUp = true;
@@ -218,30 +225,52 @@ namespace GeekDesk.Control.UserControls.Config
prevKeyTemp = Key.None;
hotkeyFinished = true;
if (main)
switch (hkType)
{
if (MainWindow.hotKeyId != -1)
{
//Hotkey.UnRegist(new WindowInteropHelper(MainWindow.mainWindow).Handle, Hotkey.keymap[MainWindow.hotKeyId]);
GlobalHotKey.Dispose(MainWindow.hotKeyId);
}
MainWindow.RegisterHotKey(false);
case HotKeyType.Main:
if (MainWindow.hotKeyId != -1)
{
//Hotkey.UnRegist(new WindowInteropHelper(MainWindow.mainWindow).Handle, Hotkey.keymap[MainWindow.hotKeyId]);
GlobalHotKey.Dispose(MainWindow.hotKeyId);
}
MainWindow.RegisterHotKey(false);
break;
case HotKeyType.ToDo:
if (MainWindow.toDoHotKeyId != -1)
{
//Hotkey.UnRegist(new WindowInteropHelper(MainWindow.toDoInfoWindow).Handle, Hotkey.keymap[MainWindow.toDoHotKeyId]);
GlobalHotKey.Dispose(MainWindow.toDoHotKeyId);
}
MainWindow.RegisterCreateToDoHotKey(false);
break;
case HotKeyType.ColorPicker:
if (MainWindow.colorPickerHotKeyId != -1)
{
//Hotkey.UnRegist(new WindowInteropHelper(MainWindow.toDoInfoWindow).Handle, Hotkey.keymap[MainWindow.toDoHotKeyId]);
GlobalHotKey.Dispose(MainWindow.colorPickerHotKeyId);
}
MainWindow.RegisterColorPickerHotKey(false);
break;
}
else
{
if (MainWindow.toDoHotKeyId != -1)
{
//Hotkey.UnRegist(new WindowInteropHelper(MainWindow.toDoInfoWindow).Handle, Hotkey.keymap[MainWindow.toDoHotKeyId]);
GlobalHotKey.Dispose(MainWindow.toDoHotKeyId);
}
MainWindow.RegisterCreateToDoHotKey(false);
}
}
}
}
private bool CheckIsEnable(HotKeyType hkType)
{
switch (hkType)
{
case HotKeyType.Main:
return true == appConfig.EnableAppHotKey;
case HotKeyType.ToDo:
return true == appConfig.EnableTodoHotKey;
case HotKeyType.ColorPicker:
return true == appConfig.EnableColorPickerHotKey;
}
return false;
}
/// <summary>
/// 移动窗口
/// </summary>
@@ -295,5 +324,29 @@ namespace GeekDesk.Control.UserControls.Config
}
}
/// <summary>
/// 启用热键
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void EnableHotKey_Click(object sender, RoutedEventArgs e)
{
HotKeyType hkType = (HotKeyType)(sender as CheckBox).Tag;
switch (hkType)
{
case HotKeyType.Main:
if (true == appConfig.EnableAppHotKey)
MainWindow.RegisterHotKey(false);
break;
case HotKeyType.ToDo:
if (true == appConfig.EnableTodoHotKey)
MainWindow.RegisterCreateToDoHotKey(false);
break;
case HotKeyType.ColorPicker:
if (true == appConfig.EnableColorPickerHotKey)
MainWindow.RegisterColorPickerHotKey(false);
break;
}
}
}
}

View File

@@ -1,20 +1,9 @@
using GeekDesk.Constant;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;
namespace GeekDesk.Control.UserControls.Config
{

View File

@@ -18,7 +18,7 @@
<cvt:Visibility2BooleanConverter x:Key="Visibility2BooleanConverter"/>
</UserControl.Resources>
<Grid>
<Grid MouseDown="DragMove" Background="Transparent">
<Grid Background="Transparent">
<StackPanel Margin="20" >
<hc:UniformSpacingPanel Spacing="10" Margin="0,10,0,0" Grid.ColumnSpan="4">
<TextBlock Text="背景风格" VerticalAlignment="Center"/>
@@ -228,10 +228,10 @@
<SolidColorBrush Color="AliceBlue" Opacity="0.01"/>
</StackPanel.Background>-->
<hc:ColorPicker Name="MyColorPicker"
<!--<hc:ColorPicker Name="MyColorPicker"
Canceled="MyColorPicker_Canceled"
Confirmed="MyColorPicker_Confirmed"
SelectedColorChanged="MyColorPicker_SelectedColorChanged"/>
SelectedColorChanged="MyColorPicker_SelectedColorChanged"/>-->
<!--</StackPanel>-->
</Grid>

View File

@@ -1,53 +1,28 @@
using GeekDesk.Constant;
using GeekDesk.Control.Other;
using GeekDesk.Control.Windows;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace GeekDesk.Control.UserControls.Config
{
enum ColorType
{
COLOR_1 = 1,
COLOR_2 = 2,
TEXT_COLOR = 3
}
/// <summary>
/// MotionControl.xaml 的交互逻辑
/// </summary>
public partial class ThemeControl : System.Windows.Controls.UserControl
{
private static ColorType colorType;
private static AppConfig appConfig = MainWindow.appData.AppConfig;
private System.Windows.Controls.Primitives.ToggleButton toggleButton = null;
public ThemeControl()
{
InitializeComponent();
if (appConfig.BGStyle != BGStyle.GradientBac)
{
@@ -111,60 +86,9 @@ namespace GeekDesk.Control.UserControls.Config
private void ColorButton_Click(object sender, RoutedEventArgs e)
{
string tag = (sender as Button).Tag.ToString();
switch (tag)
{
case "Color1":
colorType = ColorType.COLOR_1;break;
case "Color2":
colorType = ColorType.COLOR_2;break;
default:
colorType = ColorType.TEXT_COLOR;break;
}
MyColorPicker.Visibility = Visibility.Visible;
new ColorPickerWindow().Show();
new MyColorPickerDialog(tag, "ConfigWindowDialog");
}
/// <summary>
/// 取消按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyColorPicker_Canceled(object sender, EventArgs e)
{
MyColorPickerClose(sender);
}
private void MyColorPicker_Confirmed(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
{
MyColorPickerClose(sender);
}
private void MyColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
{
SolidColorBrush scb = MyColorPicker.SelectedBrush;
switch (colorType)
{
case ColorType.COLOR_1:
appConfig.GradientBGParam.Color1 = scb.ToString();break;
case ColorType.COLOR_2:
appConfig.GradientBGParam.Color2 = scb.ToString(); break;
default:
appConfig.TextColor = scb.ToString();break;
}
}
/// <summary>
/// 移动窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Window.GetWindow(this).DragMove();
}
}
private void PreviewSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
@@ -174,6 +98,7 @@ namespace GeekDesk.Control.UserControls.Config
};
System.Threading.ThreadStart ts = new System.Threading.ThreadStart(cbu.CheckButtonUp);
System.Threading.Thread t = new System.Threading.Thread(ts);
t.IsBackground = true;
t.Start();
}
@@ -201,25 +126,6 @@ namespace GeekDesk.Control.UserControls.Config
}
}
private void MyColorPicker_Checked(object sender, RoutedEventArgs e)
{
toggleButton = e.OriginalSource as System.Windows.Controls.Primitives.ToggleButton;
}
private void MyColorPickerClose(object sender)
{
if (toggleButton != null && toggleButton.IsChecked == true)
{
HandyControl.Controls.ColorPicker cp = sender as HandyControl.Controls.ColorPicker;
const BindingFlags InstanceBindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
Type type = cp.GetType();
toggleButton.IsChecked = false;
MethodInfo mi = type.GetMethod("ToggleButtonDropper_Click", InstanceBindFlags);
mi.Invoke(cp, new object[] { null, null });
}
MyColorPicker.Visibility = Visibility.Collapsed;
}
public void BGStyle_Changed(object sender, RoutedEventArgs e)
{
@@ -228,7 +134,8 @@ namespace GeekDesk.Control.UserControls.Config
{
GradientBGConf.Visibility = Visibility.Collapsed;
ImgBGConf.Visibility = Visibility.Visible;
} else
}
else
{
ImgBGConf.Visibility = Visibility.Collapsed;
GradientBGConf.Visibility = Visibility.Visible;
@@ -248,7 +155,7 @@ namespace GeekDesk.Control.UserControls.Config
private void SysBG_Click(object sender, RoutedEventArgs e)
{
GradientBGDialog gbg = new GradientBGDialog();
gbg.dialog = HandyControl.Controls.Dialog.Show(gbg, "SysBGDialog");
gbg.dialog = HandyControl.Controls.Dialog.Show(gbg, "ConfigWindowDialog");
}
}
}