RightCardControl.xaml.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. Window parentWin = Window.GetWindow(this);
  117. parentWin.Visibility = Visibility.Collapsed;
  118. }
  119. break;// c#好像不能case穿透
  120. case IconStartType.DEFAULT_STARTUP:
  121. if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
  122. {
  123. Window parentWin = Window.GetWindow(this);
  124. parentWin.Visibility = Visibility.Collapsed;
  125. }
  126. break;
  127. case IconStartType.SHOW_IN_EXPLORE:
  128. p.StartInfo.FileName = "Explorer.exe";
  129. p.StartInfo.Arguments = "/e,/select," + icon.Path;
  130. break;
  131. }
  132. p.Start();
  133. icon.Count++;
  134. }
  135. catch (Exception)
  136. {
  137. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
  138. }
  139. }
  140. /// <summary>
  141. /// data选中事件 设置不可选中
  142. /// </summary>
  143. /// <param name="sender"></param>
  144. /// <param name="e"></param>
  145. private void IconSelectionChanged(object sender, SelectionChangedEventArgs e)
  146. {
  147. if (icons.SelectedIndex != -1) icons.SelectedIndex = -1;
  148. }
  149. private void Wrap_Drop(object sender, DragEventArgs e)
  150. {
  151. Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
  152. if (dropObject == null) return;
  153. foreach (object obj in dropObject)
  154. {
  155. string path = (string)obj;
  156. //string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Jpeg);
  157. IconInfo iconInfo = new IconInfo
  158. {
  159. Path = path,
  160. BitmapImage = ImageUtil.GetBitmapIconByPath(path)
  161. };
  162. iconInfo.DefaultImage = iconInfo.ImageByteArr;
  163. iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(path);
  164. MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo);
  165. }
  166. }
  167. /// <summary>
  168. /// 从列表删除图标
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. private void RemoveIcon(object sender, RoutedEventArgs e)
  173. {
  174. appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Remove((IconInfo)((MenuItem)sender).Tag);
  175. }
  176. private void MenuItem_Click(object sender, RoutedEventArgs e)
  177. {
  178. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  179. System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
  180. psi.Arguments = "/e,/select," + icon.Path;
  181. System.Diagnostics.Process.Start(psi);
  182. }
  183. /// <summary>
  184. /// 弹出Icon属性修改面板
  185. /// </summary>
  186. /// <param name="sender"></param>
  187. /// <param name="e"></param>
  188. private void PropertyConfig(object sender, RoutedEventArgs e)
  189. {
  190. HandyControl.Controls.Dialog.Show(new IconInfoDialog((IconInfo)((MenuItem)sender).Tag));
  191. }
  192. }
  193. }