RightCardControl.xaml.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using DraggAnimatedPanelExample;
  2. using GeekDesk.Constant;
  3. using GeekDesk.Control.Other;
  4. using GeekDesk.Util;
  5. using GeekDesk.ViewModel;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Diagnostics;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Data;
  17. using System.Windows.Documents;
  18. using System.Windows.Input;
  19. using System.Windows.Media;
  20. using System.Windows.Media.Imaging;
  21. using System.Windows.Navigation;
  22. using System.Windows.Shapes;
  23. namespace GeekDesk.Control.UserControls.PannelCard
  24. {
  25. /// <summary>
  26. /// RightCardControl.xaml 的交互逻辑
  27. /// </summary>
  28. public partial class RightCardControl : UserControl
  29. {
  30. private AppData appData = MainWindow.appData;
  31. public RightCardControl()
  32. {
  33. InitializeComponent();
  34. }
  35. #region 图标拖动
  36. DelegateCommand<int[]> _swap;
  37. public DelegateCommand<int[]> SwapCommand
  38. {
  39. get
  40. {
  41. if (_swap == null)
  42. _swap = new DelegateCommand<int[]>(
  43. (indexes) =>
  44. {
  45. int fromS = indexes[0];
  46. int to = indexes[1];
  47. ObservableCollection<IconInfo> iconList = appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList;
  48. var elementSource = iconList[to];
  49. var dragged = iconList[fromS];
  50. iconList.Remove(dragged);
  51. iconList.Insert(to, dragged);
  52. }
  53. );
  54. return _swap;
  55. }
  56. }
  57. #endregion 图标拖动
  58. /// <summary>
  59. /// 图标点击事件
  60. /// </summary>
  61. /// <param name="sender"></param>
  62. /// <param name="e"></param>
  63. private void IconClick(object sender, MouseButtonEventArgs e)
  64. {
  65. IconInfo icon = (IconInfo)((StackPanel)sender).Tag;
  66. if (icon.AdminStartUp)
  67. {
  68. StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  69. }
  70. else
  71. {
  72. StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
  73. }
  74. }
  75. /// <summary>
  76. /// 管理员方式启动
  77. /// </summary>
  78. /// <param name="sender"></param>
  79. /// <param name="e"></param>
  80. private void IconAdminStart(object sender, RoutedEventArgs e)
  81. {
  82. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  83. StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  84. }
  85. /// <summary>
  86. /// 打开文件所在位置
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void ShowInExplore(object sender, RoutedEventArgs e)
  91. {
  92. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  93. StartIconApp(icon, IconStartType.SHOW_IN_EXPLORE);
  94. }
  95. private void StartIconApp(IconInfo icon, IconStartType type)
  96. {
  97. try
  98. {
  99. if (!File.Exists(icon.Path) && !Directory.Exists(icon.Path))
  100. {
  101. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
  102. return;
  103. }
  104. Process p = new Process();
  105. p.StartInfo.FileName = icon.Path;
  106. switch (type)
  107. {
  108. case IconStartType.ADMIN_STARTUP:
  109. p.StartInfo.Arguments = "1";//启动参数
  110. p.StartInfo.Verb = "runas";
  111. p.StartInfo.CreateNoWindow = false; //设置显示窗口
  112. p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动进程
  113. p.StartInfo.ErrorDialog = false;
  114. if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
  115. {
  116. this.Visibility = Visibility.Collapsed;
  117. }
  118. break;// c#好像不能case穿透
  119. case IconStartType.DEFAULT_STARTUP:
  120. if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
  121. {
  122. this.Visibility = Visibility.Collapsed;
  123. }
  124. break;
  125. case IconStartType.SHOW_IN_EXPLORE:
  126. p.StartInfo.FileName = "Explorer.exe";
  127. p.StartInfo.Arguments = "/e,/select," + icon.Path;
  128. break;
  129. }
  130. p.Start();
  131. icon.Count++;
  132. }
  133. catch (Exception)
  134. {
  135. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
  136. }
  137. }
  138. /// <summary>
  139. /// data选中事件 设置不可选中
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. private void IconSelectionChanged(object sender, SelectionChangedEventArgs e)
  144. {
  145. if (icons.SelectedIndex != -1) icons.SelectedIndex = -1;
  146. }
  147. private void Wrap_Drop(object sender, DragEventArgs e)
  148. {
  149. Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
  150. if (dropObject == null) return;
  151. foreach (object obj in dropObject)
  152. {
  153. string path = (string)obj;
  154. //string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Jpeg);
  155. IconInfo iconInfo = new IconInfo
  156. {
  157. Path = path,
  158. BitmapImage = ImageUtil.GetBitmapIconByPath(path)
  159. };
  160. iconInfo.DefaultImage = iconInfo.ImageByteArr;
  161. iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(path);
  162. MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo);
  163. }
  164. }
  165. /// <summary>
  166. /// 从列表删除图标
  167. /// </summary>
  168. /// <param name="sender"></param>
  169. /// <param name="e"></param>
  170. private void RemoveIcon(object sender, RoutedEventArgs e)
  171. {
  172. appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Remove((IconInfo)((MenuItem)sender).Tag);
  173. }
  174. private void MenuItem_Click(object sender, RoutedEventArgs e)
  175. {
  176. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  177. System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
  178. psi.Arguments = "/e,/select," + icon.Path;
  179. System.Diagnostics.Process.Start(psi);
  180. }
  181. /// <summary>
  182. /// 弹出Icon属性修改面板
  183. /// </summary>
  184. /// <param name="sender"></param>
  185. /// <param name="e"></param>
  186. private void PropertyConfig(object sender, RoutedEventArgs e)
  187. {
  188. HandyControl.Controls.Dialog.Show(new IconInfoDialog((IconInfo)((MenuItem)sender).Tag));
  189. }
  190. }
  191. }