Files
GeekDesk/MainWindow.xaml.cs

1169 lines
38 KiB
C#
Raw Permalink Normal View History

2022-03-25 16:23:54 +08:00
using GeekDesk.Constant;
2023-04-13 16:39:24 +08:00
using GeekDesk.Control.Other;
using GeekDesk.Control.UserControls.Config;
using GeekDesk.Control.UserControls.PannelCard;
using GeekDesk.Control.Windows;
2021-12-20 09:39:27 +08:00
using GeekDesk.Interface;
2022-03-25 16:23:54 +08:00
using GeekDesk.MyThread;
2023-03-27 18:10:39 +08:00
using GeekDesk.Plugins.EveryThing;
using GeekDesk.Plugins.EveryThing.Constant;
using GeekDesk.Task;
2021-04-13 15:26:19 +08:00
using GeekDesk.Util;
using GeekDesk.ViewModel;
using GeekDesk.ViewModel.Temp;
using Microsoft.Win32;
using NPinyin;
2022-09-01 15:23:44 +08:00
using ShowSeconds;
2021-04-13 15:26:19 +08:00
using System;
using System.Collections.ObjectModel;
2021-05-14 16:48:26 +08:00
using System.Diagnostics;
2023-04-19 15:42:51 +08:00
using System.IO;
2023-04-18 18:13:25 +08:00
using System.Runtime.CompilerServices;
2023-03-27 18:10:39 +08:00
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
2021-04-12 13:46:05 +08:00
using System.Windows;
2021-04-13 15:26:19 +08:00
using System.Windows.Controls;
2021-04-12 13:46:05 +08:00
using System.Windows.Input;
using System.Windows.Interop;
2023-04-18 18:13:25 +08:00
using System.Windows.Media;
using System.Windows.Media.Animation;
2023-03-31 09:06:04 +08:00
using System.Windows.Media.Imaging;
2023-04-18 18:13:25 +08:00
using System.Windows.Media.Media3D;
2023-03-27 18:10:39 +08:00
using System.Windows.Shell;
2022-05-23 17:52:35 +08:00
using System.Windows.Threading;
2021-07-29 17:04:36 +08:00
using static GeekDesk.Util.ShowWindowFollowMouse;
2021-04-12 13:46:05 +08:00
namespace GeekDesk
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
///
2021-12-20 09:39:27 +08:00
public partial class MainWindow : Window, IWindowCommon
2021-04-12 13:46:05 +08:00
{
2023-04-19 15:50:46 +08:00
public static AppData appData;
2021-07-19 17:30:34 +08:00
public static ToDoInfoWindow toDoInfoWindow;
public static int hotKeyId = -1;
public static int toDoHotKeyId = -1;
public static int colorPickerHotKeyId = -1;
public static MainWindow mainWindow;
2023-04-19 15:42:51 +08:00
2023-04-23 20:58:12 +08:00
2023-04-19 15:42:51 +08:00
private static bool dataFileExist = true;
2021-04-12 13:46:05 +08:00
public MainWindow()
{
2023-04-19 15:50:46 +08:00
//加载数据
2021-05-20 17:33:49 +08:00
LoadData();
2021-05-31 17:31:16 +08:00
InitializeComponent();
2023-04-23 20:58:12 +08:00
//用于其他类访问
mainWindow = this;
//执行待办提醒
ToDoTask.BackLogCheck();
2022-03-25 16:23:54 +08:00
////实例化隐藏 Hide类进行时间timer设置
2022-01-09 16:00:47 +08:00
MarginHide.ReadyHide(this);
if (appData.AppConfig.MarginHide)
{
2022-01-09 16:00:47 +08:00
MarginHide.StartHide();
}
2021-04-12 13:46:05 +08:00
}
2023-04-23 20:58:12 +08:00
private void Window_SourceInitialized(object sender, EventArgs e)
{
2023-04-23 21:46:55 +08:00
try
{
//禁用窗口最大化
WindowUtil.DisableMaxWindow(this);
}
catch (Exception) { }
2023-04-23 20:58:12 +08:00
}
2022-05-09 15:25:48 +08:00
2022-03-25 16:23:54 +08:00
/// <summary>
/// 搜索快捷键按下
2022-03-25 16:23:54 +08:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2022-05-24 17:57:56 +08:00
private void SearchHotKeyDown(object sender, CanExecuteRoutedEventArgs e)
{
2023-04-06 18:10:49 +08:00
if (appData.AppConfig.SearchType == SearchType.HOT_KEY && !RunTimeStatus.SEARCH_BOX_SHOW)
2022-05-24 17:57:56 +08:00
{
ShowSearchBox();
2023-04-06 18:10:49 +08:00
} else if (RunTimeStatus.SEARCH_BOX_SHOW)
{
HidedSearchBox();
2022-05-24 17:57:56 +08:00
}
}
/// <summary>
/// 显示搜索框
/// </summary>
2022-05-24 17:57:56 +08:00
private void ShowSearchBox()
2022-03-25 16:23:54 +08:00
{
2022-04-08 16:05:48 +08:00
RunTimeStatus.SEARCH_BOX_SHOW = true;
2022-03-25 16:23:54 +08:00
RightCard.VisibilitySearchCard(Visibility.Visible);
2022-05-24 17:57:56 +08:00
SearchBox.Width = 400;
2022-03-25 16:23:54 +08:00
SearchBox.Focus();
2023-03-31 09:06:04 +08:00
//执行一遍a查询
2023-04-06 18:10:49 +08:00
//SearchBox_TextChanged(null, null);
2022-03-25 16:23:54 +08:00
}
/// <summary>
/// 搜索开始
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (!RunTimeStatus.SEARCH_BOX_SHOW
&& appData.AppConfig.SearchType != SearchType.KEY_DOWN
)
2022-05-24 17:57:56 +08:00
{
SearchBox.TextChanged -= SearchBox_TextChanged;
SearchBox.Clear();
SearchBox.TextChanged += SearchBox_TextChanged;
2022-05-24 17:57:56 +08:00
return;
}
if (!RunTimeStatus.SEARCH_BOX_SHOW) ShowSearchBox();
//刷新搜索后 鼠标移动次数置为0
RunTimeStatus.MOUSE_MOVE_COUNT = 0;
//隐藏popup
RightCard.MyPoptip.IsOpen = false;
2022-03-25 16:23:54 +08:00
string inputText = SearchBox.Text.ToLower();
if (!string.IsNullOrEmpty(inputText))
2023-03-27 18:10:39 +08:00
{
2023-03-31 09:06:04 +08:00
RunTimeStatus.EVERYTHING_SEARCH_DELAY_TIME = 300;
if (!RunTimeStatus.EVERYTHING_NEW_SEARCH)
{
RunTimeStatus.EVERYTHING_NEW_SEARCH = true;
2023-04-14 13:48:50 +08:00
//显示搜索结果列表
RightCard.VisibilitySearchCard(Visibility.Visible);
2023-04-14 21:30:15 +08:00
//暂时隐藏条目信息
2023-04-14 14:26:42 +08:00
SearchResContainer.Visibility = Visibility.Collapsed;
2023-04-14 21:30:15 +08:00
//显示加载条
RightCard.Loading_RightCard.Visibility = Visibility.Visible;
2023-04-13 16:39:24 +08:00
object obj = RightCard.VerticalCard.Content;
if (obj != null)
{
SearchResControl control = obj as SearchResControl;
control.VerticalUFG.Visibility = Visibility.Collapsed;
}
2023-04-04 17:59:06 +08:00
SearchDelay();
2023-03-31 09:06:04 +08:00
}
} else
2022-03-25 16:23:54 +08:00
{
2023-04-14 21:30:15 +08:00
//隐藏条目信息
SearchResContainer.Visibility = Visibility.Collapsed;
2023-04-13 16:39:24 +08:00
//清空查询结果
object obj = RightCard.VerticalCard.Content;
if (obj != null)
2023-03-31 09:06:04 +08:00
{
2023-04-13 16:39:24 +08:00
SearchResControl control = obj as SearchResControl;
control.VerticalUFG.Visibility = Visibility.Collapsed;
}
2023-03-27 18:10:39 +08:00
}
}
2023-04-04 17:59:06 +08:00
private void SearchDelay()
2023-03-27 18:10:39 +08:00
{
2023-03-31 09:06:04 +08:00
new Thread(() =>
{
2023-03-27 18:10:39 +08:00
2023-03-31 09:06:04 +08:00
while (RunTimeStatus.EVERYTHING_SEARCH_DELAY_TIME > 0)
2022-03-25 16:23:54 +08:00
{
2023-03-31 09:06:04 +08:00
Thread.Sleep(10);
RunTimeStatus.EVERYTHING_SEARCH_DELAY_TIME -= 10;
2022-03-25 16:23:54 +08:00
}
2023-03-31 09:06:04 +08:00
RunTimeStatus.EVERYTHING_NEW_SEARCH = false;
2023-03-27 18:10:39 +08:00
2023-03-31 09:06:04 +08:00
this.Dispatcher.Invoke(() =>
2023-03-27 18:10:39 +08:00
{
2023-03-31 09:06:04 +08:00
string inputText = SearchBox.Text.ToLower().Trim();
2023-04-17 14:12:31 +08:00
if (string.IsNullOrEmpty(inputText))
{
RightCard.Loading_RightCard.Visibility = Visibility.Collapsed;
return;
}
2023-04-13 16:39:24 +08:00
new Thread(() =>
2023-03-31 09:06:04 +08:00
{
2023-04-13 16:39:24 +08:00
ObservableCollection<IconInfo> resList = new ObservableCollection<IconInfo>();
2023-04-14 13:48:50 +08:00
if (appData.AppConfig.EnableEveryThing == true)
2023-03-27 18:10:39 +08:00
{
2023-04-14 14:26:42 +08:00
ObservableCollection<IconInfo> iconBakList = EveryThingUtil.Search(inputText);
2023-04-14 13:48:50 +08:00
foreach (IconInfo icon in iconBakList)
{
resList.Add(icon);
}
2023-03-27 18:10:39 +08:00
}
2023-04-17 14:12:31 +08:00
int geekDeskCount = 0;
2023-04-13 16:39:24 +08:00
//GeekDesk数据搜索
ObservableCollection<MenuInfo> menuList = appData.MenuList;
foreach (MenuInfo menu in menuList)
2023-03-27 18:10:39 +08:00
{
2023-04-13 16:39:24 +08:00
ObservableCollection<IconInfo> iconList = menu.IconList;
foreach (IconInfo icon in iconList)
2023-03-31 09:06:04 +08:00
{
2023-04-13 16:39:24 +08:00
if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return;
string pyName = Pinyin.GetInitials(icon.Name).ToLower();
if (icon.Name.Contains(inputText) || pyName.Contains(inputText))
2023-03-31 09:06:04 +08:00
{
2023-04-17 14:12:31 +08:00
geekDeskCount++;
2023-04-13 16:39:24 +08:00
resList.Add(icon);
2023-03-31 09:06:04 +08:00
}
}
2023-04-13 16:39:24 +08:00
}
2023-03-27 18:10:39 +08:00
2023-04-13 16:39:24 +08:00
this.Dispatcher.Invoke(() =>
{
2023-04-14 13:48:50 +08:00
if (appData.AppConfig.EnableEveryThing == true)
{
2023-04-17 14:12:31 +08:00
int everythingTotal = Convert.ToInt32(EveryThingUtil.Everything_GetNumResults());
GeekDeskSearchTotal.Text = Convert.ToString(geekDeskCount);
EverythingSearchCount.Text = Convert.ToString(resList.Count - geekDeskCount);
EverythingSearchTotal.Text = Convert.ToString(everythingTotal + geekDeskCount);
2023-04-14 14:26:42 +08:00
SearchResContainer.Visibility = Visibility.Visible;
2023-04-14 13:48:50 +08:00
}
2023-04-13 16:39:24 +08:00
SearchResControl control = new SearchResControl(resList);
RightCard.VerticalCard.Content = control;
2023-04-14 21:30:15 +08:00
//关闭加载效果
2023-04-13 16:39:24 +08:00
RightCard.Loading_RightCard.Visibility = Visibility.Collapsed;
});
}).Start();
2023-03-31 09:06:04 +08:00
});
}).Start();
2022-03-25 16:23:54 +08:00
}
2022-04-08 16:05:48 +08:00
/// <summary>
/// 隐藏搜索框
/// </summary>
2022-04-08 16:05:48 +08:00
public void HidedSearchBox()
2022-03-25 16:23:54 +08:00
{
2023-03-31 09:06:04 +08:00
RunTimeStatus.EVERYTHING_NEW_SEARCH = true;
RunTimeStatus.SEARCH_BOX_HIDED_300 = false;
new Thread(() =>
{
Thread.Sleep(300);
RunTimeStatus.SEARCH_BOX_HIDED_300 = true;
}).Start();
2023-03-31 09:06:04 +08:00
new Thread(() =>
{
Thread.Sleep(1000);
RunTimeStatus.EVERYTHING_NEW_SEARCH = false;
}).Start();
2023-04-04 17:59:06 +08:00
new Thread(() =>
{
this.Dispatcher.Invoke(() =>
{
Keyboard.Focus(SearchBox);
RunTimeStatus.SEARCH_BOX_SHOW = false;
SearchBox.TextChanged -= SearchBox_TextChanged;
SearchBox.Clear();
SearchBox.TextChanged += SearchBox_TextChanged;
SearchBox.Width = 0;
2023-04-14 14:26:42 +08:00
SearchResContainer.Visibility = Visibility.Collapsed;
2023-04-14 13:48:50 +08:00
RightCard.VerticalCard.Content = null;
2023-04-04 17:59:06 +08:00
RightCard.VisibilitySearchCard(Visibility.Collapsed);
});
}).Start();
2022-03-25 16:23:54 +08:00
}
/// <summary>
/// 加载缓存数据
/// </summary>
2021-05-20 17:33:49 +08:00
private void LoadData()
2021-04-13 15:26:19 +08:00
{
2023-04-19 15:50:46 +08:00
//判断数据文件是否存在 如果不存在那么是第一次打开程序
dataFileExist = File.Exists(Constants.DATA_FILE_PATH);
appData = CommonCode.GetAppDataByFile();
2021-04-13 15:26:19 +08:00
this.DataContext = appData;
2021-05-12 10:00:12 +08:00
if (appData.MenuList.Count == 0)
2021-04-13 15:26:19 +08:00
{
2022-01-09 16:00:47 +08:00
appData.MenuList.Add(new MenuInfo() { MenuName = "NewMenu", MenuId = System.Guid.NewGuid().ToString(), MenuEdit = Visibility.Collapsed });
2021-04-13 15:26:19 +08:00
}
2021-05-28 18:01:19 +08:00
2021-05-12 10:00:12 +08:00
this.Width = appData.AppConfig.WindowWidth;
2022-01-09 16:00:47 +08:00
this.Height = appData.AppConfig.WindowHeight;
2021-04-12 13:46:05 +08:00
}
/// <summary>
/// 窗口加载完毕 执行方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2021-04-12 13:46:05 +08:00
void Window_Loaded(object sender, RoutedEventArgs e)
{
2022-05-09 15:25:48 +08:00
BGSettingUtil.BGSetting();
2021-05-20 17:33:49 +08:00
if (!appData.AppConfig.StartedShowPanel)
{
this.Visibility = Visibility.Collapsed;
2022-01-09 16:00:47 +08:00
}
else
{
ShowApp();
2021-05-20 17:33:49 +08:00
}
2021-12-20 09:39:27 +08:00
//给任务栏图标一个名字
2021-12-13 10:53:55 +08:00
BarIcon.Text = Constants.MY_NAME;
//注册热键
if (true == appData.AppConfig.EnableAppHotKey)
{
RegisterHotKey(true);
}
if (true == appData.AppConfig.EnableTodoHotKey)
{
RegisterCreateToDoHotKey(true);
}
if (true == appData.AppConfig.EnableColorPickerHotKey)
{
RegisterColorPickerHotKey(true);
}
2021-07-21 11:15:51 +08:00
//注册自启动
if (!appData.AppConfig.SelfStartUped && !Constants.DEV)
2021-07-21 11:15:51 +08:00
{
RegisterUtil.SetSelfStarting(appData.AppConfig.SelfStartUp, Constants.MY_NAME);
}
2021-07-20 17:30:12 +08:00
//注册鼠标监听事件
2022-09-01 15:23:44 +08:00
if (appData.AppConfig.MouseMiddleShow)
{
MouseHookThread.Hook();
}
2022-09-01 15:23:44 +08:00
//显秒插件
if (appData.AppConfig.SecondsWindow == true)
{
SecondsWindow.ShowWindow();
}
//监听实时文件夹菜单
2023-04-06 16:09:33 +08:00
FileWatcher.EnableLinkMenuWatcher(appData);
//更新任务开启 检测更新
UpdateTask.Start();
2022-06-07 16:34:07 +08:00
//建立相对路径
RelativePathThread.MakeRelativePath();
2022-06-07 11:16:14 +08:00
//毛玻璃 暂时未解决阴影问题
//BlurGlassUtil.EnableBlur(this);
//设置归属桌面 解决桌面覆盖程序界面的bug
2023-03-31 18:17:24 +08:00
WindowUtil.SetOwner(this, WindowUtil.GetDesktopHandle(this, DesktopLayer.Progman));
2023-03-27 18:10:39 +08:00
2023-03-31 09:06:04 +08:00
if (appData.AppConfig.EnableEveryThing == true)
{
//开启EveryThing插件
EveryThingUtil.EnableEveryThing();
}
//启动文件备份任务
BakTask.Start();
2023-03-31 09:06:04 +08:00
Keyboard.Focus(SearchBox);
2023-03-27 18:10:39 +08:00
MessageUtil.ChangeWindowMessageFilter(MessageUtil.WM_COPYDATA, 1);
2023-04-18 18:13:25 +08:00
2023-04-19 15:42:51 +08:00
if (!dataFileExist)
{
Guide();
}
}
2023-04-18 18:13:25 +08:00
/// <summary>
/// 注册当前窗口的热键
/// </summary>
public static void RegisterHotKey(bool first)
{
2021-06-02 17:34:02 +08:00
try
{
2022-05-24 17:57:56 +08:00
if (appData.AppConfig.HotkeyModifiers != GlobalHotKey.HotkeyModifiers.None)
{
hotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.HotkeyModifiers, appData.AppConfig.Hotkey, () =>
{
if (RunTimeStatus.MAIN_HOT_KEY_DOWN) return;
RunTimeStatus.MAIN_HOT_KEY_DOWN = true;
new Thread(() =>
{
Thread.Sleep(RunTimeStatus.MAIN_HOT_KEY_TIME);
RunTimeStatus.MAIN_HOT_KEY_DOWN = false;
}).Start();
if (MotionControl.hotkeyFinished)
{
if (CheckShouldShowApp())
{
ShowApp();
}
else
{
HideApp();
}
}
});
if (!first)
{
HandyControl.Controls.Growl.Success("GeekDesk快捷键注册成功(" + appData.AppConfig.HotkeyStr + ")!", "HotKeyGrowl");
}
}
else
2022-05-24 17:57:56 +08:00
{
}
}
catch (Exception)
{
if (first)
{
HandyControl.Controls.Growl.WarningGlobal("GeekDesk启动快捷键已被其它程序占用(" + appData.AppConfig.HotkeyStr + ")!");
}
else
{
HandyControl.Controls.Growl.Warning("GeekDesk启动快捷键已被其它程序占用(" + appData.AppConfig.HotkeyStr + ")!", "HotKeyGrowl");
}
}
}
/// <summary>
/// 注册新建待办的热键
/// </summary>
public static void RegisterCreateToDoHotKey(bool first)
{
try
{
2022-05-24 17:57:56 +08:00
if (appData.AppConfig.HotkeyModifiers != GlobalHotKey.HotkeyModifiers.None)
{
//加载完毕注册热键
toDoHotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.ToDoHotkeyModifiers, appData.AppConfig.ToDoHotkey, () =>
{
if (MotionControl.hotkeyFinished)
{
2022-05-23 17:52:35 +08:00
ToDoWindow.ShowOrHide();
}
});
if (!first)
{
HandyControl.Controls.Growl.Success("新建待办任务快捷键注册成功(" + appData.AppConfig.ToDoHotkeyStr + ")!", "HotKeyGrowl");
}
}
}
catch (Exception)
2021-06-02 17:34:02 +08:00
{
if (first)
{
HandyControl.Controls.Growl.WarningGlobal("新建待办任务快捷键已被其它程序占用(" + appData.AppConfig.ToDoHotkeyStr + ")!");
}
else
{
HandyControl.Controls.Growl.Warning("新建待办任务快捷键已被其它程序占用(" + appData.AppConfig.ToDoHotkeyStr + ")!", "HotKeyGrowl");
}
2021-06-02 17:34:02 +08:00
}
}
/// <summary>
/// 注册新建待办的热键
/// </summary>
public static void RegisterColorPickerHotKey(bool first)
{
try
{
2022-05-24 17:57:56 +08:00
if (appData.AppConfig.HotkeyModifiers != GlobalHotKey.HotkeyModifiers.None)
{
//加载完毕注册热键
colorPickerHotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.ColorPickerHotkeyModifiers, appData.AppConfig.ColorPickerHotkey, () =>
{
if (MotionControl.hotkeyFinished)
{
2022-05-23 17:52:35 +08:00
GlobalColorPickerWindow.CreateNoShow();
}
});
if (!first)
{
HandyControl.Controls.Growl.Success("拾色器快捷键注册成功(" + appData.AppConfig.ColorPickerHotkeyStr + ")!", "HotKeyGrowl");
}
}
}
catch (Exception)
{
if (first)
{
HandyControl.Controls.Growl.WarningGlobal("拾色器快捷键已被其它程序占用(" + appData.AppConfig.ColorPickerHotkeyStr + ")!");
}
else
{
HandyControl.Controls.Growl.Warning("拾色器快捷键已被其它程序占用(" + appData.AppConfig.ColorPickerHotkeyStr + ")!", "HotKeyGrowl");
}
}
}
2021-04-12 13:46:05 +08:00
2022-01-09 16:00:47 +08:00
/// <summary>
/// 程序窗体拖动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2021-05-12 10:00:12 +08:00
private void DragMove(object sender, MouseEventArgs e)
2021-04-12 13:46:05 +08:00
{
2021-05-12 10:00:12 +08:00
if (e.LeftButton == MouseButtonState.Pressed)
{
2021-05-19 17:31:28 +08:00
DragMove();
2021-05-12 10:00:12 +08:00
}
2021-05-08 17:27:41 +08:00
}
2021-04-12 13:46:05 +08:00
2021-05-12 10:00:12 +08:00
/// <summary>
/// 关闭按钮单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CloseButtonClick(object sender, RoutedEventArgs e)
{
2022-05-24 17:57:56 +08:00
HideApp();
2021-05-12 10:00:12 +08:00
}
2022-01-09 16:00:47 +08:00
2021-05-19 17:31:28 +08:00
2021-05-28 18:01:19 +08:00
///// <summary>
///// 左侧栏宽度改变 持久化
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void LeftCardResize(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
//{
// appData.AppConfig.MenuCardWidth = LeftColumn.Width.Value;
//}
2021-05-19 17:31:28 +08:00
2022-01-09 16:00:47 +08:00
2021-06-01 21:49:50 +08:00
/// <summary>
/// 右键任务栏图标 显示主面板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2022-04-12 16:57:29 +08:00
public void ShowApp(object sender, RoutedEventArgs e)
2021-06-01 21:49:50 +08:00
{
ShowApp();
}
public static void ShowApp()
2021-06-01 21:49:50 +08:00
{
//有全屏化应用则不显示
//if (CommonCode.IsPrimaryFullScreen())
//{
// return;
//}
2022-04-20 16:38:55 +08:00
if (MarginHide.ON_HIDE)
{
//修改贴边隐藏状态为未隐藏
2022-04-20 16:38:55 +08:00
MarginHide.IS_HIDE = false;
if (!CommonCode.MouseInWindow(mainWindow))
{
RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW = true;
MarginHide.WaitHide(3000);
}
}
2021-06-01 21:49:50 +08:00
if (appData.AppConfig.FollowMouse)
{
ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0);
//ShowWindowFollowMouse.FollowMouse(mainWindow);
2021-06-01 21:49:50 +08:00
}
2023-03-31 18:17:24 +08:00
MainWindow.mainWindow.Activate();
mainWindow.Show();
//mainWindow.Visibility = Visibility.Visible;
if (appData.AppConfig.AppAnimation)
{
appData.AppConfig.IsShow = true;
}
else
{
appData.AppConfig.IsShow = null;
//防止永远不显示界面
if (mainWindow.Opacity < 1)
{
mainWindow.Opacity = 1;
}
}
//FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible);
2022-04-20 16:38:55 +08:00
Keyboard.Focus(mainWindow);
if (RunTimeStatus.SHOW_MENU_PASSWORDBOX)
{
mainWindow.RightCard.PDDialog.SetFocus();
}
else
{
Keyboard.Focus(mainWindow.SearchBox);
}
2021-06-01 21:49:50 +08:00
}
public static void HideApp()
{
if (appData.AppConfig.AppAnimation)
2022-04-12 16:57:29 +08:00
{
appData.AppConfig.IsShow = false;
}
else
{
appData.AppConfig.IsShow = null;
HideAppVis();
}
}
private static void HideAppVis()
{
//关闭锁定
RunTimeStatus.LOCK_APP_PANEL = false;
if (RunTimeStatus.SEARCH_BOX_SHOW)
{
mainWindow.HidedSearchBox();
}
mainWindow.Visibility = Visibility.Collapsed;
//if (!MarginHide.IS_HIDE)
//{
//}
//else
//{
// ShowApp();
//}
}
2022-01-09 16:00:47 +08:00
/// <summary>
/// 淡入淡出效果
/// </summary>
/// <param name="opacity"></param>
/// <param name="milliseconds"></param>
/// <param name="visibility"></param>
public static void FadeStoryBoard(int opacity, int milliseconds, Visibility visibility)
{
if (appData.AppConfig.AppAnimation)
{
DoubleAnimation opacityAnimation = new DoubleAnimation
{
From = mainWindow.Opacity,
To = opacity,
Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds))
};
opacityAnimation.Completed += (s, e) =>
{
mainWindow.BeginAnimation(OpacityProperty, null);
if (visibility == Visibility.Visible)
{
mainWindow.Opacity = 1;
}
else
{
mainWindow.Opacity = 0;
2022-03-25 16:23:54 +08:00
CommonCode.SortIconList();
2022-01-09 16:00:47 +08:00
}
};
Timeline.SetDesiredFrameRate(opacityAnimation, 60);
mainWindow.BeginAnimation(OpacityProperty, opacityAnimation);
}
else
{
//防止关闭动画后 窗体仍是0透明度
mainWindow.Opacity = 1;
mainWindow.Visibility = visibility;
2022-03-25 16:23:54 +08:00
if (visibility == Visibility.Collapsed)
{
CommonCode.SortIconList();
}
2022-01-09 16:00:47 +08:00
}
}
2021-05-19 17:31:28 +08:00
2021-05-12 10:00:12 +08:00
/// <summary>
/// 图片图标单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void NotifyIcon_Click(object sender, RoutedEventArgs e)
{
if (CheckShouldShowApp())
2021-05-12 10:00:12 +08:00
{
2021-05-19 17:31:28 +08:00
ShowApp();
}
else
2021-05-12 10:00:12 +08:00
{
HideApp();
2021-05-12 10:00:12 +08:00
}
}
private static bool CheckShouldShowApp()
2023-03-31 18:17:24 +08:00
{
return mainWindow.Visibility == Visibility.Collapsed
|| mainWindow.Opacity == 0
|| MarginHide.IS_HIDE
|| !WindowUtil.WindowIsTop(mainWindow);
}
2021-05-14 16:48:26 +08:00
/// <summary>
2021-05-19 17:31:28 +08:00
/// 右键任务栏图标 设置
2021-05-14 16:48:26 +08:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2021-05-19 17:31:28 +08:00
private void ConfigApp(object sender, RoutedEventArgs e)
2021-05-14 16:48:26 +08:00
{
ConfigWindow.Show(appData.AppConfig, this);
2021-05-14 16:48:26 +08:00
}
/// <summary>
/// 右键任务栏图标打开程序目录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenThisDir(object sender, RoutedEventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = "Explorer.exe";
p.StartInfo.Arguments = "/e,/select," + Constants.APP_DIR + Constants.MY_NAME + ".exe";
p.Start();
}
2021-05-19 17:31:28 +08:00
2021-05-28 18:01:19 +08:00
2021-05-14 16:48:26 +08:00
/// <summary>
/// 设置图标
2021-05-14 16:48:26 +08:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2021-05-19 17:31:28 +08:00
private void ConfigButtonClick(object sender, RoutedEventArgs e)
2021-05-14 16:48:26 +08:00
{
SettingMenus.IsOpen = true;
2021-05-19 17:31:28 +08:00
}
/// <summary>
/// 设置菜单点击
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ConfigMenuClick(object sender, RoutedEventArgs e)
{
ConfigWindow.Show(appData.AppConfig, this);
}
/// <summary>
/// 待办任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BacklogMenuClick(object sender, RoutedEventArgs e)
{
ToDoWindow.Show();
}
2021-05-19 17:31:28 +08:00
/// <summary>
/// 禁用设置按钮右键菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SettingButton_Initialized(object sender, EventArgs e)
{
SettingButton.ContextMenu = null;
2021-05-14 16:48:26 +08:00
}
2021-05-20 17:33:49 +08:00
private void AppWindowLostFocus()
2021-05-20 17:33:49 +08:00
{
2022-03-25 16:23:54 +08:00
if (appData.AppConfig.AppHideType == AppHideType.LOST_FOCUS
&& this.Opacity == 1 && !RunTimeStatus.LOCK_APP_PANEL)
2021-05-20 17:33:49 +08:00
{
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
2022-03-25 16:23:54 +08:00
if (!appData.AppConfig.MarginHide || (appData.AppConfig.MarginHide && !MarginHide.IS_HIDE))
{
2022-03-25 16:23:54 +08:00
HideApp();
}
2021-05-20 17:33:49 +08:00
}
}
2021-05-21 17:19:46 +08:00
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
2021-07-07 17:28:29 +08:00
{
if (this.DataContext != null)
{
AppData appData = this.DataContext as AppData;
appData.AppConfig.WindowWidth = this.Width;
appData.AppConfig.WindowHeight = this.Height;
}
if (guideRun)
{
Guide();
}
2021-07-07 17:28:29 +08:00
}
2022-01-09 16:00:47 +08:00
/// <summary>
/// 右键任务栏图标退出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ExitApp(object sender, RoutedEventArgs e)
{
if (appData.AppConfig.MouseMiddleShow || appData.AppConfig.SecondsWindow == true)
2022-01-09 16:00:47 +08:00
{
MouseHookThread.Dispose();
}
2023-03-31 09:06:04 +08:00
if (appData.AppConfig.EnableEveryThing == true)
{
EveryThingUtil.DisableEveryThing();
}
2022-01-09 16:00:47 +08:00
Application.Current.Shutdown();
}
/// <summary>
/// 重启
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void ReStartApp(object sender, RoutedEventArgs e)
{
ProcessUtil.ReStartApp();
}
2021-12-13 10:53:55 +08:00
/// <summary>
/// 关闭托盘图标
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CloseBarIcon(object sender, RoutedEventArgs e)
{
appData.AppConfig.ShowBarIcon = false;
}
2021-12-20 09:39:27 +08:00
public void OnKeyDown(object sender, KeyEventArgs e)
{
//char c = (char)e.Key;
2022-05-24 17:57:56 +08:00
2021-12-20 09:39:27 +08:00
if (e.Key == Key.Escape)
{
HideApp();
}
if (RunTimeStatus.SEARCH_BOX_SHOW && (e.Key == Key.Up
|| e.Key == Key.Down
|| e.Key == Key.Tab
|| e.Key == Key.Enter
))
{
if (e.Key == Key.Down || e.Key == Key.Tab)
{
2023-04-13 16:39:24 +08:00
SearchResControl res = RightCard.VerticalCard.Content as SearchResControl;
res.SearchListBoxIndexAdd();
}
else if (e.Key == Key.Up)
{
2023-04-13 16:39:24 +08:00
SearchResControl res = RightCard.VerticalCard.Content as SearchResControl;
res.SearchListBoxIndexSub();
}
else if (e.Key == Key.Enter)
{
2023-04-13 16:39:24 +08:00
SearchResControl res = RightCard.VerticalCard.Content as SearchResControl;
res.StartupSelectionItem();
}
}
2021-12-20 09:39:27 +08:00
}
2021-04-12 13:46:05 +08:00
2022-05-24 17:57:56 +08:00
2022-03-25 16:23:54 +08:00
/// <summary>
/// 为了让修改菜单的textBox失去焦点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e)
{
2022-05-24 17:57:56 +08:00
SearchBox.Focus();
2022-03-25 16:23:54 +08:00
}
2021-04-12 13:46:05 +08:00
2022-04-20 16:38:55 +08:00
/// <summary>
/// 鼠标进入后
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainWindow_MouseEnter(object sender, MouseEventArgs e)
{
//防止延迟贴边隐藏
RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW = false;
}
2022-05-23 17:52:35 +08:00
/// <summary>
/// 打开屏幕拾色器
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ColorPicker(object sender, RoutedEventArgs e)
{
TaskbarContextMenu.IsOpen = false;
2022-05-23 17:52:35 +08:00
GlobalColorPickerWindow.CreateNoShow();
}
private void Window_GotFocus(object sender, RoutedEventArgs e)
{
// 如果没有在修改菜单 并且不是右键点击了面板
if (!RunTimeStatus.IS_MENU_EDIT
&& !RunTimeStatus.SHOW_RIGHT_BTN_MENU
&& !RunTimeStatus.APP_BTN_IS_DOWN)
{
if (RunTimeStatus.SHOW_MENU_PASSWORDBOX)
{
//必须在其它文本框没有工作的时候才给密码框焦点
RightCard.PDDialog.SetFocus();
}
else
{
//必须在其它文本框没有工作的时候才给搜索框焦点
Keyboard.Focus(SearchBox);
}
}
}
private void AppWindow_Deactivated(object sender, EventArgs e)
{
AppWindowLostFocus();
}
/// <summary>
/// 备份数据文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[Obsolete]
private void BakDataFile(object sender, RoutedEventArgs e)
{
Thread t = new Thread(() =>
{
CommonCode.BakAppData();
});
t.ApartmentState = ApartmentState.STA;
t.Start();
}
private void AppButton_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
//点击了面板
RunTimeStatus.APP_BTN_IS_DOWN = true;
new Thread(() =>
{
Thread.Sleep(50);
RunTimeStatus.APP_BTN_IS_DOWN = false;
}).Start();
}
private ICommand _hideCommand;
public ICommand HideCommand
{
get
{
if (_hideCommand == null)
{
_hideCommand = new RelayCommand(
p =>
{
return true;
},
p =>
{
HideAppVis();
});
}
return _hideCommand;
}
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
if (hwndSource != null)
{
IntPtr handle = hwndSource.Handle;
hwndSource.AddHook(new HwndSourceHook(WndProc));
}
}
IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == MessageUtil.WM_COPYDATA)
{
MessageUtil.CopyDataStruct cds = (MessageUtil.CopyDataStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(lParam, typeof(MessageUtil.CopyDataStruct));
if ("ShowApp".Equals(cds.msg))
{
ShowApp();
}
}
return hwnd;
}
2023-04-19 15:42:51 +08:00
#region
private int guideIndex = 0;
private bool guideRun = false;
2023-04-18 18:13:25 +08:00
private void Guide()
{
2023-04-19 15:44:50 +08:00
try
2023-04-18 18:13:25 +08:00
{
guideRun = true;
2023-04-19 15:44:50 +08:00
//防止影响主程序进程
if (CheckShouldShowApp())
{
ShowApp();
}
GrayBorder.Visibility = Visibility.Visible;
GuideSwitch(guideIndex);
2023-04-19 15:44:50 +08:00
GuideCard.Visibility = Visibility.Visible;
2023-04-19 15:42:51 +08:00
}
catch (Exception) { guideRun = false; }
2023-04-18 18:13:25 +08:00
}
2023-04-19 15:42:51 +08:00
private void GuideSwitch(int index)
2023-04-18 18:13:25 +08:00
{
guideIndex = index;
2023-04-19 15:42:51 +08:00
GuideNum.Text = Convert.ToString(index + 1);
GuideTitle1.Text = GuideInfoList.mainWindowGuideList[index].Title1;
GuideTitle2.Text = GuideInfoList.mainWindowGuideList[index].Title2;
GuideText.Text = GuideInfoList.mainWindowGuideList[index].GuideText;
if (index == 0)
{
PreviewGuideBtn.Visibility = Visibility.Collapsed;
NextGuideBtn.Content = "下一步";
} else if (index > 0 && index < GuideInfoList.mainWindowGuideList.Count - 1)
{
PreviewGuideBtn.Visibility = Visibility.Visible;
NextGuideBtn.Content = "下一步";
} else
{
NextGuideBtn.Content = "完成";
}
switch (index)
2023-04-18 18:13:25 +08:00
{
default: //0 //右侧列表区域
2023-04-19 15:42:51 +08:00
2023-04-18 18:13:25 +08:00
Point point = RightCard.TransformToAncestor(this).Transform(new Point(0, 0));
//内部中上
GrayBoderClip(point.X, point.Y, RightCard.ActualWidth, RightCard.ActualHeight,
new Thickness(point.X + RightCard.ActualWidth / 2 - GuideCard.ActualWidth / 2, point.Y, 0, 0));
break;
case 1: //左侧菜单
Point leftCardPoint = LeftCard.TransformToAncestor(this).Transform(new Point(0, 0));
GrayBoderClip(leftCardPoint.X , leftCardPoint.Y , LeftCard.ActualWidth, LeftCard.ActualHeight,
// 外部中下侧
new Thickness(leftCardPoint.X + LeftCard.ActualWidth,
leftCardPoint.Y + LeftCard.ActualHeight / 2 - GuideCard.ActualHeight / 2, 0, 0));
break;
case 2: //头部拖拽栏
GrayBoderClip(0, 0, this.Width, 50,
// 外部中下侧
new Thickness(this.Width / 2 - GuideCard.ActualWidth / 2, 50, 0, 0));
break;
2023-04-19 15:42:51 +08:00
case 3:
Point mainBtnPoint = MainBtnPanel.TransformToAncestor(this).Transform(new Point(0, 0));
GrayBoderClip(mainBtnPoint.X, mainBtnPoint.Y, MainBtnPanel.ActualWidth, MainBtnPanel.ActualHeight,
// 外部左下侧
new Thickness(mainBtnPoint.X - GuideCard.Width,
mainBtnPoint.Y, 0, 0));
break;
2023-04-18 18:13:25 +08:00
}
}
private void GrayBoderClip(double x, double y, double w, double h, Thickness margin)
{
PathGeometry borGeometry = new PathGeometry();
RectangleGeometry rg = new RectangleGeometry();
rg.Rect = new Rect(0, 0, this.Width, this.Height);
borGeometry = Geometry.Combine(borGeometry, rg, GeometryCombineMode.Union, null);
GrayBorder.Clip = borGeometry;
RectangleGeometry rg1 = new RectangleGeometry();
rg1.Rect = new Rect(x - 20, y - 20, w, h);
borGeometry = Geometry.Combine(borGeometry, rg1, GeometryCombineMode.Exclude, null);
GuideCard.Margin = margin;
GrayBorder.Clip = borGeometry;
}
private void PreviewGuideBtn_Click(object sender, RoutedEventArgs e)
{
2023-04-19 15:42:51 +08:00
int index = Convert.ToInt32(GuideNum.Text.ToString()) - 1;
2023-04-18 18:13:25 +08:00
int previewIndex = index - 1;
GuideSwitch(previewIndex);
}
private void NextGuideBtn_Click(object sender, RoutedEventArgs e)
{
if ("完成".Equals(NextGuideBtn.Content.ToString())) {
GrayBorder.Visibility = Visibility.Collapsed;
GuideCard.Visibility = Visibility.Collapsed;
guideIndex = 0;
guideRun = false;
2023-04-18 18:13:25 +08:00
return;
}
2023-04-19 15:42:51 +08:00
int index = Convert.ToInt32(GuideNum.Text.ToString()) - 1;
2023-04-18 18:13:25 +08:00
int nextIndex = index + 1;
GuideSwitch(nextIndex);
}
2023-04-19 15:42:51 +08:00
#endregion
private void Guide_Click(object sender, RoutedEventArgs e)
{
Guide();
}
2022-03-25 16:23:54 +08:00
}
2021-04-12 13:46:05 +08:00
}