MainWindow.xaml.cs 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. using GeekDesk.Constant;
  2. using GeekDesk.Control.Other;
  3. using GeekDesk.Control.UserControls.Config;
  4. using GeekDesk.Control.UserControls.PannelCard;
  5. using GeekDesk.Control.Windows;
  6. using GeekDesk.Interface;
  7. using GeekDesk.MyThread;
  8. using GeekDesk.Plugins.EveryThing;
  9. using GeekDesk.Plugins.EveryThing.Constant;
  10. using GeekDesk.Task;
  11. using GeekDesk.Util;
  12. using GeekDesk.ViewModel;
  13. using GeekDesk.ViewModel.Temp;
  14. using Microsoft.Win32;
  15. using NPinyin;
  16. using ShowSeconds;
  17. using System;
  18. using System.Collections.ObjectModel;
  19. using System.Diagnostics;
  20. using System.Runtime.CompilerServices;
  21. using System.Runtime.InteropServices;
  22. using System.Text;
  23. using System.Threading;
  24. using System.Windows;
  25. using System.Windows.Controls;
  26. using System.Windows.Input;
  27. using System.Windows.Interop;
  28. using System.Windows.Media;
  29. using System.Windows.Media.Animation;
  30. using System.Windows.Media.Imaging;
  31. using System.Windows.Media.Media3D;
  32. using System.Windows.Shell;
  33. using System.Windows.Threading;
  34. using static GeekDesk.Util.ShowWindowFollowMouse;
  35. namespace GeekDesk
  36. {
  37. /// <summary>
  38. /// MainWindow.xaml 的交互逻辑
  39. /// </summary>
  40. ///
  41. public partial class MainWindow : Window, IWindowCommon
  42. {
  43. public static AppData appData = CommonCode.GetAppDataByFile();
  44. public static ToDoInfoWindow toDoInfoWindow;
  45. public static int hotKeyId = -1;
  46. public static int toDoHotKeyId = -1;
  47. public static int colorPickerHotKeyId = -1;
  48. public static MainWindow mainWindow;
  49. public MainWindow()
  50. {
  51. //加载数据
  52. LoadData();
  53. InitializeComponent();
  54. //用于其他类访问
  55. mainWindow = this;
  56. //执行待办提醒
  57. ToDoTask.BackLogCheck();
  58. ////实例化隐藏 Hide类,进行时间timer设置
  59. MarginHide.ReadyHide(this);
  60. if (appData.AppConfig.MarginHide)
  61. {
  62. MarginHide.StartHide();
  63. }
  64. }
  65. /// <summary>
  66. /// 搜索快捷键按下
  67. /// </summary>
  68. /// <param name="sender"></param>
  69. /// <param name="e"></param>
  70. private void SearchHotKeyDown(object sender, CanExecuteRoutedEventArgs e)
  71. {
  72. if (appData.AppConfig.SearchType == SearchType.HOT_KEY && !RunTimeStatus.SEARCH_BOX_SHOW)
  73. {
  74. ShowSearchBox();
  75. } else if (RunTimeStatus.SEARCH_BOX_SHOW)
  76. {
  77. HidedSearchBox();
  78. }
  79. }
  80. /// <summary>
  81. /// 显示搜索框
  82. /// </summary>
  83. private void ShowSearchBox()
  84. {
  85. RunTimeStatus.SEARCH_BOX_SHOW = true;
  86. RightCard.VisibilitySearchCard(Visibility.Visible);
  87. SearchBox.Width = 400;
  88. SearchBox.Focus();
  89. //执行一遍a查询
  90. //SearchBox_TextChanged(null, null);
  91. }
  92. /// <summary>
  93. /// 搜索开始
  94. /// </summary>
  95. /// <param name="sender"></param>
  96. /// <param name="e"></param>
  97. private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
  98. {
  99. if (!RunTimeStatus.SEARCH_BOX_SHOW
  100. && appData.AppConfig.SearchType != SearchType.KEY_DOWN
  101. )
  102. {
  103. SearchBox.TextChanged -= SearchBox_TextChanged;
  104. SearchBox.Clear();
  105. SearchBox.TextChanged += SearchBox_TextChanged;
  106. return;
  107. }
  108. if (!RunTimeStatus.SEARCH_BOX_SHOW) ShowSearchBox();
  109. //刷新搜索后 鼠标移动次数置为0
  110. RunTimeStatus.MOUSE_MOVE_COUNT = 0;
  111. //隐藏popup
  112. RightCard.MyPoptip.IsOpen = false;
  113. string inputText = SearchBox.Text.ToLower();
  114. if (!string.IsNullOrEmpty(inputText))
  115. {
  116. RunTimeStatus.EVERYTHING_SEARCH_DELAY_TIME = 300;
  117. if (!RunTimeStatus.EVERYTHING_NEW_SEARCH)
  118. {
  119. RunTimeStatus.EVERYTHING_NEW_SEARCH = true;
  120. //显示搜索结果列表
  121. RightCard.VisibilitySearchCard(Visibility.Visible);
  122. //暂时隐藏条目信息
  123. SearchResContainer.Visibility = Visibility.Collapsed;
  124. //显示加载条
  125. RightCard.Loading_RightCard.Visibility = Visibility.Visible;
  126. object obj = RightCard.VerticalCard.Content;
  127. if (obj != null)
  128. {
  129. SearchResControl control = obj as SearchResControl;
  130. control.VerticalUFG.Visibility = Visibility.Collapsed;
  131. }
  132. SearchDelay();
  133. }
  134. } else
  135. {
  136. //隐藏条目信息
  137. SearchResContainer.Visibility = Visibility.Collapsed;
  138. //清空查询结果
  139. object obj = RightCard.VerticalCard.Content;
  140. if (obj != null)
  141. {
  142. SearchResControl control = obj as SearchResControl;
  143. control.VerticalUFG.Visibility = Visibility.Collapsed;
  144. }
  145. }
  146. }
  147. private void SearchDelay()
  148. {
  149. new Thread(() =>
  150. {
  151. while (RunTimeStatus.EVERYTHING_SEARCH_DELAY_TIME > 0)
  152. {
  153. Thread.Sleep(10);
  154. RunTimeStatus.EVERYTHING_SEARCH_DELAY_TIME -= 10;
  155. }
  156. RunTimeStatus.EVERYTHING_NEW_SEARCH = false;
  157. this.Dispatcher.Invoke(() =>
  158. {
  159. string inputText = SearchBox.Text.ToLower().Trim();
  160. if (string.IsNullOrEmpty(inputText))
  161. {
  162. RightCard.Loading_RightCard.Visibility = Visibility.Collapsed;
  163. return;
  164. }
  165. new Thread(() =>
  166. {
  167. ObservableCollection<IconInfo> resList = new ObservableCollection<IconInfo>();
  168. if (appData.AppConfig.EnableEveryThing == true)
  169. {
  170. ObservableCollection<IconInfo> iconBakList = EveryThingUtil.Search(inputText);
  171. foreach (IconInfo icon in iconBakList)
  172. {
  173. resList.Add(icon);
  174. }
  175. }
  176. int geekDeskCount = 0;
  177. //GeekDesk数据搜索
  178. ObservableCollection<MenuInfo> menuList = appData.MenuList;
  179. foreach (MenuInfo menu in menuList)
  180. {
  181. ObservableCollection<IconInfo> iconList = menu.IconList;
  182. foreach (IconInfo icon in iconList)
  183. {
  184. if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return;
  185. string pyName = Pinyin.GetInitials(icon.Name).ToLower();
  186. if (icon.Name.Contains(inputText) || pyName.Contains(inputText))
  187. {
  188. geekDeskCount++;
  189. resList.Add(icon);
  190. }
  191. }
  192. }
  193. this.Dispatcher.Invoke(() =>
  194. {
  195. if (appData.AppConfig.EnableEveryThing == true)
  196. {
  197. int everythingTotal = Convert.ToInt32(EveryThingUtil.Everything_GetNumResults());
  198. GeekDeskSearchTotal.Text = Convert.ToString(geekDeskCount);
  199. EverythingSearchCount.Text = Convert.ToString(resList.Count - geekDeskCount);
  200. EverythingSearchTotal.Text = Convert.ToString(everythingTotal + geekDeskCount);
  201. SearchResContainer.Visibility = Visibility.Visible;
  202. }
  203. SearchResControl control = new SearchResControl(resList);
  204. RightCard.VerticalCard.Content = control;
  205. //关闭加载效果
  206. RightCard.Loading_RightCard.Visibility = Visibility.Collapsed;
  207. });
  208. }).Start();
  209. });
  210. }).Start();
  211. }
  212. /// <summary>
  213. /// 隐藏搜索框
  214. /// </summary>
  215. public void HidedSearchBox()
  216. {
  217. RunTimeStatus.EVERYTHING_NEW_SEARCH = true;
  218. new Thread(() =>
  219. {
  220. Thread.Sleep(1000);
  221. RunTimeStatus.EVERYTHING_NEW_SEARCH = false;
  222. }).Start();
  223. new Thread(() =>
  224. {
  225. this.Dispatcher.Invoke(() =>
  226. {
  227. Keyboard.Focus(SearchBox);
  228. RunTimeStatus.SEARCH_BOX_SHOW = false;
  229. SearchBox.TextChanged -= SearchBox_TextChanged;
  230. SearchBox.Clear();
  231. SearchBox.TextChanged += SearchBox_TextChanged;
  232. SearchBox.Width = 0;
  233. SearchResContainer.Visibility = Visibility.Collapsed;
  234. RightCard.VerticalCard.Content = null;
  235. RightCard.VisibilitySearchCard(Visibility.Collapsed);
  236. });
  237. }).Start();
  238. }
  239. /// <summary>
  240. /// 加载缓存数据
  241. /// </summary>
  242. private void LoadData()
  243. {
  244. this.DataContext = appData;
  245. if (appData.MenuList.Count == 0)
  246. {
  247. appData.MenuList.Add(new MenuInfo() { MenuName = "NewMenu", MenuId = System.Guid.NewGuid().ToString(), MenuEdit = Visibility.Collapsed });
  248. }
  249. this.Width = appData.AppConfig.WindowWidth;
  250. this.Height = appData.AppConfig.WindowHeight;
  251. }
  252. /// <summary>
  253. /// 窗口加载完毕 执行方法
  254. /// </summary>
  255. /// <param name="sender"></param>
  256. /// <param name="e"></param>
  257. void Window_Loaded(object sender, RoutedEventArgs e)
  258. {
  259. BGSettingUtil.BGSetting();
  260. if (!appData.AppConfig.StartedShowPanel)
  261. {
  262. this.Visibility = Visibility.Collapsed;
  263. }
  264. else
  265. {
  266. ShowApp();
  267. }
  268. //给任务栏图标一个名字
  269. BarIcon.Text = Constants.MY_NAME;
  270. //注册热键
  271. if (true == appData.AppConfig.EnableAppHotKey)
  272. {
  273. RegisterHotKey(true);
  274. }
  275. if (true == appData.AppConfig.EnableTodoHotKey)
  276. {
  277. RegisterCreateToDoHotKey(true);
  278. }
  279. if (true == appData.AppConfig.EnableColorPickerHotKey)
  280. {
  281. RegisterColorPickerHotKey(true);
  282. }
  283. //注册自启动
  284. if (!appData.AppConfig.SelfStartUped && !Constants.DEV)
  285. {
  286. RegisterUtil.SetSelfStarting(appData.AppConfig.SelfStartUp, Constants.MY_NAME);
  287. }
  288. //注册鼠标监听事件
  289. if (appData.AppConfig.MouseMiddleShow)
  290. {
  291. MouseHookThread.Hook();
  292. }
  293. //显秒插件
  294. if (appData.AppConfig.SecondsWindow == true)
  295. {
  296. SecondsWindow.ShowWindow();
  297. }
  298. //监听实时文件夹菜单
  299. FileWatcher.EnableLinkMenuWatcher(appData);
  300. //更新线程开启 检测更新
  301. UpdateThread.Update();
  302. //建立相对路径
  303. RelativePathThread.MakeRelativePath();
  304. //毛玻璃 暂时未解决阴影问题
  305. //BlurGlassUtil.EnableBlur(this);
  306. //设置归属桌面 解决桌面覆盖程序界面的bug
  307. WindowUtil.SetOwner(this, WindowUtil.GetDesktopHandle(this, DesktopLayer.Progman));
  308. if (appData.AppConfig.EnableEveryThing == true)
  309. {
  310. //开启EveryThing插件
  311. EveryThingUtil.EnableEveryThing();
  312. }
  313. Keyboard.Focus(SearchBox);
  314. MessageUtil.ChangeWindowMessageFilter(MessageUtil.WM_COPYDATA, 1);
  315. Guide();
  316. }
  317. /// <summary>
  318. /// 注册当前窗口的热键
  319. /// </summary>
  320. public static void RegisterHotKey(bool first)
  321. {
  322. try
  323. {
  324. if (appData.AppConfig.HotkeyModifiers != GlobalHotKey.HotkeyModifiers.None)
  325. {
  326. hotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.HotkeyModifiers, appData.AppConfig.Hotkey, () =>
  327. {
  328. if (RunTimeStatus.MAIN_HOT_KEY_DOWN) return;
  329. RunTimeStatus.MAIN_HOT_KEY_DOWN = true;
  330. new Thread(() =>
  331. {
  332. Thread.Sleep(RunTimeStatus.MAIN_HOT_KEY_TIME);
  333. RunTimeStatus.MAIN_HOT_KEY_DOWN = false;
  334. }).Start();
  335. if (MotionControl.hotkeyFinished)
  336. {
  337. if (CheckShouldShowApp())
  338. {
  339. ShowApp();
  340. }
  341. else
  342. {
  343. HideApp();
  344. }
  345. }
  346. });
  347. if (!first)
  348. {
  349. HandyControl.Controls.Growl.Success("GeekDesk快捷键注册成功(" + appData.AppConfig.HotkeyStr + ")!", "HotKeyGrowl");
  350. }
  351. }
  352. else
  353. {
  354. }
  355. }
  356. catch (Exception)
  357. {
  358. if (first)
  359. {
  360. HandyControl.Controls.Growl.WarningGlobal("GeekDesk启动快捷键已被其它程序占用(" + appData.AppConfig.HotkeyStr + ")!");
  361. }
  362. else
  363. {
  364. HandyControl.Controls.Growl.Warning("GeekDesk启动快捷键已被其它程序占用(" + appData.AppConfig.HotkeyStr + ")!", "HotKeyGrowl");
  365. }
  366. }
  367. }
  368. /// <summary>
  369. /// 注册新建待办的热键
  370. /// </summary>
  371. public static void RegisterCreateToDoHotKey(bool first)
  372. {
  373. try
  374. {
  375. if (appData.AppConfig.HotkeyModifiers != GlobalHotKey.HotkeyModifiers.None)
  376. {
  377. //加载完毕注册热键
  378. toDoHotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.ToDoHotkeyModifiers, appData.AppConfig.ToDoHotkey, () =>
  379. {
  380. if (MotionControl.hotkeyFinished)
  381. {
  382. ToDoWindow.ShowOrHide();
  383. }
  384. });
  385. if (!first)
  386. {
  387. HandyControl.Controls.Growl.Success("新建待办任务快捷键注册成功(" + appData.AppConfig.ToDoHotkeyStr + ")!", "HotKeyGrowl");
  388. }
  389. }
  390. }
  391. catch (Exception)
  392. {
  393. if (first)
  394. {
  395. HandyControl.Controls.Growl.WarningGlobal("新建待办任务快捷键已被其它程序占用(" + appData.AppConfig.ToDoHotkeyStr + ")!");
  396. }
  397. else
  398. {
  399. HandyControl.Controls.Growl.Warning("新建待办任务快捷键已被其它程序占用(" + appData.AppConfig.ToDoHotkeyStr + ")!", "HotKeyGrowl");
  400. }
  401. }
  402. }
  403. /// <summary>
  404. /// 注册新建待办的热键
  405. /// </summary>
  406. public static void RegisterColorPickerHotKey(bool first)
  407. {
  408. try
  409. {
  410. if (appData.AppConfig.HotkeyModifiers != GlobalHotKey.HotkeyModifiers.None)
  411. {
  412. //加载完毕注册热键
  413. colorPickerHotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.ColorPickerHotkeyModifiers, appData.AppConfig.ColorPickerHotkey, () =>
  414. {
  415. if (MotionControl.hotkeyFinished)
  416. {
  417. GlobalColorPickerWindow.CreateNoShow();
  418. }
  419. });
  420. if (!first)
  421. {
  422. HandyControl.Controls.Growl.Success("拾色器快捷键注册成功(" + appData.AppConfig.ColorPickerHotkeyStr + ")!", "HotKeyGrowl");
  423. }
  424. }
  425. }
  426. catch (Exception)
  427. {
  428. if (first)
  429. {
  430. HandyControl.Controls.Growl.WarningGlobal("拾色器快捷键已被其它程序占用(" + appData.AppConfig.ColorPickerHotkeyStr + ")!");
  431. }
  432. else
  433. {
  434. HandyControl.Controls.Growl.Warning("拾色器快捷键已被其它程序占用(" + appData.AppConfig.ColorPickerHotkeyStr + ")!", "HotKeyGrowl");
  435. }
  436. }
  437. }
  438. /// <summary>
  439. /// 程序窗体拖动
  440. /// </summary>
  441. /// <param name="sender"></param>
  442. /// <param name="e"></param>
  443. private void DragMove(object sender, MouseEventArgs e)
  444. {
  445. if (e.LeftButton == MouseButtonState.Pressed)
  446. {
  447. DragMove();
  448. }
  449. }
  450. /// <summary>
  451. /// 关闭按钮单击事件
  452. /// </summary>
  453. /// <param name="sender"></param>
  454. /// <param name="e"></param>
  455. private void CloseButtonClick(object sender, RoutedEventArgs e)
  456. {
  457. HideApp();
  458. }
  459. ///// <summary>
  460. ///// 左侧栏宽度改变 持久化
  461. ///// </summary>
  462. ///// <param name="sender"></param>
  463. ///// <param name="e"></param>
  464. //private void LeftCardResize(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  465. //{
  466. // appData.AppConfig.MenuCardWidth = LeftColumn.Width.Value;
  467. //}
  468. /// <summary>
  469. /// 右键任务栏图标 显示主面板
  470. /// </summary>
  471. /// <param name="sender"></param>
  472. /// <param name="e"></param>
  473. public void ShowApp(object sender, RoutedEventArgs e)
  474. {
  475. ShowApp();
  476. }
  477. public static void ShowApp()
  478. {
  479. //有全屏化应用则不显示
  480. //if (CommonCode.IsPrimaryFullScreen())
  481. //{
  482. // return;
  483. //}
  484. if (MarginHide.ON_HIDE)
  485. {
  486. //修改贴边隐藏状态为未隐藏
  487. MarginHide.IS_HIDE = false;
  488. if (!CommonCode.MouseInWindow(mainWindow))
  489. {
  490. RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW = true;
  491. MarginHide.WaitHide(3000);
  492. }
  493. }
  494. if (appData.AppConfig.FollowMouse)
  495. {
  496. ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0);
  497. }
  498. MainWindow.mainWindow.Activate();
  499. mainWindow.Show();
  500. //mainWindow.Visibility = Visibility.Visible;
  501. if (appData.AppConfig.AppAnimation)
  502. {
  503. appData.AppConfig.IsShow = true;
  504. }
  505. else
  506. {
  507. appData.AppConfig.IsShow = null;
  508. //防止永远不显示界面
  509. if (mainWindow.Opacity < 1)
  510. {
  511. mainWindow.Opacity = 1;
  512. }
  513. }
  514. //FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible);
  515. Keyboard.Focus(mainWindow);
  516. if (RunTimeStatus.SHOW_MENU_PASSWORDBOX)
  517. {
  518. mainWindow.RightCard.PDDialog.SetFocus();
  519. }
  520. else
  521. {
  522. Keyboard.Focus(mainWindow.SearchBox);
  523. }
  524. }
  525. public static void HideApp()
  526. {
  527. if (appData.AppConfig.AppAnimation)
  528. {
  529. appData.AppConfig.IsShow = false;
  530. }
  531. else
  532. {
  533. appData.AppConfig.IsShow = null;
  534. HideAppVis();
  535. }
  536. }
  537. private static void HideAppVis()
  538. {
  539. //关闭锁定
  540. RunTimeStatus.LOCK_APP_PANEL = false;
  541. if (RunTimeStatus.SEARCH_BOX_SHOW)
  542. {
  543. mainWindow.HidedSearchBox();
  544. }
  545. mainWindow.Visibility = Visibility.Collapsed;
  546. //if (!MarginHide.IS_HIDE)
  547. //{
  548. //}
  549. //else
  550. //{
  551. // ShowApp();
  552. //}
  553. }
  554. /// <summary>
  555. /// 淡入淡出效果
  556. /// </summary>
  557. /// <param name="opacity"></param>
  558. /// <param name="milliseconds"></param>
  559. /// <param name="visibility"></param>
  560. public static void FadeStoryBoard(int opacity, int milliseconds, Visibility visibility)
  561. {
  562. if (appData.AppConfig.AppAnimation)
  563. {
  564. DoubleAnimation opacityAnimation = new DoubleAnimation
  565. {
  566. From = mainWindow.Opacity,
  567. To = opacity,
  568. Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds))
  569. };
  570. opacityAnimation.Completed += (s, e) =>
  571. {
  572. mainWindow.BeginAnimation(OpacityProperty, null);
  573. if (visibility == Visibility.Visible)
  574. {
  575. mainWindow.Opacity = 1;
  576. }
  577. else
  578. {
  579. mainWindow.Opacity = 0;
  580. CommonCode.SortIconList();
  581. }
  582. };
  583. Timeline.SetDesiredFrameRate(opacityAnimation, 60);
  584. mainWindow.BeginAnimation(OpacityProperty, opacityAnimation);
  585. }
  586. else
  587. {
  588. //防止关闭动画后 窗体仍是0透明度
  589. mainWindow.Opacity = 1;
  590. mainWindow.Visibility = visibility;
  591. if (visibility == Visibility.Collapsed)
  592. {
  593. CommonCode.SortIconList();
  594. }
  595. }
  596. }
  597. /// <summary>
  598. /// 图片图标单击事件
  599. /// </summary>
  600. /// <param name="sender"></param>
  601. /// <param name="e"></param>
  602. private void NotifyIcon_Click(object sender, RoutedEventArgs e)
  603. {
  604. if (CheckShouldShowApp())
  605. {
  606. ShowApp();
  607. }
  608. else
  609. {
  610. HideApp();
  611. }
  612. }
  613. private static bool CheckShouldShowApp()
  614. {
  615. return mainWindow.Visibility == Visibility.Collapsed
  616. || mainWindow.Opacity == 0
  617. || MarginHide.IS_HIDE
  618. || !WindowUtil.WindowIsTop(mainWindow);
  619. }
  620. /// <summary>
  621. /// 右键任务栏图标 设置
  622. /// </summary>
  623. /// <param name="sender"></param>
  624. /// <param name="e"></param>
  625. private void ConfigApp(object sender, RoutedEventArgs e)
  626. {
  627. ConfigWindow.Show(appData.AppConfig, this);
  628. }
  629. /// <summary>
  630. /// 右键任务栏图标打开程序目录
  631. /// </summary>
  632. /// <param name="sender"></param>
  633. /// <param name="e"></param>
  634. private void OpenThisDir(object sender, RoutedEventArgs e)
  635. {
  636. Process p = new Process();
  637. p.StartInfo.FileName = "Explorer.exe";
  638. p.StartInfo.Arguments = "/e,/select," + Constants.APP_DIR + Constants.MY_NAME + ".exe";
  639. p.Start();
  640. }
  641. /// <summary>
  642. /// 设置图标
  643. /// </summary>
  644. /// <param name="sender"></param>
  645. /// <param name="e"></param>
  646. private void ConfigButtonClick(object sender, RoutedEventArgs e)
  647. {
  648. SettingMenus.IsOpen = true;
  649. }
  650. /// <summary>
  651. /// 设置菜单点击
  652. /// </summary>
  653. /// <param name="sender"></param>
  654. /// <param name="e"></param>
  655. private void ConfigMenuClick(object sender, RoutedEventArgs e)
  656. {
  657. ConfigWindow.Show(appData.AppConfig, this);
  658. }
  659. /// <summary>
  660. /// 待办任务
  661. /// </summary>
  662. /// <param name="sender"></param>
  663. /// <param name="e"></param>
  664. private void BacklogMenuClick(object sender, RoutedEventArgs e)
  665. {
  666. ToDoWindow.Show();
  667. }
  668. /// <summary>
  669. /// 禁用设置按钮右键菜单
  670. /// </summary>
  671. /// <param name="sender"></param>
  672. /// <param name="e"></param>
  673. private void SettingButton_Initialized(object sender, EventArgs e)
  674. {
  675. SettingButton.ContextMenu = null;
  676. }
  677. private void AppWindowLostFocus()
  678. {
  679. if (appData.AppConfig.AppHideType == AppHideType.LOST_FOCUS
  680. && this.Opacity == 1 && !RunTimeStatus.LOCK_APP_PANEL)
  681. {
  682. //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
  683. if (!appData.AppConfig.MarginHide || (appData.AppConfig.MarginHide && !MarginHide.IS_HIDE))
  684. {
  685. HideApp();
  686. }
  687. }
  688. }
  689. private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
  690. {
  691. if (this.DataContext != null)
  692. {
  693. AppData appData = this.DataContext as AppData;
  694. appData.AppConfig.WindowWidth = this.Width;
  695. appData.AppConfig.WindowHeight = this.Height;
  696. }
  697. }
  698. /// <summary>
  699. /// 右键任务栏图标退出
  700. /// </summary>
  701. /// <param name="sender"></param>
  702. /// <param name="e"></param>
  703. private void ExitApp(object sender, RoutedEventArgs e)
  704. {
  705. if (appData.AppConfig.MouseMiddleShow || appData.AppConfig.SecondsWindow == true)
  706. {
  707. MouseHookThread.Dispose();
  708. }
  709. if (appData.AppConfig.EnableEveryThing == true)
  710. {
  711. EveryThingUtil.DisableEveryThing();
  712. }
  713. Application.Current.Shutdown();
  714. }
  715. /// <summary>
  716. /// 重启
  717. /// </summary>
  718. /// <param name="sender"></param>
  719. /// <param name="e"></param>
  720. private void ReStartApp(object sender, RoutedEventArgs e)
  721. {
  722. if (appData.AppConfig.MouseMiddleShow || appData.AppConfig.SecondsWindow == true)
  723. {
  724. MouseHookThread.Dispose();
  725. }
  726. Process p = new Process();
  727. p.StartInfo.FileName = Constants.APP_DIR + "GeekDesk.exe";
  728. p.StartInfo.WorkingDirectory = Constants.APP_DIR;
  729. p.Start();
  730. Application.Current.Shutdown();
  731. }
  732. /// <summary>
  733. /// 关闭托盘图标
  734. /// </summary>
  735. /// <param name="sender"></param>
  736. /// <param name="e"></param>
  737. private void CloseBarIcon(object sender, RoutedEventArgs e)
  738. {
  739. appData.AppConfig.ShowBarIcon = false;
  740. }
  741. public void OnKeyDown(object sender, KeyEventArgs e)
  742. {
  743. //char c = (char)e.Key;
  744. if (e.Key == Key.Escape)
  745. {
  746. HideApp();
  747. }
  748. if (RunTimeStatus.SEARCH_BOX_SHOW && (e.Key == Key.Up
  749. || e.Key == Key.Down
  750. || e.Key == Key.Tab
  751. || e.Key == Key.Enter
  752. ))
  753. {
  754. if (e.Key == Key.Down || e.Key == Key.Tab)
  755. {
  756. SearchResControl res = RightCard.VerticalCard.Content as SearchResControl;
  757. res.SearchListBoxIndexAdd();
  758. }
  759. else if (e.Key == Key.Up)
  760. {
  761. SearchResControl res = RightCard.VerticalCard.Content as SearchResControl;
  762. res.SearchListBoxIndexSub();
  763. }
  764. else if (e.Key == Key.Enter)
  765. {
  766. SearchResControl res = RightCard.VerticalCard.Content as SearchResControl;
  767. res.StartupSelectionItem();
  768. }
  769. }
  770. }
  771. /// <summary>
  772. /// 为了让修改菜单的textBox失去焦点
  773. /// </summary>
  774. /// <param name="sender"></param>
  775. /// <param name="e"></param>
  776. private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e)
  777. {
  778. SearchBox.Focus();
  779. }
  780. /// <summary>
  781. /// 鼠标进入后
  782. /// </summary>
  783. /// <param name="sender"></param>
  784. /// <param name="e"></param>
  785. private void MainWindow_MouseEnter(object sender, MouseEventArgs e)
  786. {
  787. //防止延迟贴边隐藏
  788. RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW = false;
  789. }
  790. /// <summary>
  791. /// 打开屏幕拾色器
  792. /// </summary>
  793. /// <param name="sender"></param>
  794. /// <param name="e"></param>
  795. private void ColorPicker(object sender, RoutedEventArgs e)
  796. {
  797. TaskbarContextMenu.IsOpen = false;
  798. GlobalColorPickerWindow.CreateNoShow();
  799. }
  800. private void Window_GotFocus(object sender, RoutedEventArgs e)
  801. {
  802. // 如果没有在修改菜单 并且不是右键点击了面板
  803. if (!RunTimeStatus.IS_MENU_EDIT
  804. && !RunTimeStatus.SHOW_RIGHT_BTN_MENU
  805. && !RunTimeStatus.APP_BTN_IS_DOWN)
  806. {
  807. if (RunTimeStatus.SHOW_MENU_PASSWORDBOX)
  808. {
  809. //必须在其它文本框没有工作的时候才给密码框焦点
  810. RightCard.PDDialog.SetFocus();
  811. }
  812. else
  813. {
  814. //必须在其它文本框没有工作的时候才给搜索框焦点
  815. Keyboard.Focus(SearchBox);
  816. }
  817. }
  818. }
  819. private void AppWindow_Deactivated(object sender, EventArgs e)
  820. {
  821. AppWindowLostFocus();
  822. }
  823. /// <summary>
  824. /// 备份数据文件
  825. /// </summary>
  826. /// <param name="sender"></param>
  827. /// <param name="e"></param>
  828. [Obsolete]
  829. private void BakDataFile(object sender, RoutedEventArgs e)
  830. {
  831. Thread t = new Thread(() =>
  832. {
  833. CommonCode.BakAppData();
  834. });
  835. t.ApartmentState = ApartmentState.STA;
  836. t.Start();
  837. }
  838. private void AppButton_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  839. {
  840. //点击了面板
  841. RunTimeStatus.APP_BTN_IS_DOWN = true;
  842. new Thread(() =>
  843. {
  844. Thread.Sleep(50);
  845. RunTimeStatus.APP_BTN_IS_DOWN = false;
  846. }).Start();
  847. }
  848. private ICommand _hideCommand;
  849. public ICommand HideCommand
  850. {
  851. get
  852. {
  853. if (_hideCommand == null)
  854. {
  855. _hideCommand = new RelayCommand(
  856. p =>
  857. {
  858. return true;
  859. },
  860. p =>
  861. {
  862. HideAppVis();
  863. });
  864. }
  865. return _hideCommand;
  866. }
  867. }
  868. protected override void OnSourceInitialized(EventArgs e)
  869. {
  870. base.OnSourceInitialized(e);
  871. HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
  872. if (hwndSource != null)
  873. {
  874. IntPtr handle = hwndSource.Handle;
  875. hwndSource.AddHook(new HwndSourceHook(WndProc));
  876. }
  877. }
  878. IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
  879. {
  880. if (msg == MessageUtil.WM_COPYDATA)
  881. {
  882. MessageUtil.CopyDataStruct cds = (MessageUtil.CopyDataStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(lParam, typeof(MessageUtil.CopyDataStruct));
  883. if ("ShowApp".Equals(cds.msg))
  884. {
  885. ShowApp();
  886. }
  887. }
  888. return hwnd;
  889. }
  890. class GuideInfo
  891. {
  892. private string title1;
  893. private string title2;
  894. private string guideText;
  895. public string Title1 { get; set; }
  896. public string Title2 { get; set; }
  897. public string GuideText { get; set; }
  898. }
  899. enum GuidePopOffect
  900. {
  901. TOP,
  902. INNER_TOP,
  903. LEFT,
  904. INNER_LEFT,
  905. CENTER,
  906. RIGHT,
  907. INNER_RIGHT,
  908. BOTTOM,
  909. INNER_BOTTOM
  910. }
  911. private ObservableCollection<GuideInfo> list = new ObservableCollection<GuideInfo>();
  912. private void Guide()
  913. {
  914. GuideInfo guideInfo = new GuideInfo
  915. {
  916. Title1 = "提示1",
  917. Title2 = "快捷方式创建",
  918. GuideText = "将文件拖动到这里自动创建快捷方式, 或者鼠标右键单击添加系统项目"
  919. };
  920. list.Add(guideInfo);
  921. guideInfo = new GuideInfo
  922. {
  923. Title1 = "提示2",
  924. Title2 = "快捷方式创建",
  925. GuideText = "将文件拖动到这里自动创建快捷方式, 或者鼠标右键单击添加系统项目"
  926. };
  927. list.Add(guideInfo);
  928. guideInfo = new GuideInfo
  929. {
  930. Title1 = "提示3",
  931. Title2 = "快捷方式创建",
  932. GuideText = "将文件拖动到这里自动创建快捷方式, 或者鼠标右键单击添加系统项目"
  933. };
  934. list.Add(guideInfo);
  935. GrayBorder.Visibility = Visibility.Visible;
  936. GuideSwitch(0);
  937. GuideCard.Visibility = Visibility.Visible;
  938. }
  939. private void GuideSwitch(int num)
  940. {
  941. switch (num)
  942. {
  943. default: //0 //右侧列表区域
  944. PreviewGuideBtn.Visibility = Visibility.Collapsed;
  945. NextGuideBtn.Content = "下一步";
  946. Point point = RightCard.TransformToAncestor(this).Transform(new Point(0, 0));
  947. //内部中上
  948. GrayBoderClip(point.X, point.Y, RightCard.ActualWidth, RightCard.ActualHeight,
  949. new Thickness(point.X + RightCard.ActualWidth / 2 - GuideCard.ActualWidth / 2, point.Y, 0, 0));
  950. break;
  951. case 1: //左侧菜单
  952. PreviewGuideBtn.Visibility = Visibility.Visible;
  953. NextGuideBtn.Content = "下一步";
  954. Point leftCardPoint = LeftCard.TransformToAncestor(this).Transform(new Point(0, 0));
  955. GrayBoderClip(leftCardPoint.X , leftCardPoint.Y , LeftCard.ActualWidth, LeftCard.ActualHeight,
  956. // 外部中下侧
  957. new Thickness(leftCardPoint.X + LeftCard.ActualWidth,
  958. leftCardPoint.Y + LeftCard.ActualHeight / 2 - GuideCard.ActualHeight / 2, 0, 0));
  959. break;
  960. case 2: //头部拖拽栏
  961. NextGuideBtn.Content = "完成";
  962. GrayBoderClip(0, 0, this.Width, 50,
  963. // 外部中下侧
  964. new Thickness(this.Width / 2 - GuideCard.ActualWidth / 2, 50, 0, 0));
  965. break;
  966. }
  967. }
  968. private void GrayBoderClip(double x, double y, double w, double h, Thickness margin)
  969. {
  970. PathGeometry borGeometry = new PathGeometry();
  971. RectangleGeometry rg = new RectangleGeometry();
  972. rg.Rect = new Rect(0, 0, this.Width, this.Height);
  973. borGeometry = Geometry.Combine(borGeometry, rg, GeometryCombineMode.Union, null);
  974. GrayBorder.Clip = borGeometry;
  975. RectangleGeometry rg1 = new RectangleGeometry();
  976. rg1.Rect = new Rect(x - 20, y - 20, w, h);
  977. borGeometry = Geometry.Combine(borGeometry, rg1, GeometryCombineMode.Exclude, null);
  978. GuideCard.Margin = margin;
  979. GrayBorder.Clip = borGeometry;
  980. }
  981. private void PreviewGuideBtn_Click(object sender, RoutedEventArgs e)
  982. {
  983. int index = Convert.ToInt32(GuideTitle1.Text.ToString().Substring(2)) - 1;
  984. int previewIndex = index - 1;
  985. GuideTitle1.Text = list[previewIndex].Title1;
  986. GuideTitle2.Text = list[previewIndex].Title2;
  987. GuideText.Text = list[previewIndex].GuideText;
  988. GuideSwitch(previewIndex);
  989. }
  990. private void NextGuideBtn_Click(object sender, RoutedEventArgs e)
  991. {
  992. if ("完成".Equals(NextGuideBtn.Content.ToString())) {
  993. GrayBorder.Visibility = Visibility.Collapsed;
  994. GuideCard.Visibility = Visibility.Collapsed;
  995. return;
  996. }
  997. int index = Convert.ToInt32(GuideTitle1.Text.ToString().Substring(2)) - 1;
  998. int nextIndex = index + 1;
  999. GuideTitle1.Text = list[nextIndex].Title1;
  1000. GuideTitle2.Text = list[nextIndex].Title2;
  1001. GuideText.Text = list[nextIndex].GuideText;
  1002. GuideSwitch(nextIndex);
  1003. }
  1004. }
  1005. }