RightCardControl.xaml.cs 7.2 KB

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